private WorkflowTask getModeratedInvitationReviewTask(String invitationId) { WorkflowTask reviewTask = null; // since the invitation may have been updated e.g. invitee comments (and therefore modified date) // we need to get the properties from the review task (which should be the only active // task) List<WorkflowTask> tasks = workflowService.getTasksForWorkflowPath(invitationId); for(WorkflowTask task : tasks) { if(taskTypeMatches(task, WorkflowModelModeratedInvitation.WF_ACTIVITI_REVIEW_TASK)) { reviewTask = task; break; } } return reviewTask; }
private WorkflowTask getModeratedInvitationReviewTask(String invitationId) { WorkflowTask reviewTask = null; // since the invitation may have been updated e.g. invitee comments (and therefore modified date) // we need to get the properties from the review task (which should be the only active // task) List<WorkflowTask> tasks = workflowService.getTasksForWorkflowPath(invitationId); for(WorkflowTask task : tasks) { if(taskTypeMatches(task, WorkflowModelModeratedInvitation.WF_ACTIVITI_REVIEW_TASK)) { reviewTask = task; break; } } return reviewTask; }
private void endStartTaskForPath(WorkflowPath path) { if (path != null) { List<WorkflowTask> tasks = this.workflowService.getTasksForWorkflowPath(path.id); if (tasks.size() == 1) { WorkflowTask startTask = tasks.get(0); if (startTask.state == WorkflowTaskState.IN_PROGRESS) { // end the start task to trigger the first 'proper' // task in the workflow this.workflowService.endTask(startTask.id, null); } } } } }
private void endStartTaskForPath(WorkflowPath path) { if (path != null) { List<WorkflowTask> tasks = this.workflowService.getTasksForWorkflowPath(path.id); if (tasks.size() == 1) { WorkflowTask startTask = tasks.get(0); if (startTask.state == WorkflowTaskState.IN_PROGRESS) { // end the start task to trigger the first 'proper' // task in the workflow this.workflowService.endTask(startTask.id, null); } } } } }
private void signalStartTask(WorkflowPath path) { List<WorkflowTask> tasks = workflowService.getTasksForWorkflowPath(path.getId()); if (tasks.size() == 1) { WorkflowTask startTask = tasks.get(0); workflowService.endTask(startTask.getId(), null); } else { throw new WorkflowException("Start task not found! Expected 1 task but found: " + tasks.size()); } } }
private void signalStartTask(WorkflowPath path) { List<WorkflowTask> tasks = workflowService.getTasksForWorkflowPath(path.getId()); if (tasks.size() == 1) { WorkflowTask startTask = tasks.get(0); workflowService.endTask(startTask.getId(), null); } else { throw new WorkflowException("Start task not found! Expected 1 task but found: " + tasks.size()); } } }
/** * Get all tasks associated with this workflow path * * @return all the tasks associated with this workflow path instance */ public Scriptable getTasks() { WorkflowService workflowService = serviceRegistry.getWorkflowService(); List<WorkflowTask> cmrTasks = workflowService.getTasksForWorkflowPath(id); ArrayList<Serializable> tasks = new ArrayList<Serializable>(); for (WorkflowTask cmrTask : cmrTasks) { tasks.add(new JscriptWorkflowTask(cmrTask, this.serviceRegistry, this.scope)); } Scriptable tasksScriptable = (Scriptable)new ValueConverter().convertValueForScript(this.serviceRegistry, scope, null, tasks); return tasksScriptable; }
/** * Get all tasks associated with this workflow path * * @return all the tasks associated with this workflow path instance */ public Scriptable getTasks() { WorkflowService workflowService = serviceRegistry.getWorkflowService(); List<WorkflowTask> cmrTasks = workflowService.getTasksForWorkflowPath(id); ArrayList<Serializable> tasks = new ArrayList<Serializable>(); for (WorkflowTask cmrTask : cmrTasks) { tasks.add(new JscriptWorkflowTask(cmrTask, this.serviceRegistry, this.scope)); } Scriptable tasksScriptable = (Scriptable)new ValueConverter().convertValueForScript(this.serviceRegistry, scope, null, tasks); return tasksScriptable; }
private WorkflowTask getTaskForPath(WorkflowPath path) { List<WorkflowTask> tasks = workflowService.getTasksForWorkflowPath(path.getId()); assertNotNull(tasks); assertTrue(tasks.size() > 0); WorkflowTask task = tasks.get(0); return task; }
private void endInvitation(WorkflowTask startTask, String transition, Map<QName, Serializable> properties, QName... taskTypes ) { // Deleting a person can cancel their invitations. Cancelling invitations can delete inactive persons! So prevent infinite looping here if (TransactionalResourceHelper.getSet(getClass().getName()).add(startTask.getPath().getInstance().getId())) { List<WorkflowTask> tasks = workflowService.getTasksForWorkflowPath(startTask.getPath().getId()); if(tasks.size()==1) { WorkflowTask task = tasks.get(0); if(taskTypeMatches(task, taskTypes)) { if(properties != null) { workflowService.updateTask(task.getId(), properties, null, null); } workflowService.endTask(task.getId(), transition); return; } } // Throw exception if the task not found. Object objs[] = { startTask.getPath().getInstance().getId() }; throw new InvitationExceptionUserError("invitation.invite.already_finished", objs); } }
private void endInvitation(WorkflowTask startTask, String transition, Map<QName, Serializable> properties, QName... taskTypes ) { // Deleting a person can cancel their invitations. Cancelling invitations can delete inactive persons! So prevent infinite looping here if (TransactionalResourceHelper.getSet(getClass().getName()).add(startTask.getPath().getInstance().getId())) { List<WorkflowTask> tasks = workflowService.getTasksForWorkflowPath(startTask.getPath().getId()); if(tasks.size()==1) { WorkflowTask task = tasks.get(0); if(taskTypeMatches(task, taskTypes)) { if(properties != null) { workflowService.updateTask(task.getId(), properties, null, null); } workflowService.endTask(task.getId(), transition); return; } } // Throw exception if the task not found. Object objs[] = { startTask.getPath().getInstance().getId() }; throw new InvitationExceptionUserError("invitation.invite.already_finished", objs); } }
List<WorkflowTask> tasks = workflowService.getTasksForWorkflowPath(path.getId()); for (WorkflowTask task : tasks)
@SuppressWarnings("unchecked") private WorkflowService makeWorkflowService() { WorkflowService service = mock(WorkflowService.class); when(service.getDefinitionByName(WF_DEF_NAME)).thenReturn(definition); String instanceId = "foo$instanceId"; newInstance = new WorkflowInstance(instanceId, definition, null, null, null, null, true, null, null); WorkflowTask startTask = new WorkflowTask("foo$taskId", null, null, null, null, null, null, null); String pathId = "foo$pathId"; final WorkflowPath path = new WorkflowPath(pathId, newInstance, null, true); when(service.startWorkflow(eq(definition.getId()), anyMap())) .thenAnswer(new Answer<WorkflowPath>() { public WorkflowPath answer(InvocationOnMock invocation) throws Throwable { Object[] arguments = invocation.getArguments(); actualProperties = (Map<QName, Serializable>) arguments[1]; return path; } }); when(service.getTasksForWorkflowPath(path.getId())) .thenReturn(Collections.singletonList(startTask)); when(service.createPackage(null)).thenReturn(PCKG_NODE); return service; }
/** * Test for MNT-11247 */ @Test public void testAssignmentListener() { WorkflowDefinition definition = deployDefinition(getAssignmentListenerDefinitionPath()); Map<QName, Serializable> params = new HashMap<QName, Serializable>(); params.put(ContentModel.PROP_OWNER, USER1); NodeRef assignee = personManager.get(USER1); params.put(WorkflowModel.ASSOC_ASSIGNEE, assignee); WorkflowPath path = workflowService.startWorkflow(definition.getId(), params); // end start task List<WorkflowTask> tasks = workflowService.getTasksForWorkflowPath(path.getId()); workflowService.endTask(tasks.get(0).getId(), null); // end user task 1 tasks = workflowService.getTasksForWorkflowPath(path.getId()); workflowService.updateTask(tasks.get(0).getId(), params, null, null); workflowService.endTask(tasks.get(0).getId(), null); WorkflowTask result = workflowService.getTaskById(tasks.get(0).getId()); Map<QName, Serializable> props = result.getProperties(); Double create1 = (Double) props.get(QName.createQName("http://www.alfresco.org/model/bpm/1.0", "create1")); assertEquals("Create listener was not triggered", new Double(1), create1); Double complete1 = (Double) props.get(QName.createQName("http://www.alfresco.org/model/bpm/1.0", "complete1")); assertEquals("Complete listener was not triggered", new Double(1), complete1); Double assignment1 = (Double) props.get(QName.createQName("http://www.alfresco.org/model/bpm/1.0", "assignment1")); assertEquals("Assign listener was not triggered", new Double(1), assignment1); }
path = paths.get(0); List<WorkflowTask> tasks = workflowService.getTasksForWorkflowPath(path.getId()); assertEquals(1, tasks.size()); WorkflowTask reviewTask = tasks.get(0);
@Test public void testStartTaskEndsAutomatically() { // Deploy the test workflow definition which uses the // default Start Task type, so it should end automatically. WorkflowDefinition definition = deployDefinition(getTestDefinitionPath()); // Start the Workflow WorkflowPath path = workflowService.startWorkflow(definition.getId(), null); String instanceId = path.getInstance().getId(); // Check the Start Task is completed. WorkflowTask startTask = workflowService.getStartTask(instanceId); assertEquals(WorkflowTaskState.COMPLETED, startTask.getState()); List<WorkflowTask> tasks = workflowService.getTasksForWorkflowPath(path.getId()); assertEquals(1, tasks.size()); String taskName = tasks.get(0).getName(); assertEquals("bpm_foo_task", taskName); }
List<WorkflowTask> tasks = workflowService.getTasksForWorkflowPath(path.getId()); assertEquals(1, tasks.size()); WorkflowTask startTask = tasks.get(0);
/** * Actually tests if the priority is the default value. This is based on the assumption that custom * tasks are defaulted to a priority of 50 (which is invalid). I'm testing that the code I wrote decides this is an * invalid number and sets it to the default value (2). */ @Test public void testPriorityIsValid() { WorkflowDefinition definition = deployDefinition("activiti/testCustomActiviti.bpmn20.xml"); personManager.setUser(USER1); // Start the Workflow WorkflowPath path = workflowService.startWorkflow(definition.getId(), null); String instanceId = path.getInstance().getId(); // Check the Start Task is completed. WorkflowTask startTask = workflowService.getStartTask(instanceId); assertEquals(WorkflowTaskState.COMPLETED, startTask.getState()); List<WorkflowTask> tasks = workflowService.getTasksForWorkflowPath(path.getId()); for (WorkflowTask workflowTask : tasks) { Map<QName, Serializable> props = workflowTask.getProperties(); TypeDefinition typeDefinition = workflowTask.getDefinition().getMetadata(); Map<QName, PropertyDefinition> propertyDefs = typeDefinition.getProperties(); PropertyDefinition priorDef = propertyDefs.get(WorkflowModel.PROP_PRIORITY); assertEquals(props.get(WorkflowModel.PROP_PRIORITY),Integer.valueOf(priorDef.getDefaultValue())); } }
List<WorkflowTask> tasks = workflowService.getTasksForWorkflowPath(path.getId()); assertNotNull(tasks); assertEquals(1, tasks.size());
assertTrue(packageContents.isEmpty()); List<WorkflowTask> tasks = workflowService.getTasksForWorkflowPath(path.getId()); assertEquals(1, tasks.size());