Search in sources :

Example 6 with WorkflowDefinition

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

the class AbstractWorkflowRestApiTest method testTaskInstancesGet.

public void testTaskInstancesGet() throws Exception {
    // Check USER2 starts with no tasks.
    personManager.setUser(USER2);
    Response response = sendRequest(new GetRequest(MessageFormat.format(URL_USER_TASKS, USER2)), 200);
    assertEquals(Status.STATUS_OK, response.getStatus());
    String jsonStr = response.getContentAsString();
    JSONObject json = new JSONObject(jsonStr);
    JSONArray results = json.getJSONArray("data");
    assertNotNull(results);
    assertTrue(results.length() == 0);
    // 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));
    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 USER2 now has one task.
    List<WorkflowTask> tasks = workflowService.getAssignedTasks(USER2, WorkflowTaskState.IN_PROGRESS);
    WorkflowTask task = tasks.get(0);
    Map<QName, Serializable> updateParams = new HashMap<QName, Serializable>(1);
    updateParams.put(WorkflowModel.PROP_DUE_DATE, new Date());
    workflowService.updateTask(task.getId(), updateParams, null, null);
    personManager.setUser(USER2);
    response = sendRequest(new GetRequest(MessageFormat.format(URL_USER_TASKS, USER2)), 200);
    jsonStr = response.getContentAsString();
    json = new JSONObject(jsonStr);
    results = json.getJSONArray("data");
    assertNotNull(results);
    assertTrue(results.length() == tasks.size());
    JSONObject result = results.getJSONObject(0);
    int totalItems = results.length();
    String expUrl = "api/task-instances/" + task.getId();
    assertEquals(expUrl, result.getString("url"));
    assertEquals(task.getName(), result.getString("name"));
    assertEquals(task.getTitle(), result.getString("title"));
    assertEquals(task.getDescription(), result.getString("description"));
    assertEquals(task.getState().name(), result.getString("state"));
    assertEquals("api/workflow-paths/" + adhocPath.getId(), result.getString("path"));
    assertFalse(result.getBoolean("isPooled"));
    assertTrue(result.getBoolean("isEditable"));
    assertTrue(result.getBoolean("isReassignable"));
    assertFalse(result.getBoolean("isClaimable"));
    assertFalse(result.getBoolean("isReleasable"));
    JSONObject owner = result.getJSONObject("owner");
    assertEquals(USER2, owner.getString("userName"));
    assertEquals(personManager.getFirstName(USER2), owner.getString("firstName"));
    assertEquals(personManager.getLastName(USER2), owner.getString("lastName"));
    JSONObject properties = result.getJSONObject("properties");
    assertNotNull(properties);
    JSONObject instance = result.getJSONObject("workflowInstance");
    assertNotNull(instance);
    // Check state filtering
    checkTasksState(URL_TASKS + "?state=completed", WorkflowTaskState.COMPLETED);
    checkTasksState(URL_TASKS + "?state=in_progress", WorkflowTaskState.IN_PROGRESS);
    // TODO: Add more tests to check pooled actors.
    // Check for priority filtering
    checkPriorityFiltering(URL_TASKS + "?priority=2");
    // Due after yesterday, started task should be in it
    dueDateCal.add(Calendar.DAY_OF_MONTH, -1);
    checkTasksPresent(MessageFormat.format(URL_TASKS_DUE_AFTER, ISO8601DateFormat.format(dueDateCal.getTime())), true, task.getId());
    // Due before yesterday, started task shouldn't be in it
    checkTasksPresent(MessageFormat.format(URL_TASKS_DUE_BEFORE, ISO8601DateFormat.format(dueDateCal.getTime())), false, task.getId());
    // Due before tomorrow, started task should be in it
    dueDateCal.add(Calendar.DAY_OF_MONTH, 2);
    checkTasksPresent(MessageFormat.format(URL_TASKS_DUE_BEFORE, ISO8601DateFormat.format(dueDateCal.getTime())), true, task.getId());
    // Due after tomorrow, started task shouldn't be in it
    checkTasksPresent(MessageFormat.format(URL_TASKS_DUE_AFTER, ISO8601DateFormat.format(dueDateCal.getTime())), false, task.getId());
    // checkFiltering(URL_TASKS + "?dueAfter=" +
    // ISO8601DateFormat.format(dueDate));
    // checkFiltering(URL_TASKS + "?dueBefore=" +
    // ISO8601DateFormat.format(new Date()));
    // Check property filtering on the task assigned to USER2
    String customProperties = "bpm_description,bpm_priority";
    checkTaskPropertyFiltering(customProperties, Arrays.asList("bpm_description", "bpm_priority"));
    // Properties that aren't explicitally present on task should be
    // returned as wel
    customProperties = "bpm_unexistingProperty,bpm_description,bpm_priority";
    checkTaskPropertyFiltering(customProperties, Arrays.asList("bpm_description", "bpm_priority", "bpm_unexistingProperty"));
    // Check paging
    int maxItems = 3;
    for (int skipCount = 0; skipCount < totalItems; skipCount += maxItems) {
        // one of this should test situation when skipCount + maxItems >
        // totalItems
        checkPaging(MessageFormat.format(URL_USER_TASKS, USER2) + "&maxItems=" + maxItems + "&skipCount=" + skipCount, totalItems, maxItems, skipCount);
    }
    // testing when skipCount > totalItems
    checkPaging(MessageFormat.format(URL_USER_TASKS, USER2) + "&maxItems=" + maxItems + "&skipCount=" + (totalItems + 1), totalItems, maxItems, totalItems + 1);
    // check the exclude filtering
    String exclude = "wf:submitAdhocTask";
    response = sendRequest(new GetRequest(URL_TASKS + "?exclude=" + exclude), 200);
    assertEquals(Status.STATUS_OK, response.getStatus());
    jsonStr = response.getContentAsString();
    json = new JSONObject(jsonStr);
    results = json.getJSONArray("data");
    assertNotNull(results);
    boolean adhocTasksPresent = false;
    for (int i = 0; i < results.length(); i++) {
        JSONObject taskJSON = results.getJSONObject(i);
        String type = taskJSON.getString("name");
        if (exclude.equals(type)) {
            adhocTasksPresent = true;
            break;
        }
    }
    assertFalse("Found wf:submitAdhocTask when they were supposed to be excluded", adhocTasksPresent);
    // CLOUD-1928: Check skip-count works toghether with filter, start another process
    personManager.setUser(USER1);
    params.clear();
    params.put(WorkflowModel.ASSOC_ASSIGNEE, personManager.get(USER2));
    dueDateCal.add(Calendar.DAY_OF_YEAR, 2);
    params.put(WorkflowModel.PROP_DUE_DATE, dueDateCal.getTime());
    params.put(WorkflowModel.PROP_PRIORITY, 1);
    params.put(WorkflowModel.ASSOC_PACKAGE, workflowService.createPackage(null));
    WorkflowPath adhocPath2 = workflowService.startWorkflow(adhocDef.getId(), params);
    String workflowId2 = adhocPath2.getInstance().getId();
    workflows.add(workflowId2);
    WorkflowTask startTask2 = workflowService.getStartTask(workflowId2);
    workflowService.endTask(startTask2.getId(), null);
    // Filter based on due-date and skip first result. Should return nothing instead of
    // the second task, since only one matches and one is skipped
    // Due after tomorrow, started task shouldn't be in it
    String url = MessageFormat.format(URL_TASKS_DUE_AFTER_AND_SKIP, ISO8601DateFormat.format(dueDateCal.getTime()), 1);
    json = getDataFromRequest(url);
    JSONArray resultArray = json.getJSONArray("data");
    assertEquals(0, resultArray.length());
}
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 7 with WorkflowDefinition

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

