Search in sources :

Example 11 with WorkflowDefinition

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

the class WorkflowModelBuilderTest method testBuildWorkflowDefinition.

public void testBuildWorkflowDefinition() throws Exception {
    WorkflowTaskDefinition workflowTaskDefinition = makeTaskDefinition();
    WorkflowDefinition workflowDefinition = new WorkflowDefinition("The Id", "The Name", "The Version", "The Title", "The Description", workflowTaskDefinition);
    Map<String, Object> model = builder.buildSimple(workflowDefinition);
    assertEquals(workflowDefinition.getId(), model.get(WorkflowModelBuilder.WORKFLOW_DEFINITION_ID));
    assertEquals("api/workflow-definitions/" + workflowDefinition.getId(), model.get(WorkflowModelBuilder.WORKFLOW_DEFINITION_URL));
    assertEquals(workflowDefinition.getName(), model.get(WorkflowModelBuilder.WORKFLOW_DEFINITION_NAME));
    assertEquals(workflowDefinition.getTitle(), model.get(WorkflowModelBuilder.WORKFLOW_DEFINITION_TITLE));
    assertEquals(workflowDefinition.getDescription(), model.get(WorkflowModelBuilder.WORKFLOW_DEFINITION_DESCRIPTION));
}
Also used : WorkflowTaskDefinition(org.alfresco.service.cmr.workflow.WorkflowTaskDefinition) WorkflowDefinition(org.alfresco.service.cmr.workflow.WorkflowDefinition)

Example 12 with WorkflowDefinition

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

the class WorkflowDefinitionsGet method buildModel.

@Override
protected Map<String, Object> buildModel(WorkflowModelBuilder modelBuilder, WebScriptRequest req, Status status, Cache cache) {
    ExcludeFilter excludeFilter = null;
    String excludeParam = req.getParameter(PARAM_EXCLUDE);
    if (excludeParam != null && excludeParam.length() > 0) {
        excludeFilter = new ExcludeFilter(excludeParam);
    }
    // list all workflow's definitions simple representation
    List<WorkflowDefinition> workflowDefinitions = workflowService.getDefinitions();
    ArrayList<Map<String, Object>> results = new ArrayList<Map<String, Object>>();
    for (WorkflowDefinition workflowDefinition : workflowDefinitions) {
        // if present, filter out excluded definitions
        if (excludeFilter == null || !excludeFilter.isMatch(workflowDefinition.getName())) {
            results.add(modelBuilder.buildSimple(workflowDefinition));
        }
    }
    Map<String, Object> model = new HashMap<String, Object>();
    model.put("workflowDefinitions", results);
    return model;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) WorkflowDefinition(org.alfresco.service.cmr.workflow.WorkflowDefinition) Map(java.util.Map) HashMap(java.util.HashMap)

Example 13 with WorkflowDefinition

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

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

the class StartWorkflowWizard method getWorkflowDefinitionImageUrl.

/**
 * Returns the URL to the Workflow Definition Image of the current task
 *
 * @return  the url
 */
public String getWorkflowDefinitionImageUrl() {
    String url = null;
    if (selectedWorkflow != null) {
        WorkflowDefinition def = getWorkflows().get(selectedWorkflow);
        url = "/workflowdefinitionimage/" + def.id;
    }
    return url;
}
Also used : WorkflowDefinition(org.alfresco.service.cmr.workflow.WorkflowDefinition)

Example 15 with WorkflowDefinition

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

the class StartWorkflowWizard method getPackageActionGroup.

/**
 * Returns the action group the current task uses for the workflow package
 *
 * @return action group id
 */
public String getPackageActionGroup() {
    String actionGroup = null;
    WorkflowDefinition flowDef = this.getWorkflows().get(this.selectedWorkflow);
    WorkflowTaskDefinition taskDef = flowDef.getStartTaskDefinition();
    if (taskDef != null) {
        PropertyDefinition propDef = taskDef.metadata.getProperties().get(WorkflowModel.PROP_PACKAGE_ACTION_GROUP);
        if (propDef != null) {
            actionGroup = propDef.getDefaultValue();
        }
    }
    return actionGroup;
}
Also used : WorkflowTaskDefinition(org.alfresco.service.cmr.workflow.WorkflowTaskDefinition) WorkflowDefinition(org.alfresco.service.cmr.workflow.WorkflowDefinition) PropertyDefinition(org.alfresco.service.cmr.dictionary.PropertyDefinition)

Aggregations

WorkflowDefinition (org.alfresco.service.cmr.workflow.WorkflowDefinition)31 HashMap (java.util.HashMap)19 Date (java.util.Date)18 WorkflowPath (org.alfresco.service.cmr.workflow.WorkflowPath)16 QName (org.alfresco.service.namespace.QName)16 Serializable (java.io.Serializable)15 WorkflowTask (org.alfresco.service.cmr.workflow.WorkflowTask)14 GetRequest (org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest)13 JSONObject (org.json.JSONObject)12 Response (org.springframework.extensions.webscripts.TestWebScriptServer.Response)12 JSONArray (org.json.JSONArray)9 WorkflowInstance (org.alfresco.service.cmr.workflow.WorkflowInstance)8 Calendar (java.util.Calendar)6 WorkflowTaskDefinition (org.alfresco.service.cmr.workflow.WorkflowTaskDefinition)5 ArrayList (java.util.ArrayList)3 Map (java.util.Map)3 NodeRef (org.alfresco.service.cmr.repository.NodeRef)3 DeleteRequest (org.springframework.extensions.webscripts.TestWebScriptServer.DeleteRequest)3 PutRequest (org.springframework.extensions.webscripts.TestWebScriptServer.PutRequest)3 PropertyDefinition (org.alfresco.service.cmr.dictionary.PropertyDefinition)2