@Override protected String getItemURI(WorkflowDefinition item) { return "api/workflow-definitions/"+item.getId(); }
@Override protected String getItemURI(WorkflowDefinition item) { return "api/workflow-definitions/"+item.getId(); }
public WorkflowInstance build() { NodeRef packageRef = packageMgr.create(packageNode); params.put(WorkflowModel.ASSOC_PACKAGE, packageRef); WorkflowPath path = workflowService.startWorkflow(definition.getId(), params); if (path.isActive()){ signalStartTask(path); } return path.getInstance(); }
public WorkflowInstance build() { NodeRef packageRef = packageMgr.create(packageNode); params.put(WorkflowModel.ASSOC_PACKAGE, packageRef); WorkflowPath path = workflowService.startWorkflow(definition.getId(), params); if (path.isActive()){ signalStartTask(path); } return path.getInstance(); }
public void testGetWorkflowTaskDefinitions() { //TODO Implement WorkflowDefinition definition = deployDefinition(getAdhocDefinitionPath()); String workflowDefId = definition.getId(); List<WorkflowTaskDefinition> taskDefs = workflowService.getTaskDefinitions(workflowDefId); assertEquals(3, taskDefs.size()); }
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(); }
@Test public void testGetDefinitionByName() throws Exception { WorkflowDefinition definition = deployTestTaskDefinition(); WorkflowDefinition result = workflowEngine.getDefinitionByName(definition.getName()); assertNotNull("The workflow definition was not found!", result); assertEquals(definition.getId(), result.getId()); assertEquals(definition.getDescription(), result.getDescription()); assertEquals(definition.getName(), result.getName()); assertEquals(definition.getTitle(), result.getTitle()); assertEquals(definition.getVersion(), result.getVersion()); workflowEngine.undeployDefinition(definition.getId()); WorkflowDefinition nullResult = workflowEngine.getDefinitionByName(definition.getName()); assertNull("The workflow definition was found but should be null!", nullResult); }
public void testStartWorkflow() { WorkflowDefinition definition = deployDefinition(getTestDefinitionPath()); WorkflowPath path = workflowService.startWorkflow(definition.getId(), null); assertNotNull(path); assertTrue(path.isActive()); assertNotNull(path.getNode()); WorkflowInstance instance = path.getInstance(); assertNotNull(instance); assertEquals(definition.getId(), instance.getDefinition().getId()); }
@Test public void testGetWorkflowTaskDefinitionsWithMultiInstanceTask() { // Test added to validate fix for ALF-14224 WorkflowDefinition definition = deployDefinition(getParallelReviewDefinitionPath()); String workflowDefId = definition.getId(); List<WorkflowTaskDefinition> taskDefs = workflowService.getTaskDefinitions(workflowDefId); assertEquals(4, taskDefs.size()); // The first task is the start-task, the second one is a multi-instance UserTask. This should have the right form-key WorkflowTaskDefinition taskDef = taskDefs.get(1); assertEquals("wf:activitiReviewTask", taskDef.getId()); }
@Test public void testQueryUsingNodeRef() { NodeRef nodeRef = new NodeRef("workspace:///someRef"); QName nodeRefPropQname = QName.createQName("testProp"); HashMap<QName, Serializable> props = new HashMap<QName, Serializable>(); props.put(nodeRefPropQname, nodeRef); // Start the workflow-path workflowEngine.startWorkflow(workflowDef.getId(), props); // Test querying with a value of type NodeRef WorkflowTaskQuery taskQuery = createWorkflowTaskQuery(WorkflowTaskState.IN_PROGRESS); HashMap<QName, Object> queryParams = new HashMap<QName, Object>(); queryParams.put(nodeRefPropQname, nodeRef); taskQuery.setProcessCustomProps(queryParams); List<WorkflowTask> tasks = workflowEngine.queryTasks(taskQuery); assertNotNull(tasks); assertEquals(1, tasks.size()); }
@Test public void testUndeployDefinition() throws Exception { WorkflowDefinition definition = deployTestTaskDefinition(); String localId = BPMEngineRegistry.getLocalId(definition.getId()); long defCount = repo.createProcessDefinitionQuery() .processDefinitionId(localId) .count(); assertEquals("The deployed process definition should exist!", 1, defCount); workflowEngine.undeployDefinition(definition.getId()); defCount = repo.createProcessDefinitionQuery() .processDefinitionId(localId) .count(); assertEquals("The undeployed process definition should not exist!", 0, defCount); }
@Test public void testCompletedTaskInWorkflowWithSubProcess() { WorkflowDefinition definition = deployDefinition(ACTIVITI_TEST_WITH_SUB_PROCESS_XML); String workflowDefId = definition.getId(); List<WorkflowTaskDefinition> taskDefs = workflowService.getTaskDefinitions(workflowDefId); assertEquals(2, taskDefs.size()); // Prior to the fix for MNT-17601 this list only contained "Alfresco start". assertEquals("Alfresco start", taskDefs.get(0).getNode().getTitle()); assertEquals("Alfresco User Task", taskDefs.get(1).getNode().getTitle()); }
@Test public void testGetWorkflowImage() { WorkflowDefinition definitionWithoutImage = deployTestAdhocDefinition(); WorkflowDefinition definitionWithImage = deployTestDiagramDefinition(); // Start process-instance that shouldn't have an image ProcessInstance processInstance = runtime.startProcessInstanceById(BPMEngineRegistry.getLocalId(definitionWithoutImage.getId())); String worklfowId = BPMEngineRegistry.createGlobalId(ActivitiConstants.ENGINE_ID, processInstance.getId()); assertFalse(workflowEngine.hasWorkflowImage(worklfowId)); assertNull(workflowEngine.getWorkflowImage(worklfowId)); // Start process-instance that SHOULD have an image ProcessInstance processInstanceWithImage = runtime.startProcessInstanceById(BPMEngineRegistry.getLocalId(definitionWithImage.getId())); String worklfowWithImageId = BPMEngineRegistry.createGlobalId(ActivitiConstants.ENGINE_ID, processInstanceWithImage.getId()); assertTrue(workflowEngine.hasWorkflowImage(worklfowWithImageId)); assertNotNull(workflowEngine.getWorkflowImage(worklfowWithImageId)); }
private WorkflowTask getWorkflowTask(String definitionName) { WorkflowDefinition reviewDef = workflowService.getDefinitionByName(definitionName); Map<QName, Serializable> properties = new HashMap<QName, Serializable>(); properties.put(WorkflowModel.ASSOC_ASSIGNEE, personManager.get(USER_ONE)); properties.put(WorkflowModel.ASSOC_PACKAGE, folder); WorkflowPath path = workflowService.startWorkflow(reviewDef.getId(), properties); WorkflowTask task = getTaskForPath(path); String startTaskId = reviewDef.getStartTaskDefinition().getId(); if (startTaskId.equals(task.getDefinition().getId())) { workflowService.endTask(task.getId(), null); task = getTaskForPath(path); } return task; }
private void checkDefinition(WorkflowDefinition expDef, WorkflowDefinition actualDef) { assertEquals(expDef.getId(), actualDef.getId()); assertEquals(expDef.getName(), actualDef.getName()); assertEquals(expDef.getDescription(), actualDef.getDescription()); assertEquals(expDef.getTitle(), actualDef.getTitle()); assertEquals(expDef.getVersion(), actualDef.getVersion()); }
@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); }
@Test public void testBuildWorkflowWithNoUserTasks() throws Exception { // Deploy a definition containing only a service task WorkflowDefinition testDefinition = deployDefinition("activiti/testWorkflowNoUserTasks.bpmn20.xml"); WorkflowBuilder builder = new WorkflowBuilder(testDefinition, workflowService, nodeService, null); // Build a workflow WorkflowInstance builtInstance = builder.build(); assertNotNull(builtInstance); // Check that there is no active workflow for the deployed definition(it should have finished already due to absence of user tasks) List<WorkflowInstance> activeInstances = workflowService.getActiveWorkflows(testDefinition.getId()); assertNotNull(activeInstances); assertEquals(0, activeInstances.size()); // Check that there's a historic record of our 'only service task' workflow being run. HistoricProcessInstance historicProcessInstance = historyService.createHistoricProcessInstanceQuery() .finishedAfter(builtInstance.getStartDate()) .singleResult(); assertNotNull(historicProcessInstance); }
public void testGenerateSetsItemAndUrl() throws Exception { Form form = ((WorkflowFormProcessor) processor).generate(item, null, null, null); Item formItem = form.getItem(); assertEquals(item.getId(), formItem.getId()); assertEquals(item.getKind(), formItem.getKind()); assertEquals(WF_DEF_NAME, formItem.getType()); assertEquals("api/workflow-definitions/" + definition.getId(), formItem.getUrl()); }
@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 testWorkflowQueries() throws Exception { WorkflowDefinition definition = deployDefinition(getTestDefinitionPath()); WorkflowInstanceQuery workflowInstanceQuery = new WorkflowInstanceQuery(true); long active = workflowService.countWorkflows(workflowInstanceQuery); assertNotNull(active); workflowInstanceQuery.setWorkflowDefinitionId(definition.getId()); workflowInstanceQuery.setEngineId(getEngine()); active = workflowService.countWorkflows(workflowInstanceQuery); assertNotNull(active); WorkflowTaskQuery workflowTaskQuery = createWorkflowTaskQuery(WorkflowTaskState.COMPLETED); long completed = workflowService.countTasks(workflowTaskQuery); assertNotNull(completed); workflowTaskQuery.setEngineId(getEngine()); completed = workflowService.countTasks(workflowTaskQuery); assertNotNull(completed); }