You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nifi.apache.org by bb...@apache.org on 2019/09/13 15:21:55 UTC
[nifi] branch master updated: NIFI-6024: When fetching names of
buckets and flows for registry, sort them alphanumerically
This is an automated email from the ASF dual-hosted git repository.
bbende pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nifi.git
The following commit(s) were added to refs/heads/master by this push:
new 7623e6f NIFI-6024: When fetching names of buckets and flows for registry, sort them alphanumerically
7623e6f is described below
commit 7623e6f5a1bd135ab58bbb9fb4b25686931d8fbf
Author: Mark Payne <ma...@hotmail.com>
AuthorDate: Fri Sep 6 16:31:46 2019 -0400
NIFI-6024: When fetching names of buckets and flows for registry, sort them alphanumerically
This closes #3709.
Signed-off-by: Bryan Bende <bb...@apache.org>
---
.../java/org/apache/nifi/web/api/FlowResource.java | 42 ++++++++++++++++++++--
1 file changed, 40 insertions(+), 2 deletions(-)
diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/FlowResource.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/FlowResource.java
index 6f28d44..d67e455 100644
--- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/FlowResource.java
+++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/FlowResource.java
@@ -129,7 +129,9 @@ import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
+import java.text.Collator;
import java.util.ArrayList;
+import java.util.Comparator;
import java.util.Date;
import java.util.EnumSet;
import java.util.HashMap;
@@ -137,6 +139,8 @@ import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
+import java.util.SortedSet;
+import java.util.TreeSet;
import java.util.function.Predicate;
import java.util.function.Supplier;
import java.util.stream.Collectors;
@@ -1430,13 +1434,30 @@ public class FlowResource extends ApplicationResource {
authorizeFlow();
final Set<BucketEntity> buckets = serviceFacade.getBucketsForUser(id, NiFiUserUtils.getNiFiUser());
+ final SortedSet<BucketEntity> sortedBuckets = sortBuckets(buckets);
final BucketsEntity bucketsEntity = new BucketsEntity();
- bucketsEntity.setBuckets(buckets);
+ bucketsEntity.setBuckets(sortedBuckets);
return generateOkResponse(bucketsEntity).build();
}
+ private SortedSet<BucketEntity> sortBuckets(final Set<BucketEntity> buckets) {
+ final SortedSet<BucketEntity> sortedBuckets = new TreeSet<>(new Comparator<BucketEntity>() {
+ @Override
+ public int compare(final BucketEntity entity1, final BucketEntity entity2) {
+ return Collator.getInstance().compare(getBucketName(entity1), getBucketName(entity2));
+ }
+ });
+
+ sortedBuckets.addAll(buckets);
+ return sortedBuckets;
+ }
+
+ private String getBucketName(final BucketEntity entity) {
+ return entity.getBucket() == null ? null : entity.getBucket().getName();
+ }
+
@GET
@Consumes(MediaType.WILDCARD)
@Produces(MediaType.APPLICATION_JSON)
@@ -1466,13 +1487,30 @@ public class FlowResource extends ApplicationResource {
authorizeFlow();
final Set<VersionedFlowEntity> versionedFlows = serviceFacade.getFlowsForUser(registryId, bucketId, NiFiUserUtils.getNiFiUser());
+ final SortedSet<VersionedFlowEntity> sortedFlows = sortFlows(versionedFlows);
final VersionedFlowsEntity versionedFlowsEntity = new VersionedFlowsEntity();
- versionedFlowsEntity.setVersionedFlows(versionedFlows);
+ versionedFlowsEntity.setVersionedFlows(sortedFlows);
return generateOkResponse(versionedFlowsEntity).build();
}
+ private SortedSet<VersionedFlowEntity> sortFlows(final Set<VersionedFlowEntity> versionedFlows) {
+ final SortedSet<VersionedFlowEntity> sortedFlows = new TreeSet<>(new Comparator<VersionedFlowEntity>() {
+ @Override
+ public int compare(final VersionedFlowEntity entity1, final VersionedFlowEntity entity2) {
+ return Collator.getInstance().compare(getFlowName(entity1), getFlowName(entity2));
+ }
+ });
+
+ sortedFlows.addAll(versionedFlows);
+ return sortedFlows;
+ }
+
+ private String getFlowName(final VersionedFlowEntity flowEntity) {
+ return flowEntity.getVersionedFlow() == null ? "" : flowEntity.getVersionedFlow().getFlowName();
+ }
+
@GET
@Consumes(MediaType.WILDCARD)
@Produces(MediaType.APPLICATION_JSON)