use of org.eclipse.bpmn2.Definitions in project kie-wb-common by kiegroup.
the class Bpmn2JsonUnmarshaller method revisitMessages.
/**
* Revisit message to set their item ref to a item definition
* @param def Definitions
*/
private void revisitMessages(Definitions def) {
List<RootElement> rootElements = def.getRootElements();
List<ItemDefinition> toAddDefinitions = new ArrayList<ItemDefinition>();
for (RootElement root : rootElements) {
if (root instanceof Message) {
if (!existsMessageItemDefinition(rootElements, root.getId())) {
ItemDefinition itemdef = Bpmn2Factory.eINSTANCE.createItemDefinition();
itemdef.setId(root.getId() + "Type");
toAddDefinitions.add(itemdef);
((Message) root).setItemRef(itemdef);
}
}
}
for (ItemDefinition id : toAddDefinitions) {
def.getRootElements().add(id);
}
}
use of org.eclipse.bpmn2.Definitions in project kie-wb-common by kiegroup.
the class Bpmn2JsonUnmarshaller method revisitItemDefinitions.
public void revisitItemDefinitions(Definitions def) {
List<String> itemIds = new ArrayList<String>();
for (RootElement root : def.getRootElements()) {
if (root instanceof ItemDefinition) {
if (!itemIds.contains(root.getId())) {
itemIds.add(root.getId());
} else {
ItemDefinition idef = (ItemDefinition) root;
Random rand = new Random();
int randomNum = rand.nextInt((1000 - 10) + 1) + 10;
idef.setId(idef.getId() + randomNum);
}
}
}
}
use of org.eclipse.bpmn2.Definitions in project kie-wb-common by kiegroup.
the class Bpmn2JsonUnmarshaller method updateEdgeBoundsInLanes.
public void updateEdgeBoundsInLanes(Definitions def, BPMNPlane plane, BPMNEdge edge, BaseElement ele) {
if (ele instanceof SequenceFlow) {
SequenceFlow sq = (SequenceFlow) ele;
// update the source and target on BPMNEdge
if (sq.getSourceRef() != null) {
edge.setSourceElement(getBPMNShapeForElement(sq.getSourceRef(), plane));
}
if (sq.getTargetRef() != null) {
edge.setTargetElement(getBPMNShapeForElement(sq.getTargetRef(), plane));
}
List<RootElement> rootElements = def.getRootElements();
for (RootElement root : rootElements) {
if (root instanceof Process) {
Process process = (Process) root;
if (sq.getSourceRef() != null && sq.getTargetRef() != null) {
if (process.getLaneSets() != null && process.getLaneSets().size() > 0) {
for (LaneSet ls : process.getLaneSets()) {
for (Lane newLane : ls.getLanes()) {
List<FlowNode> laneFlowNodes = newLane.getFlowNodeRefs();
Bounds laneBounds = getBoundsForElement(newLane, plane);
for (FlowNode newFlowNode : laneFlowNodes) {
if (newFlowNode.getId().equals(sq.getSourceRef().getId())) {
List<DiagramElement> diagramElements = plane.getPlaneElement();
for (DiagramElement dia : diagramElements) {
if (dia instanceof BPMNShape) {
BPMNShape shape = (BPMNShape) dia;
if (shape.getBpmnElement().getId().equals(sq.getSourceRef().getId())) {
Bounds eleBounds = shape.getBounds();
List<Point> edgePoints = edge.getWaypoint();
if (edgePoints != null && edgePoints.size() > 1) {
if (eleBounds != null) {
Point first = edgePoints.get(0);
first.setX(first.getX() + laneBounds.getX());
first.setY(first.getY() + laneBounds.getY());
}
}
}
}
}
} else if (newFlowNode.getId().equals(sq.getTargetRef().getId())) {
List<DiagramElement> diagramElements = plane.getPlaneElement();
for (DiagramElement dia : diagramElements) {
if (dia instanceof BPMNShape) {
BPMNShape shape = (BPMNShape) dia;
if (shape.getBpmnElement().getId().equals(sq.getTargetRef().getId())) {
Bounds eleBounds = shape.getBounds();
List<Point> edgePoints = edge.getWaypoint();
if (edgePoints != null && edgePoints.size() > 1) {
if (eleBounds != null) {
Point last = edgePoints.get(edgePoints.size() - 1);
last.setX(last.getX() + laneBounds.getX());
last.setY(last.getY() + laneBounds.getY());
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
use of org.eclipse.bpmn2.Definitions in project kie-wb-common by kiegroup.
the class Bpmn2JsonUnmarshaller method setThrowEventsInfoForLanes.
public void setThrowEventsInfoForLanes(Lane lane, Definitions def, List<RootElement> rootElements, List<Signal> toAddSignals, Set<Error> toAddErrors, Set<Escalation> toAddEscalations, Set<Message> toAddMessages, Set<ItemDefinition> toAddItemDefinitions) {
List<FlowNode> laneFlowNodes = lane.getFlowNodeRefs();
for (FlowNode fe : laneFlowNodes) {
if (fe instanceof ThrowEvent) {
if (((ThrowEvent) fe).getEventDefinitions().size() > 0) {
EventDefinition ed = ((ThrowEvent) fe).getEventDefinitions().get(0);
if (ed instanceof SignalEventDefinition) {
SignalEventDefinition sed = (SignalEventDefinition) ed;
if (sed.getSignalRef() != null && sed.getSignalRef().length() > 0) {
String signalRef = sed.getSignalRef();
boolean shouldAddSignal = true;
for (RootElement re : rootElements) {
if (re instanceof Signal) {
if (((Signal) re).getName().equals(signalRef)) {
shouldAddSignal = false;
break;
}
}
}
if (toAddSignals != null) {
for (Signal s : toAddSignals) {
if (s.getName().equals(signalRef)) {
shouldAddSignal = false;
break;
}
}
}
if (shouldAddSignal) {
Signal signal = Bpmn2Factory.eINSTANCE.createSignal();
signal.setName(signalRef);
toAddSignals.add(signal);
}
}
} else if (ed instanceof ErrorEventDefinition) {
String errorCode = null;
String errorId = null;
Iterator<FeatureMap.Entry> iter = ed.getAnyAttribute().iterator();
while (iter.hasNext()) {
FeatureMap.Entry entry = iter.next();
if (entry.getEStructuralFeature().getName().equals("erefname")) {
errorId = (String) entry.getValue();
errorCode = (String) entry.getValue();
}
}
Error err = this._errors.get(errorCode);
if (err == null) {
err = Bpmn2Factory.eINSTANCE.createError();
err.setId(errorId);
err.setErrorCode(errorCode);
this._errors.put(errorCode, err);
}
toAddErrors.add(err);
((ErrorEventDefinition) ed).setErrorRef(err);
} else if (ed instanceof EscalationEventDefinition) {
String escalationCode = null;
Iterator<FeatureMap.Entry> iter = ed.getAnyAttribute().iterator();
while (iter.hasNext()) {
FeatureMap.Entry entry = iter.next();
if (entry.getEStructuralFeature().getName().equals("esccode")) {
escalationCode = (String) entry.getValue();
break;
}
}
Escalation escalation = this._escalations.get(escalationCode);
if (escalation == null) {
escalation = Bpmn2Factory.eINSTANCE.createEscalation();
escalation.setEscalationCode(escalationCode);
this._escalations.put(escalationCode, escalation);
}
toAddEscalations.add(escalation);
((EscalationEventDefinition) ed).setEscalationRef(escalation);
} else if (ed instanceof MessageEventDefinition) {
((MessageEventDefinition) ed).setMessageRef(extractMessage(ed, toAddMessages, toAddItemDefinitions));
} else if (ed instanceof CompensateEventDefinition) {
Iterator<FeatureMap.Entry> iter = ed.getAnyAttribute().iterator();
while (iter.hasNext()) {
FeatureMap.Entry entry = iter.next();
if (entry.getEStructuralFeature().getName().equals("actrefname")) {
String activityNameRef = (String) entry.getValue();
// we have to iterate again through all flow
// elements
// in order to find our activity name
List<RootElement> re = def.getRootElements();
for (RootElement r : re) {
if (r instanceof Process) {
Process p = (Process) r;
List<FlowElement> fes = p.getFlowElements();
for (FlowElement f : fes) {
if (f instanceof Activity && ((Activity) f).getName().equals(activityNameRef)) {
((CompensateEventDefinition) ed).setActivityRef((Activity) f);
((Activity) f).setIsForCompensation(true);
}
}
}
}
}
}
}
}
} else if (fe instanceof FlowElementsContainer) {
setThrowEventsInfo((FlowElementsContainer) fe, def, rootElements, toAddSignals, toAddErrors, toAddEscalations, toAddMessages, toAddItemDefinitions);
}
}
}
use of org.eclipse.bpmn2.Definitions in project kie-wb-common by kiegroup.
the class Bpmn2JsonUnmarshaller method revisitDIColors.
public void revisitDIColors(Definitions def) {
BPMNPlane plane = def.getDiagrams().get(0).getPlane();
List<DiagramElement> diagramElements = plane.getPlaneElement();
for (DiagramElement dia : diagramElements) {
if (dia instanceof BPMNShape) {
BPMNShape shape = (BPMNShape) dia;
updateShapeColors(shape);
}
if (dia instanceof BPMNEdge) {
BPMNEdge edge = (BPMNEdge) dia;
updateEdgeColors(edge);
}
}
}
Aggregations