use of org.activiti.workflow.simple.definition.WorkflowDefinition in project Activiti by Activiti.
the class WorkflowDefinitionConversionTest method testGeneratedWorkflowDefinitionId.
/**
* Check if all required artifacts are created when converting an empty workflow-definition.
*/
@Test
public void testGeneratedWorkflowDefinitionId() {
WorkflowDefinition definition = new WorkflowDefinition();
WorkflowDefinitionConversion conversion = conversionFactory.createWorkflowDefinitionConversion(definition);
conversion.convert();
BpmnModel bpmnModel = conversion.getBpmnModel();
assertNotNull(bpmnModel);
Process process = bpmnModel.getMainProcess();
assertNotNull(process);
String generatedProcessId = process.getId();
assertNotNull(generatedProcessId);
}
use of org.activiti.workflow.simple.definition.WorkflowDefinition in project Activiti by Activiti.
the class SimpleWorkflowResource method createWorkflow.
@RequestMapping(value = "/simple-workflow", method = RequestMethod.POST, produces = "application/json")
public SimpleWorkflowSuccessResponse createWorkflow(@RequestBody String json) {
// Convert json to simple workflow definition
SimpleWorkflowJsonConverter jsonConverter = new SimpleWorkflowJsonConverter();
WorkflowDefinition workflowDefinition = jsonConverter.readWorkflowDefinition(json.getBytes());
WorkflowDefinitionConversionFactory conversionFactory = new WorkflowDefinitionConversionFactory();
WorkflowDefinitionConversion conversion = conversionFactory.createWorkflowDefinitionConversion(workflowDefinition);
conversion.convert();
// Deploy process
BpmnModel bpmnModel = conversion.getBpmnModel();
Deployment deployment = repositoryService.createDeployment().addBpmnModel(bpmnModel.getProcesses().get(0).getName() + ".bpmn20.xml", bpmnModel).deploy();
// Fetch process definition id
ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().deploymentId(deployment.getId()).singleResult();
return new SimpleWorkflowSuccessResponse(processDefinition.getId());
}
use of org.activiti.workflow.simple.definition.WorkflowDefinition in project Activiti by Activiti.
the class DefaultWorkflowDefinitionConversionListener method initializeProcess.
protected void initializeProcess(WorkflowDefinitionConversion conversion) {
WorkflowDefinition workflowDefinition = conversion.getWorkflowDefinition();
// Create new process
Process process = conversion.getProcess();
process.setId(generateProcessId(workflowDefinition));
process.setName(workflowDefinition.getName());
process.setDocumentation(workflowDefinition.getDescription());
if (workflowDefinition.getCategory() != null) {
conversion.getBpmnModel().setTargetNamespace(workflowDefinition.getCategory());
}
conversion.setProcess(process);
// Add start-event
StartEvent startEvent = new StartEvent();
startEvent.setId(START_EVENT_ID);
if (workflowDefinition.getStartFormDefinition() != null && workflowDefinition.getStartFormDefinition().getFormKey() != null) {
startEvent.setFormKey(workflowDefinition.getStartFormDefinition().getFormKey());
}
process.addFlowElement(startEvent);
conversion.setLastActivityId(startEvent.getId());
}
use of org.activiti.workflow.simple.definition.WorkflowDefinition in project Activiti by Activiti.
the class WorkflowConversionTest method testInitiatorOnHumanStep.
@Test
public void testInitiatorOnHumanStep() {
WorkflowDefinition workflowDefinition = new WorkflowDefinition().name("testWorkflow").description("This is a test workflow").addHumanStep("step1", "kermit").addHumanStepForWorkflowInitiator("step2");
activitiRule.getIdentityService().setAuthenticatedUserId("MrPink");
activitiRule.getRuntimeService().startProcessInstanceByKey(convertAndDeploy(workflowDefinition));
activitiRule.getIdentityService().setAuthenticatedUserId("null");
// Complete first task
TaskService taskService = activitiRule.getTaskService();
assertEquals(1, taskService.createTaskQuery().taskAssignee("kermit").count());
taskService.complete(taskService.createTaskQuery().singleResult().getId());
// Second task should be done by initiator of workflow
assertEquals(1, taskService.createTaskQuery().taskAssignee("MrPink").count());
assertEquals(0, taskService.createTaskQuery().taskAssignee("kermit").count());
}
use of org.activiti.workflow.simple.definition.WorkflowDefinition in project Activiti by Activiti.
the class WorkflowConversionTest method testThreeUserTasksInParallel.
@Test
public void testThreeUserTasksInParallel() throws Exception {
TaskService taskService = activitiRule.getTaskService();
WorkflowDefinition workflowDefinition = new WorkflowDefinition().name("testWorkflow").description("This is a test workflow").inParallel().inList().addHumanStep("first task", "kermit").endList().inList().addHumanStep("second step", "gonzo").endList().inList().addHumanStep("third task", "mispiggy").endList().endParallel().addHumanStep("Task in between", "kermit").inParallel().inList().addHumanStep("fourth task", "gonzo").endList().inList().addHumanStep("fifth step", "gonzo").endList().endParallel();
// Validate
activitiRule.getRuntimeService().startProcessInstanceByKey(convertAndDeploy(workflowDefinition));
assertEquals(1, taskService.createTaskQuery().taskAssignee("kermit").count());
assertEquals(1, taskService.createTaskQuery().taskAssignee("gonzo").count());
assertEquals(1, taskService.createTaskQuery().taskAssignee("mispiggy").count());
// Complete tasks
for (Task task : taskService.createTaskQuery().list()) {
activitiRule.getTaskService().complete(task.getId());
}
// In between task should be active
Task task = taskService.createTaskQuery().singleResult();
assertEquals("Task in between", task.getName());
taskService.complete(task.getId());
// There should be two task open now for gonzo
assertEquals(2, taskService.createTaskQuery().taskAssignee("gonzo").count());
}
Aggregations