Search in sources :

Example 6 with WorkflowInstance

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

the class WorkflowModelBuilderTest method makePath.

private WorkflowPath makePath() {
    String id = "pathId$1";
    Date startDate = new Date();
    WorkflowDefinition definition = new WorkflowDefinition("The Id", "The Name", "1", "The Title", "The Description", null);
    WorkflowInstance instance = new WorkflowInstance("", definition, null, null, null, workflowPackage, true, startDate, null);
    return new WorkflowPath(id, instance, null, true);
}
Also used : WorkflowDefinition(org.alfresco.service.cmr.workflow.WorkflowDefinition) WorkflowPath(org.alfresco.service.cmr.workflow.WorkflowPath) WorkflowInstance(org.alfresco.service.cmr.workflow.WorkflowInstance) Date(java.util.Date)

Example 7 with WorkflowInstance

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

the class WorkflowInstanceGet method buildModel.

@Override
protected Map<String, Object> buildModel(WorkflowModelBuilder modelBuilder, WebScriptRequest req, Status status, Cache cache) {
    Map<String, String> params = req.getServiceMatch().getTemplateVars();
    // getting workflow instance id from request parameters
    String workflowInstanceId = params.get("workflow_instance_id");
    boolean includeTasks = getIncludeTasks(req);
    WorkflowInstance workflowInstance = workflowService.getWorkflowById(workflowInstanceId);
    // task was not found -> return 404
    if (workflowInstance == null) {
        throw new WebScriptException(HttpServletResponse.SC_NOT_FOUND, "Unable to find workflow instance with id: " + workflowInstanceId);
    }
    Map<String, Object> model = new HashMap<String, Object>();
    // build the model for ftl
    model.put("workflowInstance", modelBuilder.buildDetailed(workflowInstance, includeTasks));
    return model;
}
Also used : WebScriptException(org.springframework.extensions.webscripts.WebScriptException) HashMap(java.util.HashMap) WorkflowInstance(org.alfresco.service.cmr.workflow.WorkflowInstance)

Example 8 with WorkflowInstance

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

the class WorkflowInstancesGet method buildModel.

