[SYNCOPE-1250] splits filtering (performed on schema set) and sorting (performed...
authorfmartelli <fabio.martelli@gmail.com>
Wed, 13 Dec 2017 09:24:06 +0000 (10:24 +0100)
committerfmartelli <fabio.martelli@gmail.com>
Wed, 13 Dec 2017 09:28:55 +0000 (10:28 +0100)
client/console/src/main/java/org/apache/syncope/client/console/wizards/any/AbstractAttrs.java

index 2e77c8c..bae86f1 100644 (file)
@@ -22,7 +22,6 @@ import java.io.Serializable;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Comparator;
-import java.util.HashMap;
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
@@ -161,27 +160,11 @@ public abstract class AbstractAttrs<S extends AbstractSchemaTO> extends WizardSt
             // 1. remove attributes not selected for display
             allSchemas.removeAll(allSchemas.stream().
                     filter(schemaTO -> !whichAttrs.contains(schemaTO.getKey())).collect(Collectors.toSet()));
-
-            // 2. sort remainig attributes according to configuration, e.g. attrLayout
-            final Map<String, Integer> attrLayoutMap = new HashMap<>(whichAttrs.size());
-            for (int i = 0; i < whichAttrs.size(); i++) {
-                attrLayoutMap.put(whichAttrs.get(i), i);
-            }
-            Collections.sort(allSchemas, (schema1, schema2) -> {
-                int value = 0;
-
-                if (attrLayoutMap.get(schema1.getKey()) > attrLayoutMap.get(schema2.getKey())) {
-                    value = 1;
-                } else if (attrLayoutMap.get(schema1.getKey()) < attrLayoutMap.get(schema2.getKey())) {
-                    value = -1;
-                }
-
-                return value;
-            });
-        }
+        
         allSchemas.forEach(schemaTO -> {
             scs.put(schemaTO.getKey(), schemaTO);
-        });
+            });
+        }
     }
 
     @Override
@@ -225,7 +208,7 @@ public abstract class AbstractAttrs<S extends AbstractSchemaTO> extends WizardSt
         return null;
     }
 
-    protected static class AttrComparator implements Comparator<AttrTO>, Serializable {
+    protected class AttrComparator implements Comparator<AttrTO>, Serializable {
 
         private static final long serialVersionUID = -5105030477767941060L;
 
@@ -236,6 +219,17 @@ public abstract class AbstractAttrs<S extends AbstractSchemaTO> extends WizardSt
             }
             if (right == null || StringUtils.isEmpty(right.getSchema())) {
                 return 1;
+            } else if (AbstractAttrs.this.reoderSchemas()) {
+                int leftIndex = AbstractAttrs.this.whichAttrs.indexOf(left.getSchema());
+                int rightIndex = AbstractAttrs.this.whichAttrs.indexOf(right.getSchema());
+
+                if (leftIndex > rightIndex) {
+                    return 1;
+                } else if (leftIndex < rightIndex) {
+                    return -1;
+                } else {
+                    return 0;
+                }
             } else {
                 return left.getSchema().compareTo(right.getSchema());
             }