Search in sources :

Example 1 with ObjectParser

use of org.kie.workbench.common.stunner.bpmn.backend.marshall.json.parser.common.ObjectParser in project kie-wb-common by kiegroup.

the class EdgeParser method initialize.

@SuppressWarnings("unchecked")
@Override
public void initialize(final Context context) {
    super.initialize(context);
    String outNodeId = element.getTargetNode() != null ? element.getTargetNode().getUUID() : null;
    // Outgoing.
    if (null != outNodeId) {
        ArrayParser outgoingParser = new ArrayParser("outgoing");
        outgoingParser.addParser(new ObjectParser("").addParser(new StringFieldParser("resourceId", outNodeId)));
        super.addParser(outgoingParser);
    }
    // Use dockers
    ArrayParser dockersParser = new ArrayParser("dockers");
    ViewConnector viewConnector = (ViewConnector) element.getContent();
    // insert source
    dockersParser.addParser(createDockerObjectParser(viewConnector.getSourceConnection()));
    // inserting ControlPoints
    viewConnector.getControlPoints().stream().sequential().map(ControlPoint::getLocation).map(this::createDockerObjectParser).forEach(dockersParser::addParser);
    // insert target
    dockersParser.addParser(createDockerObjectParser(viewConnector.getTargetConnection()));
    super.addParser(dockersParser);
}
Also used : ObjectParser(org.kie.workbench.common.stunner.bpmn.backend.marshall.json.parser.common.ObjectParser) ViewConnector(org.kie.workbench.common.stunner.core.graph.content.view.ViewConnector) ControlPoint(org.kie.workbench.common.stunner.core.graph.content.view.ControlPoint) ArrayParser(org.kie.workbench.common.stunner.bpmn.backend.marshall.json.parser.common.ArrayParser) StringFieldParser(org.kie.workbench.common.stunner.bpmn.backend.marshall.json.parser.common.StringFieldParser)

Example 2 with ObjectParser

use of org.kie.workbench.common.stunner.bpmn.backend.marshall.json.parser.common.ObjectParser in project kie-wb-common by kiegroup.

the class ElementParser method parseBounds.

protected void parseBounds(final Bounds.Bound ul, final Bounds.Bound lr) {
    // Bounds.
    ObjectParser ulBoundParser = new ObjectParser("upperLeft").addParser(new IntegerFieldParser("x", ul.getX().intValue())).addParser(new IntegerFieldParser("y", ul.getY().intValue()));
    ObjectParser lrBoundParser = new ObjectParser("lowerRight").addParser(new IntegerFieldParser("x", lr.getX().intValue())).addParser(new IntegerFieldParser("y", lr.getY().intValue()));
    ObjectParser boundsParser = new ObjectParser("bounds").addParser(lrBoundParser).addParser(ulBoundParser);
    super.addParser(boundsParser);
}
Also used : ObjectParser(org.kie.workbench.common.stunner.bpmn.backend.marshall.json.parser.common.ObjectParser) IntegerFieldParser(org.kie.workbench.common.stunner.bpmn.backend.marshall.json.parser.common.IntegerFieldParser)

Example 3 with ObjectParser

use of org.kie.workbench.common.stunner.bpmn.backend.marshall.json.parser.common.ObjectParser in project kie-wb-common by kiegroup.

the class ElementParser method initialize.

@Override
@SuppressWarnings("unchecked")
public void initialize(final Context context) {
    this.context = context;
    Object definition = element.getContent().getDefinition();
    // Resource id field.
    super.addParser(new StringFieldParser("resourceId", element.getUUID()));
    // Properties array.
    Object def = element.getContent().getDefinition();
    Set<?> properties = context.getDefinitionManager().adapters().forDefinition().getProperties(def);
    ObjectParser propertiesParser = new ObjectParser("properties");
    super.addParser(propertiesParser);
    if (null != properties && !properties.isEmpty()) {
        for (Object property : properties) {
            PropertyAdapter propertyAdapter = context.getDefinitionManager().adapters().registry().getPropertyAdapter(property.getClass());
            PropertyType propertyType = propertyAdapter.getType(property);
            String oryxPropId = context.getOryxManager().getMappingsManager().getOryxPropertyId(def.getClass(), property.getClass());
            Object value = propertyAdapter.getValue(property);
            String valueStr = value != null ? context.getOryxManager().getPropertyManager().serialize(property, propertyType, value) : "";
            propertiesParser.addParser(new StringFieldParser(oryxPropId, valueStr));
        }
    }
    // Custom extended prpoerties, if any.
    parseExtendedProperties(propertiesParser);
    // Stencil id field.
    String defId = context.getOryxManager().getMappingsManager().getOryxDefinitionId(definition);
    super.addParser(new ObjectParser("stencil").addParser(new StringFieldParser("id", defId)));
    // Bounds.
    Bounds.Bound ul = element.getContent().getBounds().getUpperLeft();
    Bounds.Bound lr = element.getContent().getBounds().getLowerRight();
    parseBounds(ul, lr);
}
Also used : ObjectParser(org.kie.workbench.common.stunner.bpmn.backend.marshall.json.parser.common.ObjectParser) Bounds(org.kie.workbench.common.stunner.core.graph.content.Bounds) PropertyAdapter(org.kie.workbench.common.stunner.core.definition.adapter.PropertyAdapter) PropertyType(org.kie.workbench.common.stunner.core.definition.property.PropertyType) StringFieldParser(org.kie.workbench.common.stunner.bpmn.backend.marshall.json.parser.common.StringFieldParser)

