[SYNCOPE-1315] Do not sort client-side if sort is done server-side
authorFrancesco Chicchiriccò <ilgrosso@apache.org>
Mon, 28 May 2018 13:16:55 +0000 (15:16 +0200)
committerFrancesco Chicchiriccò <ilgrosso@apache.org>
Mon, 28 May 2018 13:17:07 +0000 (15:17 +0200)
client/console/src/main/java/org/apache/syncope/client/console/panels/AccessTokenDirectoryPanel.java
client/console/src/main/java/org/apache/syncope/client/console/tasks/AnyPropagationTaskDirectoryPanel.java
client/console/src/main/java/org/apache/syncope/client/console/tasks/ExecutionsDirectoryPanel.java
client/console/src/main/java/org/apache/syncope/client/console/tasks/NotificationTaskDirectoryPanel.java
client/console/src/main/java/org/apache/syncope/client/console/tasks/PropagationTaskDirectoryPanel.java
client/console/src/main/java/org/apache/syncope/client/console/tasks/ProvisioningTaskDirectoryPanel.java
client/console/src/main/java/org/apache/syncope/client/console/tasks/SchedTaskDirectoryPanel.java
core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPATaskDAO.java
fit/core-reference/src/test/java/org/apache/syncope/fit/console/AbstractConsoleITCase.java
fit/core-reference/src/test/java/org/apache/syncope/fit/console/TopologyITCase.java

index 082b860..29924fc 100644 (file)
@@ -30,7 +30,6 @@ import org.apache.cxf.rs.security.jose.jws.JwsJwtCompactConsumer;
 import org.apache.syncope.client.console.SyncopeConsoleSession;
 import org.apache.syncope.client.console.commons.Constants;
 import org.apache.syncope.client.console.commons.DirectoryDataProvider;
-import org.apache.syncope.client.console.commons.SortableDataProviderComparator;
 import org.apache.syncope.client.console.pages.BasePage;
 import org.apache.syncope.client.console.panels.AccessTokenDirectoryPanel.AccessTokenDataProvider;
 import org.apache.syncope.client.console.rest.AccessTokenRestClient;
@@ -162,24 +161,20 @@ public class AccessTokenDirectoryPanel
 
         private static final long serialVersionUID = 6267494272884913376L;
 
-        private final SortableDataProviderComparator<AccessTokenTO> comparator;
-
         private final AccessTokenRestClient restClient = new AccessTokenRestClient();
 
         public AccessTokenDataProvider(final int paginatorRows) {
             super(paginatorRows);
 
             setSort("owner", SortOrder.ASCENDING);
-            this.comparator = new SortableDataProviderComparator<>(this);
         }
 
         @Override
         public Iterator<AccessTokenTO> iterator(final long first, final long count) {
             int page = ((int) first / paginatorRows);
-            List<AccessTokenTO> tasks = restClient.list((page < 0 ? 0 : page) + 1, paginatorRows, getSort());
-
-            Collections.sort(tasks, comparator);
-            return tasks.iterator();
+            return restClient.list(
+                    (page < 0 ? 0 : page) + 1, paginatorRows, getSort()).
+                    iterator();
         }
 
         @Override
index dbd2047..824c2b1 100644 (file)
@@ -18,9 +18,7 @@
  */
 package org.apache.syncope.client.console.tasks;
 
-import java.util.Collections;
 import java.util.Iterator;
-import java.util.List;
 import org.apache.syncope.client.console.panels.MultilevelPanel;
 import org.apache.syncope.client.console.wicket.markup.html.bootstrap.dialog.BaseModal;
 import org.apache.syncope.common.lib.to.PropagationTaskTO;
@@ -67,13 +65,10 @@ public abstract class AnyPropagationTaskDirectoryPanel extends PropagationTaskDi
 
         @Override
         public Iterator<PropagationTaskTO> iterator(final long first, final long count) {
-            final int page = ((int) first / paginatorRows);
-
-            final List<PropagationTaskTO> tasks = restClient.listPropagationTasks(
-                    anyTypeKind, entityKey, (page < 0 ? 0 : page) + 1, paginatorRows, getSort());
-
-            Collections.sort(tasks, getComparator());
-            return tasks.iterator();
+            int page = ((int) first / paginatorRows);
+            return restClient.listPropagationTasks(
+                    anyTypeKind, entityKey, (page < 0 ? 0 : page) + 1, paginatorRows, getSort()).
+                    iterator();
         }
     }
 }
