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()); } } }
private Invitation getInvitation(WorkflowTask startTask) { Invitation invitation = getNominatedInvitation(startTask); if(invitation == null) { invitation = getModeratedInvitation(startTask.getPath().getId()); } return invitation; }
private Invitation getInvitation(WorkflowTask startTask) { Invitation invitation = getNominatedInvitation(startTask); if(invitation == null) { invitation = getModeratedInvitation(startTask.getPath().getId()); } return invitation; }
private Invitation rejectModeratedInvitation(WorkflowTask startTask, String reason) { ModeratedInvitation invitation = getModeratedInvitation(startTask.getPath().getId()); // Check rejecter is a site manager and throw and exception if not String rejecterUserName = this.authenticationService.getCurrentUserName(); checkManagerRole(rejecterUserName, invitation.getResourceType(), invitation.getResourceName()); Map<QName, Serializable> properties = new HashMap<QName, Serializable>(); properties.put(ContentModel.PROP_OWNER, rejecterUserName); properties.put(WorkflowModelModeratedInvitation.WF_PROP_REVIEW_COMMENTS, reason); endInvitation(startTask, WorkflowModelModeratedInvitation.WF_TRANSITION_REJECT, properties, WorkflowModelModeratedInvitation.WF_ACTIVITI_REVIEW_TASK); return invitation; }
private Invitation rejectModeratedInvitation(WorkflowTask startTask, String reason) { ModeratedInvitation invitation = getModeratedInvitation(startTask.getPath().getId()); // Check rejecter is a site manager and throw and exception if not String rejecterUserName = this.authenticationService.getCurrentUserName(); checkManagerRole(rejecterUserName, invitation.getResourceType(), invitation.getResourceName()); Map<QName, Serializable> properties = new HashMap<QName, Serializable>(); properties.put(ContentModel.PROP_OWNER, rejecterUserName); properties.put(WorkflowModelModeratedInvitation.WF_PROP_REVIEW_COMMENTS, reason); endInvitation(startTask, WorkflowModelModeratedInvitation.WF_TRANSITION_REJECT, properties, WorkflowModelModeratedInvitation.WF_ACTIVITI_REVIEW_TASK); return invitation; }
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); } }
@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 public void testSignal() throws Exception { WorkflowDefinition def = deployTestSignallingDefinition(); ProcessInstance processInstance = runtime.startProcessInstanceById(BPMEngineRegistry.getLocalId(def.getId())); String procId = processInstance.getId(); List<String> nodeIds = runtime.getActiveActivityIds(procId); assertEquals(1, nodeIds.size()); assertEquals("task1", nodeIds.get(0)); String pathId = BPMEngineRegistry.createGlobalId(ActivitiConstants.ENGINE_ID, procId); WorkflowPath path = workflowEngine.signal(pathId, null); assertEquals(pathId, path.getId()); assertEquals("task2", path.getNode().getName()); assertEquals(pathId, path.getInstance().getId()); assertTrue(path.isActive()); nodeIds = runtime.getActiveActivityIds(procId); assertEquals(1, nodeIds.size()); assertEquals("task2", nodeIds.get(0)); // Should end the WorkflowInstance path = workflowEngine.signal(pathId, null); assertEquals(pathId, path.getId()); assertNull(path.getNode()); assertEquals(pathId, path.getInstance().getId()); assertFalse(path.isActive()); }
private Invitation cancelModeratedInvitation(WorkflowTask startTask) { ModeratedInvitation invitation = getModeratedInvitation(startTask.getPath().getId()); String currentUserName = this.authenticationService.getCurrentUserName(); if (!AuthenticationUtil.isRunAsUserTheSystemUser()) { if (false == currentUserName.equals(invitation.getInviteeUserName())) { checkManagerRole(currentUserName, invitation.getResourceType(), invitation.getResourceName()); } } // Only proceed with the cancel if the site still exists (the site may have been deleted and invitations may be // getting cancelled in the background) if (this.siteService.getSite(invitation.getResourceName()) != null) { workflowService.cancelWorkflow(invitation.getInviteId()); } return invitation; }
private Invitation cancelModeratedInvitation(WorkflowTask startTask) { ModeratedInvitation invitation = getModeratedInvitation(startTask.getPath().getId()); String currentUserName = this.authenticationService.getCurrentUserName(); if (!AuthenticationUtil.isRunAsUserTheSystemUser()) { if (false == currentUserName.equals(invitation.getInviteeUserName())) { checkManagerRole(currentUserName, invitation.getResourceType(), invitation.getResourceName()); } } // Only proceed with the cancel if the site still exists (the site may have been deleted and invitations may be // getting cancelled in the background) if (this.siteService.getSite(invitation.getResourceName()) != null) { workflowService.cancelWorkflow(invitation.getInviteId()); } return invitation; }
/** * 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 testGetStartTaskById() throws Exception { WorkflowTask result = workflowEngine.getTaskById(ActivitiConstants.ENGINE_ID + "$Foo"); assertNull("Should not find any result for fake (but valid) Id.", result); WorkflowPath path = workflowEngine.startWorkflow(workflowDef.getId(), new HashMap<QName, Serializable>()); Task task = taskService.createTaskQuery() .executionId(BPMEngineRegistry.getLocalId(path.getId())) .singleResult(); // A start task should be available for the process instance String startTaskId = ActivitiConstants.START_TASK_PREFIX + task.getProcessInstanceId(); String taskId = createGlobalId(startTaskId); WorkflowTask wfTask = workflowEngine.getTaskById(taskId); assertNotNull(wfTask); assertEquals(createGlobalId(task.getProcessInstanceId()), wfTask.getPath().getId()); }
@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); }
assertEquals(expectedTimerPathId, timer.getPath().getId());
/** * 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())); } }
@Test public void testGetTaskById() throws Exception { try { workflowEngine.getTaskById("Foo"); fail("Should blow up if Id is wrong format!"); } catch(WorkflowException e) { // Do Nothing } WorkflowTask result = workflowEngine.getTaskById(ActivitiConstants.ENGINE_ID + "$Foo"); assertNull("Should not find any result for fake (but valid) Id.", result); WorkflowPath path = workflowEngine.startWorkflow(workflowDef.getId(), new HashMap<QName, Serializable>()); Task task = taskService.createTaskQuery() .executionId(BPMEngineRegistry.getLocalId(path.getId())) .singleResult(); assertNotNull("Task shoudl exist!", task); String taskId = BPMEngineRegistry.createGlobalId(ActivitiConstants.ENGINE_ID, task.getId()); WorkflowTask wfTask = workflowEngine.getTaskById(taskId); assertNotNull(wfTask); }