Search in sources :

Example 26 with DataInput

use of org.eclipse.bpmn2.DataInput in project kie-wb-common by kiegroup.

the class Bpmn2JsonMarshaller method marshallSubProcess.

protected void marshallSubProcess(SubProcess subProcess, BPMNPlane plane, JsonGenerator generator, float xOffset, float yOffset, String preProcessingData, Definitions def, Map<String, Object> flowElementProperties) throws JsonGenerationException, IOException {
    Map<String, Object> properties = new LinkedHashMap<String, Object>(flowElementProperties);
    if (subProcess.getName() != null) {
        properties.put(NAME, StringEscapeUtils.unescapeXml(subProcess.getName()));
    } else {
        properties.put(NAME, "");
    }
    putDocumentationProperty(subProcess, properties);
    // overwrite name if elementname extension element is present
    String elementName = Utils.getMetaDataValue(subProcess.getExtensionValues(), "elementname");
    if (elementName != null) {
        properties.put(NAME, elementName);
    }
    if (subProcess instanceof AdHocSubProcess) {
        setAdHocSubProcessProperties((AdHocSubProcess) subProcess, properties);
    }
    // custom async
    String customAsyncMetaData = Utils.getMetaDataValue(subProcess.getExtensionValues(), "customAsync");
    String customAsync = (customAsyncMetaData != null && customAsyncMetaData.length() > 0) ? customAsyncMetaData : "false";
    properties.put(ISASYNC, customAsync);
    // data inputs
    String datainputset = marshallDataInputSet(subProcess, properties);
    // data outputs
    String dataoutputset = marshallDataOutputSet(subProcess, properties);
    // assignments
    StringBuilder associationBuff = new StringBuilder();
    List<DataInputAssociation> inputAssociations = subProcess.getDataInputAssociations();
    List<DataOutputAssociation> outputAssociations = subProcess.getDataOutputAssociations();
    marshallDataInputAssociations(associationBuff, inputAssociations);
    marshallDataOutputAssociations(associationBuff, outputAssociations);
    String assignmentString = associationBuff.toString();
    if (assignmentString.endsWith(",")) {
        assignmentString = assignmentString.substring(0, assignmentString.length() - 1);
    }
    properties.put(ASSIGNMENTS, assignmentString);
    setAssignmentsInfoProperty(null, datainputset, null, dataoutputset, assignmentString, properties);
    // on-entry and on-exit actions
    ScriptTypeListValue onEntryActions = getOnEntryActions(subProcess.getExtensionValues());
    ScriptTypeListValue onExitActions = getOnExitActions(subProcess.getExtensionValues());
    if (!onEntryActions.isEmpty()) {
        properties.put(ONENTRYACTIONS, new ScriptTypeListTypeSerializer().serialize(onEntryActions));
    }
    if (!onExitActions.isEmpty()) {
        properties.put(ONEXITACTIONS, new ScriptTypeListTypeSerializer().serialize(onExitActions));
    }
    // loop characteristics
    boolean haveValidLoopCharacteristics = false;
    if (subProcess.getLoopCharacteristics() != null && subProcess.getLoopCharacteristics() instanceof MultiInstanceLoopCharacteristics) {
        haveValidLoopCharacteristics = true;
        properties.put(MITRIGGER, "true");
        MultiInstanceLoopCharacteristics taskmi = (MultiInstanceLoopCharacteristics) subProcess.getLoopCharacteristics();
        if (taskmi.getLoopDataInputRef() != null) {
            ItemAwareElement iedatainput = taskmi.getLoopDataInputRef();
            List<DataInputAssociation> taskInputAssociations = subProcess.getDataInputAssociations();
            for (DataInputAssociation dia : taskInputAssociations) {
                if (dia.getTargetRef().equals(iedatainput)) {
                    properties.put(MULTIPLEINSTANCECOLLECTIONINPUT, dia.getSourceRef().get(0).getId());
                    break;
                }
            }
        }
        if (taskmi.getLoopDataOutputRef() != null) {
            ItemAwareElement iedataoutput = taskmi.getLoopDataOutputRef();
            List<DataOutputAssociation> taskOutputAssociations = subProcess.getDataOutputAssociations();
            for (DataOutputAssociation dout : taskOutputAssociations) {
                if (dout.getSourceRef().get(0).equals(iedataoutput)) {
                    properties.put(MULTIPLEINSTANCECOLLECTIONOUTPUT, dout.getTargetRef().getId());
                    break;
                }
            }
        }
        if (taskmi.getInputDataItem() != null) {
            List<DataInput> taskDataInputs = subProcess.getIoSpecification().getDataInputs();
            for (DataInput din : taskDataInputs) {
                if (din.getItemSubjectRef() == null) {
                    // for backward compatibility as the where only input supported
                    properties.put(MULTIPLEINSTANCEDATAINPUT, taskmi.getInputDataItem().getId());
                }
                if (din.getItemSubjectRef() != null && din.getItemSubjectRef().getId().equals(taskmi.getInputDataItem().getItemSubjectRef().getId())) {
                    properties.put(MULTIPLEINSTANCEDATAINPUT, din.getName());
                    break;
                }
            }
        }
        if (taskmi.getOutputDataItem() != null) {
            List<DataOutput> taskDataOutputs = subProcess.getIoSpecification().getDataOutputs();
            for (DataOutput dout : taskDataOutputs) {
                if (dout.getItemSubjectRef() == null) {
                    properties.put(MULTIPLEINSTANCEDATAOUTPUT, taskmi.getOutputDataItem().getId());
                    break;
                }
                if (dout.getItemSubjectRef() != null && dout.getItemSubjectRef().getId().equals(taskmi.getOutputDataItem().getItemSubjectRef().getId())) {
                    properties.put(MULTIPLEINSTANCEDATAOUTPUT, dout.getName());
                    break;
                }
            }
        }
        if (taskmi.getCompletionCondition() != null) {
            if (taskmi.getCompletionCondition() instanceof FormalExpression) {
                properties.put(MULTIPLEINSTANCECOMPLETIONCONDITION, ((FormalExpression) taskmi.getCompletionCondition()).getBody());
            }
        }
    }
    // properties
    List<Property> processProperties = subProcess.getProperties();
    if (processProperties != null && processProperties.size() > 0) {
        String propVal = "";
        for (int i = 0; i < processProperties.size(); i++) {
            Property p = processProperties.get(i);
            String pKPI = Utils.getMetaDataValue(p.getExtensionValues(), "customKPI");
            propVal += p.getId();
            // check the structureRef value
            if (p.getItemSubjectRef() != null && p.getItemSubjectRef().getStructureRef() != null) {
                propVal += ":" + p.getItemSubjectRef().getStructureRef();
            }
            if (pKPI != null && pKPI.length() > 0) {
                propVal += ":" + pKPI;
            }
            if (i != processProperties.size() - 1) {
                propVal += ",";
            }
        }
        properties.put(VARDEFS, propVal);
    }
    // simulation properties
    setSimulationProperties(subProcess.getId(), properties);
    marshallProperties(properties, generator);
    generator.writeObjectFieldStart("stencil");
    if (subProcess instanceof AdHocSubProcess) {
        generator.writeObjectField("id", "AdHocSubprocess");
    } else {
        if (subProcess.isTriggeredByEvent()) {
            generator.writeObjectField("id", "EventSubprocess");
        } else {
            if (haveValidLoopCharacteristics) {
                generator.writeObjectField("id", "MultipleInstanceSubprocess");
            } else {
                generator.writeObjectField("id", "Subprocess");
            }
        }
    }
    generator.writeEndObject();
    generator.writeArrayFieldStart("childShapes");
    Bounds bounds = ((BPMNShape) findDiagramElement(plane, subProcess)).getBounds();
    for (FlowElement flowElement : subProcess.getFlowElements()) {
        if (coordianteManipulation) {
            marshallFlowElement(flowElement, plane, generator, bounds.getX(), bounds.getY(), preProcessingData, def);
        } else {
            marshallFlowElement(flowElement, plane, generator, 0, 0, preProcessingData, def);
        }
    }
    for (Artifact artifact : subProcess.getArtifacts()) {
        if (coordianteManipulation) {
            marshallArtifact(artifact, plane, generator, bounds.getX(), bounds.getY(), preProcessingData, def);
        } else {
            marshallArtifact(artifact, plane, generator, 0, 0, preProcessingData, def);
        }
    }
    generator.writeEndArray();
    generator.writeArrayFieldStart("outgoing");
    for (BoundaryEvent boundaryEvent : subProcess.getBoundaryEventRefs()) {
        generator.writeStartObject();
        generator.writeObjectField("resourceId", boundaryEvent.getId());
        generator.writeEndObject();
    }
    for (SequenceFlow outgoing : subProcess.getOutgoing()) {
        generator.writeStartObject();
        generator.writeObjectField("resourceId", outgoing.getId());
        generator.writeEndObject();
    }
    Process process = (Process) plane.getBpmnElement();
    writeAssociations(process, subProcess.getId(), generator);
    // subprocess boundary events
    List<BoundaryEvent> boundaryEvents = new ArrayList<BoundaryEvent>();
    findBoundaryEvents(process, boundaryEvents);
    for (BoundaryEvent be : boundaryEvents) {
        if (be.getAttachedToRef().getId().equals(subProcess.getId())) {
            generator.writeStartObject();
            generator.writeObjectField("resourceId", be.getId());
            generator.writeEndObject();
        }
    }
    generator.writeEndArray();
    generator.writeObjectFieldStart("bounds");
    generator.writeObjectFieldStart("lowerRight");
    generator.writeObjectField("x", bounds.getX() + bounds.getWidth() - xOffset);
    generator.writeObjectField("y", bounds.getY() + bounds.getHeight() - yOffset);
    generator.writeEndObject();
    generator.writeObjectFieldStart("upperLeft");
    generator.writeObjectField("x", bounds.getX() - xOffset);
    generator.writeObjectField("y", bounds.getY() - yOffset);
    generator.writeEndObject();
    generator.writeEndObject();
}
Also used : DataOutput(org.eclipse.bpmn2.DataOutput) BoundaryEvent(org.eclipse.bpmn2.BoundaryEvent) SequenceFlow(org.eclipse.bpmn2.SequenceFlow) ArrayList(java.util.ArrayList) AdHocSubProcess(org.eclipse.bpmn2.AdHocSubProcess) Process(org.eclipse.bpmn2.Process) SubProcess(org.eclipse.bpmn2.SubProcess) LinkedHashMap(java.util.LinkedHashMap) AdHocSubProcess(org.eclipse.bpmn2.AdHocSubProcess) MultiInstanceLoopCharacteristics(org.eclipse.bpmn2.MultiInstanceLoopCharacteristics) DataOutputAssociation(org.eclipse.bpmn2.DataOutputAssociation) ScriptTypeListTypeSerializer(org.kie.workbench.common.stunner.bpmn.backend.marshall.json.oryx.property.ScriptTypeListTypeSerializer) Property(org.eclipse.bpmn2.Property) Bounds(org.eclipse.dd.dc.Bounds) ItemAwareElement(org.eclipse.bpmn2.ItemAwareElement) FormalExpression(org.eclipse.bpmn2.FormalExpression) BPMNShape(org.eclipse.bpmn2.di.BPMNShape) Point(org.eclipse.dd.dc.Point) Artifact(org.eclipse.bpmn2.Artifact) DataInput(org.eclipse.bpmn2.DataInput) FlowElement(org.eclipse.bpmn2.FlowElement) DataObject(org.eclipse.bpmn2.DataObject) DataInputAssociation(org.eclipse.bpmn2.DataInputAssociation) ScriptTypeListValue(org.kie.workbench.common.stunner.bpmn.definition.property.task.ScriptTypeListValue)

