use of org.alfresco.service.cmr.workflow.WorkflowInstance in project alfresco-repository by Alfresco.
the class ActivitiTimerExecutionTest method testTimerExecutionAuthentication.
@SuppressWarnings("deprecation")
@Test
public void testTimerExecutionAuthentication() throws Exception {
try {
WorkflowInstance taskAssigneeWorkflowInstance = transactionHelper.doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<WorkflowInstance>() {
public WorkflowInstance execute() throws Throwable {
// Create test person
personManager.createPerson(USER1);
WorkflowDefinition definition = deployDefinition("activiti/testTimerTransaction.bpmn20.xml");
// Start the test timer transaction process, with 'error' = false, expecting a timer job
// to be executed without an error, with task timer is assigned to assigned to USER1
Map<QName, Serializable> params = new HashMap<QName, Serializable>();
params.put(QName.createQName("error"), Boolean.FALSE);
params.put(QName.createQName("theTaskAssignee"), USER1);
WorkflowPath path = workflowService.startWorkflow(definition.getId(), params);
// End start-task
workflowService.endTask(workflowService.getStartTask(path.getInstance().getId()).getId(), null);
return path.getInstance();
}
}, false, true);
// No timers should be available after a while they should have been executed, otherwise test fails
waitForTimersToBeExecuted(taskAssigneeWorkflowInstance.getId());
// Test assigned task
WorkflowPath path = workflowService.getWorkflowPaths(taskAssigneeWorkflowInstance.getId()).get(0);
// Check if job executed without exception, process should be waiting in "waitTask"
List<WorkflowTask> tasks = workflowService.getTasksForWorkflowPath(path.getId());
assertNotNull(tasks);
assertEquals(1, tasks.size());
assertEquals("waitTask", tasks.get(0).getDefinition().getNode().getName());
// Check if timer was executed as task assignee, was set while executing timer
Map<QName, Serializable> pathProps = workflowService.getPathProperties(path.getId());
assertEquals(USER1, pathProps.get(QName.createQName("timerExecutedAs")));
} finally {
cleanUp();
}
}
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