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());
}
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;
}
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();
}
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;
}
Aggregations