syncope-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ilgro...@apache.org
Subject [syncope] branch 2_0_X updated: Activiti/Flowable: simplifying forms retrieval
Date Mon, 04 Feb 2019 16:52:05 GMT
This is an automated email from the ASF dual-hosted git repository.

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


The following commit(s) were added to refs/heads/2_0_X by this push:
     new 57d7793  Activiti/Flowable: simplifying forms retrieval
57d7793 is described below

commit 57d779306830bad343e569a8e6f3ad6d9bfcb14f
Author: Francesco Chicchiriccò <ilgrosso@apache.org>
AuthorDate: Mon Feb 4 17:51:55 2019 +0100

    Activiti/Flowable: simplifying forms retrieval
---
 .../src/test/resources/domains/MasterContent.xml   |  1 +
 .../activiti/ActivitiUserWorkflowAdapter.java      | 33 ++++------------------
 .../flowable/FlowableUserWorkflowAdapter.java      | 33 ++++------------------
 .../syncope/fit/core/UserWorkflowITCase.java       |  3 +-
 4 files changed, 13 insertions(+), 57 deletions(-)

diff --git a/core/persistence-jpa/src/test/resources/domains/MasterContent.xml b/core/persistence-jpa/src/test/resources/domains/MasterContent.xml
index 437596c..5b6c7e8 100644
--- a/core/persistence-jpa/src/test/resources/domains/MasterContent.xml
+++ b/core/persistence-jpa/src/test/resources/domains/MasterContent.xml
@@ -259,6 +259,7 @@ under the License.
   <SyncopeRole_entitlements entitlement="ANYTYPE_READ" role_id="User manager"/>
   <SyncopeRole_entitlements entitlement="ANYTYPECLASS_LIST" role_id="User manager"/>
   <SyncopeRole_entitlements entitlement="ANYTYPECLASS_READ" role_id="User manager"/>
+  <SyncopeRole_entitlements entitlement="WORKFLOW_FORM_LIST" role_id="User manager"/>
   <SyncopeRole_entitlements entitlement="WORKFLOW_FORM_CLAIM" role_id="User manager"/>
   <SyncopeRole_entitlements entitlement="WORKFLOW_FORM_SUBMIT" role_id="User manager"/>
   <SyncopeRole_Realm role_id="User manager" realm_id="e4c28e7a-9dbf-4ee7-9441-93812a0d4a28"/>
