syncope-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ilgro...@apache.org
Subject svn commit: r1414824 - in /syncope/branches/1_0_X: console/src/main/java/org/apache/syncope/console/rest/ core/src/main/java/org/apache/syncope/core/rest/controller/ core/src/main/java/org/apache/syncope/core/workflow/ core/src/test/java/org/apache/syn...
Date Wed, 28 Nov 2012 17:13:29 GMT
Author: ilgrosso
Date: Wed Nov 28 17:13:28 2012
New Revision: 1414824

URL: http://svn.apache.org/viewvc?rev=1414824&view=rev
Log:
[SYNCOPE-238] Now the Activiti query is performed only against users currently holding a form
task

Modified:
    syncope/branches/1_0_X/console/src/main/java/org/apache/syncope/console/rest/ApprovalRestClient.java
    syncope/branches/1_0_X/core/src/main/java/org/apache/syncope/core/rest/controller/WorkflowController.java
    syncope/branches/1_0_X/core/src/main/java/org/apache/syncope/core/workflow/ActivitiUserWorkflowAdapter.java
    syncope/branches/1_0_X/core/src/test/java/org/apache/syncope/core/rest/UserTestITCase.java

Modified: syncope/branches/1_0_X/console/src/main/java/org/apache/syncope/console/rest/ApprovalRestClient.java
URL: http://svn.apache.org/viewvc/syncope/branches/1_0_X/console/src/main/java/org/apache/syncope/console/rest/ApprovalRestClient.java?rev=1414824&r1=1414823&r2=1414824&view=diff
==============================================================================
--- syncope/branches/1_0_X/console/src/main/java/org/apache/syncope/console/rest/ApprovalRestClient.java
(original)
+++ syncope/branches/1_0_X/console/src/main/java/org/apache/syncope/console/rest/ApprovalRestClient.java
Wed Nov 28 17:13:28 2012
@@ -20,10 +20,10 @@ package org.apache.syncope.console.rest;
 
 import java.util.Arrays;
 import java.util.List;
-import org.springframework.stereotype.Component;
 import org.apache.syncope.client.to.UserTO;
 import org.apache.syncope.client.to.WorkflowFormTO;
 import org.apache.syncope.console.SyncopeSession;
