Search in sources :

Example 1 with WorkflowTransition

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

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

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

the class WorkflowModelBuilder method buildWorkflowNode.

private Map<String, Object> buildWorkflowNode(WorkflowNode workflowNode, WorkflowTask workflowTask) {
    Map<String, Object> model = new HashMap<String, Object>();
    model.put(WORKFLOW_NODE_NAME, workflowNode.getName());
    model.put(WORKFLOW_NODE_TITLE, workflowNode.getTitle());
    model.put(WORKFLOW_NODE_DESCRIPTION, workflowNode.getDescription());
    model.put(WORKFLOW_NODE_IS_TASK_NODE, workflowNode.isTaskNode());
    List<Map<String, Object>> transitions = new ArrayList<Map<String, Object>>();
    List<?> hiddenTransitions = getHiddenTransitions(workflowTask.getProperties());
    for (WorkflowTransition workflowTransition : workflowNode.getTransitions()) {
        Map<String, Object> transitionModel = buildTransition(workflowTransition, hiddenTransitions);
        transitions.add(transitionModel);
    }
    model.put(WORKFLOW_NODE_TRANSITIONS, transitions);
    return model;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) WorkflowTransition(org.alfresco.service.cmr.workflow.WorkflowTransition) HashMap(java.util.HashMap) Map(java.util.Map)

Example 4 with WorkflowTransition

use of org.alfresco.service.cmr.workflow.WorkflowTransition in project acs-community-packaging by Alfresco.

the class UIWorkflowHistory method encodeBegin.

@Override
@SuppressWarnings("unchecked")
public void encodeBegin(FacesContext context) throws IOException {
    if (!isRendered())
        return;
    WorkflowInstance wi = getValue();
    if (wi != null) {
        ResponseWriter out = context.getResponseWriter();
        ResourceBundle bundle = Application.getBundle(context);
        if (logger.isDebugEnabled())
            logger.debug("Retrieving workflow history for workflow instance: " + wi);
        WorkflowTaskQuery query = new WorkflowTaskQuery();
        query.setActive(null);
        query.setProcessId(wi.id);
        query.setTaskState(WorkflowTaskState.COMPLETED);
        query.setOrderBy(new WorkflowTaskQuery.OrderBy[] { WorkflowTaskQuery.OrderBy.TaskCreated_Desc, WorkflowTaskQuery.OrderBy.TaskActor_Asc });
        List<WorkflowTask> tasks = Repository.getServiceRegistry(context).getWorkflowService().queryTasks(query);
        if (tasks.size() == 0) {
            out.write("<div style='margin-left:18px;margin-top: 6px;'>");
            out.write(bundle.getString(MSG_NO_HISTORY));
            out.write("</div>");
        } else {
            // output surrounding table and style if necessary
            out.write("<table cellspacing='2' cellpadding='1' border='0'");
            if (this.getAttributes().get("style") != null) {
                out.write(" style=\"");
                out.write((String) this.getAttributes().get("style"));
                out.write("\"");
            }
            if (this.getAttributes().get("styleClass") != null) {
                out.write(" class=\"");
                out.write((String) this.getAttributes().get("styleClass"));
                out.write("\"");
            }
            out.write(">");
            // output a header row
            out.write("<tr align=left><th>");
            out.write(bundle.getString(MSG_DESCRIPTION));
            out.write("</th><th>");
            out.write(bundle.getString(MSG_TASK));
            out.write("</th><th>");
            out.write(bundle.getString(MSG_ID));
            out.write("</th><th>");
            out.write(bundle.getString(MSG_CREATED));
            out.write("</th><th>");
            out.write(bundle.getString(MSG_ASSIGNEE));
            out.write("</th><th>");
            out.write(bundle.getString(MSG_COMMENT));
            out.write("</th><th>");
            out.write(bundle.getString(MSG_DATE_COMPLETED));
            out.write("</th><th>");
            out.write(bundle.getString(MSG_OUTCOME));
            out.write("</th></tr>");
            // output a row for each previous completed task
            for (WorkflowTask task : tasks) {
                String id = null;
                Serializable idObject = task.properties.get(WorkflowModel.PROP_TASK_ID);
                if (idObject instanceof Long) {
                    id = ((Long) idObject).toString();
                } else {
                    id = idObject.toString();
                }
                String desc = (String) task.properties.get(WorkflowModel.PROP_DESCRIPTION);
                Date createdDate = (Date) task.properties.get(ContentModel.PROP_CREATED);
                String owner = (String) task.properties.get(ContentModel.PROP_OWNER);
                String comment = (String) task.properties.get(WorkflowModel.PROP_COMMENT);
                Date completedDate = (Date) task.properties.get(WorkflowModel.PROP_COMPLETION_DATE);
                String transition = (String) task.properties.get(WorkflowModel.PROP_OUTCOME);
                String outcome = "";
                if (transition != null) {
                    WorkflowTransition[] transitions = task.definition.node.transitions;
                    for (WorkflowTransition trans : transitions) {
                        if (trans.id.equals(transition)) {
                            outcome = trans.title;
                            break;
                        }
                    }
                }
                if ((outcome == null || outcome.equals("")) && transition != null) {
                    // it's possible in Activiti to have tasks without an outcome set,
                    // in this case default to the transition, if there is one.
                    outcome = transition;
                }
                // ACE-1154
                if (outcome.equals("")) {
                    outcome = I18NUtil.getMessage(DEFAULT_TRANSITION_TITLE);
                }
                out.write("<tr><td>");
                out.write(desc == null ? "" : Utils.encode(desc));
                out.write("</td><td>");
                out.write(Utils.encode(task.title));
                out.write("</td><td>");
                out.write(id);
                out.write("</td><td>");
                out.write(Utils.getDateTimeFormat(context).format(createdDate));
                out.write("</td><td>");
                out.write(owner == null ? "" : owner);
                out.write("</td><td>");
                out.write(comment == null ? "" : Utils.encode(comment));
                out.write("</td><td>");
                out.write(Utils.getDateTimeFormat(context).format(completedDate));
                out.write("</td><td>");
                out.write(outcome);
                out.write("</td></tr>");
            }
            // output the end of the table
            out.write("</table>");
        }
    }
}
Also used : Serializable(java.io.Serializable) ResponseWriter(javax.faces.context.ResponseWriter) WorkflowTransition(org.alfresco.service.cmr.workflow.WorkflowTransition) ResourceBundle(java.util.ResourceBundle) WorkflowTask(org.alfresco.service.cmr.workflow.WorkflowTask) WorkflowInstance(org.alfresco.service.cmr.workflow.WorkflowInstance) Date(java.util.Date) WorkflowTaskQuery(org.alfresco.service.cmr.workflow.WorkflowTaskQuery)

