Search in sources :

Example 11 with BPMNShape

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

the class Bpmn2JsonMarshaller method marshallSequenceFlow.

protected void marshallSequenceFlow(SequenceFlow sequenceFlow, BPMNPlane plane, JsonGenerator generator, float xOffset, float yOffset) throws JsonGenerationException, IOException {
    // dont marshal "dangling" sequence flow..better to just omit than fail
    if (sequenceFlow.getSourceRef() == null || sequenceFlow.getTargetRef() == null) {
        return;
    }
    Map<String, Object> properties = new LinkedHashMap<String, Object>();
    // check null for sequence flow name
    if (sequenceFlow.getName() != null && !"".equals(sequenceFlow.getName())) {
        properties.put(NAME, StringEscapeUtils.unescapeXml(sequenceFlow.getName()));
    } else {
        properties.put(NAME, "");
    }
    // overwrite name if elementname extension element is present
    String elementName = Utils.getMetaDataValue(sequenceFlow.getExtensionValues(), "elementname");
    if (elementName != null) {
        properties.put(NAME, elementName);
    }
    putDocumentationProperty(sequenceFlow, properties);
    if (sequenceFlow.isIsImmediate()) {
        properties.put(ISIMMEDIATE, "true");
    } else {
        properties.put(ISIMMEDIATE, "false");
    }
    Expression conditionExpression = sequenceFlow.getConditionExpression();
    if (conditionExpression instanceof FormalExpression) {
        setConditionExpressionProperties((FormalExpression) conditionExpression, properties, "mvel");
    }
    boolean foundBgColor = false;
    boolean foundBrColor = false;
    boolean foundFontColor = false;
    boolean foundSelectable = false;
    Iterator<FeatureMap.Entry> iter = sequenceFlow.getAnyAttribute().iterator();
    while (iter.hasNext()) {
        FeatureMap.Entry entry = iter.next();
        if (entry.getEStructuralFeature().getName().equals("priority")) {
            String priorityStr = String.valueOf(entry.getValue());
            if (priorityStr != null) {
                try {
                    Integer priorityInt = Integer.parseInt(priorityStr);
                    if (priorityInt >= 1) {
                        properties.put(PRIORITY, entry.getValue());
                    } else {
                        _logger.error("Priority must be equal or greater than 1.");
                    }
                } catch (NumberFormatException e) {
                    _logger.error("Priority must be a number.");
                }
            }
        }
        if (entry.getEStructuralFeature().getName().equals("background-color") || entry.getEStructuralFeature().getName().equals("bgcolor")) {
            properties.put(BGCOLOR, entry.getValue());
            foundBgColor = true;
        }
        if (entry.getEStructuralFeature().getName().equals("border-color") || entry.getEStructuralFeature().getName().equals("bordercolor")) {
            properties.put(BORDERCOLOR, entry.getValue());
            foundBrColor = true;
        }
        if (entry.getEStructuralFeature().getName().equals("fontsize")) {
            properties.put(FONTSIZE, entry.getValue());
            foundBrColor = true;
        }
        if (entry.getEStructuralFeature().getName().equals("color") || entry.getEStructuralFeature().getName().equals("fontcolor")) {
            properties.put(FONTCOLOR, entry.getValue());
            foundFontColor = true;
        }
        if (entry.getEStructuralFeature().getName().equals("selectable")) {
            properties.put(ISSELECTABLE, entry.getValue());
            foundSelectable = true;
        }
    }
    if (!foundBgColor) {
        properties.put(BGCOLOR, defaultSequenceflowColor);
    }
    if (!foundBrColor) {
        properties.put(BORDERCOLOR, defaultSequenceflowColor);
    }
    if (!foundFontColor) {
        properties.put(FONTCOLOR, defaultSequenceflowColor);
    }
    if (!foundSelectable) {
        properties.put(ISSELECTABLE, "true");
    }
    // simulation properties
    setSimulationProperties(sequenceFlow.getId(), properties);
    // Custom attributes for Stunner's connectors - source/target auto connection flag.
    String sourcePropertyName = Bpmn2OryxManager.MAGNET_AUTO_CONNECTION + Bpmn2OryxManager.SOURCE;
    String sourceConnectorAuto = Utils.getMetaDataValue(sequenceFlow.getExtensionValues(), sourcePropertyName);
    if (sourceConnectorAuto != null && sourceConnectorAuto.trim().length() > 0) {
        properties.put(sourcePropertyName, sourceConnectorAuto);
    }
    String targetPropertyName = Bpmn2OryxManager.MAGNET_AUTO_CONNECTION + Bpmn2OryxManager.TARGET;
    String targetConnectorAuto = Utils.getMetaDataValue(sequenceFlow.getExtensionValues(), targetPropertyName);
    if (targetConnectorAuto != null && targetConnectorAuto.trim().length() > 0) {
        properties.put(targetPropertyName, targetConnectorAuto);
    }
    marshallProperties(properties, generator);
    generator.writeObjectFieldStart("stencil");
    generator.writeObjectField("id", "SequenceFlow");
    generator.writeEndObject();
    generator.writeArrayFieldStart("childShapes");
    generator.writeEndArray();
    generator.writeArrayFieldStart("outgoing");
    generator.writeStartObject();
    generator.writeObjectField("resourceId", sequenceFlow.getTargetRef().getId());
    generator.writeEndObject();
    generator.writeEndArray();
    Bounds sourceBounds = ((BPMNShape) findDiagramElement(plane, sequenceFlow.getSourceRef())).getBounds();
    Bounds targetBounds = ((BPMNShape) findDiagramElement(plane, sequenceFlow.getTargetRef())).getBounds();
    generator.writeArrayFieldStart("dockers");
    List<Point> waypoints = ((BPMNEdge) findDiagramElement(plane, sequenceFlow)).getWaypoint();
    if (waypoints.size() > 1) {
        Point waypoint = waypoints.get(0);
        writeWaypointObject(generator, waypoint.getX() - sourceBounds.getX(), waypoint.getY() - sourceBounds.getY());
    } else {
        writeWaypointObject(generator, sourceBounds.getWidth() / 2, sourceBounds.getHeight() / 2);
    }
    for (int i = 1; i < waypoints.size() - 1; i++) {
        Point waypoint = waypoints.get(i);
        writeWaypointObject(generator, waypoint.getX(), waypoint.getY());
    }
    if (waypoints.size() > 1) {
        Point waypoint = waypoints.get(waypoints.size() - 1);
        writeWaypointObject(generator, waypoint.getX() - targetBounds.getX(), waypoint.getY() - targetBounds.getY());
    } else {
        writeWaypointObject(generator, targetBounds.getWidth() / 2, targetBounds.getHeight() / 2);
    }
    generator.writeEndArray();
}
Also used : Bounds(org.eclipse.dd.dc.Bounds) Point(org.eclipse.dd.dc.Point) FormalExpression(org.eclipse.bpmn2.FormalExpression) BPMNShape(org.eclipse.bpmn2.di.BPMNShape) Point(org.eclipse.dd.dc.Point) LinkedHashMap(java.util.LinkedHashMap) FeatureMap(org.eclipse.emf.ecore.util.FeatureMap) Entry(java.util.Map.Entry) Expression(org.eclipse.bpmn2.Expression) FormalExpression(org.eclipse.bpmn2.FormalExpression) DataObject(org.eclipse.bpmn2.DataObject) BPMNEdge(org.eclipse.bpmn2.di.BPMNEdge)

