Search in sources :

Example 21 with WorkflowDefinition

use of org.alfresco.service.cmr.workflow.WorkflowDefinition in project alfresco-remote-api by Alfresco.

the class AbstractWorkflowRestApiTest method testWorkflowInstanceDeleteAsAdministrator.

public void testWorkflowInstanceDeleteAsAdministrator() throws Exception {
    // Start workflow as USER1
    personManager.setUser(USER1);
    WorkflowDefinition adhocDef = workflowService.getDefinitionByName(getAdhocWorkflowDefinitionName());
    Map<QName, Serializable> params = new HashMap<QName, Serializable>();
    params.put(WorkflowModel.ASSOC_ASSIGNEE, personManager.get(USER2));
    Date dueDate = new Date();
    params.put(WorkflowModel.PROP_DUE_DATE, dueDate);
    params.put(WorkflowModel.PROP_PRIORITY, 1);
    params.put(WorkflowModel.ASSOC_PACKAGE, packageRef);
    params.put(WorkflowModel.PROP_CONTEXT, packageRef);
    WorkflowPath adhocPath = workflowService.startWorkflow(adhocDef.getId(), params);
    WorkflowTask startTask = workflowService.getTasksForWorkflowPath(adhocPath.getId()).get(0);
    startTask = workflowService.endTask(startTask.getId(), null);
    WorkflowInstance adhocInstance = startTask.getPath().getInstance();
    // Run next request as admin
    String admin = authenticationComponent.getDefaultAdministratorUserNames().iterator().next();
    AuthenticationUtil.setFullyAuthenticatedUser(admin);
    sendRequest(new DeleteRequest(URL_WORKFLOW_INSTANCES + "/" + adhocInstance.getId()), Status.STATUS_OK);
    WorkflowInstance instance = workflowService.getWorkflowById(adhocInstance.getId());
    if (instance != null) {
        assertFalse("The deleted workflow is still active!", instance.isActive());
    }
    List<WorkflowInstance> instances = workflowService.getActiveWorkflows(adhocInstance.getDefinition().getId());
    for (WorkflowInstance activeInstance : instances) {
        assertFalse(adhocInstance.getId().equals(activeInstance.getId()));
    }
}
Also used : Serializable(java.io.Serializable) HashMap(java.util.HashMap) QName(org.alfresco.service.namespace.QName) WorkflowDefinition(org.alfresco.service.cmr.workflow.WorkflowDefinition) WorkflowPath(org.alfresco.service.cmr.workflow.WorkflowPath) WorkflowTask(org.alfresco.service.cmr.workflow.WorkflowTask) WorkflowInstance(org.alfresco.service.cmr.workflow.WorkflowInstance) DeleteRequest(org.springframework.extensions.webscripts.TestWebScriptServer.DeleteRequest) Date(java.util.Date)

Example 22 with WorkflowDefinition

use of org.alfresco.service.cmr.workflow.WorkflowDefinition in project alfresco-remote-api by Alfresco.

the class AbstractWorkflowRestApiTest method testWorkflowPermissions.

public void testWorkflowPermissions() throws Exception {
    // Start workflow as USER1 and assign task to USER1.
    personManager.setUser(USER1);
    WorkflowDefinition adhocDef = workflowService.getDefinitionByName(getAdhocWorkflowDefinitionName());
    Map<QName, Serializable> params = new HashMap<QName, Serializable>();
    params.put(WorkflowModel.ASSOC_ASSIGNEE, personManager.get(USER1));
    Calendar dueDateCal = Calendar.getInstance();
    Date dueDate = dueDateCal.getTime();
    params.put(WorkflowModel.PROP_DUE_DATE, dueDate);
    params.put(WorkflowModel.PROP_PRIORITY, 1);
    params.put(WorkflowModel.ASSOC_PACKAGE, packageRef);
    WorkflowPath adhocPath = workflowService.startWorkflow(adhocDef.getId(), params);
    String workflowId = adhocPath.getInstance().getId();
    workflows.add(workflowId);
    WorkflowTask startTask = workflowService.getStartTask(workflowId);
    workflowService.endTask(startTask.getId(), null);
    // Check tasks of USER1 from behalf of USER2
    personManager.setUser(USER2);
    Response response = sendRequest(new GetRequest(MessageFormat.format(URL_USER_TASKS, USER1)), 200);
    assertEquals(Status.STATUS_OK, response.getStatus());
    String jsonStr = response.getContentAsString();
    JSONObject json = new JSONObject(jsonStr);
    JSONArray results = json.getJSONArray("data");
    assertNotNull(results);
    assertTrue("User2 should not see any tasks if he is not initiator or assignee", results.length() == 0);
}
Also used : Serializable(java.io.Serializable) HashMap(java.util.HashMap) QName(org.alfresco.service.namespace.QName) Calendar(java.util.Calendar) JSONArray(org.json.JSONArray) WorkflowDefinition(org.alfresco.service.cmr.workflow.WorkflowDefinition) WorkflowPath(org.alfresco.service.cmr.workflow.WorkflowPath) WorkflowTask(org.alfresco.service.cmr.workflow.WorkflowTask) Date(java.util.Date) Response(org.springframework.extensions.webscripts.TestWebScriptServer.Response) JSONObject(org.json.JSONObject) GetRequest(org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest)

