Search in sources :

Example 6 with WorkflowDefinition

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);
}
Also used : WorkflowDefinitionConversion(org.activiti.workflow.simple.converter.WorkflowDefinitionConversion) WorkflowDefinition(org.activiti.workflow.simple.definition.WorkflowDefinition) Process(org.activiti.bpmn.model.Process) BpmnModel(org.activiti.bpmn.model.BpmnModel) Test(org.junit.Test)

Example 7 with WorkflowDefinition

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());
}
Also used : WorkflowDefinitionConversion(org.activiti.workflow.simple.converter.WorkflowDefinitionConversion) WorkflowDefinitionConversionFactory(org.activiti.workflow.simple.converter.WorkflowDefinitionConversionFactory) WorkflowDefinition(org.activiti.workflow.simple.definition.WorkflowDefinition) Deployment(org.activiti.engine.repository.Deployment) SimpleWorkflowJsonConverter(org.activiti.workflow.simple.converter.json.SimpleWorkflowJsonConverter) ProcessDefinition(org.activiti.engine.repository.ProcessDefinition) BpmnModel(org.activiti.bpmn.model.BpmnModel) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 8 with WorkflowDefinition

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());
}
Also used : StartEvent(org.activiti.bpmn.model.StartEvent) WorkflowDefinition(org.activiti.workflow.simple.definition.WorkflowDefinition) Process(org.activiti.bpmn.model.Process)

Example 9 with WorkflowDefinition

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());
}
Also used : TaskService(org.activiti.engine.TaskService) WorkflowDefinition(org.activiti.workflow.simple.definition.WorkflowDefinition) Test(org.junit.Test)

Example 10 with WorkflowDefinition

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());
}
Also used : Task(org.activiti.engine.task.Task) TaskService(org.activiti.engine.TaskService) WorkflowDefinition(org.activiti.workflow.simple.definition.WorkflowDefinition) Test(org.junit.Test)

Aggregations

WorkflowDefinition (org.activiti.workflow.simple.definition.WorkflowDefinition)32 Test (org.junit.Test)24 WorkflowDefinitionConversion (org.activiti.workflow.simple.converter.WorkflowDefinitionConversion)16 HumanStepDefinition (org.activiti.workflow.simple.definition.HumanStepDefinition)10 Task (org.activiti.engine.task.Task)7 FormDefinition (org.activiti.workflow.simple.definition.form.FormDefinition)7 ByteArrayOutputStream (java.io.ByteArrayOutputStream)6 TaskService (org.activiti.engine.TaskService)6 OutputStreamWriter (java.io.OutputStreamWriter)5 Process (org.activiti.bpmn.model.Process)5 Writer (java.io.Writer)4 BpmnModel (org.activiti.bpmn.model.BpmnModel)4 FlowElement (org.activiti.bpmn.model.FlowElement)4 M2Model (org.activiti.workflow.simple.alfresco.model.M2Model)4 ListStepDefinition (org.activiti.workflow.simple.definition.ListStepDefinition)4 RepositoryService (org.activiti.engine.RepositoryService)3 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)3 M2Type (org.activiti.workflow.simple.alfresco.model.M2Type)3 ListConditionStepDefinition (org.activiti.workflow.simple.definition.ListConditionStepDefinition)3 StepDefinition (org.activiti.workflow.simple.definition.StepDefinition)3