Example 12 with BPMNShape

use of org.eclipse.bpmn2.di.BPMNShape 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 13 with BPMNShape

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

the class Bpmn2JsonMarshaller method findDiagramElement.

private DiagramElement findDiagramElement(BPMNPlane plane, BaseElement baseElement) {
    DiagramElement result = _diagramElements.get(baseElement.getId());
    if (result != null) {
        return result;
    }
    for (DiagramElement element : plane.getPlaneElement()) {
        if ((element instanceof BPMNEdge && ((BPMNEdge) element).getBpmnElement() == baseElement) || (element instanceof BPMNShape && ((BPMNShape) element).getBpmnElement() == baseElement)) {
            _diagramElements.put(baseElement.getId(), element);
            return element;
        }
    }
    _logger.debug("Could not find BPMNDI information for " + baseElement);
    return null;
}
Also used : DiagramElement(org.eclipse.dd.di.DiagramElement) BPMNShape(org.eclipse.bpmn2.di.BPMNShape) BPMNEdge(org.eclipse.bpmn2.di.BPMNEdge)

Aggregations

BPMNShape (org.eclipse.bpmn2.di.BPMNShape)12 Bounds (org.eclipse.dd.dc.Bounds)9 DataObject (org.eclipse.bpmn2.DataObject)7 LinkedHashMap (java.util.LinkedHashMap)6 SubProcess (org.eclipse.bpmn2.SubProcess)6 ArrayList (java.util.ArrayList)5 AdHocSubProcess (org.eclipse.bpmn2.AdHocSubProcess)5 Process (org.eclipse.bpmn2.Process)5 BPMNEdge (org.eclipse.bpmn2.di.BPMNEdge)5 Point (org.eclipse.dd.dc.Point)5 DiagramElement (org.eclipse.dd.di.DiagramElement)5 Entry (java.util.Map.Entry)4 FeatureMap (org.eclipse.emf.ecore.util.FeatureMap)4 SequenceFlow (org.eclipse.bpmn2.SequenceFlow)3 List (java.util.List)2 Artifact (org.eclipse.bpmn2.Artifact)2 BoundaryEvent (org.eclipse.bpmn2.BoundaryEvent)2 DataInputAssociation (org.eclipse.bpmn2.DataInputAssociation)2 DataOutputAssociation (org.eclipse.bpmn2.DataOutputAssociation)2 FlowElement (org.eclipse.bpmn2.FlowElement)2