Example 4 with ObjectParser

use of org.kie.workbench.common.stunner.bpmn.backend.marshall.json.parser.common.ObjectParser in project kie-wb-common by kiegroup.

the class NodeParser method initialize.

@Override
public void initialize(final Context context) {
    super.initialize(context);
    // Children.
    ArrayParser childrenParser = new ArrayParser("childShapes");
    for (Parser childParser : children) {
        if (childParser instanceof ContextualParser) {
            ((ContextualParser) childParser).initialize(context);
            childrenParser.addParser(childParser);
        }
    }
    super.addParser(childrenParser);
    // Outgoing.
    ArrayParser outgoingParser = new ArrayParser("outgoing");
    super.addParser(outgoingParser);
    List<Edge> outEdges = element.getOutEdges();
    if (null != outEdges && !outEdges.isEmpty()) {
        for (Edge edge : outEdges) {
            String outId = null;
            if (isViewEdge(edge)) {
                // View connectors, such as sequence flows.
                outId = edge.getUUID();
            } else if (isDockEdge(edge)) {
                // Docked nodes. Oryx marshallers do not expect an outgoing sequence flow id here, it expects the
                // id of the docked node.
                Node docked = edge.getTargetNode();
                outId = docked.getUUID();
            }
            if (null != outId) {
                outgoingParser.addParser(new ObjectParser("").addParser(new StringFieldParser("resourceId", outId)));
            }
        }
    }
    // Dockers - Only use if this node is docked.
    if (isDocked(element)) {
        Bounds.Bound ul = element.getContent().getBounds().getUpperLeft();
        ObjectParser docker1ObjParser = new ObjectParser("").addParser(new IntegerFieldParser("x", ul.getX().intValue())).addParser(new IntegerFieldParser("y", ul.getY().intValue()));
        ArrayParser dockersParser = new ArrayParser("dockers").addParser(docker1ObjParser);
        super.addParser(dockersParser);
    }
}
Also used : ObjectParser(org.kie.workbench.common.stunner.bpmn.backend.marshall.json.parser.common.ObjectParser) IntegerFieldParser(org.kie.workbench.common.stunner.bpmn.backend.marshall.json.parser.common.IntegerFieldParser) Node(org.kie.workbench.common.stunner.core.graph.Node) Bounds(org.kie.workbench.common.stunner.core.graph.content.Bounds) ArrayParser(org.kie.workbench.common.stunner.bpmn.backend.marshall.json.parser.common.ArrayParser) Edge(org.kie.workbench.common.stunner.core.graph.Edge) StringFieldParser(org.kie.workbench.common.stunner.bpmn.backend.marshall.json.parser.common.StringFieldParser) ObjectParser(org.kie.workbench.common.stunner.bpmn.backend.marshall.json.parser.common.ObjectParser) IntegerFieldParser(org.kie.workbench.common.stunner.bpmn.backend.marshall.json.parser.common.IntegerFieldParser) StringFieldParser(org.kie.workbench.common.stunner.bpmn.backend.marshall.json.parser.common.StringFieldParser) ArrayParser(org.kie.workbench.common.stunner.bpmn.backend.marshall.json.parser.common.ArrayParser)

Aggregations

ObjectParser (org.kie.workbench.common.stunner.bpmn.backend.marshall.json.parser.common.ObjectParser)4 StringFieldParser (org.kie.workbench.common.stunner.bpmn.backend.marshall.json.parser.common.StringFieldParser)3 ArrayParser (org.kie.workbench.common.stunner.bpmn.backend.marshall.json.parser.common.ArrayParser)2 IntegerFieldParser (org.kie.workbench.common.stunner.bpmn.backend.marshall.json.parser.common.IntegerFieldParser)2 Bounds (org.kie.workbench.common.stunner.core.graph.content.Bounds)2 PropertyAdapter (org.kie.workbench.common.stunner.core.definition.adapter.PropertyAdapter)1 PropertyType (org.kie.workbench.common.stunner.core.definition.property.PropertyType)1 Edge (org.kie.workbench.common.stunner.core.graph.Edge)1 Node (org.kie.workbench.common.stunner.core.graph.Node)1 ControlPoint (org.kie.workbench.common.stunner.core.graph.content.view.ControlPoint)1 ViewConnector (org.kie.workbench.common.stunner.core.graph.content.view.ViewConnector)1