Search in sources :

Example 16 with WorkflowTask

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

the class WorkflowBean method getTasksToDo.

/**
 * Returns a list of nodes representing the to do tasks the
 * current user has.
 *
 * @return List of to do tasks
 */
public List<Node> getTasksToDo() {
    if (this.tasks == null) {
        // get the current username
        FacesContext context = FacesContext.getCurrentInstance();
        User user = Application.getCurrentUser(context);
        String userName = user.getUserName();
        UserTransaction tx = null;
        try {
            tx = Repository.getUserTransaction(context, true);
            tx.begin();
            // get the current in progress tasks for the current user
            List<WorkflowTask> tasks = this.getWorkflowService().getAssignedTasks(userName, WorkflowTaskState.IN_PROGRESS, true);
            // create a list of transient nodes to represent
            this.tasks = new ArrayList<Node>(tasks.size());
            for (WorkflowTask task : tasks) {
                Node node = createTask(task);
                this.tasks.add(node);
                if (logger.isDebugEnabled())
                    logger.debug("Added to do task: " + node);
            }
            // commit the changes
            tx.commit();
        } catch (Throwable e) {
            // rollback the transaction
            try {
                if (tx != null) {
                    tx.rollback();
                }
            } catch (Exception ex) {
            }
            Utils.addErrorMessage("Failed to get to do tasks: " + e.toString(), e);
        }
    }
    return this.tasks;
}
Also used : UserTransaction(javax.transaction.UserTransaction) FacesContext(javax.faces.context.FacesContext) User(org.alfresco.web.bean.repository.User) Node(org.alfresco.web.bean.repository.Node) TransientNode(org.alfresco.web.bean.repository.TransientNode) TransientMapNode(org.alfresco.web.bean.repository.TransientMapNode) WorkflowTask(org.alfresco.service.cmr.workflow.WorkflowTask)

Example 17 with WorkflowTask

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

the class TaskInfoBean method sendTaskInfo.

/**
 * Returns information for the workflow task identified by the 'taskId'
 * parameter found in the ExternalContext.
 * <p>
 * The result is the formatted HTML to show on the client.
 */
public void sendTaskInfo() throws IOException {
    FacesContext context = FacesContext.getCurrentInstance();
    ResponseWriter out = context.getResponseWriter();
    String taskId = (String) context.getExternalContext().getRequestParameterMap().get("taskId");
    if (taskId == null || taskId.length() == 0) {
        throw new IllegalArgumentException("'taskId' parameter is missing");
    }
    WorkflowTask task = this.getWorkflowService().getTaskById(taskId);
    if (task != null) {
        Repository.getServiceRegistry(context).getTemplateService().processTemplate("/alfresco/templates/client/task_summary_panel.ftl", getModel(task), out);
    } else {
        out.write("<span class='errorMessage'>Task could not be found.</span>");
    }
}
Also used : FacesContext(javax.faces.context.FacesContext) ResponseWriter(javax.faces.context.ResponseWriter) WorkflowTask(org.alfresco.service.cmr.workflow.WorkflowTask)

Example 18 with WorkflowTask

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

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

the class ManageTaskDialog method returnOwnership.

@SuppressWarnings("deprecation")
public String returnOwnership() {
    String outcome = getDefaultFinishOutcome();
    if (LOGGER.isDebugEnabled())
        LOGGER.debug("Returning ownership of task to pool: " + this.getWorkflowTask().id);
    FacesContext context = FacesContext.getCurrentInstance();
    // before returning ownership check the task still exists and is not
    // completed
    WorkflowTask checkTask = this.getWorkflowService().getTaskById(this.getWorkflowTask().id);
    if (checkTask == null || checkTask.state == WorkflowTaskState.COMPLETED) {
        Utils.addErrorMessage(Application.getMessage(context, "invalid_task"));
        return outcome;
    }
    UserTransaction tx = null;
    try {
        tx = Repository.getUserTransaction(context);
        tx.begin();
        // prepare the edited parameters for saving
        Map<QName, Serializable> params = new HashMap<QName, Serializable>();
        params.put(ContentModel.PROP_OWNER, null);
        // update the task with the updated parameters and resources
        updateResources();
        this.getWorkflowService().updateTask(this.getWorkflowTask().id, params, null, null);
        // commit the changes
        tx.commit();
    } 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) HashMap(java.util.HashMap) QName(org.alfresco.service.namespace.QName) WorkflowTask(org.alfresco.service.cmr.workflow.WorkflowTask)

Example 20 with WorkflowTask

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

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