use of org.eclipse.bpmn2.FlowElement in project kie-wb-common by kiegroup.
the class Bpmn2JsonUnmarshaller method revisitServiceTasksExecuteForLanes.
private void revisitServiceTasksExecuteForLanes(Lane lane, Definitions def, List<RootElement> rootElements, List<Interface> toAddInterfaces, List<Message> toAddMessages, List<ItemDefinition> toAddDefinitions) {
List<FlowNode> laneFlowNodes = lane.getFlowNodeRefs();
for (FlowElement fe : laneFlowNodes) {
if (fe instanceof ServiceTask) {
Iterator<FeatureMap.Entry> iter = fe.getAnyAttribute().iterator();
String serviceImplementation = null;
String serviceInterface = null;
String serviceOperation = null;
EStructuralFeature serviceInterfaceFeature = null;
EStructuralFeature serviceOperationFeature = null;
while (iter.hasNext()) {
FeatureMap.Entry entry = iter.next();
if (entry.getEStructuralFeature().getName().equals("serviceimplementation")) {
serviceImplementation = (String) entry.getValue();
}
if (entry.getEStructuralFeature().getName().equals("serviceoperation")) {
serviceOperation = (String) entry.getValue();
serviceOperationFeature = entry.getEStructuralFeature();
}
if (entry.getEStructuralFeature().getName().equals("serviceinterface")) {
serviceInterface = (String) entry.getValue();
serviceInterfaceFeature = entry.getEStructuralFeature();
}
}
boolean foundInterface = false;
Interface touseInterface = null;
if (serviceImplementation != null && serviceImplementation.equals("Java")) {
for (RootElement iroot : rootElements) {
if (iroot instanceof Interface && ((Interface) iroot).getName().equals(serviceInterface)) {
foundInterface = true;
touseInterface = (Interface) iroot;
break;
}
}
if (!foundInterface) {
for (Interface toadd : toAddInterfaces) {
if (toadd.getName() != null && toadd.getName().equals(serviceInterface)) {
foundInterface = true;
touseInterface = toadd;
break;
}
}
}
} else if (serviceImplementation != null && serviceImplementation.equals("##WebService")) {
for (RootElement iroot : rootElements) {
if (iroot instanceof Interface && ((Interface) iroot).getImplementationRef().equals(serviceInterface)) {
foundInterface = true;
touseInterface = (Interface) iroot;
break;
}
}
if (!foundInterface) {
for (Interface toadd : toAddInterfaces) {
if (toadd.getImplementationRef().equals(serviceInterface)) {
foundInterface = true;
touseInterface = toadd;
break;
}
}
}
}
if (!foundInterface) {
touseInterface = Bpmn2Factory.eINSTANCE.createInterface();
if (serviceInterface == null || serviceInterface.length() == 0) {
serviceInterface = fe.getId() + "_ServiceInterface";
if (serviceInterfaceFeature != null) {
fe.getAnyAttribute().set(serviceInterfaceFeature, serviceInterface);
}
}
touseInterface.setName(serviceInterface);
touseInterface.setImplementationRef(serviceInterface);
touseInterface.setId(fe.getId() + "_ServiceInterface");
toAddInterfaces.add(touseInterface);
}
if (serviceOperation != null) {
boolean foundOperation = false;
for (Operation oper : touseInterface.getOperations()) {
if (serviceImplementation != null && serviceImplementation.equals("Java")) {
if (oper.getName().equals(serviceOperation)) {
foundOperation = true;
break;
}
} else if (serviceImplementation != null && serviceImplementation.equals("##WebService")) {
if (oper.getImplementationRef().equals(serviceOperation)) {
foundOperation = true;
break;
}
}
}
if (!foundOperation) {
Operation touseOperation = Bpmn2Factory.eINSTANCE.createOperation();
if (serviceOperation == null || serviceOperation.length() == 0) {
serviceOperation = fe.getId() + "_ServiceOperation";
if (serviceOperationFeature != null) {
fe.getAnyAttribute().set(serviceOperationFeature, serviceOperation);
}
}
touseOperation.setId(fe.getId() + "_ServiceOperation");
touseOperation.setName(serviceOperation);
touseOperation.setImplementationRef(serviceOperation);
Message message = Bpmn2Factory.eINSTANCE.createMessage();
message.setId(fe.getId() + "_InMessage");
ItemDefinition itemdef = Bpmn2Factory.eINSTANCE.createItemDefinition();
itemdef.setId(message.getId() + "Type");
message.setItemRef(itemdef);
toAddDefinitions.add(itemdef);
toAddMessages.add(message);
touseOperation.setInMessageRef(message);
touseInterface.getOperations().add(touseOperation);
((ServiceTask) fe).setOperationRef(touseOperation);
}
}
} else if (fe instanceof FlowElementsContainer) {
revisitServiceTasksExecute((FlowElementsContainer) fe, rootElements, toAddInterfaces, toAddMessages, toAddDefinitions);
}
}
}
use of org.eclipse.bpmn2.FlowElement in project kie-wb-common by kiegroup.
the class Bpmn2JsonUnmarshaller method revisitServiceTasksExecute.
private void revisitServiceTasksExecute(FlowElementsContainer container, List<RootElement> rootElements, List<Interface> toAddInterfaces, List<Message> toAddMessages, List<ItemDefinition> toAddDefinitions) {
List<FlowElement> flowElements = container.getFlowElements();
for (FlowElement fe : flowElements) {
if (fe instanceof ServiceTask) {
Iterator<FeatureMap.Entry> iter = fe.getAnyAttribute().iterator();
String serviceImplementation = null;
String serviceInterface = null;
String serviceOperation = null;
EStructuralFeature serviceInterfaceFeature = null;
EStructuralFeature serviceOperationFeature = null;
while (iter.hasNext()) {
FeatureMap.Entry entry = iter.next();
if (entry.getEStructuralFeature().getName().equals("serviceimplementation")) {
serviceImplementation = (String) entry.getValue();
}
if (entry.getEStructuralFeature().getName().equals("serviceoperation")) {
serviceOperation = (String) entry.getValue();
serviceOperationFeature = entry.getEStructuralFeature();
}
if (entry.getEStructuralFeature().getName().equals("serviceinterface")) {
serviceInterface = (String) entry.getValue();
serviceInterfaceFeature = entry.getEStructuralFeature();
}
}
boolean foundInterface = false;
Interface touseInterface = null;
if (serviceImplementation != null && serviceImplementation.equals("Java")) {
for (RootElement iroot : rootElements) {
if (iroot instanceof Interface && ((Interface) iroot).getName().equals(serviceInterface)) {
foundInterface = true;
touseInterface = (Interface) iroot;
break;
}
}
if (!foundInterface) {
for (Interface toadd : toAddInterfaces) {
if (toadd.getName() != null && toadd.getName().equals(serviceInterface)) {
foundInterface = true;
touseInterface = toadd;
break;
}
}
}
} else if (serviceImplementation != null && serviceImplementation.equals("##WebService")) {
for (RootElement iroot : rootElements) {
if (iroot instanceof Interface && ((Interface) iroot).getImplementationRef().equals(serviceInterface)) {
foundInterface = true;
touseInterface = (Interface) iroot;
break;
}
}
if (!foundInterface) {
for (Interface toadd : toAddInterfaces) {
if (toadd.getImplementationRef().equals(serviceInterface)) {
foundInterface = true;
touseInterface = toadd;
break;
}
}
}
}
if (!foundInterface) {
touseInterface = Bpmn2Factory.eINSTANCE.createInterface();
if (serviceInterface == null || serviceInterface.length() == 0) {
serviceInterface = fe.getId() + "_ServiceInterface";
if (serviceInterfaceFeature != null) {
fe.getAnyAttribute().set(serviceInterfaceFeature, serviceInterface);
}
}
touseInterface.setName(serviceInterface);
touseInterface.setImplementationRef(serviceInterface);
touseInterface.setId(fe.getId() + "_ServiceInterface");
toAddInterfaces.add(touseInterface);
}
if (serviceOperation != null) {
boolean foundOperation = false;
for (Operation oper : touseInterface.getOperations()) {
if (serviceImplementation != null && serviceImplementation.equals("Java")) {
if (oper.getName().equals(serviceOperation)) {
foundOperation = true;
break;
}
} else if (serviceImplementation != null && serviceImplementation.equals("##WebService")) {
if (oper.getImplementationRef().equals(serviceOperation)) {
foundOperation = true;
break;
}
}
}
if (!foundOperation) {
Operation touseOperation = Bpmn2Factory.eINSTANCE.createOperation();
if (serviceOperation == null || serviceOperation.length() == 0) {
serviceOperation = fe.getId() + "_ServiceOperation";
if (serviceOperationFeature != null) {
fe.getAnyAttribute().set(serviceOperationFeature, serviceOperation);
}
}
touseOperation.setId(fe.getId() + "_ServiceOperation");
touseOperation.setName(serviceOperation);
touseOperation.setImplementationRef(serviceOperation);
Message message = Bpmn2Factory.eINSTANCE.createMessage();
message.setId(fe.getId() + "_InMessage");
ItemDefinition itemdef = Bpmn2Factory.eINSTANCE.createItemDefinition();
itemdef.setId(message.getId() + "Type");
message.setItemRef(itemdef);
toAddDefinitions.add(itemdef);
toAddMessages.add(message);
touseOperation.setInMessageRef(message);
touseInterface.getOperations().add(touseOperation);
((ServiceTask) fe).setOperationRef(touseOperation);
}
}
} else if (fe instanceof FlowElementsContainer) {
revisitServiceTasksExecute((FlowElementsContainer) fe, rootElements, toAddInterfaces, toAddMessages, toAddDefinitions);
}
}
}
use of org.eclipse.bpmn2.FlowElement in project kie-wb-common by kiegroup.
the class Scripts method addExtensionValue.
private static void addExtensionValue(FlowElement flowElement, FeatureMap.Entry value) {
ExtensionAttributeValue eav = bpmn2.createExtensionAttributeValue();
flowElement.getExtensionValues().add(eav);
eav.getValue().add(value);
}
use of org.eclipse.bpmn2.FlowElement 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;
}
use of org.eclipse.bpmn2.FlowElement in project kie-wb-common by kiegroup.
the class Bpmn2JsonMarshaller method marshallSubProcess.
protected void marshallSubProcess(SubProcess subProcess, BPMNPlane plane, JsonGenerator generator, float xOffset, float yOffset, String preProcessingData, Definitions def, Map<String, Object> flowElementProperties) throws JsonGenerationException, IOException {
Map<String, Object> properties = new LinkedHashMap<String, Object>(flowElementProperties);
if (subProcess.getName() != null) {
properties.put(NAME, StringEscapeUtils.unescapeXml(subProcess.getName()));
} else {
properties.put(NAME, "");
}
putDocumentationProperty(subProcess, properties);
// overwrite name if elementname extension element is present
String elementName = Utils.getMetaDataValue(subProcess.getExtensionValues(), "elementname");
if (elementName != null) {
properties.put(NAME, elementName);
}
if (subProcess instanceof AdHocSubProcess) {
setAdHocSubProcessProperties((AdHocSubProcess) subProcess, properties);
}
// custom async
String customAsyncMetaData = Utils.getMetaDataValue(subProcess.getExtensionValues(), "customAsync");
String customAsync = (customAsyncMetaData != null && customAsyncMetaData.length() > 0) ? customAsyncMetaData : "false";
properties.put(ISASYNC, customAsync);
// data inputs
String datainputset = marshallDataInputSet(subProcess, properties);
// data outputs
String dataoutputset = marshallDataOutputSet(subProcess, properties);
// assignments
StringBuilder associationBuff = new StringBuilder();
List<DataInputAssociation> inputAssociations = subProcess.getDataInputAssociations();
List<DataOutputAssociation> outputAssociations = subProcess.getDataOutputAssociations();
marshallDataInputAssociations(associationBuff, inputAssociations);
marshallDataOutputAssociations(associationBuff, outputAssociations);
String assignmentString = associationBuff.toString();
if (assignmentString.endsWith(",")) {
assignmentString = assignmentString.substring(0, assignmentString.length() - 1);
}
properties.put(ASSIGNMENTS, assignmentString);
setAssignmentsInfoProperty(null, datainputset, null, dataoutputset, assignmentString, properties);
// on-entry and on-exit actions
ScriptTypeListValue onEntryActions = getOnEntryActions(subProcess.getExtensionValues());
ScriptTypeListValue onExitActions = getOnExitActions(subProcess.getExtensionValues());
if (!onEntryActions.isEmpty()) {
properties.put(ONENTRYACTIONS, new ScriptTypeListTypeSerializer().serialize(onEntryActions));
}
if (!onExitActions.isEmpty()) {
properties.put(ONEXITACTIONS, new ScriptTypeListTypeSerializer().serialize(onExitActions));
}
// loop characteristics
boolean haveValidLoopCharacteristics = false;
if (subProcess.getLoopCharacteristics() != null && subProcess.getLoopCharacteristics() instanceof MultiInstanceLoopCharacteristics) {
haveValidLoopCharacteristics = true;
properties.put(MITRIGGER, "true");
MultiInstanceLoopCharacteristics taskmi = (MultiInstanceLoopCharacteristics) subProcess.getLoopCharacteristics();
if (taskmi.getLoopDataInputRef() != null) {
ItemAwareElement iedatainput = taskmi.getLoopDataInputRef();
List<DataInputAssociation> taskInputAssociations = subProcess.getDataInputAssociations();
for (DataInputAssociation dia : taskInputAssociations) {
if (dia.getTargetRef().equals(iedatainput)) {
properties.put(MULTIPLEINSTANCECOLLECTIONINPUT, dia.getSourceRef().get(0).getId());
break;
}
}
}
if (taskmi.getLoopDataOutputRef() != null) {
ItemAwareElement iedataoutput = taskmi.getLoopDataOutputRef();
List<DataOutputAssociation> taskOutputAssociations = subProcess.getDataOutputAssociations();
for (DataOutputAssociation dout : taskOutputAssociations) {
if (dout.getSourceRef().get(0).equals(iedataoutput)) {
properties.put(MULTIPLEINSTANCECOLLECTIONOUTPUT, dout.getTargetRef().getId());
break;
}
}
}
if (taskmi.getInputDataItem() != null) {
List<DataInput> taskDataInputs = subProcess.getIoSpecification().getDataInputs();
for (DataInput din : taskDataInputs) {
if (din.getItemSubjectRef() == null) {
// for backward compatibility as the where only input supported
properties.put(MULTIPLEINSTANCEDATAINPUT, taskmi.getInputDataItem().getId());
}
if (din.getItemSubjectRef() != null && din.getItemSubjectRef().getId().equals(taskmi.getInputDataItem().getItemSubjectRef().getId())) {
properties.put(MULTIPLEINSTANCEDATAINPUT, din.getName());
break;
}
}
}
if (taskmi.getOutputDataItem() != null) {
List<DataOutput> taskDataOutputs = subProcess.getIoSpecification().getDataOutputs();
for (DataOutput dout : taskDataOutputs) {
if (dout.getItemSubjectRef() == null) {
properties.put(MULTIPLEINSTANCEDATAOUTPUT, taskmi.getOutputDataItem().getId());
break;
}
if (dout.getItemSubjectRef() != null && dout.getItemSubjectRef().getId().equals(taskmi.getOutputDataItem().getItemSubjectRef().getId())) {
properties.put(MULTIPLEINSTANCEDATAOUTPUT, dout.getName());
break;
}
}
}
if (taskmi.getCompletionCondition() != null) {
if (taskmi.getCompletionCondition() instanceof FormalExpression) {
properties.put(MULTIPLEINSTANCECOMPLETIONCONDITION, ((FormalExpression) taskmi.getCompletionCondition()).getBody());
}
}
}
// properties
List<Property> processProperties = subProcess.getProperties();
if (processProperties != null && processProperties.size() > 0) {
String propVal = "";
for (int i = 0; i < processProperties.size(); i++) {
Property p = processProperties.get(i);
String pKPI = Utils.getMetaDataValue(p.getExtensionValues(), "customKPI");
propVal += p.getId();
// check the structureRef value
if (p.getItemSubjectRef() != null && p.getItemSubjectRef().getStructureRef() != null) {
propVal += ":" + p.getItemSubjectRef().getStructureRef();
}
if (pKPI != null && pKPI.length() > 0) {
propVal += ":" + pKPI;
}
if (i != processProperties.size() - 1) {
propVal += ",";
}
}
properties.put(VARDEFS, propVal);
}
// simulation properties
setSimulationProperties(subProcess.getId(), properties);
marshallProperties(properties, generator);
generator.writeObjectFieldStart("stencil");
if (subProcess instanceof AdHocSubProcess) {
generator.writeObjectField("id", "AdHocSubprocess");
} else {
if (subProcess.isTriggeredByEvent()) {
generator.writeObjectField("id", "EventSubprocess");
} else {
if (haveValidLoopCharacteristics) {
generator.writeObjectField("id", "MultipleInstanceSubprocess");
} else {
generator.writeObjectField("id", "Subprocess");
}
}
}
generator.writeEndObject();
generator.writeArrayFieldStart("childShapes");
Bounds bounds = ((BPMNShape) findDiagramElement(plane, subProcess)).getBounds();
for (FlowElement flowElement : subProcess.getFlowElements()) {
if (coordianteManipulation) {
marshallFlowElement(flowElement, plane, generator, bounds.getX(), bounds.getY(), preProcessingData, def);
} else {
marshallFlowElement(flowElement, plane, generator, 0, 0, preProcessingData, def);
}
}
for (Artifact artifact : subProcess.getArtifacts()) {
if (coordianteManipulation) {
marshallArtifact(artifact, plane, generator, bounds.getX(), bounds.getY(), preProcessingData, def);
} else {
marshallArtifact(artifact, plane, generator, 0, 0, preProcessingData, def);
}
}
generator.writeEndArray();
generator.writeArrayFieldStart("outgoing");
for (BoundaryEvent boundaryEvent : subProcess.getBoundaryEventRefs()) {
generator.writeStartObject();
generator.writeObjectField("resourceId", boundaryEvent.getId());
generator.writeEndObject();
}
for (SequenceFlow outgoing : subProcess.getOutgoing()) {
generator.writeStartObject();
generator.writeObjectField("resourceId", outgoing.getId());
generator.writeEndObject();
}
Process process = (Process) plane.getBpmnElement();
writeAssociations(process, subProcess.getId(), generator);
// subprocess boundary events
List<BoundaryEvent> boundaryEvents = new ArrayList<BoundaryEvent>();
findBoundaryEvents(process, boundaryEvents);
for (BoundaryEvent be : boundaryEvents) {
if (be.getAttachedToRef().getId().equals(subProcess.getId())) {
generator.writeStartObject();
generator.writeObjectField("resourceId", be.getId());
generator.writeEndObject();
}
}
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();
}
Aggregations