syncope-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ilgro...@apache.org
Subject [2/2] syncope git commit: Polishing few methods for paginated results
Date Thu, 21 Sep 2017 12:08:58 GMT
Polishing few methods for paginated results


Project: http://git-wip-us.apache.org/repos/asf/syncope/repo
Commit: http://git-wip-us.apache.org/repos/asf/syncope/commit/29f9c5e3
Tree: http://git-wip-us.apache.org/repos/asf/syncope/tree/29f9c5e3
Diff: http://git-wip-us.apache.org/repos/asf/syncope/diff/29f9c5e3

Branch: refs/heads/2_0_X
Commit: 29f9c5e39350b2ec90e21577b2a4fcdc2c2fce76
Parents: b6419fb
Author: Francesco Chicchiriccò <ilgrosso@apache.org>
Authored: Thu Sep 21 14:01:44 2017 +0200
Committer: Francesco Chicchiriccò <ilgrosso@apache.org>
Committed: Thu Sep 21 14:08:50 2017 +0200

----------------------------------------------------------------------
 .../core/logic/AbstractExecutableLogic.java     |  6 ++--
 .../syncope/core/logic/AccessTokenLogic.java    | 13 ++++---
 .../apache/syncope/core/logic/ReportLogic.java  | 15 ++++----
 .../apache/syncope/core/logic/TaskLogic.java    | 36 ++++++++------------
 .../cxf/service/AbstractExecutableService.java  | 12 +++----
 .../cxf/service/AccessTokenServiceImpl.java     | 10 +++---
 .../core/rest/cxf/service/TaskServiceImpl.java  | 28 ++++++---------
 7 files changed, 50 insertions(+), 70 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/syncope/blob/29f9c5e3/core/logic/src/main/java/org/apache/syncope/core/logic/AbstractExecutableLogic.java
----------------------------------------------------------------------
diff --git a/core/logic/src/main/java/org/apache/syncope/core/logic/AbstractExecutableLogic.java
b/core/logic/src/main/java/org/apache/syncope/core/logic/AbstractExecutableLogic.java
index 8a7d677..d1b7cb3 100644
--- a/core/logic/src/main/java/org/apache/syncope/core/logic/AbstractExecutableLogic.java
+++ b/core/logic/src/main/java/org/apache/syncope/core/logic/AbstractExecutableLogic.java
@@ -20,6 +20,7 @@ package org.apache.syncope.core.logic;
 
 import java.util.Date;
 import java.util.List;
+import org.apache.commons.lang3.tuple.Pair;
 import org.apache.syncope.common.lib.AbstractBaseBean;
 import org.apache.syncope.common.lib.to.BulkActionResult;
 import org.apache.syncope.common.lib.to.ExecTO;
@@ -31,9 +32,8 @@ public abstract class AbstractExecutableLogic<T extends AbstractBaseBean>
extend
 
     public abstract ExecTO execute(String key, Date startAt, boolean dryRun);
 
-    public abstract int countExecutions(String key);
-
-    public abstract List<ExecTO> listExecutions(String key, int page, int size, List<OrderByClause>
orderByClauses);
+    public abstract Pair<Integer, List<ExecTO>> listExecutions(
+            String key, int page, int size, List<OrderByClause> orderByClauses);
 
     public abstract List<ExecTO> listRecentExecutions(int max);
 

http://git-wip-us.apache.org/repos/asf/syncope/blob/29f9c5e3/core/logic/src/main/java/org/apache/syncope/core/logic/AccessTokenLogic.java
----------------------------------------------------------------------
diff --git a/core/logic/src/main/java/org/apache/syncope/core/logic/AccessTokenLogic.java
b/core/logic/src/main/java/org/apache/syncope/core/logic/AccessTokenLogic.java
index f1a39c1..6389909 100644
--- a/core/logic/src/main/java/org/apache/syncope/core/logic/AccessTokenLogic.java
+++ b/core/logic/src/main/java/org/apache/syncope/core/logic/AccessTokenLogic.java
@@ -105,17 +105,14 @@ public class AccessTokenLogic extends AbstractTransactionalLogic<AccessTokenTO>
     }
 
     @PreAuthorize("hasRole('" + StandardEntitlement.ACCESS_TOKEN_LIST + "')")
