Search in sources :

Example 51 with WorkflowInstance

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();
    }
}
Also used : Serializable(java.io.Serializable) RetryingTransactionHelper(org.alfresco.repo.transaction.RetryingTransactionHelper) QName(org.alfresco.service.namespace.QName) WorkflowDefinition(org.alfresco.service.cmr.workflow.WorkflowDefinition) WorkflowPath(org.alfresco.service.cmr.workflow.WorkflowPath) WorkflowTask(org.alfresco.service.cmr.workflow.WorkflowTask) WorkflowInstance(org.alfresco.service.cmr.workflow.WorkflowInstance) HashMap(java.util.HashMap) Map(java.util.Map) MimetypeMap(org.alfresco.repo.content.MimetypeMap) BaseSpringTest(org.alfresco.util.BaseSpringTest) Test(org.junit.Test)

Example 52 with WorkflowInstance

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;
}
Also used : HistoricProcessInstanceQuery(org.activiti.engine.history.HistoricProcessInstanceQuery) HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance) ProcessDefinition(org.activiti.engine.repository.ProcessDefinition) ReadOnlyProcessDefinition(org.activiti.engine.impl.pvm.ReadOnlyProcessDefinition) WorkflowInstance(org.alfresco.service.cmr.workflow.WorkflowInstance) LinkedList(java.util.LinkedList)

Example 53 with WorkflowInstance

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;
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) ScriptNode(org.alfresco.repo.jscript.ScriptNode) WorkflowInstance(org.alfresco.service.cmr.workflow.WorkflowInstance) Date(java.util.Date)

Example 54 with 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;
}
Also used : WorkflowInstance(org.alfresco.service.cmr.workflow.WorkflowInstance)

Example 55 with WorkflowInstance

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;
}
Also used : WorkflowTask(org.alfresco.service.cmr.workflow.WorkflowTask) WorkflowInstance(org.alfresco.service.cmr.workflow.WorkflowInstance)

Aggregations

WorkflowInstance (org.alfresco.service.cmr.workflow.WorkflowInstance)56 WorkflowDefinition (org.alfresco.service.cmr.workflow.WorkflowDefinition)26 HashMap (java.util.HashMap)22 WorkflowTask (org.alfresco.service.cmr.workflow.WorkflowTask)19 WorkflowPath (org.alfresco.service.cmr.workflow.WorkflowPath)16 QName (org.alfresco.service.namespace.QName)16 Serializable (java.io.Serializable)15 Date (java.util.Date)15 HistoricProcessInstance (org.activiti.engine.history.HistoricProcessInstance)15 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)13 Test (org.junit.Test)13 Map (java.util.Map)11 NodeRef (org.alfresco.service.cmr.repository.NodeRef)10 ArrayList (java.util.ArrayList)9 WorkflowException (org.alfresco.service.cmr.workflow.WorkflowException)7 WorkflowNode (org.alfresco.service.cmr.workflow.WorkflowNode)5 Execution (org.activiti.engine.runtime.Execution)4 List (java.util.List)3 ActivitiException (org.activiti.engine.ActivitiException)3 MimetypeMap (org.alfresco.repo.content.MimetypeMap)3