Example 23 with WorkflowDefinition

use of org.alfresco.service.cmr.workflow.WorkflowDefinition in project alfresco-remote-api by Alfresco.

the class AbstractWorkflowRestApiTest method testWorkflowInstancesForNodeGet.

public void testWorkflowInstancesForNodeGet() throws Exception {
    // Start workflow as USER1 and assign task to USER2.
    personManager.setUser(USER1);
    WorkflowDefinition adhocDef = workflowService.getDefinitionByName(getAdhocWorkflowDefinitionName());
    Map<QName, Serializable> params = new HashMap<QName, Serializable>();
    params.put(WorkflowModel.ASSOC_ASSIGNEE, personManager.get(USER2));
    params.put(WorkflowModel.PROP_DUE_DATE, new Date());
    params.put(WorkflowModel.PROP_PRIORITY, 1);
    params.put(WorkflowModel.ASSOC_PACKAGE, packageRef);
    nodeService.addChild(packageRef, contentNodeRef, WorkflowModel.ASSOC_PACKAGE_CONTAINS, QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, QName.createValidLocalName((String) nodeService.getProperty(contentNodeRef, ContentModel.PROP_NAME))));
    WorkflowPath adhocPath = workflowService.startWorkflow(adhocDef.getId(), params);
    String url = MessageFormat.format(URL_WORKFLOW_INSTANCES_FOR_NODE, contentNodeRef.getStoreRef().getProtocol(), contentNodeRef.getStoreRef().getIdentifier(), contentNodeRef.getId());
    Response response = sendRequest(new GetRequest(url), 200);
    assertEquals(Status.STATUS_OK, response.getStatus());
    String jsonStr = response.getContentAsString();
    JSONObject json = new JSONObject(jsonStr);
    JSONArray result = json.getJSONArray("data");
    assertNotNull(result);
    assertTrue(result.length() > 0);
    workflowService.cancelWorkflow(adhocPath.getInstance().getId());
    Response afterCancelResponse = sendRequest(new GetRequest(url), 200);
    assertEquals(Status.STATUS_OK, afterCancelResponse.getStatus());
    String afterCancelJsonStr = afterCancelResponse.getContentAsString();
    JSONObject afterCancelJson = new JSONObject(afterCancelJsonStr);
    JSONArray afterCancelResult = afterCancelJson.getJSONArray("data");
    assertNotNull(afterCancelResult);
    assertTrue(afterCancelResult.length() == 0);
}
Also used : Response(org.springframework.extensions.webscripts.TestWebScriptServer.Response) Serializable(java.io.Serializable) JSONObject(org.json.JSONObject) HashMap(java.util.HashMap) QName(org.alfresco.service.namespace.QName) GetRequest(org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest) JSONArray(org.json.JSONArray) WorkflowDefinition(org.alfresco.service.cmr.workflow.WorkflowDefinition) WorkflowPath(org.alfresco.service.cmr.workflow.WorkflowPath) Date(java.util.Date)

Example 24 with WorkflowDefinition

use of org.alfresco.service.cmr.workflow.WorkflowDefinition in project alfresco-remote-api by Alfresco.

the class AbstractWorkflowRestApiTest method testTaskInstancesGetWithFiltering.