+import org.springframework.stereotype.Component;
 
 /**
  * Console client for invoking Rest Todo services.

Modified: syncope/branches/1_0_X/core/src/main/java/org/apache/syncope/core/rest/controller/WorkflowController.java
URL: http://svn.apache.org/viewvc/syncope/branches/1_0_X/core/src/main/java/org/apache/syncope/core/rest/controller/WorkflowController.java?rev=1414824&r1=1414823&r2=1414824&view=diff
==============================================================================
--- syncope/branches/1_0_X/core/src/main/java/org/apache/syncope/core/rest/controller/WorkflowController.java
(original)
+++ syncope/branches/1_0_X/core/src/main/java/org/apache/syncope/core/rest/controller/WorkflowController.java
Wed Nov 28 17:13:28 2012
@@ -20,6 +20,13 @@ package org.apache.syncope.core.rest.con
 
 import java.util.List;
 import javassist.NotFoundException;
+import org.apache.syncope.client.to.WorkflowDefinitionTO;
+import org.apache.syncope.core.audit.AuditManager;
+import org.apache.syncope.core.workflow.UserWorkflowAdapter;
+import org.apache.syncope.core.workflow.WorkflowException;
+import org.apache.syncope.types.AuditElements.Category;
+import org.apache.syncope.types.AuditElements.Result;
+import org.apache.syncope.types.AuditElements.WorkflowSubCategory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.stereotype.Controller;
@@ -28,13 +35,6 @@ import org.springframework.web.bind.anno
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestMethod;
 import org.springframework.web.servlet.ModelAndView;
-import org.apache.syncope.client.to.WorkflowDefinitionTO;
-import org.apache.syncope.core.audit.AuditManager;
-import org.apache.syncope.core.workflow.UserWorkflowAdapter;
-import org.apache.syncope.core.workflow.WorkflowException;
-import org.apache.syncope.types.AuditElements.Category;
-import org.apache.syncope.types.AuditElements.Result;
-import org.apache.syncope.types.AuditElements.WorkflowSubCategory;
 
 @Controller
 @RequestMapping("/workflow")
@@ -50,7 +50,6 @@ public class WorkflowController extends 
     @RequestMapping(method = RequestMethod.GET, value = "/definition")
     @Transactional(readOnly = true)
     public WorkflowDefinitionTO getDefinition() throws WorkflowException {
-
         WorkflowDefinitionTO result = wfAdapter.getDefinition();
 
         auditManager.audit(Category.workflow, WorkflowSubCategory.getDefinition, Result.success,
@@ -73,7 +72,6 @@ public class WorkflowController extends 
     @PreAuthorize("hasRole('WORKFLOW_TASK_LIST')")
     @RequestMapping(method = RequestMethod.GET, value = "/tasks")
     public ModelAndView getDefinedTasks() throws WorkflowException {
-
         List<String> definedTasks = wfAdapter.getDefinedTasks();
 
         auditManager.audit(Category.workflow, WorkflowSubCategory.getDefinedTasks, Result.success,

Modified: syncope/branches/1_0_X/core/src/main/java/org/apache/syncope/core/workflow/ActivitiUserWorkflowAdapter.java
URL: http://svn.apache.org/viewvc/syncope/branches/1_0_X/core/src/main/java/org/apache/syncope/core/workflow/ActivitiUserWorkflowAdapter.java?rev=1414824&r1=1414823&r2=1414824&view=diff
==============================================================================
--- syncope/branches/1_0_X/core/src/main/java/org/apache/syncope/core/workflow/ActivitiUserWorkflowAdapter.java
(original)
+++ syncope/branches/1_0_X/core/src/main/java/org/apache/syncope/core/workflow/ActivitiUserWorkflowAdapter.java
Wed Nov 28 17:13:28 2012
@@ -113,6 +113,8 @@ public class ActivitiUserWorkflowAdapter
 
     public static final String ENCRYPTED_PWD = "encryptedPwd";
 
+    public static final String TASK_IS_FORM = "taskIsForm";
+
     @Resource(name = "adminUser")
     private String adminUser;
 
@@ -145,8 +147,8 @@ public class ActivitiUserWorkflowAdapter
         }
     }
 
-    private boolean waitingForForm(final SyncopeUser user) {
-        boolean result = false;
+    private String getFormTask(final SyncopeUser user) {
+        String result = null;
 
         List<Task> tasks = taskService.createTaskQuery().processInstanceId(user.getWorkflowId()).list();
         if (tasks.isEmpty() || tasks.size() > 1) {
@@ -154,7 +156,9 @@ public class ActivitiUserWorkflowAdapter
         } else {
             try {
                 TaskFormData formData = formService.getTaskFormData(tasks.get(0).getId());
-                result = formData != null && !formData.getFormProperties().isEmpty();
+                if (formData != null && !formData.getFormProperties().isEmpty())
{
+                    result = tasks.get(0).getId();
+                }
             } catch (ActivitiException e) {
                 LOG.warn("Could not get task form data", e);
             }
@@ -191,6 +195,7 @@ public class ActivitiUserWorkflowAdapter
     @Override
     public WorkflowResult<Map.Entry<Long, Boolean>> create(final UserTO userTO,
final boolean disablePwdPolicyCheck)
             throws WorkflowException {
+
         return create(userTO, disablePwdPolicyCheck, null);
     }
 
@@ -213,8 +218,7 @@ public class ActivitiUserWorkflowAdapter
         SyncopeUser user = (SyncopeUser) runtimeService.getVariable(processInstance.getProcessInstanceId(),
                 SYNCOPE_USER);
 
-        // this will make SyncopeUserValidator not to consider
-        // password policies at all
+        // this will make SyncopeUserValidator not to consider password policies at all
         if (disablePwdPolicyCheck) {
             user.removeClearPassword();
         }
@@ -224,7 +228,6 @@ public class ActivitiUserWorkflowAdapter
 
         Boolean propagateEnable = (Boolean) runtimeService.getVariable(processInstance.getProcessInstanceId(),
                 PROPAGATE_ENABLE);
-
         if (propagateEnable == null) {
             propagateEnable = enabled;
         }
@@ -234,7 +237,11 @@ public class ActivitiUserWorkflowAdapter
         PropagationByResource propByRes = new PropagationByResource();
         propByRes.set(PropagationOperation.CREATE, user.getResourceNames());
 
-        if (waitingForForm(user)) {
+        String formTaskId = getFormTask(user);
+        if (formTaskId != null) {
+            // SYNCOPE-238: This is needed to simplify the task query in this.getForms()
+            taskService.setVariableLocal(formTaskId, TASK_IS_FORM, Boolean.TRUE);
+
             runtimeService.setVariable(processInstance.getProcessInstanceId(), PROP_BY_RESOURCE,
propByRes);
             propByRes = null;
 
@@ -248,8 +255,8 @@ public class ActivitiUserWorkflowAdapter
                 propByRes, getPerformedTasks(user));
     }
 
-    private Set<String> doExecuteTask(final SyncopeUser user, final String task, final
Map<String, Object> moreVariables)
-            throws WorkflowException {
+    private Set<String> doExecuteTask(final SyncopeUser user, final String task,
+            final Map<String, Object> moreVariables) throws WorkflowException {
 
         Set<String> preTasks = getPerformedTasks(user);
 
@@ -266,14 +273,14 @@ public class ActivitiUserWorkflowAdapter
         }
 
         List<Task> tasks = taskService.createTaskQuery().processInstanceId(user.getWorkflowId()).list();
-        if (tasks.size() != 1) {
-            LOG.warn("Expected a single task, found {}", tasks.size());
-        } else {
+        if (tasks.size() == 1) {
             try {
                 taskService.complete(tasks.get(0).getId(), variables);
             } catch (ActivitiException e) {
                 throw new WorkflowException(e);
             }
+        } else {
+            LOG.warn("Expected a single task, found {}", tasks.size());
         }
 
         Set<String> postTasks = getPerformedTasks(user);
@@ -305,10 +312,14 @@ public class ActivitiUserWorkflowAdapter
         PropagationByResource propByRes = (PropagationByResource) runtimeService.getVariable(user.getWorkflowId(),
                 PROP_BY_RESOURCE);
 
-        // save resources to be propagated and password for later -
-        // after form submission - propagation
-        if (waitingForForm(user) && StringUtils.isNotBlank(userMod.getPassword()))
{
-            runtimeService.setVariable(user.getWorkflowId(), ENCRYPTED_PWD, encrypt(userMod.getPassword()));
+        // save resources to be propagated and password for later - after form submission
- propagation
+        String formTaskId = getFormTask(user);
+        if (formTaskId != null) {
+            // SYNCOPE-238: This is needed to simplify the task query in this.getForms()
+            taskService.setVariableLocal(formTaskId, TASK_IS_FORM, Boolean.TRUE);
+            if (StringUtils.isNotBlank(userMod.getPassword())) {
+                runtimeService.setVariable(user.getWorkflowId(), ENCRYPTED_PWD, encrypt(userMod.getPassword()));
+            }
         }
 
         Boolean propagateEnable = (Boolean) runtimeService.getVariable(user.getWorkflowId(),
PROPAGATE_ENABLE);
@@ -469,7 +480,6 @@ public class ActivitiUserWorkflowAdapter
     }
 
     private WorkflowFormPropertyType fromActivitiFormType(final FormType activitiFormType)
{
-
         WorkflowFormPropertyType result = WorkflowFormPropertyType.String;
 
         if ("string".equals(activitiFormType.getName())) {
@@ -492,7 +502,6 @@ public class ActivitiUserWorkflowAdapter
     }
 
     private WorkflowFormTO getFormTO(final Task task, final TaskFormData formData) {
-
         WorkflowFormTO formTO = new WorkflowFormTO();
         formTO.setTaskId(task.getId());
         formTO.setKey(formData.getFormKey());
@@ -523,7 +532,7 @@ public class ActivitiUserWorkflowAdapter
         List<WorkflowFormTO> forms = new ArrayList<WorkflowFormTO>();
 
         TaskFormData formData;
-        for (Task task : taskService.createTaskQuery().list()) {
+        for (Task task : taskService.createTaskQuery().taskVariableValueEquals(TASK_IS_FORM,
Boolean.TRUE).list()) {
             try {
                 formData = formService.getTaskFormData(task.getId());
             } catch (ActivitiException e) {

Modified: syncope/branches/1_0_X/core/src/test/java/org/apache/syncope/core/rest/UserTestITCase.java
URL: http://svn.apache.org/viewvc/syncope/branches/1_0_X/core/src/test/java/org/apache/syncope/core/rest/UserTestITCase.java?rev=1414824&r1=1414823&r2=1414824&view=diff
==============================================================================
--- syncope/branches/1_0_X/core/src/test/java/org/apache/syncope/core/rest/UserTestITCase.java
(original)
+++ syncope/branches/1_0_X/core/src/test/java/org/apache/syncope/core/rest/UserTestITCase.java
Wed Nov 28 17:13:28 2012
@@ -748,7 +748,12 @@ public class UserTestITCase extends Abst
         }
         assertNotNull(exception);
 
-        // 2. request if there is any pending task for user just created
+        // 2. request if there is any pending form for user just created
+        List<WorkflowFormTO> forms = Arrays.asList(restTemplate.getForObject(
+                BASE_URL + "user/workflow/form/list", WorkflowFormTO[].class));
+        assertNotNull(forms);
+        assertEquals(1, forms.size());
+
         WorkflowFormTO form = restTemplate.getForObject(BASE_URL + "user/workflow/form/{userId}",
WorkflowFormTO.class,
                 userTO.getId());
         assertNotNull(form);



Mime
View raw message