use of org.eclipse.bpmn2.SequenceFlow in project kie-wb-common by kiegroup.
the class Bpmn2JsonUnmarshaller method setGatewayInfo.
private void setGatewayInfo(FlowElementsContainer container) {
List<FlowElement> flowElements = container.getFlowElements();
for (FlowElement fe : flowElements) {
if (fe instanceof Gateway) {
Gateway gateway = (Gateway) fe;
int incoming = gateway.getIncoming() == null ? 0 : gateway.getIncoming().size();
int outgoing = gateway.getOutgoing() == null ? 0 : gateway.getOutgoing().size();
if (incoming <= 1 && outgoing > 1) {
gateway.setGatewayDirection(GatewayDirection.DIVERGING);
} else if (incoming > 1 && outgoing <= 1) {
gateway.setGatewayDirection(GatewayDirection.CONVERGING);
} else // temp. removing support for mixed gateway direction (not supported by runtime yet)
// else if (incoming > 1 && outgoing > 1) {
// gateway.setGatewayDirection(GatewayDirection.MIXED);
// }
// else if (incoming == 1 && outgoing == 1) {
// // this handles the 1:1 case of the diverging gateways
// }
{
gateway.setGatewayDirection(GatewayDirection.UNSPECIFIED);
}
}
if (fe instanceof InclusiveGateway) {
InclusiveGateway ig = (InclusiveGateway) fe;
List<SequenceFlow> sqList = new ArrayList<SequenceFlow>();
if (ig.getIncoming() != null) {
sqList.addAll(ig.getIncoming());
}
if (ig.getOutgoing() != null) {
sqList.addAll(ig.getOutgoing());
}
setDefaultGateway(fe, sqList);
}
if (fe instanceof ExclusiveGateway) {
ExclusiveGateway eg = (ExclusiveGateway) fe;
List<SequenceFlow> sqList = new ArrayList<SequenceFlow>();
if (eg.getIncoming() != null) {
sqList.addAll(eg.getIncoming());
}
if (eg.getOutgoing() != null) {
sqList.addAll(eg.getOutgoing());
}
setDefaultGateway(fe, sqList);
}
if (fe instanceof FlowElementsContainer) {
setGatewayInfo((FlowElementsContainer) fe);
}
}
}
use of org.eclipse.bpmn2.SequenceFlow in project kie-wb-common by kiegroup.
the class Bpmn2JsonMarshaller method marshallInclusiveGateway.
protected void marshallInclusiveGateway(InclusiveGateway gateway, BPMNPlane plane, JsonGenerator generator, float xOffset, float yOffset, Map<String, Object> flowElementProperties) throws JsonGenerationException, IOException {
if (gateway.getDefault() != null) {
SequenceFlow defsf = gateway.getDefault();
String defGatewayStr = defsf.getId();
flowElementProperties.put("defaultgate", defGatewayStr);
}
marshallNode(gateway, flowElementProperties, "InclusiveGateway", plane, generator, xOffset, yOffset);
}
use of org.eclipse.bpmn2.SequenceFlow in project kie-wb-common by kiegroup.
the class Bpmn2JsonMarshaller method marshallNode.
protected void marshallNode(FlowNode node, Map<String, Object> properties, String stencil, BPMNPlane plane, JsonGenerator generator, float xOffset, float yOffset) throws JsonGenerationException, IOException {
if (properties == null) {
properties = new LinkedHashMap<String, Object>();
}
putDocumentationProperty(node, properties);
if (node.getName() != null) {
properties.put(NAME, StringEscapeUtils.unescapeXml(node.getName()));
} else {
if (node instanceof TextAnnotation) {
if (((TextAnnotation) node).getText() != null) {
properties.put(NAME, ((TextAnnotation) node).getText());
} else {
properties.put(NAME, "");
}
} else {
properties.put(NAME, "");
}
}
// overwrite name if elementname extension element is present
String elementName = Utils.getMetaDataValue(node.getExtensionValues(), "elementname");
if (elementName != null) {
properties.put("name", elementName);
}
marshallProperties(properties, generator);
generator.writeObjectFieldStart("stencil");
generator.writeObjectField("id", stencil);
generator.writeEndObject();
generator.writeArrayFieldStart("childShapes");
generator.writeEndArray();
generator.writeArrayFieldStart("outgoing");
for (SequenceFlow outgoing : node.getOutgoing()) {
generator.writeStartObject();
generator.writeObjectField("resourceId", outgoing.getId());
generator.writeEndObject();
}
// we need to also add associations as outgoing elements
Process process = (Process) plane.getBpmnElement();
writeAssociations(process, node.getId(), generator);
// and boundary events for activities
List<BoundaryEvent> boundaryEvents = new ArrayList<BoundaryEvent>();
findBoundaryEvents(process, boundaryEvents);
for (BoundaryEvent be : boundaryEvents) {
if (be.getAttachedToRef().getId().equals(node.getId())) {
generator.writeStartObject();
generator.writeObjectField("resourceId", be.getId());
generator.writeEndObject();
}
}
generator.writeEndArray();
// boundary events have a docker
if (node instanceof BoundaryEvent) {
Iterator<FeatureMap.Entry> iter = node.getAnyAttribute().iterator();
boolean foundDockerInfo = false;
while (iter.hasNext()) {
FeatureMap.Entry entry = iter.next();
if (entry.getEStructuralFeature().getName().equals("dockerinfo")) {
foundDockerInfo = true;
String dockerInfoStr = String.valueOf(entry.getValue());
if (dockerInfoStr != null && dockerInfoStr.length() > 0) {
if (dockerInfoStr.endsWith("|")) {
dockerInfoStr = dockerInfoStr.substring(0, dockerInfoStr.length() - 1);
String[] dockerInfoParts = dockerInfoStr.split("\\|");
String infoPartsToUse = dockerInfoParts[0];
String[] infoPartsToUseParts = infoPartsToUse.split("\\^");
if (infoPartsToUseParts != null && infoPartsToUseParts.length > 0) {
generator.writeArrayFieldStart("dockers");
generator.writeStartObject();
generator.writeObjectField("x", Double.valueOf(infoPartsToUseParts[0]));
generator.writeObjectField("y", Double.valueOf(infoPartsToUseParts[1]));
generator.writeEndObject();
generator.writeEndArray();
}
}
}
}
}
// backwards compatibility to older versions -- BZ 1196259
if (!foundDockerInfo) {
// find the edge associated with this boundary event
for (DiagramElement element : plane.getPlaneElement()) {
if (element instanceof BPMNEdge && ((BPMNEdge) element).getBpmnElement() == node) {
List<Point> waypoints = ((BPMNEdge) element).getWaypoint();
if (waypoints != null && waypoints.size() > 0) {
// one per boundary event
Point p = waypoints.get(0);
if (p != null) {
generator.writeArrayFieldStart("dockers");
generator.writeStartObject();
generator.writeObjectField("x", p.getX());
generator.writeObjectField("y", p.getY());
generator.writeEndObject();
generator.writeEndArray();
}
}
}
}
}
}
BPMNShape shape = (BPMNShape) findDiagramElement(plane, node);
Bounds bounds = shape.getBounds();
correctEventNodeSize(shape);
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.SequenceFlow 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();
}
use of org.eclipse.bpmn2.SequenceFlow in project kie-wb-common by kiegroup.
the class BPMNDirectDiagramMarshallerTest method testUnmarshallSequenceFlow.
@Test
public void testUnmarshallSequenceFlow() throws Exception {
Diagram<Graph, Metadata> diagram = unmarshall(BPMN_SEQUENCEFLOW);
SequenceFlow sequenceFlow1 = null;
SequenceFlow sequenceFlow2 = null;
Iterator<Element> it = nodesIterator(diagram);
while (it.hasNext()) {
Element element = it.next();
if (element.getContent() instanceof View) {
Object oDefinition = ((View) element.getContent()).getDefinition();
if (oDefinition instanceof ExclusiveGateway) {
List<Edge> outEdges = ((NodeImpl) element).getOutEdges();
for (Edge edge : outEdges) {
SequenceFlow flow = (SequenceFlow) ((ViewConnectorImpl) edge.getContent()).getDefinition();
if ("route1".equals(flow.getGeneral().getName().getValue())) {
sequenceFlow1 = flow;
}
if ("route2".equals(flow.getGeneral().getName().getValue())) {
sequenceFlow2 = flow;
}
}
}
}
}
assertNotNull(sequenceFlow1);
assertNotNull(sequenceFlow1.getExecutionSet());
assertNotNull(sequenceFlow1.getExecutionSet().getConditionExpression());
assertNotNull(sequenceFlow1.getExecutionSet().getPriority());
assertNotNull(sequenceFlow1.getGeneral());
assertNotNull(sequenceFlow1.getGeneral().getName());
assertEquals("route1", sequenceFlow1.getGeneral().getName().getValue());
assertEquals("age >= 10;", sequenceFlow1.getExecutionSet().getConditionExpression().getValue().getScript());
assertEquals("javascript", sequenceFlow1.getExecutionSet().getConditionExpression().getValue().getLanguage());
assertEquals("2", sequenceFlow1.getExecutionSet().getPriority().getValue());
assertNotNull(sequenceFlow2);
assertNotNull(sequenceFlow2.getExecutionSet());
assertNotNull(sequenceFlow2.getExecutionSet().getConditionExpression());
assertNotNull(sequenceFlow2.getExecutionSet().getPriority());
assertNotNull(sequenceFlow2.getGeneral());
assertNotNull(sequenceFlow2.getGeneral().getName());
assertEquals("route2", sequenceFlow2.getGeneral().getName().getValue());
assertEquals("age\n" + "<\n" + "10;", sequenceFlow2.getExecutionSet().getConditionExpression().getValue().getScript());
assertEquals("java", sequenceFlow2.getExecutionSet().getConditionExpression().getValue().getLanguage());
assertEquals("1", sequenceFlow2.getExecutionSet().getPriority().getValue());
}
Aggregations