Example 27 with DataInput

use of org.eclipse.bpmn2.DataInput in project kie-wb-common by kiegroup.

the class InputAssignmentWriter method associationOf.

private DataInputAssociation associationOf(Property source, DataInput dataInput) {
    DataInputAssociation dataInputAssociation = bpmn2.createDataInputAssociation();
    dataInputAssociation.getSourceRef().add(source);
    dataInputAssociation.setTargetRef(dataInput);
    return dataInputAssociation;
}
Also used : DataInputAssociation(org.eclipse.bpmn2.DataInputAssociation)

Example 28 with DataInput

use of org.eclipse.bpmn2.DataInput in project kie-wb-common by kiegroup.

the class InitializedVariableTest method testGetDataInput.

@Test
public void testGetDataInput() {
    final String SOURCE_VAR = "BooleanSource";
    final String DATA_INPUT_ID = "_Data-Input-TestInputX";
    final String DATA_INPUT_NAME = "Data Input Test";
    final String DATA_INPUT_ASSOCIATION_ID = "Data Input Test";
    final String DATA_INPUT_ASSOCIATION_VALUE = "BooleanSource";
    final String INIT_INPUT_VAR_ID = "Data-Input-Test";
    final String INIT_INPUT_VAR_TYPE = "Boolean";
    final VariableDeclaration varDeclaration = new VariableDeclaration("Data Input Test", "Boolean");
    InitializedVariable.InitializedInputVariable initializedInputVar = new InitializedVariable.InputVariableReference("", varScope, varDeclaration, SOURCE_VAR, new HashSet<>());
    DataInput dataInput = initializedInputVar.getDataInput();
    DataInputAssociation dataInputAssociation = initializedInputVar.getDataInputAssociation();
    List<ItemAwareElement> sourceRef = dataInputAssociation.getSourceRef();
    PropertyImpl source = (PropertyImpl) sourceRef.get(0);
    DataInput target = (DataInput) dataInputAssociation.getTargetRef();
    String dataInputId = dataInput.getId();
    String dataInputName = dataInput.getName();
    String dataInputAssociationID = target.getName();
    String dataInputAssociationValue = source.getId();
    String initVarID = initializedInputVar.getIdentifier();
    String initVarType = initializedInputVar.getType();
    assertEquals(dataInputId, DATA_INPUT_ID);
    assertEquals(dataInputName, DATA_INPUT_NAME);
    assertEquals(dataInputAssociationID, DATA_INPUT_ASSOCIATION_ID);
    assertEquals(dataInputAssociationValue, DATA_INPUT_ASSOCIATION_VALUE);
    assertEquals(initVarID, INIT_INPUT_VAR_ID);
    assertEquals(initVarType, INIT_INPUT_VAR_TYPE);
}
Also used : DataInput(org.eclipse.bpmn2.DataInput) InitializedVariable(org.kie.workbench.common.stunner.bpmn.backend.converters.customproperties.InitializedVariable) ItemAwareElement(org.eclipse.bpmn2.ItemAwareElement) VariableDeclaration(org.kie.workbench.common.stunner.bpmn.backend.converters.customproperties.VariableDeclaration) PropertyImpl(org.eclipse.bpmn2.impl.PropertyImpl) DataInputAssociation(org.eclipse.bpmn2.DataInputAssociation) Test(org.junit.Test)

