Search in sources :

Example 31 with FlowElement

use of org.activiti.bpmn.model.FlowElement in project Activiti by Activiti.

the class BpmnXMLConverter method convertToXML.

public byte[] convertToXML(BpmnModel model, String encoding) {
    try {
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        XMLOutputFactory xof = XMLOutputFactory.newInstance();
        OutputStreamWriter out = new OutputStreamWriter(outputStream, encoding);
        XMLStreamWriter writer = xof.createXMLStreamWriter(out);
        XMLStreamWriter xtw = new IndentingXMLStreamWriter(writer);
        DefinitionsRootExport.writeRootElement(model, xtw, encoding);
        CollaborationExport.writePools(model, xtw);
        DataStoreExport.writeDataStores(model, xtw);
        SignalAndMessageDefinitionExport.writeSignalsAndMessages(model, xtw);
        for (Process process : model.getProcesses()) {
            if (process.getFlowElements().isEmpty() && process.getLanes().isEmpty()) {
                // empty process, ignore it 
                continue;
            }
            ProcessExport.writeProcess(process, xtw);
            for (FlowElement flowElement : process.getFlowElements()) {
                createXML(flowElement, model, xtw);
            }
            for (Artifact artifact : process.getArtifacts()) {
                createXML(artifact, model, xtw);
            }
            // end process element
            xtw.writeEndElement();
        }
        BPMNDIExport.writeBPMNDI(model, xtw);
        // end definitions root element
        xtw.writeEndElement();
        xtw.writeEndDocument();
        xtw.flush();
        outputStream.close();
        xtw.close();
        return outputStream.toByteArray();
    } catch (Exception e) {
        LOGGER.error("Error writing BPMN XML", e);
        throw new XMLException("Error writing BPMN XML", e);
    }
}
Also used : XMLOutputFactory(javax.xml.stream.XMLOutputFactory) XMLException(org.activiti.bpmn.exceptions.XMLException) XMLStreamWriter(javax.xml.stream.XMLStreamWriter) FlowElement(org.activiti.bpmn.model.FlowElement) OutputStreamWriter(java.io.OutputStreamWriter) EventSubProcess(org.activiti.bpmn.model.EventSubProcess) Process(org.activiti.bpmn.model.Process) SubProcess(org.activiti.bpmn.model.SubProcess) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Artifact(org.activiti.bpmn.model.Artifact) XMLStreamException(javax.xml.stream.XMLStreamException) XMLException(org.activiti.bpmn.exceptions.XMLException) SAXException(org.xml.sax.SAXException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IOException(java.io.IOException)

Example 32 with FlowElement

use of org.activiti.bpmn.model.FlowElement in project Activiti by Activiti.

the class WorkflowDefinitionConversionTest method testTaskListenerForOutgoingProperties.

@Test
public void testTaskListenerForOutgoingProperties() throws Exception {
    WorkflowDefinition definition = new WorkflowDefinition();
    definition.setId("process");
    HumanStepDefinition humanStep = new HumanStepDefinition();
    humanStep.setId("step1");
    FormDefinition form = new FormDefinition();
    humanStep.setForm(form);
    TextPropertyDefinition text = new TextPropertyDefinition();
    text.setName("my text");
    text.getParameters().put(AlfrescoConversionConstants.PARAMETER_ADD_PROPERTY_TO_OUTPUT, true);
    FormPropertyGroup group = new FormPropertyGroup();
    group.setId("group");
    form.getFormGroups().add(group);
    group.getFormPropertyDefinitions().add(text);
    definition.addStep(humanStep);
    WorkflowDefinitionConversion conversion = conversionFactory.createWorkflowDefinitionConversion(definition);
    conversion.convert();
    Process process = conversion.getProcess();
    assertNotNull(process);
    boolean listenerFound = false;
    for (FlowElement flowElement : process.getFlowElements()) {
        if (flowElement instanceof UserTask) {
            UserTask task = (UserTask) flowElement;
            assertNotNull(task.getTaskListeners());
            assertEquals(2L, task.getTaskListeners().size());
            assertEquals("create", task.getTaskListeners().get(0).getEvent());
            assertEquals("complete", task.getTaskListeners().get(1).getEvent());
            listenerFound = true;
        }
    }
    assertTrue(listenerFound);
}
Also used : WorkflowDefinitionConversion(org.activiti.workflow.simple.converter.WorkflowDefinitionConversion) HumanStepDefinition(org.activiti.workflow.simple.definition.HumanStepDefinition) TextPropertyDefinition(org.activiti.workflow.simple.definition.form.TextPropertyDefinition) FlowElement(org.activiti.bpmn.model.FlowElement) UserTask(org.activiti.bpmn.model.UserTask) WorkflowDefinition(org.activiti.workflow.simple.definition.WorkflowDefinition) FormPropertyGroup(org.activiti.workflow.simple.definition.form.FormPropertyGroup) Process(org.activiti.bpmn.model.Process) FormDefinition(org.activiti.workflow.simple.definition.form.FormDefinition) Test(org.junit.Test)

Example 33 with FlowElement

use of org.activiti.bpmn.model.FlowElement in project Activiti by Activiti.

the class WorkflowDefinitionConversionTest method testTaskListenerForIncomingProperties.

@Test
public void testTaskListenerForIncomingProperties() throws Exception {
    WorkflowDefinition definition = new WorkflowDefinition();
    definition.setId("process");
    HumanStepDefinition humanStep = new HumanStepDefinition();
    humanStep.setId("step1");
    FormDefinition form = new FormDefinition();
    form.setFormKey("myform");
    humanStep.setForm(form);
    definition.addStep(humanStep);
    WorkflowDefinitionConversion conversion = conversionFactory.createWorkflowDefinitionConversion(definition);
    conversion.convert();
    Process process = conversion.getProcess();
    assertNotNull(process);
    boolean listenerFound = false;
    for (FlowElement flowElement : process.getFlowElements()) {
        if (flowElement instanceof UserTask) {
            UserTask task = (UserTask) flowElement;
            assertNotNull(task.getTaskListeners());
            assertEquals(1L, task.getTaskListeners().size());
            assertEquals("create", task.getTaskListeners().get(0).getEvent());
            listenerFound = true;
        }
    }
    assertTrue(listenerFound);
}
Also used : WorkflowDefinitionConversion(org.activiti.workflow.simple.converter.WorkflowDefinitionConversion) HumanStepDefinition(org.activiti.workflow.simple.definition.HumanStepDefinition) FlowElement(org.activiti.bpmn.model.FlowElement) UserTask(org.activiti.bpmn.model.UserTask) WorkflowDefinition(org.activiti.workflow.simple.definition.WorkflowDefinition) Process(org.activiti.bpmn.model.Process) FormDefinition(org.activiti.workflow.simple.definition.form.FormDefinition) Test(org.junit.Test)

Example 34 with FlowElement

use of org.activiti.bpmn.model.FlowElement 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 35 with FlowElement

use of org.activiti.bpmn.model.FlowElement in project Activiti by Activiti.

the class BaseBpmnXMLConverter method convertToXML.

public void convertToXML(XMLStreamWriter xtw, BaseElement baseElement, BpmnModel model) throws Exception {
    xtw.writeStartElement(getXMLElementName());
    boolean didWriteExtensionStartElement = false;
    writeDefaultAttribute(ATTRIBUTE_ID, baseElement.getId(), xtw);
    if (baseElement instanceof FlowElement) {
        writeDefaultAttribute(ATTRIBUTE_NAME, ((FlowElement) baseElement).getName(), xtw);
    }
    if (baseElement instanceof FlowNode) {
        final FlowNode flowNode = (FlowNode) baseElement;
        if (flowNode.isAsynchronous()) {
            writeQualifiedAttribute(ATTRIBUTE_ACTIVITY_ASYNCHRONOUS, ATTRIBUTE_VALUE_TRUE, xtw);
            if (flowNode.isNotExclusive()) {
                writeQualifiedAttribute(ATTRIBUTE_ACTIVITY_EXCLUSIVE, ATTRIBUTE_VALUE_FALSE, xtw);
            }
        }
        if (baseElement instanceof Activity) {
            final Activity activity = (Activity) baseElement;
            if (activity.isForCompensation()) {
                writeDefaultAttribute(ATTRIBUTE_ACTIVITY_ISFORCOMPENSATION, ATTRIBUTE_VALUE_TRUE, xtw);
            }
            if (StringUtils.isNotEmpty(activity.getDefaultFlow())) {
                FlowElement defaultFlowElement = model.getFlowElement(activity.getDefaultFlow());
                if (defaultFlowElement instanceof SequenceFlow) {
                    writeDefaultAttribute(ATTRIBUTE_DEFAULT, activity.getDefaultFlow(), xtw);
                }
            }
        }
        if (baseElement instanceof Gateway) {
            final Gateway gateway = (Gateway) baseElement;
            if (StringUtils.isNotEmpty(gateway.getDefaultFlow())) {
                FlowElement defaultFlowElement = model.getFlowElement(gateway.getDefaultFlow());
                if (defaultFlowElement instanceof SequenceFlow) {
                    writeDefaultAttribute(ATTRIBUTE_DEFAULT, gateway.getDefaultFlow(), xtw);
                }
            }
        }
    }
    writeAdditionalAttributes(baseElement, model, xtw);
    if (baseElement instanceof FlowElement) {
        final FlowElement flowElement = (FlowElement) baseElement;
        if (StringUtils.isNotEmpty(flowElement.getDocumentation())) {
            xtw.writeStartElement(ELEMENT_DOCUMENTATION);
            xtw.writeCharacters(flowElement.getDocumentation());
            xtw.writeEndElement();
        }
    }
    didWriteExtensionStartElement = writeExtensionChildElements(baseElement, didWriteExtensionStartElement, xtw);
    didWriteExtensionStartElement = writeListeners(baseElement, didWriteExtensionStartElement, xtw);
    didWriteExtensionStartElement = BpmnXMLUtil.writeExtensionElements(baseElement, didWriteExtensionStartElement, model.getNamespaces(), xtw);
    if (baseElement instanceof Activity) {
        final Activity activity = (Activity) baseElement;
        FailedJobRetryCountExport.writeFailedJobRetryCount(activity, xtw);
    }
    if (didWriteExtensionStartElement) {
        xtw.writeEndElement();
    }
    if (baseElement instanceof Activity) {
        final Activity activity = (Activity) baseElement;
        MultiInstanceExport.writeMultiInstance(activity, xtw);
    }
    writeAdditionalChildElements(baseElement, model, xtw);
    xtw.writeEndElement();
}
Also used : FlowElement(org.activiti.bpmn.model.FlowElement) SequenceFlow(org.activiti.bpmn.model.SequenceFlow) Gateway(org.activiti.bpmn.model.Gateway) Activity(org.activiti.bpmn.model.Activity) FlowNode(org.activiti.bpmn.model.FlowNode)

Aggregations

FlowElement (org.activiti.bpmn.model.FlowElement)77 SubProcess (org.activiti.bpmn.model.SubProcess)27 UserTask (org.activiti.bpmn.model.UserTask)26 SequenceFlow (org.activiti.bpmn.model.SequenceFlow)24 StartEvent (org.activiti.bpmn.model.StartEvent)14 Process (org.activiti.bpmn.model.Process)13 ArrayList (java.util.ArrayList)11 BoundaryEvent (org.activiti.bpmn.model.BoundaryEvent)11 HashMap (java.util.HashMap)9 ActivitiListener (org.activiti.bpmn.model.ActivitiListener)9 Activity (org.activiti.bpmn.model.Activity)9 ServiceTask (org.activiti.bpmn.model.ServiceTask)9 Gateway (org.activiti.bpmn.model.Gateway)8 GraphicInfo (org.activiti.bpmn.model.GraphicInfo)7 TimerEventDefinition (org.activiti.bpmn.model.TimerEventDefinition)7 Artifact (org.activiti.bpmn.model.Artifact)6 FlowNode (org.activiti.bpmn.model.FlowNode)6 SignalEventDefinition (org.activiti.bpmn.model.SignalEventDefinition)6 BpmnModel (org.activiti.bpmn.model.BpmnModel)5 EventDefinition (org.activiti.bpmn.model.EventDefinition)5