Search in sources :

Example 1 with WorkflowDefinitionConversionFactory

use of org.activiti.workflow.simple.converter.WorkflowDefinitionConversionFactory 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 2 with WorkflowDefinitionConversionFactory

use of org.activiti.workflow.simple.converter.WorkflowDefinitionConversionFactory in project Activiti by Activiti.

the class ChoiceStepsDefinitionConverter method createProcessArtifact.

protected ExclusiveGateway createProcessArtifact(ChoiceStepsDefinition choiceStepsDefinition, WorkflowDefinitionConversion conversion) {
    // First choice gateway
    ExclusiveGateway forkGateway = createExclusiveGateway(conversion);
    // Sequence flow from last activity to first gateway
    addSequenceFlow(conversion, conversion.getLastActivityId(), forkGateway.getId());
    conversion.setLastActivityId(forkGateway.getId());
    // Convert all other steps, disabling activity id updates which makes all 
    // generated steps have a sequence flow to the first gateway
    WorkflowDefinitionConversionFactory conversionFactory = conversion.getConversionFactory();
    List<FlowElement> endElements = new ArrayList<FlowElement>();
    List<SequenceFlow> bypassingFlows = new ArrayList<SequenceFlow>();
    for (ListConditionStepDefinition<ChoiceStepsDefinition> stepListDefinition : choiceStepsDefinition.getStepList()) {
        StringBuilder conditionBuilder = new StringBuilder();
        for (ConditionDefinition conditionDefintion : stepListDefinition.getConditions()) {
            if (conditionBuilder.length() > 0) {
                conditionBuilder.append(" && ");
            } else {
                conditionBuilder.append("${");
            }
            conditionBuilder.append(conditionDefintion.getLeftOperand());
            conditionBuilder.append(" ");
            conditionBuilder.append(conditionDefintion.getOperator());
            conditionBuilder.append(" ");
            conditionBuilder.append(conditionDefintion.getRightOperand());
        }
        for (int i = 0; i < stepListDefinition.getSteps().size(); i++) {
            if (i == 0) {
                conversion.setSequenceflowGenerationEnabled(false);
            } else {
                conversion.setSequenceflowGenerationEnabled(true);
            }
            StepDefinition step = stepListDefinition.getSteps().get(i);
            FlowElement flowElement = (FlowElement) conversionFactory.getStepConverterFor(step).convertStepDefinition(step, conversion);
            if (i == 0) {
                if (conditionBuilder.length() > 0) {
                    conditionBuilder.append("}");
                    SequenceFlow mainFlow = addSequenceFlow(conversion, forkGateway.getId(), flowElement.getId(), conditionBuilder.toString());
                    if (stepListDefinition.getName() != null) {
                        mainFlow.setName(stepListDefinition.getName());
                    }
                } else {
                    addSequenceFlow(conversion, forkGateway.getId(), flowElement.getId());
                }
            }
            if ((i + 1) == stepListDefinition.getSteps().size()) {
                endElements.add(flowElement);
            }
        }
        if (stepListDefinition.getSteps().isEmpty()) {
            // Special case for a "stepless" stepListDefinition, which should just create a sequence-flow from the fork to the join
            SequenceFlow created = null;
            if (conditionBuilder.length() > 0) {
                conditionBuilder.append("}");
                created = addSequenceFlow(conversion, forkGateway.getId(), null, conditionBuilder.toString());
            } else {
                created = addSequenceFlow(conversion, forkGateway.getId(), null);
            }
            if (stepListDefinition.getName() != null) {
                created.setName(stepListDefinition.getName());
            }
            bypassingFlows.add(created);
        }
    }
    conversion.setSequenceflowGenerationEnabled(false);
    // Second choice gateway
    ExclusiveGateway joinGateway = createExclusiveGateway(conversion);
    conversion.setLastActivityId(joinGateway.getId());
    conversion.setSequenceflowGenerationEnabled(true);
    // Create sequenceflow from all generated steps to the second gateway
    for (FlowElement endElement : endElements) {
        if (!(endElement instanceof EndEvent)) {
            addSequenceFlow(conversion, endElement.getId(), joinGateway.getId());
        }
    }
    for (SequenceFlow bypassingFlow : bypassingFlows) {
        bypassingFlow.setTargetRef(joinGateway.getId());
    }
    return forkGateway;
}
Also used : SequenceFlow(org.activiti.bpmn.model.SequenceFlow) ChoiceStepsDefinition(org.activiti.workflow.simple.definition.ChoiceStepsDefinition) ArrayList(java.util.ArrayList) ExclusiveGateway(org.activiti.bpmn.model.ExclusiveGateway) WorkflowDefinitionConversionFactory(org.activiti.workflow.simple.converter.WorkflowDefinitionConversionFactory) FlowElement(org.activiti.bpmn.model.FlowElement) StepDefinition(org.activiti.workflow.simple.definition.StepDefinition) ListConditionStepDefinition(org.activiti.workflow.simple.definition.ListConditionStepDefinition) EndEvent(org.activiti.bpmn.model.EndEvent) ConditionDefinition(org.activiti.workflow.simple.definition.ConditionDefinition)

Example 3 with WorkflowDefinitionConversionFactory