diff --git a/core/workflow-activiti/src/main/java/org/apache/syncope/core/workflow/activiti/ActivitiUserWorkflowAdapter.java
b/core/workflow-activiti/src/main/java/org/apache/syncope/core/workflow/activiti/ActivitiUserWorkflowAdapter.java
index 0953276..676ad4f 100644
--- a/core/workflow-activiti/src/main/java/org/apache/syncope/core/workflow/activiti/ActivitiUserWorkflowAdapter.java
+++ b/core/workflow-activiti/src/main/java/org/apache/syncope/core/workflow/activiti/ActivitiUserWorkflowAdapter.java
@@ -623,36 +623,13 @@ public class ActivitiUserWorkflowAdapter extends AbstractUserWorkflowAdapter
{
     public Pair<Integer, List<WorkflowFormTO>> getForms(
             final int page, final int size, final List<OrderByClause> orderByClauses)
{
 
-        Pair<Integer, List<WorkflowFormTO>> forms = null;
-
         String authUser = AuthContextUtils.getUsername();
-        if (adminUser.equals(authUser)) {
-            forms = getForms(engine.getTaskService().createTaskQuery().
-                    taskVariableValueEquals(TASK_IS_FORM, Boolean.TRUE), page, size, orderByClauses);
-        } else {
-            User user = userDAO.findByUsername(authUser);
-            if (user == null) {
-                throw new NotFoundException("Syncope User " + authUser);
-            }
-
-            forms = getForms(engine.getTaskService().createTaskQuery().
-                    taskVariableValueEquals(TASK_IS_FORM, Boolean.TRUE).
-                    taskCandidateOrAssigned(user.getUsername()), page, size, orderByClauses);
-
-            List<String> candidateGroups = new ArrayList<>();
-            for (String groupName : userDAO.findAllGroupNames(user)) {
-                candidateGroups.add(groupName);
-            }
-            if (!candidateGroups.isEmpty()) {
-                forms = getForms(engine.getTaskService().createTaskQuery().
+        return adminUser.equals(authUser)
+                ? getForms(engine.getTaskService().createTaskQuery().
+                        taskVariableValueEquals(TASK_IS_FORM, Boolean.TRUE), page, size,
orderByClauses)
+                : getForms(engine.getTaskService().createTaskQuery().
                         taskVariableValueEquals(TASK_IS_FORM, Boolean.TRUE).
-                        taskCandidateGroupIn(candidateGroups), page, size, orderByClauses);
-            }
-        }
-
-        return forms == null
-                ? Pair.of(0, Collections.<WorkflowFormTO>emptyList())
-                : forms;
+                        taskCandidateOrAssigned(authUser), page, size, orderByClauses);
     }
 
     protected Pair<Integer, List<WorkflowFormTO>> getForms(
diff --git a/core/workflow-flowable/src/main/java/org/apache/syncope/core/workflow/flowable/FlowableUserWorkflowAdapter.java
b/core/workflow-flowable/src/main/java/org/apache/syncope/core/workflow/flowable/FlowableUserWorkflowAdapter.java
index 872c816..459d6dc 100644
--- a/core/workflow-flowable/src/main/java/org/apache/syncope/core/workflow/flowable/FlowableUserWorkflowAdapter.java
+++ b/core/workflow-flowable/src/main/java/org/apache/syncope/core/workflow/flowable/FlowableUserWorkflowAdapter.java
@@ -622,36 +622,13 @@ public class FlowableUserWorkflowAdapter extends AbstractUserWorkflowAdapter
{
     public Pair<Integer, List<WorkflowFormTO>> getForms(
             final int page, final int size, final List<OrderByClause> orderByClauses)
{
 
-        Pair<Integer, List<WorkflowFormTO>> forms = null;
-
         String authUser = AuthContextUtils.getUsername();
-        if (adminUser.equals(authUser)) {
-            forms = getForms(engine.getTaskService().createTaskQuery().
-                    taskVariableValueEquals(TASK_IS_FORM, Boolean.TRUE), page, size, orderByClauses);
-        } else {
-            User user = userDAO.findByUsername(authUser);
-            if (user == null) {
-                throw new NotFoundException("Syncope User " + authUser);
-            }
-
-            forms = getForms(engine.getTaskService().createTaskQuery().
-                    taskVariableValueEquals(TASK_IS_FORM, Boolean.TRUE).
-                    taskCandidateOrAssigned(user.getUsername()), page, size, orderByClauses);
-
-            List<String> candidateGroups = new ArrayList<>();
-            for (String groupName : userDAO.findAllGroupNames(user)) {
-                candidateGroups.add(groupName);
-            }
-            if (!candidateGroups.isEmpty()) {
-                forms = getForms(engine.getTaskService().createTaskQuery().
+        return adminUser.equals(authUser)
+                ? getForms(engine.getTaskService().createTaskQuery().
+                        taskVariableValueEquals(TASK_IS_FORM, Boolean.TRUE), page, size,
orderByClauses)
+                : getForms(engine.getTaskService().createTaskQuery().
                         taskVariableValueEquals(TASK_IS_FORM, Boolean.TRUE).
-                        taskCandidateGroupIn(candidateGroups), page, size, orderByClauses);
-            }
-        }
-
-        return forms == null
-                ? Pair.of(0, Collections.<WorkflowFormTO>emptyList())
-                : forms;
+                        taskCandidateOrAssigned(authUser), page, size, orderByClauses);
     }
 
     protected Pair<Integer, List<WorkflowFormTO>> getForms(
diff --git a/fit/core-reference/src/test/java/org/apache/syncope/fit/core/UserWorkflowITCase.java
b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/UserWorkflowITCase.java
index f1f92a8..1db7749 100644
--- a/fit/core-reference/src/test/java/org/apache/syncope/fit/core/UserWorkflowITCase.java
+++ b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/UserWorkflowITCase.java
@@ -119,6 +119,7 @@ public class UserWorkflowITCase extends AbstractITCase {
         // 4. claim task from bellini, with role "User manager" and in group 7
         UserWorkflowService userService3 = clientFactory.create("bellini", ADMIN_PWD).
                 getService(UserWorkflowService.class);
+        assertEquals(1, userService3.getForms(new WorkflowFormQuery.Builder().build()).getTotalCount());
         form = userService3.claimForm(form.getTaskId());
         assertNotNull(form);
         assertNotNull(form.getTaskId());
@@ -308,7 +309,7 @@ public class UserWorkflowITCase extends AbstractITCase {
             exception = e;
         }
         assertNotNull(exception);
-        
+
         // 7. claim task again (as admin)
         form = userWorkflowService.claimForm(form.getTaskId());
         assertNotNull(form);


Mime
View raw message