index e264bff..345a1eb 100644 (file)
@@ -20,7 +20,6 @@ package org.apache.syncope.client.console.tasks;
 
 import java.util.ArrayList;
 import java.util.Collection;
-import java.util.Collections;
 import java.util.Iterator;
 import java.util.List;
 import org.apache.syncope.client.console.SyncopeConsoleSession;
@@ -187,10 +186,10 @@ public abstract class ExecutionsDirectoryPanel
 
         @Override
         public Iterator<ExecTO> iterator(final long first, final long count) {
-            final int page = ((int) first / paginatorRows);
-            List<ExecTO> list = restClient.listExecutions(taskKey, (page < 0 ? 0 : page) + 1, paginatorRows, getSort());
-            Collections.sort(list, comparator);
-            return list.iterator();
+            int page = ((int) first / paginatorRows);
+            return restClient.listExecutions(
+                    taskKey, (page < 0 ? 0 : page) + 1, paginatorRows, getSort()).
+                    iterator();
         }
 
         @Override
index a0bc61f..656b707 100644 (file)
@@ -20,7 +20,6 @@ package org.apache.syncope.client.console.tasks;
 
 import java.util.ArrayList;
 import java.util.Collection;
-import java.util.Collections;
 import java.util.Iterator;
 import java.util.List;
 import org.apache.commons.lang3.StringUtils;
@@ -223,13 +222,10 @@ public abstract class NotificationTaskDirectoryPanel
 
         @Override
         public Iterator<NotificationTaskTO> iterator(final long first, final long count) {
-            final int page = ((int) first / paginatorRows);
-
-            final List<NotificationTaskTO> tasks = restClient.listNotificationTasks(
-                    notification, anyTypeKind, entityKey, (page < 0 ? 0 : page) + 1, paginatorRows, getSort());
-
-            Collections.sort(tasks, getComparator());
-            return tasks.iterator();
+            int page = ((int) first / paginatorRows);
+            return restClient.listNotificationTasks(
+                    notification, anyTypeKind, entityKey, (page < 0 ? 0 : page) + 1, paginatorRows, getSort()).
+                    iterator();
         }
     }
 }
index ae30e66..5298b22 100644 (file)
@@ -20,7 +20,6 @@ package org.apache.syncope.client.console.tasks;
 
 import java.util.ArrayList;
 import java.util.Collection;
-import java.util.Collections;
 import java.util.Iterator;
 import java.util.List;
 import org.apache.commons.lang3.StringUtils;
@@ -216,13 +215,10 @@ public abstract class PropagationTaskDirectoryPanel
 
         @Override
         public Iterator<PropagationTaskTO> iterator(final long first, final long count) {
-            final int page = ((int) first / paginatorRows);
-
-            final List<PropagationTaskTO> tasks = restClient.listPropagationTasks(
-                    resource, (page < 0 ? 0 : page) + 1, paginatorRows, getSort());
-
-            Collections.sort(tasks, getComparator());
-            return tasks.iterator();
+            int page = ((int) first / paginatorRows);
+            return restClient.listPropagationTasks(
+                    resource, (page < 0 ? 0 : page) + 1, paginatorRows, getSort()).
+                    iterator();
         }
     }
 
index 504e767..0577433 100644 (file)
@@ -19,7 +19,6 @@
 package org.apache.syncope.client.console.tasks;
 
 import java.util.ArrayList;
-import java.util.Collections;
 import java.util.Iterator;
 import java.util.List;
 import org.apache.syncope.client.console.panels.MultilevelPanel;
@@ -185,13 +184,10 @@ public abstract class ProvisioningTaskDirectoryPanel<T extends ProvisioningTaskT
 
         @Override
         public Iterator<T> iterator(final long first, final long count) {
-            final int page = ((int) first / paginatorRows);
-
-            final List<T> tasks = restClient.list(
-                    resource, reference, (page < 0 ? 0 : page) + 1, paginatorRows, getSort());
-
-            Collections.sort(tasks, getComparator());
-            return tasks.iterator();
+            int page = ((int) first / paginatorRows);
+            return restClient.list(
+                    resource, reference, (page < 0 ? 0 : page) + 1, paginatorRows, getSort()).
+                    iterator();
         }
     }
 }