@Override
protected Map<String, Object> buildModel(WorkflowModelBuilder modelBuilder, WebScriptRequest req, Status status, Cache cache) {
    WorkflowInstanceQuery workflowInstanceQuery = new WorkflowInstanceQuery();
    Map<String, String> params = req.getServiceMatch().getTemplateVars();
    // state is not included into filters list as it will be taken into account before filtering
    WorkflowState state = getState(req);
    // get filter param values
    Map<QName, Object> filters = new HashMap<QName, Object>(9);
    if (req.getParameter(PARAM_INITIATOR) != null)
        filters.put(QNAME_INITIATOR, personService.getPerson(req.getParameter(PARAM_INITIATOR)));
    if (req.getParameter(PARAM_PRIORITY) != null)
        filters.put(WorkflowModel.PROP_WORKFLOW_PRIORITY, req.getParameter(PARAM_PRIORITY));
    String excludeParam = req.getParameter(PARAM_EXCLUDE);
    if (excludeParam != null && excludeParam.length() > 0) {
        workflowInstanceQuery.setExcludedDefinitions(Arrays.asList(StringUtils.tokenizeToStringArray(excludeParam, ",")));
    }
    // process all the date related parameters
    Map<DatePosition, Date> dateParams = new HashMap<DatePosition, Date>();
    Date dueBefore = getDateFromRequest(req, PARAM_DUE_BEFORE);
    if (dueBefore != null) {
        dateParams.put(DatePosition.BEFORE, dueBefore);
    }
    Date dueAfter = getDateFromRequest(req, PARAM_DUE_AFTER);
    if (dueAfter != null) {
        dateParams.put(DatePosition.AFTER, dueAfter);
    }
    if (dateParams.isEmpty()) {
        if (req.getParameter(PARAM_DUE_BEFORE) != null || req.getParameter(PARAM_DUE_AFTER) != null) {
            filters.put(WorkflowModel.PROP_WORKFLOW_DUE_DATE, null);
        }
    } else {
        filters.put(WorkflowModel.PROP_WORKFLOW_DUE_DATE, dateParams);
    }
    workflowInstanceQuery.setStartBefore(getDateFromRequest(req, PARAM_STARTED_BEFORE));
    workflowInstanceQuery.setStartAfter(getDateFromRequest(req, PARAM_STARTED_AFTER));
    workflowInstanceQuery.setEndBefore(getDateFromRequest(req, PARAM_COMPLETED_BEFORE));
    workflowInstanceQuery.setEndAfter(getDateFromRequest(req, PARAM_COMPLETED_AFTER));
    // determine if there is a definition id to filter by
    String workflowDefinitionId = params.get(VAR_DEFINITION_ID);
    if (workflowDefinitionId == null) {
        workflowDefinitionId = req.getParameter(PARAM_DEFINITION_ID);
    }
    // default workflow state to ACTIVE if not supplied
    if (state == null) {
        state = WorkflowState.ACTIVE;
    }
    workflowInstanceQuery.setActive(state == WorkflowState.ACTIVE);
    workflowInstanceQuery.setCustomProps(filters);
    List<WorkflowInstance> workflows = new ArrayList<WorkflowInstance>();
    int total = 0;
    // MNT-9074 My Tasks fails to render if tasks quantity is excessive
    int maxItems = getIntParameter(req, PARAM_MAX_ITEMS, DEFAULT_MAX_ITEMS);
    int skipCount = getIntParameter(req, PARAM_SKIP_COUNT, DEFAULT_SKIP_COUNT);
    if (workflowDefinitionId == null && req.getParameter(PARAM_DEFINITION_NAME) != null) {
        /**
         * If we are searching by workflow definition name then there may be many workflow definition instances.
         */
        int workingSkipCount = skipCount;
        /**
         * Yes there could be multiple process definitions with that definition name
         */
        String definitionName = req.getParameter(PARAM_DEFINITION_NAME);
        List<WorkflowDefinition> defs = workflowService.getAllDefinitionsByName(definitionName);
        int itemsToQuery = maxItems;
        for (WorkflowDefinition def : defs) {
            workflowDefinitionId = def.getId();
            workflowInstanceQuery.setWorkflowDefinitionId(workflowDefinitionId);
            if (maxItems < 0 || itemsToQuery > 0) {
                workflows.addAll(workflowService.getWorkflows(workflowInstanceQuery, itemsToQuery, workingSkipCount));
            }
            if (maxItems > 0) {
                itemsToQuery = maxItems - workflows.size();
            }
            total += (int) workflowService.countWorkflows(workflowInstanceQuery);
            if (workingSkipCount > 0) {
                workingSkipCount = skipCount - total;
                if (workingSkipCount < 0) {
                    workingSkipCount = 0;
                }
            }
        }
    } else {
        /**
         * This is the old single task implementation
         */
        if (workflowDefinitionId != null) {
            workflowInstanceQuery.setWorkflowDefinitionId(workflowDefinitionId);
        }
        workflows.addAll(workflowService.getWorkflows(workflowInstanceQuery, maxItems, skipCount));
        total = (int) workflowService.countWorkflows(workflowInstanceQuery);
    }
    List<Map<String, Object>> results = new ArrayList<Map<String, Object>>(total);
    // init empty list
    results.addAll(Arrays.asList((Map<String, Object>[]) new Map[total]));
    for (WorkflowInstance workflow : workflows) {
        // set to special index
        results.set(skipCount, modelBuilder.buildSimple(workflow));
        skipCount++;
    }
    // create and return results, paginated if necessary
    return createResultModel(req, "workflowInstances", results);
}
Also used : HashMap(java.util.HashMap) QName(org.alfresco.service.namespace.QName) ArrayList(java.util.ArrayList) WorkflowDefinition(org.alfresco.service.cmr.workflow.WorkflowDefinition) WorkflowInstance(org.alfresco.service.cmr.workflow.WorkflowInstance) Date(java.util.Date) WorkflowInstanceQuery(org.alfresco.service.cmr.workflow.WorkflowInstanceQuery) DatePosition(org.alfresco.service.cmr.workflow.WorkflowInstanceQuery.DatePosition) HashMap(java.util.HashMap) Map(java.util.Map)

