Search in sources :

Example 16 with WorkflowTaskQuery

use of org.alfresco.service.cmr.workflow.WorkflowTaskQuery in project alfresco-repository by Alfresco.

the class AbstractWorkflowServiceIntegrationTest method checkProcessNameQuery.

@SuppressWarnings("deprecation")
protected void checkProcessNameQuery(List<String> expectedTaskIds, WorkflowTaskState state) {
    WorkflowTaskQuery taskQuery = createWorkflowTaskQuery(state);
    // Test depricated method, using QName
    taskQuery.setProcessName(getAdhocProcessName());
    checkTasksFoundUsingQuery(expectedTaskIds, taskQuery);
    taskQuery = createWorkflowTaskQuery(state);
    taskQuery.setProcessName(QName.createQName("dummyProcessName"));
    checkNoTasksFoundUsingQuery(taskQuery);
    // Test method, using String
    taskQuery.setWorkflowDefinitionName(getAdhocProcessName().toPrefixString());
    checkTasksFoundUsingQuery(expectedTaskIds, taskQuery);
    taskQuery = createWorkflowTaskQuery(state);
    taskQuery.setWorkflowDefinitionName("dummyProcessName");
    checkNoTasksFoundUsingQuery(taskQuery);
}
Also used : WorkflowTaskQuery(org.alfresco.service.cmr.workflow.WorkflowTaskQuery)

Example 17 with WorkflowTaskQuery

use of org.alfresco.service.cmr.workflow.WorkflowTaskQuery in project alfresco-repository by Alfresco.

the class AbstractWorkflowServiceIntegrationTest method checkTaskIdQuery.

protected void checkTaskIdQuery(String expectedTaskId, WorkflowTaskState state) {
    WorkflowTaskQuery taskQuery = createWorkflowTaskQuery(state);
    taskQuery.setTaskId(expectedTaskId);
    checkTasksFoundUsingQuery(Arrays.asList(expectedTaskId), taskQuery);
    taskQuery = createWorkflowTaskQuery(state);
    taskQuery.setTaskId(BPMEngineRegistry.createGlobalId(getEngine(), "99999999999"));
    checkNoTasksFoundUsingQuery(taskQuery);
}
Also used : WorkflowTaskQuery(org.alfresco.service.cmr.workflow.WorkflowTaskQuery)

Example 18 with WorkflowTaskQuery

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

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

the class WorkflowBean method getAllActiveTasks.

// ------------------------------------------------------------------------------
// Bean Getters and Setters
/**
 * Returns a list of nodes representing the "all" active tasks.
 *
 * @return List of all active tasks
 */
public List<Node> getAllActiveTasks() {
    if (this.activeTasks == 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();
            // query for all active tasks
            WorkflowTaskQuery query = new WorkflowTaskQuery();
            List<WorkflowTask> tasks = this.getWorkflowService().queryTasks(query);
            // create a list of transient nodes to represent
            this.activeTasks = new ArrayList<Node>(tasks.size());
            for (WorkflowTask task : tasks) {
                Node node = createTask(task);
                this.activeTasks.add(node);
                if (logger.isDebugEnabled())
                    logger.debug("Added active 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 all active tasks: " + e.toString(), e);
        }
    }
    return this.activeTasks;
}
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) WorkflowTaskQuery(org.alfresco.service.cmr.workflow.WorkflowTaskQuery)

Example 20 with WorkflowTaskQuery

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

the class InviteByTicket method getInvitationStatus.

private String getInvitationStatus(NominatedInvitation invitation) {
    String invitee = invitation.getInviteeUserName();
    String site = invitation.getResourceName();
    // check is invitee is site member
    boolean isUserMember = serviceRegistry.getSiteService().isMember(site, invitee);
    WorkflowTaskQuery query = new WorkflowTaskQuery();
    query.setTaskName(WorkflowModelNominatedInvitation.WF_TASK_ACTIVIT_INVITE_PENDING);
    query.setProcessId(invitation.getInviteId());
    // query current workflow's task activitiInvitePendingTask
    List<WorkflowTask> pendingInvitationTasks = serviceRegistry.getWorkflowService().queryTasks(query, false);
    // if it's here - pending invitation
    if (!pendingInvitationTasks.isEmpty()) {
        return InviteInfo.INVITATION_STATUS_PENDING;
    } else if (isUserMember) {
        return InviteInfo.INVITATION_STATUS_ACCEPTED;
    } else {
        return InviteInfo.INVITATION_STATUS_REJECTED;
    }
}
Also used : WorkflowTask(org.alfresco.service.cmr.workflow.WorkflowTask) WorkflowTaskQuery(org.alfresco.service.cmr.workflow.WorkflowTaskQuery)

Aggregations

WorkflowTaskQuery (org.alfresco.service.cmr.workflow.WorkflowTaskQuery)34 WorkflowTask (org.alfresco.service.cmr.workflow.WorkflowTask)20 HashMap (java.util.HashMap)14 QName (org.alfresco.service.namespace.QName)14 Serializable (java.io.Serializable)9 ArrayList (java.util.ArrayList)6 WorkflowPath (org.alfresco.service.cmr.workflow.WorkflowPath)5 Test (org.junit.Test)5 NodeRef (org.alfresco.service.cmr.repository.NodeRef)4 WorkflowDefinition (org.alfresco.service.cmr.workflow.WorkflowDefinition)4 Map (java.util.Map)3 Task (org.activiti.engine.task.Task)3 Date (java.util.Date)2 List (java.util.List)2 FacesContext (javax.faces.context.FacesContext)2 UserTransaction (javax.transaction.UserTransaction)2 TaskQuery (org.activiti.engine.task.TaskQuery)2 WorkflowInstance (org.alfresco.service.cmr.workflow.WorkflowInstance)2 WorkflowTaskState (org.alfresco.service.cmr.workflow.WorkflowTaskState)2 WorkflowTransition (org.alfresco.service.cmr.workflow.WorkflowTransition)2