syncope-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ilgro...@apache.org
Subject syncope git commit: [SYNCOPE-741] Implementing paged list for task executions
Date Thu, 10 Dec 2015 16:35:58 GMT
Repository: syncope
Updated Branches:
  refs/heads/1_2_X b4812b218 -> 7c84a5c03


[SYNCOPE-741] Implementing paged list for task executions


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

Branch: refs/heads/1_2_X
Commit: 7c84a5c031129bb58288272337b0a6a0f4ff1a28
Parents: b4812b2
Author: Francesco Chicchiriccò <ilgrosso@apache.org>
Authored: Thu Dec 10 17:35:51 2015 +0100
Committer: Francesco Chicchiriccò <ilgrosso@apache.org>
Committed: Thu Dec 10 17:35:51 2015 +0100

----------------------------------------------------------------------
 .../syncope/common/services/TaskService.java    |  6 +--
 .../syncope/console/pages/TaskModalPage.java    | 31 +++-----------
 .../syncope/console/rest/TaskRestClient.java    |  8 ++--
 .../core/persistence/dao/TaskExecDAO.java       |  4 ++
 .../persistence/dao/impl/TaskExecDAOImpl.java   | 27 ++++++++++++
 .../core/rest/controller/TaskController.java    | 10 +++--
 .../syncope/core/services/TaskServiceImpl.java  |  6 +--
 .../syncope/core/rest/TaskTestITCase.java       | 44 +++++++++++++-------
 8 files changed, 82 insertions(+), 54 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/syncope/blob/7c84a5c0/common/src/main/java/org/apache/syncope/common/services/TaskService.java