the class AbstractWorkflowRestApiTest method testTaskInstancesForWorkflowGet.

public void testTaskInstancesForWorkflowGet() throws Exception {
    // Check starts with no workflow.
    personManager.setUser(USER2);
    sendRequest(new GetRequest(MessageFormat.format(URL_WORKFLOW_TASKS, "Foo")), Status.STATUS_INTERNAL_SERVER_ERROR);
    // 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));
    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);
    // End start task.
    WorkflowTask startTask = workflowService.getStartTask(workflowId);
    String startTaskId = startTask.getId();
    workflowService.endTask(startTaskId, null);
    // Check USER2 now has one task.
    List<WorkflowTask> tasks = workflowService.getAssignedTasks(USER2, WorkflowTaskState.IN_PROGRESS);
    assertEquals(1, tasks.size());
    WorkflowTask task = tasks.get(0);
    // Retrieve tasks using the workflow instance
    String baseUrl = MessageFormat.format(URL_WORKFLOW_TASKS, workflowId);
    // Check returns the completed start task.
    String adhocTaskId = task.getId();
    checkTasksMatch(baseUrl, startTaskId);
    String completedUrl = baseUrl + "?state=" + WorkflowTaskState.COMPLETED;
    checkTasksMatch(completedUrl, startTaskId);
    personManager.setUser(USER2);
    String inProgressUrl = baseUrl + "?state=" + WorkflowTaskState.IN_PROGRESS;
    checkTasksMatch(inProgressUrl, adhocTaskId);
    String user1Url = baseUrl + "?authority=" + USER1;
    checkTasksMatch(user1Url, startTaskId);
    String user2Url = baseUrl + "?authority=" + USER2;
    checkTasksMatch(user2Url, adhocTaskId);
    String user1CompletedURL = user1Url + "&state=" + WorkflowTaskState.COMPLETED;
    checkTasksMatch(user1CompletedURL, startTaskId);
    String user1InProgressURL = user1Url + "&state=" + WorkflowTaskState.IN_PROGRESS;
    checkTasksMatch(user1InProgressURL);
    String user2CompletedURL = user2Url + "&state=" + WorkflowTaskState.COMPLETED;
    checkTasksMatch(user2CompletedURL);
    String user2InProgressURL = user2Url + "&state=" + WorkflowTaskState.IN_PROGRESS;
    checkTasksMatch(user2InProgressURL, adhocTaskId);
}
Also used : Serializable(java.io.Serializable) HashMap(java.util.HashMap) QName(org.alfresco.service.namespace.QName) GetRequest(org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest) Calendar(java.util.Calendar) 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)