-    public int count() {
-        return accessTokenDAO.count();
-    }
-
-    @PreAuthorize("hasRole('" + StandardEntitlement.ACCESS_TOKEN_LIST + "')")
-    public List<AccessTokenTO> list(
+    public Pair<Integer, List<AccessTokenTO>> list(
             final int page,
             final int size,
             final List<OrderByClause> orderByClauses) {
 
-        return CollectionUtils.collect(accessTokenDAO.findAll(page, size, orderByClauses),
+        Integer count = accessTokenDAO.count();
+
+        List<AccessTokenTO> result = CollectionUtils.collect(accessTokenDAO.findAll(page,
size, orderByClauses),
                 new Transformer<AccessToken, AccessTokenTO>() {
 
             @Override
@@ -123,6 +120,8 @@ public class AccessTokenLogic extends AbstractTransactionalLogic<AccessTokenTO>
                 return binder.getAccessTokenTO(input);
             }
         }, new ArrayList<AccessTokenTO>());
+
+        return Pair.of(count, result);
     }
 
     @PreAuthorize("hasRole('" + StandardEntitlement.ACCESS_TOKEN_DELETE + "')")

http://git-wip-us.apache.org/repos/asf/syncope/blob/29f9c5e3/core/logic/src/main/java/org/apache/syncope/core/logic/ReportLogic.java
----------------------------------------------------------------------
diff --git a/core/logic/src/main/java/org/apache/syncope/core/logic/ReportLogic.java b/core/logic/src/main/java/org/apache/syncope/core/logic/ReportLogic.java
index 5243277..fd9ce26 100644
--- a/core/logic/src/main/java/org/apache/syncope/core/logic/ReportLogic.java
+++ b/core/logic/src/main/java/org/apache/syncope/core/logic/ReportLogic.java
@@ -38,6 +38,7 @@ import org.apache.commons.collections4.CollectionUtils;
 import org.apache.commons.collections4.Transformer;
 import org.apache.commons.io.IOUtils;
 import org.apache.commons.lang3.ArrayUtils;
+import org.apache.commons.lang3.tuple.Pair;
 import org.apache.commons.lang3.tuple.Triple;
 import org.apache.syncope.common.lib.SyncopeClientException;
 import org.apache.syncope.common.lib.to.BulkActionResult;
@@ -300,13 +301,7 @@ public class ReportLogic extends AbstractExecutableLogic<ReportTO>
{
 
     @PreAuthorize("hasRole('" + StandardEntitlement.REPORT_READ + "')")
     @Override
-    public int countExecutions(final String key) {
-        return reportExecDAO.count(key);
-    }
-
-    @PreAuthorize("hasRole('" + StandardEntitlement.REPORT_READ + "')")
-    @Override
-    public List<ExecTO> listExecutions(
+    public Pair<Integer, List<ExecTO>> listExecutions(
             final String key, final int page, final int size, final List<OrderByClause>
orderByClauses) {
 
         Report report = reportDAO.find(key);
@@ -314,7 +309,9 @@ public class ReportLogic extends AbstractExecutableLogic<ReportTO>
{
             throw new NotFoundException("Report " + key);
         }
 
-        return CollectionUtils.collect(reportExecDAO.findAll(report, page, size, orderByClauses),
+        Integer count = reportExecDAO.count(key);
+
+        List<ExecTO> result = CollectionUtils.collect(reportExecDAO.findAll(report,
page, size, orderByClauses),
                 new Transformer<ReportExec, ExecTO>() {
 
             @Override
@@ -322,6 +319,8 @@ public class ReportLogic extends AbstractExecutableLogic<ReportTO>
{
                 return binder.getExecTO(reportExec);
             }
         }, new ArrayList<ExecTO>());
+
+        return Pair.of(count, result);
     }
 
     @PreAuthorize("hasRole('" + StandardEntitlement.REPORT_LIST + "')")

http://git-wip-us.apache.org/repos/asf/syncope/blob/29f9c5e3/core/logic/src/main/java/org/apache/syncope/core/logic/TaskLogic.java
----------------------------------------------------------------------
diff --git a/core/logic/src/main/java/org/apache/syncope/core/logic/TaskLogic.java b/core/logic/src/main/java/org/apache/syncope/core/logic/TaskLogic.java
index 06e38d2..9f7008f 100644
--- a/core/logic/src/main/java/org/apache/syncope/core/logic/TaskLogic.java
+++ b/core/logic/src/main/java/org/apache/syncope/core/logic/TaskLogic.java
@@ -26,6 +26,7 @@ import java.util.Map;
 import org.apache.commons.collections4.CollectionUtils;
 import org.apache.commons.collections4.Transformer;
 import org.apache.commons.lang3.ArrayUtils;
+import org.apache.commons.lang3.tuple.Pair;
 import org.apache.commons.lang3.tuple.Triple;
 import org.apache.syncope.common.lib.SyncopeClientException;
 import org.apache.syncope.common.lib.to.AbstractTaskTO;
@@ -146,20 +147,8 @@ public class TaskLogic extends AbstractExecutableLogic<AbstractTaskTO>
{
     }
 
     @PreAuthorize("hasRole('" + StandardEntitlement.TASK_LIST + "')")
-    public int count(
-            final TaskType type,
-            final String resource,
-            final String notification,
-            final AnyTypeKind anyTypeKind,
-            final String anyTypeKey) {
-
-        return taskDAO.count(
-                type, resourceDAO.find(resource), notificationDAO.find(notification), anyTypeKind,
anyTypeKey);
-    }
-
-    @PreAuthorize("hasRole('" + StandardEntitlement.TASK_LIST + "')")
     @SuppressWarnings("unchecked")
-    public <T extends AbstractTaskTO> List<T> list(
+    public <T extends AbstractTaskTO> Pair<Integer, List<T>> list(
             final TaskType type,
             final String resource,
             final String notification,
@@ -170,7 +159,10 @@ public class TaskLogic extends AbstractExecutableLogic<AbstractTaskTO>
{
             final List<OrderByClause> orderByClauses,
             final boolean details) {
 
-        return CollectionUtils.collect(taskDAO.findAll(
+        int count = taskDAO.count(
+                type, resourceDAO.find(resource), notificationDAO.find(notification), anyTypeKind,
entityKey);
+
+        List<T> result = CollectionUtils.collect(taskDAO.findAll(
                 type, resourceDAO.find(resource), notificationDAO.find(notification), anyTypeKind,
entityKey,
                 page, size, orderByClauses), new Transformer<Task, T>() {
 
@@ -179,6 +171,8 @@ public class TaskLogic extends AbstractExecutableLogic<AbstractTaskTO>
{
                 return (T) binder.getTaskTO(task, taskUtilsFactory.getInstance(type), details);
             }
         }, new ArrayList<T>());
+
+        return Pair.of(count, result);
     }
 
     @PreAuthorize("hasRole('" + StandardEntitlement.TASK_READ + "')")
@@ -283,13 +277,7 @@ public class TaskLogic extends AbstractExecutableLogic<AbstractTaskTO>
{
 
     @PreAuthorize("hasRole('" + StandardEntitlement.TASK_READ + "')")
     @Override
-    public int countExecutions(final String key) {
-        return taskExecDAO.count(key);
-    }
-
-    @PreAuthorize("hasRole('" + StandardEntitlement.TASK_READ + "')")
-    @Override
-    public List<ExecTO> listExecutions(
+    public Pair<Integer, List<ExecTO>> listExecutions(
             final String key, final int page, final int size, final List<OrderByClause>
orderByClauses) {
 
         Task task = taskDAO.find(key);
@@ -297,7 +285,9 @@ public class TaskLogic extends AbstractExecutableLogic<AbstractTaskTO>
{
             throw new NotFoundException("Task " + key);
         }
 
-        return CollectionUtils.collect(taskExecDAO.findAll(task, page, size, orderByClauses),
+        Integer count = taskExecDAO.count(key);
+
+        List<ExecTO> result = CollectionUtils.collect(taskExecDAO.findAll(task, page,
size, orderByClauses),
                 new Transformer<TaskExec, ExecTO>() {
 
             @Override
@@ -305,6 +295,8 @@ public class TaskLogic extends AbstractExecutableLogic<AbstractTaskTO>
{
                 return binder.getExecTO(taskExec);
             }
         }, new ArrayList<ExecTO>());
+
+        return Pair.of(count, result);
     }
 
     @PreAuthorize("hasRole('" + StandardEntitlement.TASK_LIST + "')")

http://git-wip-us.apache.org/repos/asf/syncope/blob/29f9c5e3/core/rest-cxf/src/main/java/org/apache/syncope/core/rest/cxf/service/AbstractExecutableService.java
----------------------------------------------------------------------
diff --git a/core/rest-cxf/src/main/java/org/apache/syncope/core/rest/cxf/service/AbstractExecutableService.java
b/core/rest-cxf/src/main/java/org/apache/syncope/core/rest/cxf/service/AbstractExecutableService.java
index c6a1917..aadbaf3 100644
--- a/core/rest-cxf/src/main/java/org/apache/syncope/core/rest/cxf/service/AbstractExecutableService.java
+++ b/core/rest-cxf/src/main/java/org/apache/syncope/core/rest/cxf/service/AbstractExecutableService.java
@@ -19,6 +19,7 @@
 package org.apache.syncope.core.rest.cxf.service;
 
 import java.util.List;
+import org.apache.commons.lang3.tuple.Pair;
 import org.apache.syncope.common.lib.to.BulkActionResult;
 import org.apache.syncope.common.lib.to.ExecTO;
 import org.apache.syncope.common.lib.to.JobTO;
@@ -36,15 +37,12 @@ public abstract class AbstractExecutableService extends AbstractServiceImpl
impl
 
     @Override
     public PagedResult<ExecTO> listExecutions(final ExecQuery query) {
-        return buildPagedResult(
-                getExecutableLogic().listExecutions(
-                        query.getKey(),
-                        query.getPage(),
-                        query.getSize(),
-                        getOrderByClauses(query.getOrderBy())),
+        Pair<Integer, List<ExecTO>> result = getExecutableLogic().listExecutions(
+                query.getKey(),
                 query.getPage(),
                 query.getSize(),
-                getExecutableLogic().countExecutions(query.getKey()));
+                getOrderByClauses(query.getOrderBy()));
+        return buildPagedResult(result.getRight(), query.getPage(), query.getSize(), result.getLeft());
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/syncope/blob/29f9c5e3/core/rest-cxf/src/main/java/org/apache/syncope/core/rest/cxf/service/AccessTokenServiceImpl.java
----------------------------------------------------------------------
diff --git a/core/rest-cxf/src/main/java/org/apache/syncope/core/rest/cxf/service/AccessTokenServiceImpl.java
b/core/rest-cxf/src/main/java/org/apache/syncope/core/rest/cxf/service/AccessTokenServiceImpl.java
index 54db9cc..2b09324 100644
--- a/core/rest-cxf/src/main/java/org/apache/syncope/core/rest/cxf/service/AccessTokenServiceImpl.java
+++ b/core/rest-cxf/src/main/java/org/apache/syncope/core/rest/cxf/service/AccessTokenServiceImpl.java
@@ -19,6 +19,7 @@
 package org.apache.syncope.core.rest.cxf.service;
 
 import java.util.Date;
+import java.util.List;
 import javax.ws.rs.core.Response;
 import org.apache.commons.lang3.time.DateFormatUtils;
 import org.apache.commons.lang3.tuple.Pair;
@@ -64,14 +65,11 @@ public class AccessTokenServiceImpl extends AbstractServiceImpl implements
Acces
 
     @Override
     public PagedResult<AccessTokenTO> list(final AccessTokenQuery query) {
-        return buildPagedResult(
-                logic.list(
-                        query.getPage(),
-                        query.getSize(),
-                        getOrderByClauses(query.getOrderBy())),
+        Pair<Integer, List<AccessTokenTO>> result = logic.list(
                 query.getPage(),
                 query.getSize(),
-                logic.count());
+                getOrderByClauses(query.getOrderBy()));
+        return buildPagedResult(result.getRight(), query.getPage(), query.getSize(), result.getLeft());
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/syncope/blob/29f9c5e3/core/rest-cxf/src/main/java/org/apache/syncope/core/rest/cxf/service/TaskServiceImpl.java
----------------------------------------------------------------------
diff --git a/core/rest-cxf/src/main/java/org/apache/syncope/core/rest/cxf/service/TaskServiceImpl.java
b/core/rest-cxf/src/main/java/org/apache/syncope/core/rest/cxf/service/TaskServiceImpl.java
index f19aa87..1d1b612 100644
--- a/core/rest-cxf/src/main/java/org/apache/syncope/core/rest/cxf/service/TaskServiceImpl.java
+++ b/core/rest-cxf/src/main/java/org/apache/syncope/core/rest/cxf/service/TaskServiceImpl.java
@@ -19,8 +19,10 @@
 package org.apache.syncope.core.rest.cxf.service;
 
 import java.net.URI;
+import java.util.List;
 import javax.ws.rs.BadRequestException;
 import javax.ws.rs.core.Response;
+import org.apache.commons.lang3.tuple.Pair;
 import org.apache.syncope.common.lib.to.AbstractTaskTO;
 import org.apache.syncope.common.lib.to.BulkAction;
 import org.apache.syncope.common.lib.to.BulkActionResult;
@@ -68,25 +70,17 @@ public class TaskServiceImpl extends AbstractExecutableService implements
TaskSe
     @SuppressWarnings("unchecked")
     @Override
     public <T extends AbstractTaskTO> PagedResult<T> list(final TaskQuery query)
{
-        return (PagedResult<T>) buildPagedResult(
-                logic.list(
-                        query.getType(),
-                        query.getResource(),
-                        query.getNotification(),
-                        query.getAnyTypeKind(),
-                        query.getEntityKey(),
-                        query.getPage(),
-                        query.getSize(),
-                        getOrderByClauses(query.getOrderBy()),
-                        query.getDetails()),
+        Pair<Integer, List<T>> result = logic.list(
+                query.getType(),
+                query.getResource(),
+                query.getNotification(),
+                query.getAnyTypeKind(),
+                query.getEntityKey(),
                 query.getPage(),
                 query.getSize(),
-                logic.count(
-                        query.getType(),
-                        query.getResource(),
-                        query.getNotification(),
-                        query.getAnyTypeKind(),
-                        query.getEntityKey()));
+                getOrderByClauses(query.getOrderBy()),
+                query.getDetails());
+        return buildPagedResult(result.getRight(), query.getPage(), query.getSize(), result.getLeft());
     }
 
     @Override


Mime
View raw message