public void testTaskInstancesGetWithFiltering() throws Exception {
    // Check USER2 starts with no tasks.
    personManager.setUser(USER2);
    Response response = sendRequest(new GetRequest(MessageFormat.format(URL_USER_TASKS, USER2)), 200);
    getJsonArray(response, 0);
    // Start workflow as USER1 and assign the task to GROUP.
    personManager.setUser(USER1);
    WorkflowDefinition wfDefinition = workflowService.getDefinitionByName(getReviewPooledWorkflowDefinitionName());
    Map<QName, Serializable> params = new HashMap<>(3);
    params.put(WorkflowModel.ASSOC_GROUP_ASSIGNEE, groupManager.get(GROUP));
    params.put(WorkflowModel.ASSOC_PACKAGE, packageRef);
    params.put(WorkflowModel.PROP_WORKFLOW_DESCRIPTION, "descTest1");
    WorkflowPath wfPath = workflowService.startWorkflow(wfDefinition.getId(), params);
    String workflowId = wfPath.getInstance().getId();
    workflows.add(workflowId);
    WorkflowTask startTask = workflowService.getStartTask(workflowId);
    workflowService.endTask(startTask.getId(), null);
    // Start another workflow as USER1 and assign the task to GROUP.
    wfDefinition = workflowService.getDefinitionByName(getReviewPooledWorkflowDefinitionName());
    params.put(WorkflowModel.ASSOC_GROUP_ASSIGNEE, groupManager.get(GROUP));
    params.put(WorkflowModel.ASSOC_PACKAGE, workflowService.createPackage(null));
    params.put(WorkflowModel.PROP_WORKFLOW_DESCRIPTION, "descTest2/withSlash");
    wfPath = workflowService.startWorkflow(wfDefinition.getId(), params);
    workflowId = wfPath.getInstance().getId();
    workflows.add(workflowId);
    startTask = workflowService.getStartTask(workflowId);
    workflowService.endTask(startTask.getId(), null);
    // Check USER2's tasks without filtering. It should return two tasks as USER2 is a member of the GROUP
    personManager.setUser(USER2);
    response = sendRequest(new GetRequest(MessageFormat.format(URL_USER_TASKS, USER2)), 200);
    getJsonArray(response, 2);
    // Check USER2's tasks With filtering where property bpm:description should match "descTest1"
    response = sendRequest(new GetRequest(MessageFormat.format(URL_USER_TASKS, USER2) + "&property=bpm:description/descTest1"), 200);
    JSONArray results = getJsonArray(response, 1);
    JSONObject result = results.getJSONObject(0);
    assertNotNull(result);
    JSONObject properties = result.getJSONObject("properties");
    assertNotNull(properties);
    assertEquals("descTest1", properties.getString("bpm_description"));
    // Check USER2's tasks With filtering where property bpm:description should match "descTest2"
    response = sendRequest(new GetRequest(MessageFormat.format(URL_USER_TASKS, USER2) + "&property=bpm:description/descTest2/withSlash"), 200);
    results = getJsonArray(response, 1);
    result = results.getJSONObject(0);
    assertNotNull(result);
    properties = result.getJSONObject("properties");
    assertNotNull(properties);
    assertEquals("descTest2/withSlash", properties.getString("bpm_description"));
    /*
         * -ve tests
         */
    // Mismatched property value - There is no task with the description "somePropValue"
    response = sendRequest(new GetRequest(MessageFormat.format(URL_USER_TASKS, USER2) + "&property=bpm:description/somePropValue"), 200);
    getJsonArray(response, 0);
    // Unregistered namespace prefix (ignores "property" parameter)
    response = sendRequest(new GetRequest(MessageFormat.format(URL_USER_TASKS, USER2) + "&property=unknownPrefix:description/test"), 200);
    getJsonArray(response, 2);
    // Nonexistent property (ignores "property" parameter)
    response = sendRequest(new GetRequest(MessageFormat.format(URL_USER_TASKS, USER2) + "&property=bpm:nonexistentProp/test"), 200);
    getJsonArray(response, 2);
    // Not well-formed parameter
    response = sendRequest(new GetRequest(MessageFormat.format(URL_USER_TASKS, USER2) + "&property=bpm:description/"), 200);
    getJsonArray(response, 2);
    // Not well-formed parameter
    response = sendRequest(new GetRequest(MessageFormat.format(URL_USER_TASKS, USER2) + "&property=descTest1"), 200);
    getJsonArray(response, 2);
    // Not well-formed parameter
    response = sendRequest(new GetRequest(MessageFormat.format(URL_USER_TASKS, USER2) + "&property=/descTest1"), 200);
    getJsonArray(response, 2);
    // Check USER3's tasks without filtering. It should return 0 task as USER3 is not a member of the GROUP
    personManager.setUser(USER3);
    response = sendRequest(new GetRequest(MessageFormat.format(URL_USER_TASKS, USER3)), 200);
    getJsonArray(response, 0);
}
Also used : Response(org.springframework.extensions.webscripts.TestWebScriptServer.Response) Serializable(java.io.Serializable) JSONObject(org.json.JSONObject) HashMap(java.util.HashMap) QName(org.alfresco.service.namespace.QName) GetRequest(org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest) JSONArray(org.json.JSONArray) WorkflowDefinition(org.alfresco.service.cmr.workflow.WorkflowDefinition) WorkflowPath(org.alfresco.service.cmr.workflow.WorkflowPath) WorkflowTask(org.alfresco.service.cmr.workflow.WorkflowTask)