Example 8 with WorkflowDefinition

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

the class WorkflowModelBuilderTest method testBuildWorkflowTaskDetailed.

@SuppressWarnings("unchecked")
public void testBuildWorkflowTaskDetailed() throws Exception {
    Date date = new Date();
    WorkflowTask workflowTask = makeTask(date);
    Map<String, Object> model = builder.buildDetailed(workflowTask);
    Object id = model.get(WorkflowModelBuilder.TASK_ID);
    assertEquals(workflowTask.getId(), id);
    Object url = model.get(WorkflowModelBuilder.TASK_URL);
    assertEquals("api/task-instances/" + workflowTask.getId(), url);
    assertEquals(workflowTask.getName(), model.get(WorkflowModelBuilder.TASK_NAME));
    assertEquals(workflowTask.getTitle(), model.get(WorkflowModelBuilder.TASK_TITLE));
    assertEquals(workflowTask.getDescription(), model.get(WorkflowModelBuilder.TASK_DESCRIPTION));
    assertEquals(workflowTask.getState().name(), model.get(WorkflowModelBuilder.TASK_STATE));
    assertEquals(false, model.get(WorkflowModelBuilder.TASK_IS_POOLED));
    Map<String, Object> owner = (Map<String, Object>) model.get(WorkflowModelBuilder.TASK_OWNER);
    assertEquals(userName, owner.get(WorkflowModelBuilder.PERSON_USER_NAME));
    assertEquals(firstName, owner.get(WorkflowModelBuilder.PERSON_FIRST_NAME));
    assertEquals(lastName, owner.get(WorkflowModelBuilder.PERSON_LAST_NAME));
    Map<String, Object> props = (Map<String, Object>) model.get(WorkflowModelBuilder.TASK_PROPERTIES);
    assertEquals(workflowTask.getProperties().size() + 1, props.size());
    Map<String, Object> workflowInstance = (Map<String, Object>) model.get(WorkflowModelBuilder.TASK_WORKFLOW_INSTANCE);
    WorkflowInstance instance = workflowTask.getPath().getInstance();
    assertEquals(instance.getId(), workflowInstance.get(WorkflowModelBuilder.TASK_WORKFLOW_INSTANCE_ID));
    assertEquals(instance.isActive(), workflowInstance.get(WorkflowModelBuilder.TASK_WORKFLOW_INSTANCE_IS_ACTIVE));
    String startDateStr = ISO8601DateFormat.format(instance.getStartDate());
    String startDateBuilderStr = ISO8601DateFormat.formatToZulu((String) workflowInstance.get(WorkflowModelBuilder.TASK_WORKFLOW_INSTANCE_START_DATE));
    assertEquals(startDateStr, startDateBuilderStr);
    WorkflowDefinition workflowDef = instance.getDefinition();
    assertEquals(workflowDef.getName(), workflowInstance.get(WorkflowModelBuilder.TASK_WORKFLOW_INSTANCE_NAME));
    assertEquals(workflowDef.getTitle(), workflowInstance.get(WorkflowModelBuilder.TASK_WORKFLOW_INSTANCE_TITLE));
    assertEquals(workflowDef.getDescription(), workflowInstance.get(WorkflowModelBuilder.TASK_WORKFLOW_INSTANCE_DESCRIPTION));
    Map<String, Object> actualDefinition = (Map<String, Object>) model.get(WorkflowModelBuilder.TASK_DEFINITION);
    WorkflowTaskDefinition taskDef = workflowTask.getDefinition();
    assertEquals(taskDef.getId(), actualDefinition.get(WorkflowModelBuilder.TASK_DEFINITION_ID));
    Map<String, Object> actualType = (Map<String, Object>) actualDefinition.get(WorkflowModelBuilder.TASK_DEFINITION_TYPE);
    TypeDefinition taskType = taskDef.getMetadata();
    assertEquals(taskType.getName(), actualType.get(WorkflowModelBuilder.TYPE_DEFINITION_NAME));
    assertEquals(taskType.getTitle(dictionaryService), actualType.get(WorkflowModelBuilder.TYPE_DEFINITION_TITLE));
    assertEquals(taskType.getDescription(dictionaryService), actualType.get(WorkflowModelBuilder.TYPE_DEFINITION_DESCRIPTION));
    Map<String, Object> actualNode = (Map<String, Object>) actualDefinition.get(WorkflowModelBuilder.TASK_DEFINITION_NODE);
    WorkflowNode taskNode = taskDef.getNode();
    assertEquals(taskNode.getName(), actualNode.get(WorkflowModelBuilder.WORKFLOW_NODE_NAME));
    assertEquals(taskNode.getTitle(), actualNode.get(WorkflowModelBuilder.WORKFLOW_NODE_TITLE));
    assertEquals(taskNode.getDescription(), actualNode.get(WorkflowModelBuilder.WORKFLOW_NODE_DESCRIPTION));
    assertEquals(taskNode.isTaskNode(), actualNode.get(WorkflowModelBuilder.WORKFLOW_NODE_IS_TASK_NODE));
    List<Map<String, Object>> transitions = (List<Map<String, Object>>) actualNode.get(WorkflowModelBuilder.WORKFLOW_NODE_TRANSITIONS);
    WorkflowTransition[] taskTransitions = taskNode.getTransitions();
    int i = 0;
    for (Map<String, Object> transition : transitions) {
        WorkflowTransition workflowTransition = taskTransitions[i];
        assertEquals(workflowTransition.getId(), transition.get(WorkflowModelBuilder.WORKFLOW_NODE_TRANSITION_ID));
        assertEquals(workflowTransition.getTitle(), transition.get(WorkflowModelBuilder.WORKFLOW_NODE_TRANSITION_TITLE));
        assertEquals(workflowTransition.getDescription(), transition.get(WorkflowModelBuilder.WORKFLOW_NODE_TRANSITION_DESCRIPTION));
        assertEquals(workflowTransition.isDefault(), transition.get(WorkflowModelBuilder.WORKFLOW_NODE_TRANSITION_IS_DEFAULT));
        assertEquals(false, transition.get(WorkflowModelBuilder.WORKFLOW_NODE_TRANSITION_IS_HIDDEN));
        i++;
    }
}
Also used : WorkflowTaskDefinition(org.alfresco.service.cmr.workflow.WorkflowTaskDefinition) WorkflowDefinition(org.alfresco.service.cmr.workflow.WorkflowDefinition) WorkflowTask(org.alfresco.service.cmr.workflow.WorkflowTask) WorkflowInstance(org.alfresco.service.cmr.workflow.WorkflowInstance) WorkflowNode(org.alfresco.service.cmr.workflow.WorkflowNode) Date(java.util.Date) TypeDefinition(org.alfresco.service.cmr.dictionary.TypeDefinition) WorkflowTransition(org.alfresco.service.cmr.workflow.WorkflowTransition) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map)

