Search in sources :

Example 1 with DataObject

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

the class Bpmn2JsonMarshaller method marshallDataObject.

protected void marshallDataObject(DataObject dataObject, BPMNPlane plane, JsonGenerator generator, float xOffset, float yOffset, Map<String, Object> flowElementProperties) throws JsonGenerationException, IOException {
    Map<String, Object> properties = new LinkedHashMap<String, Object>(flowElementProperties);
    putDocumentationProperty(dataObject, properties);
    if (dataObject.getName() != null && dataObject.getName().length() > 0) {
        properties.put(NAME, StringEscapeUtils.unescapeXml(dataObject.getName()));
    } else {
        // we need a name, use id instead
        properties.put(NAME, dataObject.getId());
    }
    // overwrite name if elementname extension element is present
    String elementName = Utils.getMetaDataValue(dataObject.getExtensionValues(), "elementname");
    if (elementName != null) {
        properties.put(NAME, elementName);
    }
    if (dataObject.getItemSubjectRef().getStructureRef() != null && dataObject.getItemSubjectRef().getStructureRef().length() > 0) {
        if (defaultTypesList.contains(dataObject.getItemSubjectRef().getStructureRef())) {
            properties.put(STANDARDTYPE, dataObject.getItemSubjectRef().getStructureRef());
        } else {
            properties.put(CUSTOMTYPE, dataObject.getItemSubjectRef().getStructureRef());
        }
    }
    Association outgoingAssociaton = findOutgoingAssociation(plane, dataObject);
    Association incomingAssociation = null;
    Process process = (Process) plane.getBpmnElement();
    for (Artifact artifact : process.getArtifacts()) {
        if (artifact instanceof Association) {
            Association association = (Association) artifact;
            if (association.getTargetRef() == dataObject) {
                incomingAssociation = association;
            }
        }
    }
    if (outgoingAssociaton != null && incomingAssociation == null) {
        properties.put(INPUT_OUTPUT, "Input");
    }
    if (outgoingAssociaton == null && incomingAssociation != null) {
        properties.put(INPUT_OUTPUT, "Output");
    }
    marshallProperties(properties, generator);
    generator.writeObjectFieldStart("stencil");
    generator.writeObjectField("id", "DataObject");
    generator.writeEndObject();
    generator.writeArrayFieldStart("childShapes");
    generator.writeEndArray();
    generator.writeArrayFieldStart("outgoing");
    List<Association> associations = findOutgoingAssociations(plane, dataObject);
    if (associations != null) {
        for (Association as : associations) {
            generator.writeStartObject();
            generator.writeObjectField("resourceId", as.getId());
            generator.writeEndObject();
        }
    }
    generator.writeEndArray();
    Bounds bounds = ((BPMNShape) findDiagramElement(plane, dataObject)).getBounds();
    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 : Association(org.eclipse.bpmn2.Association) DataOutputAssociation(org.eclipse.bpmn2.DataOutputAssociation) DataInputAssociation(org.eclipse.bpmn2.DataInputAssociation) Bounds(org.eclipse.dd.dc.Bounds) DataObject(org.eclipse.bpmn2.DataObject) AdHocSubProcess(org.eclipse.bpmn2.AdHocSubProcess) Process(org.eclipse.bpmn2.Process) SubProcess(org.eclipse.bpmn2.SubProcess) BPMNShape(org.eclipse.bpmn2.di.BPMNShape) Artifact(org.eclipse.bpmn2.Artifact) LinkedHashMap(java.util.LinkedHashMap)

Example 2 with DataObject

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

the class Bpmn2JsonUnmarshaller method updateIDs.

public void updateIDs(Definitions def) {
    // data object id update
    List<RootElement> rootElements = def.getRootElements();
    for (RootElement root : rootElements) {
        if (root instanceof Process) {
            Process process = (Process) root;
            if (process.getId() != null) {
                String processId = process.getId().trim();
                processId = processId.replaceAll("\\s", "");
                process.setId(processId);
            }
            List<FlowElement> flowElements = process.getFlowElements();
            for (FlowElement fe : flowElements) {
                if (fe instanceof DataObject) {
                    DataObject da = (DataObject) fe;
                    if (da.getName() != null) {
                        String daId = da.getName().trim();
                        daId = daId.replaceAll("\\W", "");
                        da.setId(daId);
                    }
                }
            }
        }
    }
}
Also used : RootElement(org.eclipse.bpmn2.RootElement) DataObject(org.eclipse.bpmn2.DataObject) FlowElement(org.eclipse.bpmn2.FlowElement) AdHocSubProcess(org.eclipse.bpmn2.AdHocSubProcess) SubProcess(org.eclipse.bpmn2.SubProcess) Process(org.eclipse.bpmn2.Process)

Example 3 with DataObject

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

the class Bpmn2JsonUnmarshallerTest method testUpdateIDs.

@Test
public void testUpdateIDs() {
    Definitions defs = mock(Definitions.class);
    Process process = mock(Process.class);
    DataObject flowElement = mock(DataObject.class);
    final Value<String> processId = new Value<>("Project:Bad Id");
    final Value<String> flowElementId = new Value<>("Bad Flow Id!");
    when(process.getId()).thenAnswer((m) -> processId.get());
    doAnswer((m) -> {
        processId.set(m.getArgumentAt(0, String.class));
        return null;
    }).when(process).setId(anyString());
    when(flowElement.getId()).thenAnswer((m) -> flowElementId.get());
    when(flowElement.getName()).thenAnswer((m) -> flowElementId.get());
    doAnswer((m) -> {
        flowElementId.set(m.getArgumentAt(0, String.class));
        return null;
    }).when(flowElement).setId(anyString());
    when(process.getFlowElements()).thenReturn(Arrays.asList(flowElement));
    when(defs.getRootElements()).thenReturn(Arrays.asList(process));
    tested.updateIDs(defs);
    assertEquals("Project:BadId", processId.get());
    assertEquals("BadFlowId", flowElementId.get());
}
Also used : DataObject(org.eclipse.bpmn2.DataObject) Definitions(org.eclipse.bpmn2.Definitions) Process(org.eclipse.bpmn2.Process) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 4 with DataObject

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

the class MultipleInstanceActivityPropertyWriter method setCollectionInput.

public void setCollectionInput(String collectionInput) {
    if (isEmpty(collectionInput)) {
        return;
    }
    setUpLoopCharacteristics();
    String suffix = "IN_COLLECTION";
    String id = Ids.dataInput(activity.getId(), suffix);
    DataInput dataInputElement = createDataInput(id, suffix);
    ioSpec.getDataInputs().add(dataInputElement);
    // check whether this exist
    Optional<Property> property = findPropertyById(collectionInput);
    Optional<DataObject> dataObject = findDataObjectById(collectionInput);
    if (property.isPresent()) {
        processDataInput(dataInputElement, property.get());
    } else if (dataObject.isPresent()) {
        processDataInput(dataInputElement, dataObject.get());
    }
}
Also used : DataInput(org.eclipse.bpmn2.DataInput) DataObject(org.eclipse.bpmn2.DataObject) Property(org.eclipse.bpmn2.Property)

Example 5 with DataObject

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

the class DataObjectPropertyWriter method setType.

public void setType(String type) {
    ItemDefinition itemDefinition = bpmn2.createItemDefinition();
    itemDefinition.setStructureRef(type);
    dataObject.setItemSubjectRef(itemDefinition);
    addDataObjectToProcess(dataObject);
}
Also used : ItemDefinition(org.eclipse.bpmn2.ItemDefinition)

Aggregations

DataObject (org.eclipse.bpmn2.DataObject)13 Process (org.eclipse.bpmn2.Process)7 AdHocSubProcess (org.eclipse.bpmn2.AdHocSubProcess)5 SubProcess (org.eclipse.bpmn2.SubProcess)5 Artifact (org.eclipse.bpmn2.Artifact)4 FlowElement (org.eclipse.bpmn2.FlowElement)4 ItemDefinition (org.eclipse.bpmn2.ItemDefinition)4 RootElement (org.eclipse.bpmn2.RootElement)4 Test (org.junit.Test)4 ArrayList (java.util.ArrayList)3 Association (org.eclipse.bpmn2.Association)3 DataInputAssociation (org.eclipse.bpmn2.DataInputAssociation)3 DataOutputAssociation (org.eclipse.bpmn2.DataOutputAssociation)3 Property (org.eclipse.bpmn2.Property)3 SequenceFlow (org.eclipse.bpmn2.SequenceFlow)3 HashSet (java.util.HashSet)2 List (java.util.List)2 BoundaryEvent (org.eclipse.bpmn2.BoundaryEvent)2 BusinessRuleTask (org.eclipse.bpmn2.BusinessRuleTask)2 CallActivity (org.eclipse.bpmn2.CallActivity)2