From 902cbfab3502db1337b34c61cfa9140181c16341 Mon Sep 17 00:00:00 2001 From: Jingyi Gao Date: Thu, 5 Oct 2023 14:13:56 +1100 Subject: [PATCH 1/3] return null instead of [] --- .../uid2/admin/vertx/service/SharingService.java | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/uid2/admin/vertx/service/SharingService.java b/src/main/java/com/uid2/admin/vertx/service/SharingService.java index 019402aa..4f62e87e 100644 --- a/src/main/java/com/uid2/admin/vertx/service/SharingService.java +++ b/src/main/java/com/uid2/admin/vertx/service/SharingService.java @@ -232,13 +232,8 @@ private void handleListAllowedSites(RoutingContext rc) { return; } - JsonArray listedSites = new JsonArray(); - Set allowedSites = keyset.getAllowedSites(); - if (allowedSites != null) { - allowedSites.stream().sorted().forEach((listedSiteId) -> listedSites.add(listedSiteId)); - } JsonObject jo = new JsonObject(); - jo.put("allowed_sites", listedSites); + jo.put("allowed_sites", keyset.getAllowedSites()); jo.put("allowed_types", keyset.getAllowedTypes()); jo.put("hash", keyset.hashCode()); @@ -252,15 +247,10 @@ private void handleListAllAllowedSites(RoutingContext rc) { JsonArray ja = new JsonArray(); Map collection = this.keysetProvider.getSnapshot().getAllKeysets(); for (Map.Entry keyset : collection.entrySet()) { - JsonArray listedSites = new JsonArray(); - Set allowedSites = keyset.getValue().getAllowedSites(); - if (allowedSites != null) { - allowedSites.stream().sorted().forEach((listedSiteId) -> listedSites.add(listedSiteId)); - } JsonObject jo = new JsonObject(); jo.put("keyset_id", keyset.getValue().getKeysetId()); jo.put("site_id", keyset.getValue().getSiteId()); - jo.put("allowed_sites", listedSites); + jo.put("allowed_sites", keyset.getValue().getAllowedSites()); jo.put("allowed_types", keyset.getValue().getAllowedTypes()); jo.put("hash", keyset.getValue().hashCode()); ja.add(jo); From 8ffab997fa203cddb9f440469ef2ded76283a9d3 Mon Sep 17 00:00:00 2001 From: Jingyi Gao Date: Thu, 5 Oct 2023 14:39:44 +1100 Subject: [PATCH 2/3] Add sorting --- .../java/com/uid2/admin/vertx/service/SharingService.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/uid2/admin/vertx/service/SharingService.java b/src/main/java/com/uid2/admin/vertx/service/SharingService.java index 4f62e87e..117fa5b4 100644 --- a/src/main/java/com/uid2/admin/vertx/service/SharingService.java +++ b/src/main/java/com/uid2/admin/vertx/service/SharingService.java @@ -233,7 +233,8 @@ private void handleListAllowedSites(RoutingContext rc) { } JsonObject jo = new JsonObject(); - jo.put("allowed_sites", keyset.getAllowedSites()); + Set allowedSites = keyset.getAllowedSites(); + jo.put("allowed_sites", allowedSites != null ? allowedSites.stream().sorted() : null); jo.put("allowed_types", keyset.getAllowedTypes()); jo.put("hash", keyset.hashCode()); @@ -250,7 +251,8 @@ private void handleListAllAllowedSites(RoutingContext rc) { JsonObject jo = new JsonObject(); jo.put("keyset_id", keyset.getValue().getKeysetId()); jo.put("site_id", keyset.getValue().getSiteId()); - jo.put("allowed_sites", keyset.getValue().getAllowedSites()); + Set allowedSites = keyset.getValue().getAllowedSites(); + jo.put("allowed_sites", allowedSites != null ? allowedSites.stream().sorted() : null); jo.put("allowed_types", keyset.getValue().getAllowedTypes()); jo.put("hash", keyset.getValue().hashCode()); ja.add(jo); From 621343b5f8f1bc949dc59c78a4e6b86e9d15efd1 Mon Sep 17 00:00:00 2001 From: Jingyi Gao Date: Thu, 5 Oct 2023 15:09:10 +1100 Subject: [PATCH 3/3] Fix sort --- .../java/com/uid2/admin/vertx/service/SharingService.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/uid2/admin/vertx/service/SharingService.java b/src/main/java/com/uid2/admin/vertx/service/SharingService.java index 117fa5b4..18f5a0c0 100644 --- a/src/main/java/com/uid2/admin/vertx/service/SharingService.java +++ b/src/main/java/com/uid2/admin/vertx/service/SharingService.java @@ -234,7 +234,7 @@ private void handleListAllowedSites(RoutingContext rc) { JsonObject jo = new JsonObject(); Set allowedSites = keyset.getAllowedSites(); - jo.put("allowed_sites", allowedSites != null ? allowedSites.stream().sorted() : null); + jo.put("allowed_sites", allowedSites != null ? allowedSites.stream().sorted().toArray() : null); jo.put("allowed_types", keyset.getAllowedTypes()); jo.put("hash", keyset.hashCode()); @@ -252,7 +252,7 @@ private void handleListAllAllowedSites(RoutingContext rc) { jo.put("keyset_id", keyset.getValue().getKeysetId()); jo.put("site_id", keyset.getValue().getSiteId()); Set allowedSites = keyset.getValue().getAllowedSites(); - jo.put("allowed_sites", allowedSites != null ? allowedSites.stream().sorted() : null); + jo.put("allowed_sites", allowedSites != null ? allowedSites.stream().sorted().toArray() : null); jo.put("allowed_types", keyset.getValue().getAllowedTypes()); jo.put("hash", keyset.getValue().hashCode()); ja.add(jo);