Search in sources :

Example 1 with WorkflowNode

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

the class WorkflowModelBuilderTest method makeNode.

private WorkflowNode makeNode() {
    String name = "The Node Name";
    String title = "The Node Title";
    String description = "The Node Description";
    String type = "The Node Type";
    boolean isTaskNode = true;
    WorkflowTransition workflowTransition = makeTransition();
    return new WorkflowNode(name, title, description, type, isTaskNode, workflowTransition);
}
Also used : WorkflowTransition(org.alfresco.service.cmr.workflow.WorkflowTransition) WorkflowNode(org.alfresco.service.cmr.workflow.WorkflowNode)

Example 2 with WorkflowNode

use of org.alfresco.service.cmr.workflow.WorkflowNode 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 3 with WorkflowNode

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

the class WorkflowModelBuilderTest method makeTaskDefinition.

private WorkflowTaskDefinition makeTaskDefinition() {
    String id = "The Definition Id";
    TypeDefinition metadata = makeTypeDefinition();
    WorkflowNode node = makeNode();
    return new WorkflowTaskDefinition(id, node, metadata);
}
Also used : WorkflowTaskDefinition(org.alfresco.service.cmr.workflow.WorkflowTaskDefinition) WorkflowNode(org.alfresco.service.cmr.workflow.WorkflowNode) TypeDefinition(org.alfresco.service.cmr.dictionary.TypeDefinition)

Example 4 with WorkflowNode

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

the class AbstractWorkflowRestApiTest method checkWorkflowTaskDefinition.

private void checkWorkflowTaskDefinition(WorkflowTaskDefinition wfDefinition, JSONObject definition) throws Exception {
    assertNotNull(definition);
    assertEquals(wfDefinition.getId(), definition.getString("id"));
    assertTrue(definition.has("url"));
    JSONObject type = definition.getJSONObject("type");
    TypeDefinition startType = (wfDefinition).getMetadata();
    assertNotNull(type);
    assertEquals(startType.getName().toPrefixString(), type.getString("name"));
    assertEquals(startType.getTitle(this.dictionaryService), type.getString("title"));
    assertEquals(startType.getDescription(this.dictionaryService), type.getString("description"));
    assertTrue(type.has("url"));
    JSONObject node = definition.getJSONObject("node");
    WorkflowNode startNode = wfDefinition.getNode();
    assertNotNull(node);
    assertEquals(startNode.getName(), node.getString("name"));
    assertEquals(startNode.getTitle(), node.getString("title"));
    assertEquals(startNode.getDescription(), node.getString("description"));
    assertEquals(startNode.isTaskNode(), node.getBoolean("isTaskNode"));
    JSONArray transitions = node.getJSONArray("transitions");
    WorkflowTransition[] startTransitions = startNode.getTransitions();
    assertNotNull(transitions);
    assertEquals(startTransitions.length, transitions.length());
    for (int i = 0; i < transitions.length(); i++) {
        JSONObject transition = transitions.getJSONObject(i);
        WorkflowTransition startTransition = startTransitions[i];
        assertNotNull(transition);
        if (startTransition.getId() == null) {
            assertEquals("", transition.getString("id"));
        } else {
            assertEquals(startTransition.getId(), transition.getString("id"));
        }
        assertEquals(startTransition.getTitle(), transition.getString("title"));
        assertEquals(startTransition.getDescription(), transition.getString("description"));
        assertEquals(startTransition.isDefault(), transition.getBoolean("isDefault"));
        assertTrue(transition.has("isHidden"));
    }
}
Also used : JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) WorkflowTransition(org.alfresco.service.cmr.workflow.WorkflowTransition) WorkflowNode(org.alfresco.service.cmr.workflow.WorkflowNode) TypeDefinition(org.alfresco.service.cmr.dictionary.TypeDefinition)

Aggregations

WorkflowNode (org.alfresco.service.cmr.workflow.WorkflowNode)4 TypeDefinition (org.alfresco.service.cmr.dictionary.TypeDefinition)3 WorkflowTransition (org.alfresco.service.cmr.workflow.WorkflowTransition)3 WorkflowTaskDefinition (org.alfresco.service.cmr.workflow.WorkflowTaskDefinition)2 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 WorkflowDefinition (org.alfresco.service.cmr.workflow.WorkflowDefinition)1 WorkflowInstance (org.alfresco.service.cmr.workflow.WorkflowInstance)1 WorkflowTask (org.alfresco.service.cmr.workflow.WorkflowTask)1 JSONArray (org.json.JSONArray)1 JSONObject (org.json.JSONObject)1