You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@syncope.apache.org by md...@apache.org on 2020/04/20 18:17:29 UTC

[syncope] branch 2_1_X updated: [SYNCOPE-1521] get visible realms

This is an automated email from the ASF dual-hosted git repository.

mdisabatino pushed a commit to branch 2_1_X
in repository https://gitbox.apache.org/repos/asf/syncope.git


The following commit(s) were added to refs/heads/2_1_X by this push:
     new bbc2375  [SYNCOPE-1521] get visible realms
bbc2375 is described below

commit bbc237592638ca22b94fc0cb3b2a345bcc57ff43
Author: Marco Di Sabatino Di Diodoro <ma...@tirasa.net>
AuthorDate: Mon Apr 20 20:17:03 2020 +0200

    [SYNCOPE-1521] get visible realms
---
 .../syncope/client/console/SyncopeConsoleSession.java |  8 ++++----
 .../syncope/client/console/commons/RealmsUtils.java   | 19 +++++++++++++------
 .../client/console/panels/RealmChoicePanel.java       |  2 +-
 3 files changed, 18 insertions(+), 11 deletions(-)

diff --git a/client/console/src/main/java/org/apache/syncope/client/console/SyncopeConsoleSession.java b/client/console/src/main/java/org/apache/syncope/client/console/SyncopeConsoleSession.java
index 9c9bdd7..ba96490 100644
--- a/client/console/src/main/java/org/apache/syncope/client/console/SyncopeConsoleSession.java
+++ b/client/console/src/main/java/org/apache/syncope/client/console/SyncopeConsoleSession.java
@@ -283,15 +283,15 @@ public class SyncopeConsoleSession extends AuthenticatedWebSession {
         return auth.values().stream().flatMap(Set::stream).distinct().sorted().collect(Collectors.toList());
     }
 
-    public Set<String> getVisibleRealms() {
+    public List<String> getVisibleRealms() {
         Set<String> roots = auth.get(StandardEntitlement.REALM_LIST);
         return roots.isEmpty()
-                ? Collections.emptySet()
-                : roots.stream().sorted().collect(Collectors.toSet());
+                ? Collections.emptyList()
+                : roots.stream().sorted().collect(Collectors.toList());
     }
 
     public Optional<String> getRootRealm() {
-        Set<String> roots = getVisibleRealms();
+        List<String> roots = getVisibleRealms();
         if (roots.isEmpty()) {
             return Optional.empty();
         }
diff --git a/client/console/src/main/java/org/apache/syncope/client/console/commons/RealmsUtils.java b/client/console/src/main/java/org/apache/syncope/client/console/commons/RealmsUtils.java
index 64b091f..7a8f157 100644
--- a/client/console/src/main/java/org/apache/syncope/client/console/commons/RealmsUtils.java
+++ b/client/console/src/main/java/org/apache/syncope/client/console/commons/RealmsUtils.java
@@ -18,6 +18,7 @@
  */
 package org.apache.syncope.client.console.commons;
 
+import java.util.List;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.syncope.client.console.SyncopeConsoleSession;
 import org.apache.syncope.client.console.rest.RealmRestClient;
@@ -33,12 +34,18 @@ public final class RealmsUtils {
     }
 
     public static boolean isSearchEnabled() {
-        return new RealmRestClient().search(
-                new RealmQuery.Builder().keyword(
-                        SyncopeConsoleSession.get().getAuthRealms().contains(SyncopeConstants.ROOT_REALM)
-                        ? SyncopeConstants.ROOT_REALM
-                        : SyncopeConsoleSession.get().getAuthRealms().get(0)).build()).
-                getTotalCount() > REALMS_VIEW_SIZE;
+        return isSearchEnabled(SyncopeConsoleSession.get().getAuthRealms());
+    }
+
+    public static boolean isSearchEnabled(final List<String> realms) {
+        return realms.isEmpty()
+                ? false
+                : new RealmRestClient().search(
+                        new RealmQuery.Builder().keyword(
+                                realms.contains(SyncopeConstants.ROOT_REALM)
+                                ? SyncopeConstants.ROOT_REALM
+                                : realms.get(0)).build()).
+                        getTotalCount() > REALMS_VIEW_SIZE;
     }
 
     public static boolean checkInput(final String input) {
diff --git a/client/console/src/main/java/org/apache/syncope/client/console/panels/RealmChoicePanel.java b/client/console/src/main/java/org/apache/syncope/client/console/panels/RealmChoicePanel.java
index 5d38105..807d226 100644
--- a/client/console/src/main/java/org/apache/syncope/client/console/panels/RealmChoicePanel.java
+++ b/client/console/src/main/java/org/apache/syncope/client/console/panels/RealmChoicePanel.java
@@ -102,7 +102,7 @@ public class RealmChoicePanel extends Panel {
         this.pageRef = pageRef;
         availableRealms = SyncopeConsoleSession.get().getVisibleRealms();
         tree = new HashMap<>();
-        isSearchEnabled = RealmsUtils.isSearchEnabled();
+        isSearchEnabled = RealmsUtils.isSearchEnabled(SyncopeConsoleSession.get().getVisibleRealms());
 
         realmTree = new LoadableDetachableModel<List<Pair<String, RealmTO>>>() {