public String apply(WorkflowInstance workflow) { return workflow.getId(); } });
private Map<String, WorkflowTask> getInvitationTasks(List<String> invitationIds) { for (String invitationId: invitationIds) { validateInvitationId(invitationId); } // query for invite workflow task associate long start = (logger.isDebugEnabled()) ? System.currentTimeMillis() : 0; List<WorkflowTask> inviteStartTasks = workflowService.getStartTasks(invitationIds, true); if (logger.isDebugEnabled()) { logger.debug(" getInvitationTask("+invitationIds.size()+") in "+ (System.currentTimeMillis()-start) + " ms"); } Map<String, WorkflowTask> result = new HashMap<String, WorkflowTask>(inviteStartTasks.size() * 2); for(WorkflowTask inviteStartTask: inviteStartTasks) { String invitationId = inviteStartTask.getPath().getInstance().getId(); // The following does not work for moderated tasks // String invitationId = (String) // inviteStartTask.getProperties().get(WorkflowModel.PROP_WORKFLOW_INSTANCE_ID); result.put(invitationId, inviteStartTask); } return result; }
private Map<String, WorkflowTask> getInvitationTasks(List<String> invitationIds) { for (String invitationId: invitationIds) { validateInvitationId(invitationId); } // query for invite workflow task associate long start = (logger.isDebugEnabled()) ? System.currentTimeMillis() : 0; List<WorkflowTask> inviteStartTasks = workflowService.getStartTasks(invitationIds, true); if (logger.isDebugEnabled()) { logger.debug(" getInvitationTask("+invitationIds.size()+") in "+ (System.currentTimeMillis()-start) + " ms"); } Map<String, WorkflowTask> result = new HashMap<String, WorkflowTask>(inviteStartTasks.size() * 2); for(WorkflowTask inviteStartTask: inviteStartTasks) { String invitationId = inviteStartTask.getPath().getInstance().getId(); // The following does not work for moderated tasks // String invitationId = (String) // inviteStartTask.getProperties().get(WorkflowModel.PROP_WORKFLOW_INSTANCE_ID); result.put(invitationId, inviteStartTask); } return result; }
private void checkWorkflowsDontContain(List<WorkflowInstance> workflows, String... expectedIds) { List<String> expIds = Arrays.asList(expectedIds); for (WorkflowInstance instance : workflows) { assertFalse(expIds.contains(instance.getId())); } }
private void checkWorkflows(List<WorkflowInstance> workflows, String... expectedIds) { assertEquals(expectedIds.length, workflows.size()); List<String> expIds = Arrays.asList(expectedIds); for (WorkflowInstance workflow : workflows) { String workflowId = workflow.getId(); assertTrue("The id: "+workflowId +" was not expected! Expected Ids: "+expIds, expIds.contains(workflowId)); } }
tdas.setWorkflowInstanceId(wf.getId());
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); } }
@Override public void requestReset(String userId, String clientName) { ParameterCheck.mandatoryString("userId", userId); ParameterCheck.mandatoryString("clientName", clientName); String userEmail = validateUserAndGetEmail(userId); // Get the (latest) workflow definition for reset-password. WorkflowDefinition wfDefinition = workflowService.getDefinitionByName(WorkflowModelResetPassword.WORKFLOW_DEFINITION_NAME); // create workflow properties Map<QName, Serializable> props = new HashMap<>(7); props.put(WorkflowModel.PROP_WORKFLOW_DESCRIPTION, I18NUtil.getMessage(WORKFLOW_DESCRIPTION_KEY)); props.put(WorkflowModelResetPassword.WF_PROP_USERNAME, userId); props.put(WorkflowModelResetPassword.WF_PROP_USER_EMAIL, userEmail); props.put(WorkflowModelResetPassword.WF_PROP_CLIENT_NAME, clientName); props.put(WorkflowModel.ASSOC_PACKAGE, workflowService.createPackage(null)); String guid = GUID.generate(); props.put(WorkflowModelResetPassword.WF_PROP_KEY, guid); props.put(WorkflowModelResetPassword.WF_PROP_TIMER_END, timerEnd); // start the workflow WorkflowPath path = workflowService.startWorkflow(wfDefinition.getId(), props); if (path.isActive()) { WorkflowTask startTask = workflowService.getStartTask(path.getInstance().getId()); workflowService.endTask(startTask.getId(), null); } }
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); } }
protected String startAdhocWorkflow(WorkflowDefinition workflowDef, String assigneeId) { // Create params Map<QName, Serializable> params = new HashMap<QName, Serializable>(); Serializable wfPackage = workflowService.createPackage(null); params.put(WorkflowModel.ASSOC_PACKAGE, wfPackage); Date dueDate = new Date(); params.put(WorkflowModel.PROP_WORKFLOW_DUE_DATE, dueDate); params.put(WorkflowModel.PROP_WORKFLOW_PRIORITY, 1); params.put(WorkflowModel.PROP_WORKFLOW_DESCRIPTION, "Test workflow description"); params.put(customStringProp, "stringValue"); // Assign to USER2 NodeRef assignee = personManager.get(assigneeId); params.put(WorkflowModel.ASSOC_ASSIGNEE, assignee); // Start a workflow instance WorkflowPath path = workflowService.startWorkflow(workflowDef.getId(), params); assertNotNull(path); assertTrue(path.isActive()); return path.getInstance().getId(); }
private NominatedInvitation getNominatedInvitation(WorkflowTask startTask) { NominatedInvitation invitation = null; if (taskTypeMatches(startTask, WorkflowModelNominatedInvitation.WF_TASK_INVITE_TO_SITE)) { Date inviteDate = startTask.getPath().getInstance().getStartDate(); String invitationId = startTask.getPath().getInstance().getId(); invitation = new NominatedInvitationImpl(invitationId, inviteDate, startTask.getProperties()); } return invitation; }
private NominatedInvitation getNominatedInvitation(WorkflowTask startTask) { NominatedInvitation invitation = null; if (taskTypeMatches(startTask, WorkflowModelNominatedInvitation.WF_TASK_INVITE_TO_SITE)) { Date inviteDate = startTask.getPath().getInstance().getStartDate(); String invitationId = startTask.getPath().getInstance().getId(); invitation = new NominatedInvitationImpl(invitationId, inviteDate, startTask.getProperties()); } return invitation; }
private boolean fromSameParallelReviewWorkflow(WorkflowTask wt, String userName) { // check whether this is parallel review workflow, "parallel" will match all parallel workflows (any engine) if (wt.getPath().getInstance().getDefinition().getName().toLowerCase().contains("parallel")) { WorkflowTaskQuery tasksQuery = new WorkflowTaskQuery(); tasksQuery.setTaskState(null); tasksQuery.setActive(null); tasksQuery.setProcessId(wt.getPath().getInstance().getId()); List<WorkflowTask> allWorkflowTasks = workflowService.queryTasks(tasksQuery, true); for (WorkflowTask task : allWorkflowTasks) { if (isInitiatorOrAssignee(task, userName)) { // if at list one match then user has task from the same workflow return true; } } } return false; }
private boolean fromSameParallelReviewWorkflow(WorkflowTask wt, String userName) { // check whether this is parallel review workflow, "parallel" will match all parallel workflows (any engine) if (wt.getPath().getInstance().getDefinition().getName().toLowerCase().contains("parallel")) { WorkflowTaskQuery tasksQuery = new WorkflowTaskQuery(); tasksQuery.setTaskState(null); tasksQuery.setActive(null); tasksQuery.setProcessId(wt.getPath().getInstance().getId()); List<WorkflowTask> allWorkflowTasks = workflowService.queryTasks(tasksQuery, true); for (WorkflowTask task : allWorkflowTasks) { if (isInitiatorOrAssignee(task, userName)) { // if at list one match then user has task from the same workflow return true; } } } return false; }
@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()); }
@Test public void testDeleteWorkflow() throws Exception { WorkflowDefinition def = deployTestAdhocDefinition(); ProcessInstance processInstance = runtime.startProcessInstanceById(BPMEngineRegistry.getLocalId(def.getId())); // Validate if a workflow exists List<WorkflowInstance> instances = workflowEngine.getActiveWorkflows(def.getId()); assertNotNull(instances); assertEquals(1, instances.size()); assertEquals(processInstance.getId(), BPMEngineRegistry.getLocalId(instances.get(0).getId())); // Call delete method on component workflowEngine.deleteWorkflow(instances.get(0).getId()); instances = workflowEngine.getActiveWorkflows(def.getId()); assertNotNull(instances); assertEquals(0, instances.size()); // Historic process instance shouldn't be present HistoricProcessInstance historicProcessInstance = historyService.createHistoricProcessInstanceQuery() .processInstanceId(processInstance.getProcessInstanceId()) .singleResult(); assertNull(historicProcessInstance); }
private boolean isUserPartOfProcess(WorkflowTask wt, String userName) { WorkflowTaskQuery tasksQuery = new WorkflowTaskQuery(); tasksQuery.setTaskState(null); tasksQuery.setActive(null); tasksQuery.setProcessId(wt.getPath().getInstance().getId()); List<WorkflowTask> allWorkflowTasks = workflowService.queryTasks(tasksQuery, true); for (WorkflowTask task : allWorkflowTasks) { if (isInitiatorOrAssignee(task, userName)) { // if at list one match then user has task from the same workflow return true; } } return false; }
private boolean isUserPartOfProcess(WorkflowTask wt, String userName) { WorkflowTaskQuery tasksQuery = new WorkflowTaskQuery(); tasksQuery.setTaskState(null); tasksQuery.setActive(null); tasksQuery.setProcessId(wt.getPath().getInstance().getId()); List<WorkflowTask> allWorkflowTasks = workflowService.queryTasks(tasksQuery, true); for (WorkflowTask task : allWorkflowTasks) { if (isInitiatorOrAssignee(task, userName)) { // if at list one match then user has task from the same workflow return true; } } return false; }
@Test public void testCancelWorkflow() throws Exception { WorkflowDefinition def = deployTestAdhocDefinition(); ProcessInstance processInstance = runtime.startProcessInstanceById(BPMEngineRegistry.getLocalId(def.getId())); // Validate if a workflow exists List<WorkflowInstance> instances = workflowEngine.getActiveWorkflows(def.getId()); assertNotNull(instances); assertEquals(1, instances.size()); assertEquals(processInstance.getId(), BPMEngineRegistry.getLocalId(instances.get(0).getId())); // Call cancel method on component WorkflowInstance cancelledWorkflow = workflowEngine.cancelWorkflow(instances.get(0).getId()); assertFalse(cancelledWorkflow.isActive()); instances = workflowEngine.getActiveWorkflows(def.getId()); assertNotNull(instances); assertEquals(0, instances.size()); // Histrotic process instance shouldn't be present HistoricProcessInstance historicProcessInstance = historyService.createHistoricProcessInstanceQuery() .processInstanceId(processInstance.getProcessInstanceId()) .singleResult(); if(workflowEngine.activitiUtil.isRetentionHistoricProcessInstanceEnabled()==false){ assertNull(historicProcessInstance); } }
@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); }