use of org.eclipse.bpmn2.ItemDefinition in project kie-wb-common by kiegroup.
the class Bpmn2JsonUnmarshaller method revisitCatchEvents.
/**
* Updates event definitions for all catch events.
* @param def Definitions
*/
public void revisitCatchEvents(Definitions def) {
List<RootElement> rootElements = def.getRootElements();
List<Signal> toAddSignals = new ArrayList<Signal>();
Set<Error> toAddErrors = new HashSet<Error>();
Set<Escalation> toAddEscalations = new HashSet<Escalation>();
Set<Message> toAddMessages = new HashSet<Message>();
Set<ItemDefinition> toAddItemDefinitions = new HashSet<ItemDefinition>();
for (RootElement root : rootElements) {
if (root instanceof Process) {
setCatchEventsInfo((Process) root, def, toAddSignals, toAddErrors, toAddEscalations, toAddMessages, toAddItemDefinitions);
}
}
for (Lane lane : _lanes) {
setCatchEventsInfoForLanes(lane, def, toAddSignals, toAddErrors, toAddEscalations, toAddMessages, toAddItemDefinitions);
}
for (Signal s : toAddSignals) {
def.getRootElements().add(s);
}
for (Error er : toAddErrors) {
def.getRootElements().add(er);
}
for (Escalation es : toAddEscalations) {
def.getRootElements().add(es);
}
for (ItemDefinition idef : toAddItemDefinitions) {
def.getRootElements().add(idef);
}
for (Message msg : toAddMessages) {
def.getRootElements().add(msg);
}
}
use of org.eclipse.bpmn2.ItemDefinition in project kie-wb-common by kiegroup.
the class Bpmn2JsonUnmarshaller method setCatchEventsInfoForLanes.
public void setCatchEventsInfoForLanes(Lane lane, Definitions def, List<Signal> toAddSignals, Set<Error> toAddErrors, Set<Escalation> toAddEscalations, Set<Message> toAddMessages, Set<ItemDefinition> toAddItemDefinitions) {
List<FlowNode> laneFlowNodes = lane.getFlowNodeRefs();
for (FlowElement fe : laneFlowNodes) {
if (fe instanceof CatchEvent) {
if (((CatchEvent) fe).getEventDefinitions().size() > 0) {
EventDefinition ed = ((CatchEvent) 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;
List<RootElement> rootElements = def.getRootElements();
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) {
setCatchEventsInfo((FlowElementsContainer) fe, def, toAddSignals, toAddErrors, toAddEscalations, toAddMessages, toAddItemDefinitions);
}
}
}
use of org.eclipse.bpmn2.ItemDefinition in project kie-wb-common by kiegroup.
the class BPMNDirectDiagramMarshallerTest method validateDataInputOrOutput.
private void validateDataInputOrOutput(ItemAwareElement itemAwareElement, String idSuffix, String dataType, String itemSubjectRefSuffix) {
assertNotNull(itemAwareElement);
assertTrue(itemAwareElement.getId().endsWith(idSuffix));
ItemDefinition itemDefinition = itemAwareElement.getItemSubjectRef();
assertNotNull(itemDefinition);
assertEquals(itemDefinition.getStructureRef(), (dataType));
assertTrue(itemDefinition.getId().endsWith(itemSubjectRefSuffix));
}
use of org.eclipse.bpmn2.ItemDefinition in project kie-wb-common by kiegroup.
the class Bpmn2JsonUnmarshaller method setItemDefinitionsForActivitiesIoSpec.
public void setItemDefinitionsForActivitiesIoSpec(FlowElementsContainer container, Definitions def, List<ItemDefinition> toAddItemDefinitions) {
List<FlowElement> flowElements = container.getFlowElements();
for (FlowElement fe : flowElements) {
if (fe instanceof Activity) {
Activity ac = (Activity) fe;
if (ac.getIoSpecification() != null) {
if (ac.getIoSpecification().getDataInputs() != null) {
List<DataInput> dataInputs = ac.getIoSpecification().getDataInputs();
for (DataInput din : dataInputs) {
Iterator<FeatureMap.Entry> iter = din.getAnyAttribute().iterator();
while (iter.hasNext()) {
FeatureMap.Entry entry = iter.next();
if (entry.getEStructuralFeature().getName().equals("dtype")) {
String dinType = (String) entry.getValue();
if (dinType != null && dinType.length() > 0) {
ItemDefinition itemdef = Bpmn2Factory.eINSTANCE.createItemDefinition();
itemdef.setId("_" + din.getId() + "Item");
itemdef.setStructureRef(dinType);
toAddItemDefinitions.add(itemdef);
din.setItemSubjectRef(itemdef);
}
}
}
}
}
if (ac.getIoSpecification().getDataOutputs() != null) {
List<DataOutput> dataOutputs = ac.getIoSpecification().getDataOutputs();
for (DataOutput dout : dataOutputs) {
Iterator<FeatureMap.Entry> iter = dout.getAnyAttribute().iterator();
while (iter.hasNext()) {
FeatureMap.Entry entry = iter.next();
if (entry.getEStructuralFeature().getName().equals("dtype")) {
String doutType = (String) entry.getValue();
if (doutType != null && doutType.length() > 0) {
ItemDefinition itemdef = Bpmn2Factory.eINSTANCE.createItemDefinition();
itemdef.setId("_" + dout.getId() + "Item");
itemdef.setStructureRef(doutType);
toAddItemDefinitions.add(itemdef);
dout.setItemSubjectRef(itemdef);
}
}
}
}
}
}
} else if (fe instanceof FlowElementsContainer) {
setItemDefinitionsForActivitiesIoSpec((FlowElementsContainer) fe, def, toAddItemDefinitions);
}
}
}
use of org.eclipse.bpmn2.ItemDefinition in project kie-wb-common by kiegroup.
the class Bpmn2JsonUnmarshaller method extractMessage.
private Message extractMessage(BaseElement element, Collection<Message> toAddMessages, Collection<ItemDefinition> toAddItemDefinitions) {
String idefId = null;
String msgName = null;
Iterator<FeatureMap.Entry> iter = element.getAnyAttribute().iterator();
while (iter.hasNext()) {
FeatureMap.Entry entry = iter.next();
if (entry.getEStructuralFeature().getName().equals("msgref")) {
msgName = (String) entry.getValue();
idefId = (String) entry.getValue() + "Type";
}
}
if (msgName != null && !msgName.isEmpty() && idefId != null && !idefId.isEmpty()) {
ItemDefinition idef = _itemDefinitions.get(idefId);
if (idef == null) {
idef = Bpmn2Factory.eINSTANCE.createItemDefinition();
idef.setId(idefId);
_itemDefinitions.put(idefId, idef);
}
Message msg = _messages.get(msgName);
if (msg == null) {
msg = Bpmn2Factory.eINSTANCE.createMessage();
msg.setName(msgName);
msg.setItemRef(idef);
_messages.put(msgName, msg);
}
msg.setName(msgName);
toAddMessages.add(msg);
toAddItemDefinitions.add(idef);
return msg;
}
return null;
}
Aggregations