Example 9 with WorkflowInstance

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

the class UINodeWorkflowInfo method renderAdvancedWorkflowInfo.

/**
 * Renders the advanced workflow details for the given node.
 *
 * @param context Faces context
 * @param node The node
 * @param nodeService The NodeService instance
 * @param ddService The Data Dictionary instance
 * @param workflowService The WorkflowService instance
 * @param out The response writer
 * @param bundle Message bundle to get strings from
 */
protected void renderAdvancedWorkflowInfo(FacesContext context, Node node, NodeService nodeService, DictionaryService ddService, WorkflowService workflowService, ResponseWriter out, ResourceBundle bundle) throws IOException {
    boolean isContent = true;
    QName type = nodeService.getType(node.getNodeRef());
    if (ddService.isSubClass(type, ContentModel.TYPE_FOLDER)) {
        isContent = false;
    }
    // anything for other types
    if (isContent) {
        // Render HTML for advanved workflow
        out.write("<div class=\"nodeWorkflowInfoTitle\">");
        out.write(bundle.getString("advanced_workflows"));
        out.write("</div><div class=\"nodeWorkflowInfoText\">");
        List<WorkflowInstance> workflows = workflowService.getWorkflowsForContent(node.getNodeRef(), true);
        if (workflows != null && workflows.size() > 0) {
            // list out all the workflows the document is part of
            if (isContent) {
                out.write(bundle.getString("doc_part_of_advanced_workflows"));
            } else {
                out.write(bundle.getString("space_part_of_advanced_workflows"));
            }
            out.write(":<br/><ul>");
            for (WorkflowInstance wi : workflows) {
                out.write("<li>");
                out.write(wi.definition.title);
                if (wi.description != null && wi.description.length() > 0) {
                    out.write("&nbsp;(");
                    out.write(Utils.encode(wi.description));
                    out.write(")");
                }
                out.write(" ");
                if (wi.startDate != null) {
                    out.write(bundle.getString("started_on").toLowerCase());
                    out.write("&nbsp;");
                    out.write(Utils.getDateFormat(context).format(wi.startDate));
                    out.write(" ");
                }
                if (wi.initiator != null) {
                    out.write(bundle.getString("by"));
                    out.write("&nbsp;");
                    out.write(Utils.encode(User.getFullName(nodeService, wi.initiator)));
                    out.write(".");
                }
                out.write("</li>");
            }
            out.write("</ul>");
        } else {
            if (isContent) {
                out.write(bundle.getString("doc_not_in_advanced_workflow"));
            } else {
                out.write(bundle.getString("space_not_in_advanced_workflow"));
            }
        }
        out.write("</div>");
    }
}
Also used : QName(org.alfresco.service.namespace.QName) WorkflowInstance(org.alfresco.service.cmr.workflow.WorkflowInstance)

Example 10 with WorkflowInstance

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

Aggregations

WorkflowInstance (org.alfresco.service.cmr.workflow.WorkflowInstance)18 HashMap (java.util.HashMap)11 Date (java.util.Date)10 WorkflowDefinition (org.alfresco.service.cmr.workflow.WorkflowDefinition)8 WorkflowTask (org.alfresco.service.cmr.workflow.WorkflowTask)8 QName (org.alfresco.service.namespace.QName)8 Serializable (java.io.Serializable)6 Map (java.util.Map)6 WorkflowPath (org.alfresco.service.cmr.workflow.WorkflowPath)5 ArrayList (java.util.ArrayList)4 NodeRef (org.alfresco.service.cmr.repository.NodeRef)4 WebScriptException (org.springframework.extensions.webscripts.WebScriptException)3 ResourceBundle (java.util.ResourceBundle)2 ResponseWriter (javax.faces.context.ResponseWriter)2 WorkflowTaskDefinition (org.alfresco.service.cmr.workflow.WorkflowTaskDefinition)2 WorkflowTransition (org.alfresco.service.cmr.workflow.WorkflowTransition)2 JSONArray (org.json.JSONArray)2 JSONObject (org.json.JSONObject)2 DeleteRequest (org.springframework.extensions.webscripts.TestWebScriptServer.DeleteRequest)2 GetRequest (org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest)2