Example 29 with DataInput

use of org.eclipse.bpmn2.DataInput in project kie-wb-common by kiegroup.

the class AssociationsTest method findAssignment.

private String findAssignment(List<DataInputAssociation> associations, String varName) {
    return associations.stream().filter(a -> {
        DataInput in = (DataInput) a.getTargetRef();
        return in.getName().equals(varName);
    }).map(a -> {
        Assignment assignment = a.getAssignment().get(0);
        FormalExpression expr = (FormalExpression) assignment.getFrom();
        return expr.getBody();
    }).findFirst().get();
}
Also used : StartEvent(org.eclipse.bpmn2.StartEvent) FormalExpression(org.eclipse.bpmn2.FormalExpression) FlatVariableScope(org.kie.workbench.common.stunner.bpmn.backend.converters.fromstunner.properties.FlatVariableScope) UserTask(org.kie.workbench.common.stunner.bpmn.definition.UserTask) View(org.kie.workbench.common.stunner.core.graph.content.view.View) HashSet(java.util.HashSet) DataInput(org.eclipse.bpmn2.DataInput) Property(org.eclipse.bpmn2.Property) DefinitionsConverter(org.kie.workbench.common.stunner.bpmn.backend.converters.fromstunner.DefinitionsConverter) Diagram(org.kie.workbench.common.stunner.core.diagram.Diagram) Definitions(org.eclipse.bpmn2.Definitions) Ids(org.kie.workbench.common.stunner.bpmn.backend.converters.fromstunner.Ids) AssignmentsInfo(org.kie.workbench.common.stunner.bpmn.definition.property.dataio.AssignmentsInfo) Process(org.eclipse.bpmn2.Process) DataInputAssociation(org.eclipse.bpmn2.DataInputAssociation) Factories.bpmn2(org.kie.workbench.common.stunner.bpmn.backend.converters.fromstunner.Factories.bpmn2) Test(org.junit.Test) Metadata(org.kie.workbench.common.stunner.core.diagram.Metadata) List(java.util.List) Graph(org.kie.workbench.common.stunner.core.graph.Graph) Assignment(org.eclipse.bpmn2.Assignment) CatchEventPropertyWriter(org.kie.workbench.common.stunner.bpmn.backend.converters.fromstunner.properties.CatchEventPropertyWriter) BPMNDiagramMarshallerBaseTest(org.kie.workbench.common.stunner.bpmn.backend.service.diagram.marshalling.BPMNDiagramMarshallerBaseTest) Node(org.kie.workbench.common.stunner.core.graph.Node) TestCase.assertEquals(junit.framework.TestCase.assertEquals) DataInput(org.eclipse.bpmn2.DataInput) Assignment(org.eclipse.bpmn2.Assignment) FormalExpression(org.eclipse.bpmn2.FormalExpression)