use of org.activiti.workflow.simple.converter.WorkflowDefinitionConversionFactory in project Activiti by Activiti.

the class WorkflowConversionTest method initialiseTest.

@Before
public void initialiseTest() {
    // Alternatively, the following setup could be done using a dependency injection container
    conversionFactory = new WorkflowDefinitionConversionFactory();
    runtimeService = activitiRule.getRuntimeService();
    taskService = activitiRule.getTaskService();
}
Also used : WorkflowDefinitionConversionFactory(org.activiti.workflow.simple.converter.WorkflowDefinitionConversionFactory) Before(org.junit.Before)

Example 4 with WorkflowDefinitionConversionFactory

use of org.activiti.workflow.simple.converter.WorkflowDefinitionConversionFactory in project Activiti by Activiti.

the class ParallelStepsDefinitionConverter method createProcessArtifact.

protected ParallelGateway createProcessArtifact(ParallelStepsDefinition parallelStepsDefinition, WorkflowDefinitionConversion conversion) {
    // First parallel gateway
    ParallelGateway forkGateway = createParallelGateway(conversion);
    // Sequence flow from last activity to first gateway
    addSequenceFlow(conversion, conversion.getLastActivityId(), forkGateway.getId());
    conversion.setLastActivityId(forkGateway.getId());
    // Convert all other steps, disabling activity id updates which makes all 
    // generated steps have a sequence flow to the first gateway
    WorkflowDefinitionConversionFactory conversionFactory = conversion.getConversionFactory();
    List<FlowElement> endElements = new ArrayList<FlowElement>();
    for (ListStepDefinition<ParallelStepsDefinition> stepListDefinition : parallelStepsDefinition.getStepList()) {
        for (int i = 0; i < stepListDefinition.getSteps().size(); i++) {
            if (i == 0) {
                conversion.setSequenceflowGenerationEnabled(false);
            } else {
                conversion.setSequenceflowGenerationEnabled(true);
            }
            StepDefinition step = stepListDefinition.getSteps().get(i);
            FlowElement flowElement = (FlowElement) conversionFactory.getStepConverterFor(step).convertStepDefinition(step, conversion);
            if (i == 0) {
                addSequenceFlow(conversion, forkGateway.getId(), flowElement.getId());
            }
            if ((i + 1) == stepListDefinition.getSteps().size()) {
                endElements.add(flowElement);
            }
        }
    }
    conversion.setSequenceflowGenerationEnabled(false);
    // Second parallel gateway
    ParallelGateway joinGateway = createParallelGateway(conversion);
    conversion.setLastActivityId(joinGateway.getId());
    conversion.setSequenceflowGenerationEnabled(true);
    // Create sequence flow from all generated steps to the second gateway
    for (FlowElement endElement : endElements) {
        addSequenceFlow(conversion, endElement.getId(), joinGateway.getId());
    }
    return forkGateway;
}
Also used : ParallelGateway(org.activiti.bpmn.model.ParallelGateway) WorkflowDefinitionConversionFactory(org.activiti.workflow.simple.converter.WorkflowDefinitionConversionFactory) FlowElement(org.activiti.bpmn.model.FlowElement) ArrayList(java.util.ArrayList) ParallelStepsDefinition(org.activiti.workflow.simple.definition.ParallelStepsDefinition) ListStepDefinition(org.activiti.workflow.simple.definition.ListStepDefinition) StepDefinition(org.activiti.workflow.simple.definition.StepDefinition)

Aggregations

WorkflowDefinitionConversionFactory (org.activiti.workflow.simple.converter.WorkflowDefinitionConversionFactory)4 ArrayList (java.util.ArrayList)2 FlowElement (org.activiti.bpmn.model.FlowElement)2 StepDefinition (org.activiti.workflow.simple.definition.StepDefinition)2 BpmnModel (org.activiti.bpmn.model.BpmnModel)1 EndEvent (org.activiti.bpmn.model.EndEvent)1 ExclusiveGateway (org.activiti.bpmn.model.ExclusiveGateway)1 ParallelGateway (org.activiti.bpmn.model.ParallelGateway)1 SequenceFlow (org.activiti.bpmn.model.SequenceFlow)1 Deployment (org.activiti.engine.repository.Deployment)1 ProcessDefinition (org.activiti.engine.repository.ProcessDefinition)1 WorkflowDefinitionConversion (org.activiti.workflow.simple.converter.WorkflowDefinitionConversion)1 SimpleWorkflowJsonConverter (org.activiti.workflow.simple.converter.json.SimpleWorkflowJsonConverter)1 ChoiceStepsDefinition (org.activiti.workflow.simple.definition.ChoiceStepsDefinition)1 ConditionDefinition (org.activiti.workflow.simple.definition.ConditionDefinition)1 ListConditionStepDefinition (org.activiti.workflow.simple.definition.ListConditionStepDefinition)1 ListStepDefinition (org.activiti.workflow.simple.definition.ListStepDefinition)1 ParallelStepsDefinition (org.activiti.workflow.simple.definition.ParallelStepsDefinition)1 WorkflowDefinition (org.activiti.workflow.simple.definition.WorkflowDefinition)1 Before (org.junit.Before)1