use of org.eclipse.bpmn2.FlowElement in project kie-wb-common by kiegroup.
the class Bpmn2JsonUnmarshaller method setThrowEventsInfo.
public void setThrowEventsInfo(FlowElementsContainer container, Definitions def, List<RootElement> rootElements, List<Signal> toAddSignals, Set<Error> toAddErrors, Set<Escalation> toAddEscalations, Set<Message> toAddMessages, Set<ItemDefinition> toAddItemDefinitions) {
List<FlowElement> flowElements = container.getFlowElements();
for (FlowElement fe : flowElements) {
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.FlowElement in project kie-wb-common by kiegroup.
the class Bpmn2JsonUnmarshaller method setUserTaskInfo.
private void setUserTaskInfo(FlowElementsContainer container) {
List<FlowElement> flowElements = container.getFlowElements();
for (FlowElement fe : flowElements) {
// Set name and metaData "elementname" to "Task_n" if empty
if (fe instanceof UserTask) {
UserTask task = (UserTask) fe;
String name = task.getName();
if (name == null || name.length() == 0) {
LastUserTaskID++;
String newName = DEFAULT_USERTASK_NAME_PREFIX + LastUserTaskID;
task.setName(newName);
if (task.getExtensionValues() != null && task.getExtensionValues().size() > 0) {
for (ExtensionAttributeValue extattrval : task.getExtensionValues()) {
FeatureMap extensionElements = extattrval.getValue();
List<MetaDataType> metadataExtensions = (List<MetaDataType>) extensionElements.get(DroolsPackage.Literals.DOCUMENT_ROOT__META_DATA, true);
for (MetaDataType eleMetadata : metadataExtensions) {
if (eleMetadata.getName() != null && eleMetadata.getName().equals("elementname")) {
eleMetadata.setMetaValue(wrapInCDATABlock(newName));
}
}
}
}
}
}
if (fe instanceof FlowElementsContainer) {
setUserTaskInfo((FlowElementsContainer) fe);
}
}
}
use of org.eclipse.bpmn2.FlowElement in project kie-wb-common by kiegroup.
the class Bpmn2JsonUnmarshaller method setSendReceiveTasksInfo.
public void setSendReceiveTasksInfo(FlowElementsContainer container, Definitions def, List<Message> toAddMessages, List<ItemDefinition> toAddItemDefinitions) {
List<FlowElement> flowElements = container.getFlowElements();
for (FlowElement fe : flowElements) {
if (fe instanceof ReceiveTask) {
ReceiveTask rt = (ReceiveTask) fe;
rt.setMessageRef(extractMessage(rt, toAddMessages, toAddItemDefinitions));
} else if (fe instanceof SendTask) {
SendTask st = (SendTask) fe;
st.setMessageRef(extractMessage(st, toAddMessages, toAddItemDefinitions));
} else if (fe instanceof FlowElementsContainer) {
setSendReceiveTasksInfo((FlowElementsContainer) fe, def, toAddMessages, toAddItemDefinitions);
}
}
}
use of org.eclipse.bpmn2.FlowElement in project kie-wb-common by kiegroup.
the class Bpmn2JsonUnmarshaller method createDiagram.
private void createDiagram(Definitions def) {
for (RootElement rootElement : def.getRootElements()) {
if (rootElement instanceof Process) {
Process process = (Process) rootElement;
BpmnDiFactory factory = BpmnDiFactory.eINSTANCE;
BPMNDiagram diagram = factory.createBPMNDiagram();
BPMNPlane plane = factory.createBPMNPlane();
plane.setBpmnElement(process);
diagram.setPlane(plane);
// first process flowNodes
for (FlowElement flowElement : process.getFlowElements()) {
if (flowElement instanceof FlowNode) {
createBpmnShapeForElement(factory, plane, flowElement);
if (flowElement instanceof BoundaryEvent) {
createDockersForBoundaryEvent((BoundaryEvent) flowElement);
}
// check if its a subprocess
if (flowElement instanceof SubProcess) {
createSubProcessDiagram(plane, flowElement, factory);
}
} else if (flowElement instanceof DataObject) {
createBpmnShapeForElement(factory, plane, flowElement);
} else if (flowElement instanceof SequenceFlow) {
createBpmnEdgeForSequenceFlow(factory, plane, (SequenceFlow) flowElement);
}
}
// then process artifacts
if (process.getArtifacts() != null) {
List<Association> incompleteAssociations = new ArrayList<Association>();
for (Artifact artifact : process.getArtifacts()) {
// if (artifact instanceof TextAnnotation || artifact instanceof Group) {
if (artifact instanceof Group) {
createBpmnShapeForElement(factory, plane, artifact);
}
if (artifact instanceof Association) {
Association association = (Association) artifact;
if (association.getSourceRef() != null && association.getTargetRef() != null) {
createBpmnEdgeForAssociation(factory, plane, association);
} else {
incompleteAssociations.add(association);
}
}
}
if (!incompleteAssociations.isEmpty()) {
for (Association incompleteAssociation : incompleteAssociations) {
process.getArtifacts().remove(incompleteAssociation);
}
}
}
// finally process lanes
if (process.getLaneSets() != null && process.getLaneSets().size() > 0) {
for (LaneSet ls : process.getLaneSets()) {
for (Lane lane : ls.getLanes()) {
createBpmnShapeForElement(factory, plane, lane);
}
}
}
def.getDiagrams().add(diagram);
}
}
}
use of org.eclipse.bpmn2.FlowElement 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);
}
}
}
Aggregations