Search in sources :

Example 36 with WorkflowTask

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

the class WorkflowModelBuilderTest method testBuildWorkflowTask.

@SuppressWarnings("unchecked")
public void testBuildWorkflowTask() throws Exception {
    Date date = new Date();
    WorkflowTask task = makeTask(date);
    Map<String, Object> model = builder.buildSimple(task, null);
    Object id = model.get(WorkflowModelBuilder.TASK_ID);
    assertEquals(task.getId(), id);
    Object url = model.get(WorkflowModelBuilder.TASK_URL);
    assertEquals("api/task-instances/" + task.getId(), url);
    assertEquals(task.getName(), model.get(WorkflowModelBuilder.TASK_NAME));
    assertEquals(task.getTitle(), model.get(WorkflowModelBuilder.TASK_TITLE));
    assertEquals(task.getDescription(), model.get(WorkflowModelBuilder.TASK_DESCRIPTION));
    assertEquals(task.getState().name(), model.get(WorkflowModelBuilder.TASK_STATE));
    assertNull(model.get(WorkflowModelBuilder.TASK_OUTCOME));
    assertEquals(false, model.get(WorkflowModelBuilder.TASK_IS_POOLED));
    assertEquals(false, model.get(WorkflowModelBuilder.TASK_IS_EDITABLE));
    assertEquals(false, model.get(WorkflowModelBuilder.TASK_IS_REASSIGNABLE));
    assertEquals(false, model.get(WorkflowModelBuilder.TASK_IS_CLAIMABLE));
    assertEquals(false, model.get(WorkflowModelBuilder.TASK_IS_RELEASABLE));
    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(task.getProperties().size() + 1, props.size());
    assertEquals(5, props.get("test_int"));
    assertEquals(false, props.get("test_boolean"));
    assertEquals("foo bar", props.get("test_string"));
    String dateStr = (String) props.get("test_date");
    assertEquals(date, ISO8601DateFormat.parse(dateStr));
    Map<String, Object> workflowInstance = (Map<String, Object>) model.get(WorkflowModelBuilder.TASK_WORKFLOW_INSTANCE);
    assertNotNull(workflowInstance);
    WorkflowInstance instance = task.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 workFlowStartDateStr = (String) workflowInstance.get(WorkflowModelBuilder.TASK_WORKFLOW_INSTANCE_START_DATE);
    assertEquals(startDateStr, ISO8601DateFormat.formatToZulu(workFlowStartDateStr));
    task.getProperties().put(WorkflowModel.ASSOC_POOLED_ACTORS, new ArrayList<NodeRef>(0));
    model = builder.buildSimple(task, null);
    assertEquals(false, model.get(WorkflowModelBuilder.TASK_IS_POOLED));
    ArrayList<NodeRef> actors = new ArrayList<NodeRef>(1);
    actors.add(person);
    task.getProperties().put(WorkflowModel.ASSOC_POOLED_ACTORS, actors);
    model = builder.buildSimple(task, null);
    assertEquals(true, model.get(WorkflowModelBuilder.TASK_IS_POOLED));
    model = builder.buildSimple(task, Arrays.asList("test_int", "test_string"));
    // Check task owner still created properly.
    owner = (Map<String, Object>) model.get(WorkflowModelBuilder.TASK_OWNER);
    assertEquals(userName, owner.get(WorkflowModelBuilder.PERSON_USER_NAME));
    // Check properties populated correctly
    props = (Map<String, Object>) model.get(WorkflowModelBuilder.TASK_PROPERTIES);
    assertEquals(2, props.size());
    assertEquals(5, props.get("test_int"));
    assertEquals("foo bar", props.get("test_string"));
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) ArrayList(java.util.ArrayList) WorkflowTask(org.alfresco.service.cmr.workflow.WorkflowTask) WorkflowInstance(org.alfresco.service.cmr.workflow.WorkflowInstance) HashMap(java.util.HashMap) Map(java.util.Map) Date(java.util.Date)

Example 37 with WorkflowTask

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

the class WorkflowModelBuilderTest method makeTask.

private WorkflowTask makeTask(Date date) {
    String description = "Task Desc";
    String id = "testId$1";
    String name = "Task Name";
    WorkflowTaskState state = WorkflowTaskState.IN_PROGRESS;
    String title = "Task Title";
    WorkflowPath path = makePath();
    WorkflowTaskDefinition definition = makeTaskDefinition();
    HashMap<QName, Serializable> properties = makeTaskProperties(date);
    return new WorkflowTask(id, definition, name, title, description, state, path, properties);
}
Also used : Serializable(java.io.Serializable) QName(org.alfresco.service.namespace.QName) WorkflowTaskDefinition(org.alfresco.service.cmr.workflow.WorkflowTaskDefinition) WorkflowPath(org.alfresco.service.cmr.workflow.WorkflowPath) WorkflowTaskState(org.alfresco.service.cmr.workflow.WorkflowTaskState) WorkflowTask(org.alfresco.service.cmr.workflow.WorkflowTask)

Aggregations

WorkflowTask (org.alfresco.service.cmr.workflow.WorkflowTask)37 Serializable (java.io.Serializable)22 HashMap (java.util.HashMap)21 QName (org.alfresco.service.namespace.QName)20 Date (java.util.Date)15 WorkflowPath (org.alfresco.service.cmr.workflow.WorkflowPath)15 WorkflowDefinition (org.alfresco.service.cmr.workflow.WorkflowDefinition)14 JSONObject (org.json.JSONObject)11 GetRequest (org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest)11 FacesContext (javax.faces.context.FacesContext)10 Response (org.springframework.extensions.webscripts.TestWebScriptServer.Response)10 WorkflowInstance (org.alfresco.service.cmr.workflow.WorkflowInstance)8 UserTransaction (javax.transaction.UserTransaction)7 JSONArray (org.json.JSONArray)7 Calendar (java.util.Calendar)6 NodeRef (org.alfresco.service.cmr.repository.NodeRef)6 WorkflowTaskQuery (org.alfresco.service.cmr.workflow.WorkflowTaskQuery)6 Node (org.alfresco.web.bean.repository.Node)6 User (org.alfresco.web.bean.repository.User)6 TransientNode (org.alfresco.web.bean.repository.TransientNode)5