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();
}
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);
}
}
}
}
}
}
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());
}
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());
}
}
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);
}
Aggregations