use of org.alfresco.service.cmr.workflow.WorkflowInstance in project alfresco-repository by Alfresco.
the class ScriptNode method getActiveWorkflows.
// ------------------------------------------------------------------------------
// Workflow methods
/**
* Get active workflow instances this node belongs to
*
* @return the active workflow instances this node belongs to
*/
public Scriptable getActiveWorkflows() {
if (this.activeWorkflows == null) {
WorkflowService workflowService = this.services.getWorkflowService();
List<WorkflowInstance> workflowInstances = workflowService.getWorkflowsForContent(this.nodeRef, true);
Object[] jsWorkflowInstances = new Object[workflowInstances.size()];
int index = 0;
for (WorkflowInstance workflowInstance : workflowInstances) {
jsWorkflowInstances[index++] = new JscriptWorkflowInstance(workflowInstance, this.services, this.scope);
}
this.activeWorkflows = Context.getCurrentContext().newArray(this.scope, jsWorkflowInstances);
}
return this.activeWorkflows;
}
use of org.alfresco.service.cmr.workflow.WorkflowInstance in project alfresco-repository by Alfresco.
the class ActivitiWorkflowEngine method getWorkflowsInternal.
@SuppressWarnings("unchecked")
private List<WorkflowInstance> getWorkflowsInternal(WorkflowInstanceQuery workflowInstanceQuery, boolean isActive, int maxItems, int skipCount) {
// MNT-9074 My Tasks fails to render if tasks quantity is excessive
HistoricProcessInstanceQuery query = createQuery(workflowInstanceQuery, isActive);
LinkedList<WorkflowInstance> results = new LinkedList<WorkflowInstance>();
List<HistoricProcessInstance> completedInstances;
if (maxItems > 0) {
completedInstances = query.orderByProcessInstanceDuration().desc().listPage(skipCount, maxItems);
} else {
completedInstances = query.list();
}
List<WorkflowInstance> completedResults = typeConverter.doSpecialTenantFilterAndSafeConvert(completedInstances, new Function<HistoricProcessInstance, String>() {
public String apply(HistoricProcessInstance historicProcessInstance) {
ProcessDefinition procDef = activitiUtil.getProcessDefinition(historicProcessInstance.getProcessDefinitionId());
return procDef.getKey();
}
});
results.addAll(completedResults);
return results;
}
use of org.alfresco.service.cmr.workflow.WorkflowInstance in project alfresco-repository by Alfresco.
the class WorkflowObjectFactory method createInstance.
public WorkflowInstance createInstance(String id, WorkflowDefinition definition, Map<String, Object> variables, boolean isActive, Date startDate, Date endDate) {
String actualId = buildGlobalId(id);
String description = (String) getVariable(variables, WorkflowModel.PROP_WORKFLOW_DESCRIPTION);
NodeRef initiator = null;
ScriptNode initiatorSN = (ScriptNode) getVariable(variables, WorkflowConstants.PROP_INITIATOR);
if (initiatorSN != null) {
initiator = initiatorSN.getNodeRef();
}
NodeRef context = getNodeVariable(variables, WorkflowModel.PROP_CONTEXT);
NodeRef workflowPackage = getNodeVariable(variables, WorkflowModel.ASSOC_PACKAGE);
WorkflowInstance workflowInstance = new WorkflowInstance(actualId, definition, description, initiator, workflowPackage, context, isActive, startDate, endDate);
workflowInstance.priority = (Integer) getVariable(variables, WorkflowModel.PROP_WORKFLOW_PRIORITY);
Date dueDate = (Date) getVariable(variables, WorkflowModel.PROP_WORKFLOW_DUE_DATE);
if (dueDate != null) {
workflowInstance.dueDate = dueDate;
}
return workflowInstance;
}
use of org.alfresco.service.cmr.workflow.WorkflowInstance in project alfresco-repository by Alfresco.
the class WorkflowServiceImpl method deleteWorkflow.
/*
* (non-Javadoc)
* @see
* org.alfresco.service.cmr.workflow.WorkflowService#deleteWorkflow(java
* .lang.String)
*/
public WorkflowInstance deleteWorkflow(String workflowId) {
String engineId = BPMEngineRegistry.getEngineId(workflowId);
WorkflowComponent component = getWorkflowComponent(engineId);
WorkflowInstance instance = component.deleteWorkflow(workflowId);
// NOTE: Delete workflow package after deleting workflow, so it's still
// available
// in process-end events of workflow definition
workflowPackageComponent.deletePackage(instance.getWorkflowPackage());
return instance;
}
use of org.alfresco.service.cmr.workflow.WorkflowInstance in project alfresco-repository by Alfresco.
the class WorkflowServiceImpl method updateTask.
/*
* (non-Javadoc)
* @see
* org.alfresco.service.cmr.workflow.WorkflowService#updateTask(java.lang
* .String, java.util.Map, java.util.Map, java.util.Map)
*/
public WorkflowTask updateTask(String taskId, Map<QName, Serializable> properties, Map<QName, List<NodeRef>> add, Map<QName, List<NodeRef>> remove) {
String engineId = BPMEngineRegistry.getEngineId(taskId);
TaskComponent component = getTaskComponent(engineId);
// get the current assignee before updating the task
String originalAsignee = (String) component.getTaskById(taskId).getProperties().get(ContentModel.PROP_OWNER);
WorkflowTask task = component.updateTask(taskId, properties, add, remove);
if (add != null && add.containsKey(WorkflowModel.ASSOC_PACKAGE)) {
WorkflowInstance instance = task.getPath().getInstance();
workflowPackageComponent.setWorkflowForPackage(instance);
}
// Get the 'new' assignee
String assignee = (String) properties.get(ContentModel.PROP_OWNER);
if (assignee != null && assignee.length() != 0) {
// if the assignee has changed get the start task
if (!assignee.equals(originalAsignee)) {
String instanceId = task.getPath().getInstance().getId();
WorkflowTask startTask = component.getStartTask(instanceId);
if (startTask != null) {
// Get the email notification flag
Boolean sendEMailNotification = (Boolean) startTask.getProperties().get(WorkflowModel.PROP_SEND_EMAIL_NOTIFICATIONS);
if (Boolean.TRUE.equals(sendEMailNotification) == true) {
// calculate task type label
String workflowDefId = task.getPath().getInstance().getDefinition().getName();
if (workflowDefId.indexOf('$') != -1 && (workflowDefId.indexOf('$') < workflowDefId.length() - 1)) {
workflowDefId = workflowDefId.substring(workflowDefId.indexOf('$') + 1);
}
// Send the notification
workflowNotificationUtils.sendWorkflowAssignedNotificationEMail(taskId, null, assignee, false);
}
}
}
}
return task;
}
Aggregations