Example 9 with WorkflowDefinition

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

the class WorkflowModelBuilderTest method makeWorkflowInstance.

private WorkflowInstance makeWorkflowInstance(WorkflowTaskDefinition taskDefinition) {
    String id = "The id";
    boolean active = true;
    Date startDate = new Date();
    Date endDate = new Date();
    NodeRef initiator = person;
    WorkflowDefinition definition = new WorkflowDefinition("The Id", "The Name", "The Version", "The Title", "The Description", taskDefinition);
    return new WorkflowInstance(id, definition, "", initiator, workflowPackage, workflowPackage, active, startDate, endDate);
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) WorkflowDefinition(org.alfresco.service.cmr.workflow.WorkflowDefinition) WorkflowInstance(org.alfresco.service.cmr.workflow.WorkflowInstance) Date(java.util.Date)

Example 10 with WorkflowDefinition

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

the class WorkflowModelBuilderTest method makePath.

private WorkflowPath makePath() {
    String id = "pathId$1";
    Date startDate = new Date();
    WorkflowDefinition definition = new WorkflowDefinition("The Id", "The Name", "1", "The Title", "The Description", null);
    WorkflowInstance instance = new WorkflowInstance("", definition, null, null, null, workflowPackage, true, startDate, null);
    return new WorkflowPath(id, instance, null, true);
}
Also used : WorkflowDefinition(org.alfresco.service.cmr.workflow.WorkflowDefinition) WorkflowPath(org.alfresco.service.cmr.workflow.WorkflowPath) WorkflowInstance(org.alfresco.service.cmr.workflow.WorkflowInstance) 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