Example 30 with DataInput

use of org.eclipse.bpmn2.DataInput in project kie-wb-common by kiegroup.

the class MultipleInstanceActivityPropertyReaderTest method testGetEmptyDataInput.

@Test
public void testGetEmptyDataInput() {
    DataInput item = mockDataInput(ITEM_ID, null);
    when(miloop.getInputDataItem()).thenReturn(item);
    assertEquals(ITEM_ID + DELIMITER + DATA_TYPE, reader.getDataInput());
}
Also used : DataInput(org.eclipse.bpmn2.DataInput) ActivityPropertyReaderTest.mockDataInput(org.kie.workbench.common.stunner.bpmn.backend.converters.tostunner.properties.ActivityPropertyReaderTest.mockDataInput) Test(org.junit.Test)

Aggregations

DataInput (org.eclipse.bpmn2.DataInput)38 DataInputAssociation (org.eclipse.bpmn2.DataInputAssociation)25 DataOutput (org.eclipse.bpmn2.DataOutput)17 FormalExpression (org.eclipse.bpmn2.FormalExpression)15 ArrayList (java.util.ArrayList)12 DataOutputAssociation (org.eclipse.bpmn2.DataOutputAssociation)12 Assignment (org.eclipse.bpmn2.Assignment)11 ItemAwareElement (org.eclipse.bpmn2.ItemAwareElement)11 Test (org.junit.Test)10 List (java.util.List)9 InputSet (org.eclipse.bpmn2.InputSet)9 InputOutputSpecification (org.eclipse.bpmn2.InputOutputSpecification)8 SimpleFeatureMapEntry (org.eclipse.emf.ecore.impl.EStructuralFeatureImpl.SimpleFeatureMapEntry)8 Parameter (bpsim.Parameter)5 ItemDefinition (org.eclipse.bpmn2.ItemDefinition)5 Process (org.eclipse.bpmn2.Process)5 Property (org.eclipse.bpmn2.Property)5 NormalDistributionType (bpsim.NormalDistributionType)4 PoissonDistributionType (bpsim.PoissonDistributionType)4 TimeParameters (bpsim.TimeParameters)4