index bfc7eb6..ed2f7c2 100644 (file)
@@ -21,7 +21,6 @@ package org.apache.syncope.client.console.tasks;
 import java.io.Serializable;
 import java.util.ArrayList;
 import java.util.Collection;
-import java.util.Collections;
 import java.util.Iterator;
 import java.util.List;
 import org.apache.commons.lang3.SerializationUtils;
@@ -315,10 +314,9 @@ public abstract class SchedTaskDirectoryPanel<T extends SchedTaskTO>
         @Override
         public Iterator<T> iterator(final long first, final long count) {
             int page = ((int) first / paginatorRows);
-
-            List<T> tasks = restClient.list(reference, (page < 0 ? 0 : page) + 1, paginatorRows, getSort());
-            Collections.sort(tasks, getComparator());
-            return tasks.iterator();
+            return restClient.list(
+                    reference, (page < 0 ? 0 : page) + 1, paginatorRows, getSort()).
+                    iterator();
         }
     }
 }
index dd78ec3..fc9dbb0 100644 (file)
@@ -479,11 +479,11 @@ public class JPATaskDAO extends AbstractDAO<Task> implements TaskDAO {
                     : ((String) anyKey);
 
             @SuppressWarnings("unchecked")
-            T any = find(actualKey);
-            if (any == null) {
+            T task = find(actualKey);
+            if (task == null) {
                 LOG.error("Could not find task with id {}, even if returned by native query", actualKey);
-            } else if (!result.contains(any)) {
-                result.add(any);
+            } else if (!result.contains(task)) {
+                result.add(task);
             }
         }
 
index b7574e1..506b4a2 100644 (file)
@@ -89,6 +89,27 @@ public abstract class AbstractConsoleITCase {
                 });
     }
 
+    protected <V extends Serializable> Component findComponentByPropNotNull(
+            final String property, final String searchPath) {
+
+        Component component = TESTER.getComponentFromLastRenderedPage(searchPath);
+        return (component instanceof MarkupContainer ? MarkupContainer.class.cast(component) : component.getPage()).
+                visitChildren(ListItem.class, new IVisitor<ListItem<?>, Component>() {
+
+                    @Override
+                    public void component(final ListItem<?> object, final IVisit<Component> visit) {
+                        try {
+                            Method getter = PropertyResolver.getPropertyGetter(property, object.getModelObject());
+                            if (getter != null && getter.invoke(object.getModelObject()) != null) {
+                                visit.stop(object);
+                            }
+                        } catch (Exception e) {
+                            LOG.error("Error invoke method", e);
+                        }
+                    }
+                });
+    }
+
     protected Component findComponentById(final String searchPath, final String id) {
         Component component = TESTER.getComponentFromLastRenderedPage(searchPath);
         return (component instanceof MarkupContainer ? MarkupContainer.class.cast(component) : component.getPage()).
index 7a99aaf..81a0356 100644 (file)
@@ -369,9 +369,9 @@ public class TopologyITCase extends AbstractConsoleITCase {
         TESTER.executeAjaxEvent(component.getPageRelativePath() + ":res", Constants.ON_CLICK);
         TESTER.clickLink("body:toggle:container:content:togglePanelContainer:container:actions:propagation");
 
-        component = findComponentByProp("operation", "body:toggle:outerObjectsRepeater:1:outer:form:content:tasks:"
+        component = findComponentByPropNotNull("start", "body:toggle:outerObjectsRepeater:1:outer:form:content:tasks:"
                 + "firstLevelContainer:first:container:content:searchContainer:resultTable:tablePanel:groupForm:"
-                + "checkgroup:dataTable", ResourceOperation.CREATE);
+                + "checkgroup:dataTable");
 
         assertNotNull(component);
         TESTER.executeAjaxEvent(component.getPageRelativePath(), Constants.ON_CLICK);