Example 5 with WorkflowTransition

use of org.alfresco.service.cmr.workflow.WorkflowTransition in project acs-community-packaging by Alfresco.

the class ManageTaskDialog method transition.

@SuppressWarnings("deprecation")
public String transition() {
    String outcome = getDefaultFinishOutcome();
    if (LOGGER.isDebugEnabled())
        LOGGER.debug("Transitioning task: " + this.getWorkflowTask().id);
    // before transitioning check the task still exists and is not completed
    FacesContext context = FacesContext.getCurrentInstance();
    WorkflowTask checkTask = this.getWorkflowService().getTaskById(this.getWorkflowTask().id);
    if (checkTask == null || checkTask.state == WorkflowTaskState.COMPLETED) {
        Utils.addErrorMessage(Application.getMessage(context, "invalid_task"));
        return outcome;
    }
    // to find out which transition button was pressed we need
    // to look for the button's id in the request parameters,
    // the first non-null result is the button that was pressed.
    Map<?, ?> reqParams = context.getExternalContext().getRequestParameterMap();
    String selectedTransition = null;
    for (WorkflowTransition trans : this.getWorkflowTransitions()) {
        Object result = reqParams.get(CLIENT_ID_PREFIX + FacesHelper.makeLegalId(trans.title));
        if (result != null) {
            // this was the button that was pressed
            selectedTransition = trans.id;
            break;
        }
    }
    UserTransaction tx = null;
    try {
        tx = Repository.getUserTransaction(context);
        tx.begin();
        // prepare the edited parameters for saving
        Map<QName, Serializable> params = WorkflowUtil.prepareTaskParams(this.taskNode);
        if (LOGGER.isDebugEnabled())
            LOGGER.debug("Transitioning task with parameters: " + params);
        // update the task with the updated parameters and resources
        updateResources();
        this.getWorkflowService().updateTask(this.getWorkflowTask().id, params, null, null);
        // signal the selected transition to the workflow task
        this.getWorkflowService().endTask(this.getWorkflowTask().id, selectedTransition);
        // commit the changes
        tx.commit();
        if (LOGGER.isDebugEnabled())
            LOGGER.debug("Ended task with transition: " + selectedTransition);
    } catch (Throwable e) {
        // rollback the transaction
        try {
            if (tx != null) {
                tx.rollback();
            }
        } catch (Exception ex) {
        }
        Utils.addErrorMessage(formatErrorMessage(e), e);
        outcome = this.getErrorOutcome(e);
    }
    return outcome;
}
Also used : UserTransaction(javax.transaction.UserTransaction) FacesContext(javax.faces.context.FacesContext) Serializable(java.io.Serializable) QName(org.alfresco.service.namespace.QName) WorkflowTransition(org.alfresco.service.cmr.workflow.WorkflowTransition) WorkflowTask(org.alfresco.service.cmr.workflow.WorkflowTask)

Aggregations

WorkflowTransition (org.alfresco.service.cmr.workflow.WorkflowTransition)7 WorkflowNode (org.alfresco.service.cmr.workflow.WorkflowNode)3 WorkflowTask (org.alfresco.service.cmr.workflow.WorkflowTask)3 Serializable (java.io.Serializable)2 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 TypeDefinition (org.alfresco.service.cmr.dictionary.TypeDefinition)2 WorkflowInstance (org.alfresco.service.cmr.workflow.WorkflowInstance)2 List (java.util.List)1 ResourceBundle (java.util.ResourceBundle)1 FacesContext (javax.faces.context.FacesContext)1 ResponseWriter (javax.faces.context.ResponseWriter)1 UserTransaction (javax.transaction.UserTransaction)1 WorkflowDefinition (org.alfresco.service.cmr.workflow.WorkflowDefinition)1 WorkflowTaskDefinition (org.alfresco.service.cmr.workflow.WorkflowTaskDefinition)1 WorkflowTaskQuery (org.alfresco.service.cmr.workflow.WorkflowTaskQuery)1 QName (org.alfresco.service.namespace.QName)1 DialogButtonConfig (org.alfresco.web.config.DialogsConfigElement.DialogButtonConfig)1