use of org.eclipse.bpmn2.Definitions in project kie-wb-common by kiegroup.
the class Bpmn2UnMarshaller method unmarshall.
public Graph unmarshall(final String content) throws IOException {
final XMLResource outResource = (XMLResource) resourceSet.createResource(URI.createURI("inputStream://" + UUID.uuid() + ".xml"));
outResource.getDefaultLoadOptions().put(XMLResource.OPTION_ENCODING, "UTF-8");
outResource.setEncoding("UTF-8");
final Map<String, Object> options = new HashMap<String, Object>();
options.put(XMLResource.OPTION_ENCODING, "UTF-8");
outResource.load(new BufferedInputStream(new ByteArrayInputStream(content.getBytes("UTF-8"))), options);
final DocumentRoot root = (DocumentRoot) outResource.getContents().get(0);
final Definitions definitions = root.getDefinitions();
return unmarshall(definitions, null);
}
use of org.eclipse.bpmn2.Definitions in project kie-wb-common by kiegroup.
the class DefinitionResolver method initSimulationParameters.
private Map<String, ElementParameters> initSimulationParameters(Definitions definitions) {
Map<String, ElementParameters> simulationParameters = new HashMap<>();
List<Relationship> relationships = definitions.getRelationships();
if (relationships.isEmpty()) {
return Collections.emptyMap();
}
FeatureMap value = relationships.get(0).getExtensionValues().get(0).getValue();
Object simData = value.get(BpsimPackage.Literals.DOCUMENT_ROOT__BP_SIM_DATA, true);
List<BPSimDataType> bpsimExtensions = (List<BPSimDataType>) simData;
Scenario scenario = bpsimExtensions.get(0).getScenario().get(0);
for (ElementParameters parameters : scenario.getElementParameters()) {
simulationParameters.put(parameters.getElementRef(), parameters);
}
return simulationParameters;
}
use of org.eclipse.bpmn2.Definitions in project kie-wb-common by kiegroup.
the class IntermediateCatchEventConverter method convertBoundaryEvent.
public BpmnNode convertBoundaryEvent(BoundaryEvent event) {
CatchEventPropertyReader p = propertyReaderFactory.of(event);
List<EventDefinition> eventDefinitions = p.getEventDefinitions();
switch(eventDefinitions.size()) {
case 0:
throw new UnsupportedOperationException("A boundary event should contain exactly one definition");
case 1:
return Match.of(EventDefinition.class, BpmnNode.class).when(SignalEventDefinition.class, e -> signalEvent(event, e)).when(TimerEventDefinition.class, e -> timerEvent(event, e)).when(MessageEventDefinition.class, e -> messageEvent(event, e)).when(ErrorEventDefinition.class, e -> errorEvent(event, e)).missing(EscalationEventDefinition.class).missing(CompensateEventDefinition.class).missing(ConditionalEventDefinition.class).apply(eventDefinitions.get(0)).value();
default:
throw new UnsupportedOperationException("Multiple definitions not supported for boundary event");
}
}
use of org.eclipse.bpmn2.Definitions in project kie-wb-common by kiegroup.
the class StartEventConverter method convert.
public BpmnNode convert(StartEvent event) {
CatchEventPropertyReader p = propertyReaderFactory.of(event);
List<EventDefinition> eventDefinitions = p.getEventDefinitions();
switch(eventDefinitions.size()) {
case 0:
return noneEvent(event);
case 1:
return Match.of(EventDefinition.class, BpmnNode.class).when(SignalEventDefinition.class, e -> signalEvent(event, e)).when(MessageEventDefinition.class, e -> messageEvent(event, e)).when(TimerEventDefinition.class, e -> timerEvent(event, e)).when(ErrorEventDefinition.class, e -> errorEvent(event, e)).missing(ConditionalEventDefinition.class).missing(EscalationEventDefinition.class).missing(CompensateEventDefinition.class).apply(eventDefinitions.get(0)).value();
default:
throw new UnsupportedOperationException("Multiple event definitions not supported for start event");
}
}
use of org.eclipse.bpmn2.Definitions in project kie-wb-common by kiegroup.
the class Bpmn2JsonMarshaller method marshallLanes.
private List<String> marshallLanes(Lane lane, BPMNPlane plane, JsonGenerator generator, float xOffset, float yOffset, String preProcessingData, Definitions def) throws JsonGenerationException, IOException {
Bounds bounds = ((BPMNShape) findDiagramElement(plane, lane)).getBounds();
List<String> nodeRefIds = new ArrayList<String>();
if (bounds != null) {
generator.writeStartObject();
generator.writeObjectField("resourceId", lane.getId());
Map<String, Object> laneProperties = new LinkedHashMap<String, Object>();
if (lane.getName() != null) {
laneProperties.put(NAME, StringEscapeUtils.unescapeXml(lane.getName()));
} else {
laneProperties.put(NAME, "");
}
// overwrite name if elementname extension element is present
String elementName = Utils.getMetaDataValue(lane.getExtensionValues(), "elementname");
if (elementName != null) {
laneProperties.put(NAME, elementName);
}
putDocumentationProperty(lane, laneProperties);
Iterator<FeatureMap.Entry> iter = lane.getAnyAttribute().iterator();
boolean foundBgColor = false;
boolean foundBrColor = false;
boolean foundFontColor = false;
boolean foundSelectable = false;
while (iter.hasNext()) {
FeatureMap.Entry entry = iter.next();
if (entry.getEStructuralFeature().getName().equals("background-color") || entry.getEStructuralFeature().getName().equals("bgcolor")) {
laneProperties.put(BGCOLOR, entry.getValue());
foundBgColor = true;
}
if (entry.getEStructuralFeature().getName().equals("border-color") || entry.getEStructuralFeature().getName().equals("bordercolor")) {
laneProperties.put(BORDERCOLOR, entry.getValue());
foundBrColor = true;
}
if (entry.getEStructuralFeature().getName().equals("fontsize")) {
laneProperties.put(FONTSIZE, entry.getValue());
foundBrColor = true;
}
if (entry.getEStructuralFeature().getName().equals("color") || entry.getEStructuralFeature().getName().equals("fontcolor")) {
laneProperties.put(FONTCOLOR, entry.getValue());
foundFontColor = true;
}
if (entry.getEStructuralFeature().getName().equals("selectable")) {
laneProperties.put(ISSELECTABLE, entry.getValue());
foundSelectable = true;
}
}
if (!foundBgColor) {
laneProperties.put(BGCOLOR, defaultBgColor_Swimlanes);
}
if (!foundBrColor) {
laneProperties.put(BORDERCOLOR, defaultBrColor);
}
if (!foundFontColor) {
laneProperties.put(FONTCOLOR, defaultFontColor);
}
if (!foundSelectable) {
laneProperties.put(ISSELECTABLE, "true");
}
marshallProperties(laneProperties, generator);
generator.writeObjectFieldStart("stencil");
generator.writeObjectField("id", "Lane");
generator.writeEndObject();
generator.writeArrayFieldStart("childShapes");
for (FlowElement flowElement : lane.getFlowNodeRefs()) {
nodeRefIds.add(flowElement.getId());
if (coordianteManipulation) {
marshallFlowElement(flowElement, plane, generator, bounds.getX(), bounds.getY(), preProcessingData, def);
} else {
marshallFlowElement(flowElement, plane, generator, 0, 0, preProcessingData, def);
}
}
generator.writeEndArray();
generator.writeArrayFieldStart("outgoing");
Process process = (Process) plane.getBpmnElement();
writeAssociations(process, lane.getId(), generator);
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();
generator.writeEndObject();
} else {
// dont marshall the lane unless it has BPMNDI info (eclipse editor does not generate it for lanes currently.
for (FlowElement flowElement : lane.getFlowNodeRefs()) {
nodeRefIds.add(flowElement.getId());
// we dont want an offset here!
marshallFlowElement(flowElement, plane, generator, 0, 0, preProcessingData, def);
}
}
return nodeRefIds;
}
Aggregations