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));
}
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;
}
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);
}
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;
}
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;
}
Aggregations