Example 25 with WorkflowDefinition

use of org.alfresco.service.cmr.workflow.WorkflowDefinition in project alfresco-remote-api by Alfresco.

the class AbstractWorkflowRestApiTest method testWorkflowInstanceDeleteAsRecreatedUser.

public void testWorkflowInstanceDeleteAsRecreatedUser() throws Exception {
    // Create task as USER1 and assign it to another user
    personManager.setUser(USER1);
    WorkflowDefinition adhocDef = workflowService.getDefinitionByName(getAdhocWorkflowDefinitionName());
    Map<QName, Serializable> params = new HashMap<QName, Serializable>();
    params.put(WorkflowModel.ASSOC_ASSIGNEE, personManager.get(USER2));
    Date dueDate = new Date();
    params.put(WorkflowModel.PROP_DUE_DATE, dueDate);
    params.put(WorkflowModel.PROP_PRIORITY, 1);
    params.put(WorkflowModel.ASSOC_PACKAGE, packageRef);
    params.put(WorkflowModel.PROP_CONTEXT, packageRef);
    WorkflowPath adhocPath = workflowService.startWorkflow(adhocDef.getId(), params);
    // Check the workflow was created
    assertNotNull(workflowService.getWorkflowById(adhocPath.getInstance().getId()));
    // Delete USER1
    personManager.deletePerson(USER1);
    // Recreate USER1
    personManager.createPerson(USER1);
    // Delete workflow
    personManager.setUser(USER1);
    sendRequest(new DeleteRequest(URL_WORKFLOW_INSTANCES + "/" + adhocPath.getInstance().getId()), Status.STATUS_OK);
    // Check the workflow was deleted
    assertNull(workflowService.getWorkflowById(adhocPath.getInstance().getId()));
}
Also used : Serializable(java.io.Serializable) HashMap(java.util.HashMap) QName(org.alfresco.service.namespace.QName) WorkflowDefinition(org.alfresco.service.cmr.workflow.WorkflowDefinition) WorkflowPath(org.alfresco.service.cmr.workflow.WorkflowPath) DeleteRequest(org.springframework.extensions.webscripts.TestWebScriptServer.DeleteRequest) Date(java.util.Date)

Aggregations

WorkflowDefinition (org.alfresco.service.cmr.workflow.WorkflowDefinition)31 HashMap (java.util.HashMap)19 Date (java.util.Date)18 WorkflowPath (org.alfresco.service.cmr.workflow.WorkflowPath)16 QName (org.alfresco.service.namespace.QName)16 Serializable (java.io.Serializable)15 WorkflowTask (org.alfresco.service.cmr.workflow.WorkflowTask)14 GetRequest (org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest)13 JSONObject (org.json.JSONObject)12 Response (org.springframework.extensions.webscripts.TestWebScriptServer.Response)12 JSONArray (org.json.JSONArray)9 WorkflowInstance (org.alfresco.service.cmr.workflow.WorkflowInstance)8 Calendar (java.util.Calendar)6 WorkflowTaskDefinition (org.alfresco.service.cmr.workflow.WorkflowTaskDefinition)5 ArrayList (java.util.ArrayList)3 Map (java.util.Map)3 NodeRef (org.alfresco.service.cmr.repository.NodeRef)3 DeleteRequest (org.springframework.extensions.webscripts.TestWebScriptServer.DeleteRequest)3 PutRequest (org.springframework.extensions.webscripts.TestWebScriptServer.PutRequest)3 PropertyDefinition (org.alfresco.service.cmr.dictionary.PropertyDefinition)2