----------------------------------------------------------------------
diff --git a/common/src/main/java/org/apache/syncope/common/services/TaskService.java b/common/src/main/java/org/apache/syncope/common/services/TaskService.java
index 0deba68..6963b62 100644
--- a/common/src/main/java/org/apache/syncope/common/services/TaskService.java
+++ b/common/src/main/java/org/apache/syncope/common/services/TaskService.java
@@ -181,10 +181,10 @@ public interface TaskService extends JAXRSService {
     @GET
     @Path("{taskId}/executions")
     @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
-    PagedResult<TaskExecTO> listEexecutions(
+    PagedResult<TaskExecTO> listExecutions(
+            @NotNull @PathParam("taskId") Long taskId,
             @NotNull @Min(1) @QueryParam(PARAM_PAGE) @DefaultValue(DEFAULT_PARAM_PAGE) Integer
page,
-            @NotNull @Min(1) @QueryParam(PARAM_SIZE) @DefaultValue(DEFAULT_PARAM_SIZE) Integer
size,
-            @NotNull @PathParam("taskId") Long taskId);
+            @NotNull @Min(1) @QueryParam(PARAM_SIZE) @DefaultValue(DEFAULT_PARAM_SIZE) Integer
size);
 
     /**
      * Creates a new task.

http://git-wip-us.apache.org/repos/asf/syncope/blob/7c84a5c0/console/src/main/java/org/apache/syncope/console/pages/TaskModalPage.java
----------------------------------------------------------------------
diff --git a/console/src/main/java/org/apache/syncope/console/pages/TaskModalPage.java b/console/src/main/java/org/apache/syncope/console/pages/TaskModalPage.java
index aa4326e..e9f5c5a 100644
--- a/console/src/main/java/org/apache/syncope/console/pages/TaskModalPage.java
+++ b/console/src/main/java/org/apache/syncope/console/pages/TaskModalPage.java
@@ -22,10 +22,6 @@ import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Iterator;
 import java.util.List;
-import org.apache.syncope.common.to.NotificationTaskTO;
-import org.apache.syncope.common.to.PropagationTaskTO;
-import org.apache.syncope.common.to.SchedTaskTO;
-import org.apache.syncope.common.to.SyncTaskTO;
 import org.apache.syncope.common.to.TaskExecTO;
 import org.apache.syncope.common.to.AbstractTaskTO;
 import org.apache.syncope.common.SyncopeClientException;
@@ -173,8 +169,8 @@ public abstract class TaskModalPage extends BaseModalPage {
                     @Override
                     public void onClick(final AjaxRequestTarget target) {
                         if (target != null) {
-                            final AjaxFallbackDefaultDataTable<TaskExecTO, String>
currentTable
-                                    = new AjaxFallbackDefaultDataTable<TaskExecTO, String>("executionsTable",
columns,
+                            final AjaxFallbackDefaultDataTable<TaskExecTO, String>
currentTable =
+                                    new AjaxFallbackDefaultDataTable<TaskExecTO, String>("executionsTable",
columns,
                                             new TaskExecutionsProvider(taskTO.getId(), paginatorRows),
                                             paginatorRows);
                             currentTable.setOutputMarkupId(true);
@@ -188,8 +184,8 @@ public abstract class TaskModalPage extends BaseModalPage {
             }
         });
 
-        final AjaxFallbackDefaultDataTable<TaskExecTO, String> table
-                = new AjaxFallbackDefaultDataTable<TaskExecTO, String>("executionsTable",
columns,
+        final AjaxFallbackDefaultDataTable<TaskExecTO, String> table =
+                new AjaxFallbackDefaultDataTable<TaskExecTO, String>("executionsTable",
columns,
                         new TaskExecutionsProvider(taskTO.getId(), paginatorRows), paginatorRows);
 
         executions.add(table);
@@ -217,8 +213,7 @@ public abstract class TaskModalPage extends BaseModalPage {
         public Iterator<TaskExecTO> iterator(final long first, final long count) {
             final int page = ((int) first / paginatorRows);
 
-            final List<TaskExecTO> list = taskRestClient.listExecutions(
-                    (page < 0 ? 0 : page) + 1, paginatorRows, taskId);
+            List<TaskExecTO> list = taskRestClient.listExecutions(taskId, (page <
0 ? 0 : page) + 1, paginatorRows);
 
             Collections.sort(list, comparator);
 
@@ -244,20 +239,4 @@ public abstract class TaskModalPage extends BaseModalPage {
             };
         }
     }
-
-    private AbstractTaskTO getCurrentTaskExecution(final AbstractTaskTO taskTO) {
-        final AbstractTaskTO currentTask = taskTO.getId() == 0
-                ? taskTO
-                : taskTO instanceof PropagationTaskTO
-                        ? taskRestClient.readPropagationTask(taskTO.getId())
-                        : taskTO instanceof NotificationTaskTO
-                                ? taskRestClient.readNotificationTask(taskTO.getId())
-                                : taskTO instanceof SyncTaskTO
-                                        ? taskRestClient.readSchedTask(SyncTaskTO.class,
taskTO.getId())
-                                        : taskRestClient.readSchedTask(SchedTaskTO.class,
taskTO.getId());
-
-        taskTO.getExecutions().clear();
-        taskTO.getExecutions().addAll(currentTask.getExecutions());
-        return taskTO;
-    }
 }

http://git-wip-us.apache.org/repos/asf/syncope/blob/7c84a5c0/console/src/main/java/org/apache/syncope/console/rest/TaskRestClient.java
----------------------------------------------------------------------
diff --git a/console/src/main/java/org/apache/syncope/console/rest/TaskRestClient.java b/console/src/main/java/org/apache/syncope/console/rest/TaskRestClient.java
index b34cc95..c8995d5 100644
--- a/console/src/main/java/org/apache/syncope/console/rest/TaskRestClient.java
+++ b/console/src/main/java/org/apache/syncope/console/rest/TaskRestClient.java
@@ -96,9 +96,9 @@ public class TaskRestClient extends JobRestClient implements ExecutionRestClient
     public int count(final String kind) {
         return getService(TaskService.class).list(TaskType.fromString(kind), 1, 1).getTotalCount();
     }
-    
+
     public int countExecutions(final Long taskId) {
-        return getService(TaskService.class).listEexecutions(1, 1, taskId).getTotalCount();
+        return getService(TaskService.class).listExecutions(taskId, 1, 1).getTotalCount();
     }
 
     @SuppressWarnings("unchecked")
@@ -125,8 +125,8 @@ public class TaskRestClient extends JobRestClient implements ExecutionRestClient
         return result;
     }
 
-    public List<TaskExecTO> listExecutions(final int page, final int size, final Long
taskId) {
-        return getService(TaskService.class).listEexecutions(page, size, taskId).getResult();
+    public List<TaskExecTO> listExecutions(final Long taskId, final int page, final
int size) {
+        return getService(TaskService.class).listExecutions(taskId, page, size).getResult();
     }
 
     public PropagationTaskTO readPropagationTask(final Long taskId) {

http://git-wip-us.apache.org/repos/asf/syncope/blob/7c84a5c0/core/src/main/java/org/apache/syncope/core/persistence/dao/TaskExecDAO.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/syncope/core/persistence/dao/TaskExecDAO.java b/core/src/main/java/org/apache/syncope/core/persistence/dao/TaskExecDAO.java
index cb97416..62f5143 100644
--- a/core/src/main/java/org/apache/syncope/core/persistence/dao/TaskExecDAO.java
+++ b/core/src/main/java/org/apache/syncope/core/persistence/dao/TaskExecDAO.java
@@ -34,6 +34,10 @@ public interface TaskExecDAO extends DAO {
 
     <T extends Task> List<TaskExec> findAll(Class<T> reference);
 
+    int count(Long taskId);
+
+    List<TaskExec> findAll(Long taskId, int page, int itemsPerPage);
+
     TaskExec save(TaskExec execution) throws InvalidEntityException;
 
     void saveAndAdd(Long taskId, TaskExec execution) throws InvalidEntityException;

http://git-wip-us.apache.org/repos/asf/syncope/blob/7c84a5c0/core/src/main/java/org/apache/syncope/core/persistence/dao/impl/TaskExecDAOImpl.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/syncope/core/persistence/dao/impl/TaskExecDAOImpl.java
b/core/src/main/java/org/apache/syncope/core/persistence/dao/impl/TaskExecDAOImpl.java
index 1e2616d..b42cdff 100644
--- a/core/src/main/java/org/apache/syncope/core/persistence/dao/impl/TaskExecDAOImpl.java
+++ b/core/src/main/java/org/apache/syncope/core/persistence/dao/impl/TaskExecDAOImpl.java
@@ -19,6 +19,7 @@
 package org.apache.syncope.core.persistence.dao.impl;
 
 import java.util.List;
+import javax.persistence.Query;
 import javax.persistence.TypedQuery;
 import org.apache.syncope.core.persistence.beans.SchedTask;
 import org.apache.syncope.core.persistence.beans.SyncTask;
@@ -80,6 +81,32 @@ public class TaskExecDAOImpl extends AbstractDAOImpl implements TaskExecDAO
{
     }
 
     @Override
+    public int count(final Long taskId) {
+        Query countQuery = entityManager.createNativeQuery(
+                "SELECT COUNT(e.id) FROM " + TaskExec.class.getSimpleName() + " e WHERE e.task_id=?1");
+        countQuery.setParameter(1, taskId);
+
+        return ((Number) countQuery.getSingleResult()).intValue();
+    }
+
+    @Override
+    public List<TaskExec> findAll(final Long taskId, final int page, final int itemsPerPage)
{
+        TypedQuery<TaskExec> query = entityManager.createQuery(
+                "SELECT e FROM " + TaskExec.class.getSimpleName() + " e WHERE e.task.id=:taskId
ORDER BY e.id DESC",
+                TaskExec.class);
+        query.setParameter("taskId", taskId);
+
+        // page starts from 1, while setFirtResult() starts from 0
+        query.setFirstResult(itemsPerPage * (page <= 0 ? 0 : page - 1));
+
+        if (itemsPerPage >= 0) {
+            query.setMaxResults(itemsPerPage);
+        }
+
+        return query.getResultList();
+    }
+
+    @Override
     public TaskExec save(final TaskExec execution) {
         return entityManager.merge(execution);
     }

http://git-wip-us.apache.org/repos/asf/syncope/blob/7c84a5c0/core/src/main/java/org/apache/syncope/core/rest/controller/TaskController.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/syncope/core/rest/controller/TaskController.java
b/core/src/main/java/org/apache/syncope/core/rest/controller/TaskController.java
index c3e8f4f..0f06607 100644
--- a/core/src/main/java/org/apache/syncope/core/rest/controller/TaskController.java
+++ b/core/src/main/java/org/apache/syncope/core/rest/controller/TaskController.java
@@ -58,7 +58,6 @@ import org.quartz.JobDataMap;
 import org.quartz.JobKey;
 import org.quartz.Scheduler;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.scheduling.quartz.SchedulerFactoryBean;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.stereotype.Component;
 
@@ -191,9 +190,14 @@ public class TaskController extends AbstractJobController<AbstractTaskTO>
{
     }
 
     @PreAuthorize("hasRole('TASK_READ')")
-    public List<TaskExecTO> listExecution(final Long taskId) {
+    public int countExecutions(final Long taskId) {
+        return taskExecDAO.count(taskId);
+    }
+
+    @PreAuthorize("hasRole('TASK_READ')")
+    public List<TaskExecTO> listEexecutions(final Long taskId, final int page, final
int size) {
         final List<TaskExecTO> execsExecTOs = new ArrayList<TaskExecTO>();
-        for (final TaskExec exec : taskDAO.find(taskId).getExecs()) {
+        for (TaskExec exec : taskExecDAO.findAll(taskId, page, size)) {
             execsExecTOs.add(binder.getTaskExecTO(exec));
         }
         return execsExecTOs;

http://git-wip-us.apache.org/repos/asf/syncope/blob/7c84a5c0/core/src/main/java/org/apache/syncope/core/services/TaskServiceImpl.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/syncope/core/services/TaskServiceImpl.java b/core/src/main/java/org/apache/syncope/core/services/TaskServiceImpl.java
index 28c3eb9..738b770 100644
--- a/core/src/main/java/org/apache/syncope/core/services/TaskServiceImpl.java
+++ b/core/src/main/java/org/apache/syncope/core/services/TaskServiceImpl.java
@@ -135,9 +135,9 @@ public class TaskServiceImpl extends AbstractServiceImpl implements TaskService
     }
 
     @Override
-    public PagedResult<TaskExecTO> listEexecutions(final Integer page, final Integer
size, final Long taskId) {
-        final List<TaskExecTO> execTOs = controller.listExecution(taskId);
-        return buildPagedResult(execTOs, page, size, execTOs.size());
+    public PagedResult<TaskExecTO> listExecutions(final Long taskId, final Integer
page, final Integer size) {
+        return buildPagedResult(
+                controller.listEexecutions(taskId, page, size), page, size, controller.countExecutions(taskId));
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/syncope/blob/7c84a5c0/core/src/test/java/org/apache/syncope/core/rest/TaskTestITCase.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/syncope/core/rest/TaskTestITCase.java b/core/src/test/java/org/apache/syncope/core/rest/TaskTestITCase.java
index 89ec7ba..bba9d3e 100644
--- a/core/src/test/java/org/apache/syncope/core/rest/TaskTestITCase.java
+++ b/core/src/test/java/org/apache/syncope/core/rest/TaskTestITCase.java
@@ -303,8 +303,6 @@ public class TaskTestITCase extends AbstractTest {
     }
 
     @Test
-    // Currently test is not re-runnable.
-    // To successfully run test second time it is necessary to restart cargo.
     public void deal() {
         try {
             taskService.delete(0L);
@@ -321,13 +319,6 @@ public class TaskTestITCase extends AbstractTest {
         exec = taskService.readExecution(exec.getId());
         assertEquals(PropagationTaskExecStatus.SUCCESS.name(), exec.getStatus());
         assertEquals("OK", exec.getMessage());
-
-        taskService.delete(1L);
-        try {
-            taskService.readExecution(exec.getId());
-        } catch (SyncopeClientException e) {
-            assertEquals(Response.Status.NOT_FOUND, e.getType().getResponseStatus());
-        }
     }
 
     @Test
@@ -1577,17 +1568,40 @@ public class TaskTestITCase extends AbstractTest {
 
     @Test
     public void issueSYNCOPE741() {
-        ldapCleanup();
+        for (int i = 0; i < 3; i++) {
+            taskService.execute(1L, false);
+            taskService.execute(2L, false);
+        }
+        try {
+            Thread.sleep(3000);
+        } catch (InterruptedException e) {
+            // ignore
+        }
+
+        // check list
+        PagedResult<AbstractTaskTO> tasks = taskService.list(TaskType.PROPAGATION,
1, 2, "id", false);
+        for (AbstractTaskTO item : tasks.getResult()) {
+            assertTrue(item.getExecutions().isEmpty());
+        }
+
+        tasks = taskService.list(TaskType.PROPAGATION, 1, 2, "id", true);
+        for (AbstractTaskTO item : tasks.getResult()) {
+            assertFalse(item.getExecutions().isEmpty());
+        }
 
-        SyncTaskTO task = taskService.read(11L, false);
+        // check read
+        PropagationTaskTO task = taskService.read(1L, false);
         assertNotNull(task);
-        assertEquals(11L, task.getId());
+        assertEquals(1L, task.getId());
         assertTrue(task.getExecutions().isEmpty());
 
-        task = taskService.read(11L, true);
+        task = taskService.read(1L, true);
         assertNotNull(task);
-        assertEquals(11L, task.getId());
+        assertEquals(1L, task.getId());
         assertFalse(task.getExecutions().isEmpty());
-        assertEquals(1, task.getExecutions().size());
+
+        // check list executions
+        PagedResult<TaskExecTO> execs = taskService.listExecutions(1L, 1, 2);
+        assertTrue(execs.getTotalCount() >= execs.getResult().size());
     }
 }


Mime
View raw message