use of org.kie.workbench.common.dmn.api.definition.v1_1.ItemDefinition in project kie-wb-common by kiegroup.
the class Bpmn2JsonUnmarshaller method revisitDataObjects.
public void revisitDataObjects(Definitions def) {
List<RootElement> rootElements = def.getRootElements();
List<ItemDefinition> itemDefinitionsToAddUnfiltered = new ArrayList<ItemDefinition>();
List<ItemDefinition> itemDefinitionsToAddFiltered = new ArrayList<ItemDefinition>();
for (RootElement root : rootElements) {
if (root instanceof Process) {
Process process = (Process) root;
List<FlowElement> flowElements = process.getFlowElements();
for (FlowElement fe : flowElements) {
if (fe instanceof DataObject) {
DataObject da = (DataObject) fe;
ItemDefinition itemdef = Bpmn2Factory.eINSTANCE.createItemDefinition();
itemdef.setId("_" + da.getId() + "Item");
Iterator<FeatureMap.Entry> iter = da.getAnyAttribute().iterator();
while (iter.hasNext()) {
FeatureMap.Entry entry = iter.next();
if (entry.getEStructuralFeature().getName().equals("datype")) {
String typeValue = (String) entry.getValue();
if (typeValue != null && !typeValue.equals("None")) {
itemdef.setStructureRef((String) entry.getValue());
}
}
}
da.setItemSubjectRef(itemdef);
itemDefinitionsToAddUnfiltered.add(itemdef);
}
}
}
}
for (ItemDefinition itemDef : itemDefinitionsToAddUnfiltered) {
boolean foundItemDef = false;
for (RootElement ele : rootElements) {
if (ele instanceof ItemDefinition) {
ItemDefinition idef = (ItemDefinition) ele;
if (idef.getId().equals(itemDef.getId())) {
foundItemDef = true;
break;
}
}
}
if (!foundItemDef) {
itemDefinitionsToAddFiltered.add(itemDef);
}
}
for (ItemDefinition itemDefFil : itemDefinitionsToAddFiltered) {
def.getRootElements().add(itemDefFil);
}
for (RootElement root : rootElements) {
if (root instanceof Process) {
Process process = (Process) root;
List<Artifact> artifactElements = process.getArtifacts();
for (Artifact af : artifactElements) {
if (af instanceof Association) {
Association as = (Association) af;
if (as.getSourceRef() != null && as.getSourceRef() instanceof DataObject && as.getTargetRef() != null && (as.getTargetRef() instanceof Task || as.getTargetRef() instanceof ThrowEvent)) {
DataObject da = (DataObject) as.getSourceRef();
if (as.getTargetRef() instanceof Task) {
Task task = (Task) as.getTargetRef();
if (task.getIoSpecification() == null) {
InputOutputSpecification iospec = Bpmn2Factory.eINSTANCE.createInputOutputSpecification();
task.setIoSpecification(iospec);
}
if (task.getIoSpecification().getInputSets() == null || task.getIoSpecification().getInputSets().size() < 1) {
InputSet inset = Bpmn2Factory.eINSTANCE.createInputSet();
task.getIoSpecification().getInputSets().add(inset);
}
InputSet inSet = task.getIoSpecification().getInputSets().get(0);
boolean foundDataInput = false;
for (DataInput dataInput : inSet.getDataInputRefs()) {
if (dataInput.getId().equals(task.getId() + "_" + da.getId() + "InputX")) {
foundDataInput = true;
}
}
if (!foundDataInput) {
DataInput d = Bpmn2Factory.eINSTANCE.createDataInput();
d.setId(task.getId() + "_" + da.getId() + "InputX");
d.setName(da.getId() + "InputX");
task.getIoSpecification().getDataInputs().add(d);
task.getIoSpecification().getInputSets().get(0).getDataInputRefs().add(d);
DataInputAssociation dia = Bpmn2Factory.eINSTANCE.createDataInputAssociation();
dia.setTargetRef(d);
dia.getSourceRef().add(da);
task.getDataInputAssociations().add(dia);
}
} else if (as.getTargetRef() instanceof ThrowEvent) {
ThrowEvent te = (ThrowEvent) as.getTargetRef();
// update throw event data input and add data input association
boolean foundDataInput = false;
List<DataInput> dataInputs = te.getDataInputs();
for (DataInput din : dataInputs) {
if (din.getId().equals(te.getId() + "_" + da.getId() + "InputX")) {
foundDataInput = true;
}
}
if (!foundDataInput) {
DataInput datain = Bpmn2Factory.eINSTANCE.createDataInput();
datain.setId(te.getId() + "_" + da.getId() + "InputX");
datain.setName(da.getId() + "InputX");
te.getDataInputs().add(datain);
if (te.getInputSet() == null) {
InputSet inset = Bpmn2Factory.eINSTANCE.createInputSet();
te.setInputSet(inset);
}
te.getInputSet().getDataInputRefs().add(datain);
DataInputAssociation dia = Bpmn2Factory.eINSTANCE.createDataInputAssociation();
dia.setTargetRef(datain);
dia.getSourceRef().add(da);
te.getDataInputAssociation().add(dia);
}
}
}
if (as.getTargetRef() != null && as.getTargetRef() instanceof DataObject && as.getSourceRef() != null && (as.getSourceRef() instanceof Task || as.getSourceRef() instanceof CatchEvent)) {
DataObject da = (DataObject) as.getTargetRef();
if (as.getSourceRef() instanceof Task) {
Task task = (Task) as.getSourceRef();
if (task.getIoSpecification() == null) {
InputOutputSpecification iospec = Bpmn2Factory.eINSTANCE.createInputOutputSpecification();
task.setIoSpecification(iospec);
}
if (task.getIoSpecification().getOutputSets() == null || task.getIoSpecification().getOutputSets().size() < 1) {
OutputSet outSet = Bpmn2Factory.eINSTANCE.createOutputSet();
task.getIoSpecification().getOutputSets().add(outSet);
}
boolean foundDataOutput = false;
OutputSet outSet = task.getIoSpecification().getOutputSets().get(0);
for (DataOutput dataOut : outSet.getDataOutputRefs()) {
if (dataOut.getId().equals(task.getId() + "_" + da.getId() + "OutputX")) {
foundDataOutput = true;
}
}
if (!foundDataOutput) {
DataOutput d = Bpmn2Factory.eINSTANCE.createDataOutput();
d.setId(task.getId() + "_" + da.getId() + "OutputX");
d.setName(da.getId() + "OutputX");
task.getIoSpecification().getDataOutputs().add(d);
task.getIoSpecification().getOutputSets().get(0).getDataOutputRefs().add(d);
DataOutputAssociation doa = Bpmn2Factory.eINSTANCE.createDataOutputAssociation();
doa.getSourceRef().add(d);
doa.setTargetRef(da);
task.getDataOutputAssociations().add(doa);
}
} else if (as.getSourceRef() instanceof CatchEvent) {
CatchEvent ce = (CatchEvent) as.getSourceRef();
// update catch event data output and add data output association
boolean foundDataOutput = false;
List<DataOutput> dataOutputs = ce.getDataOutputs();
for (DataOutput dout : dataOutputs) {
if (dout.getId().equals(ce.getId() + "_" + da.getId() + "OutputX")) {
foundDataOutput = true;
}
}
if (!foundDataOutput) {
DataOutput dataout = Bpmn2Factory.eINSTANCE.createDataOutput();
dataout.setId(ce.getId() + "_" + da.getId() + "OutputX");
dataout.setName(da.getId() + "OutputX");
ce.getDataOutputs().add(dataout);
if (ce.getOutputSet() == null) {
OutputSet outset = Bpmn2Factory.eINSTANCE.createOutputSet();
ce.setOutputSet(outset);
}
ce.getOutputSet().getDataOutputRefs().add(dataout);
DataOutputAssociation dia = Bpmn2Factory.eINSTANCE.createDataOutputAssociation();
dia.setTargetRef(da);
dia.getSourceRef().add(dataout);
ce.getDataOutputAssociation().add(dia);
}
}
}
if (as.getSourceRef() != null && as.getSourceRef() instanceof DataObject && as.getTargetRef() != null && (as.getTargetRef() instanceof SequenceFlow)) {
SequenceFlow sf = (SequenceFlow) as.getTargetRef();
if (sf.getSourceRef() != null && sf.getSourceRef() instanceof Activity && sf.getTargetRef() != null && sf.getTargetRef() instanceof Activity) {
Activity sourceElement = (Activity) sf.getSourceRef();
Activity targetElement = (Activity) sf.getTargetRef();
DataObject da = (DataObject) as.getSourceRef();
if (targetElement.getIoSpecification() == null) {
InputOutputSpecification iospec = Bpmn2Factory.eINSTANCE.createInputOutputSpecification();
targetElement.setIoSpecification(iospec);
}
if (targetElement.getIoSpecification().getInputSets() == null || targetElement.getIoSpecification().getInputSets().size() < 1) {
InputSet inset = Bpmn2Factory.eINSTANCE.createInputSet();
targetElement.getIoSpecification().getInputSets().add(inset);
}
InputSet inSet = targetElement.getIoSpecification().getInputSets().get(0);
boolean foundDataInput = false;
for (DataInput dataInput : inSet.getDataInputRefs()) {
if (dataInput.getId().equals(targetElement.getId() + "_" + da.getId() + "InputX")) {
foundDataInput = true;
}
}
if (!foundDataInput) {
DataInput d = Bpmn2Factory.eINSTANCE.createDataInput();
d.setId(targetElement.getId() + "_" + da.getId() + "InputX");
d.setName(da.getId() + "InputX");
targetElement.getIoSpecification().getDataInputs().add(d);
targetElement.getIoSpecification().getInputSets().get(0).getDataInputRefs().add(d);
DataInputAssociation dia = Bpmn2Factory.eINSTANCE.createDataInputAssociation();
dia.setTargetRef(d);
dia.getSourceRef().add(da);
targetElement.getDataInputAssociations().add(dia);
}
if (sourceElement.getIoSpecification() == null) {
InputOutputSpecification iospec = Bpmn2Factory.eINSTANCE.createInputOutputSpecification();
sourceElement.setIoSpecification(iospec);
}
if (sourceElement.getIoSpecification().getOutputSets() == null || sourceElement.getIoSpecification().getOutputSets().size() < 1) {
OutputSet outSet = Bpmn2Factory.eINSTANCE.createOutputSet();
sourceElement.getIoSpecification().getOutputSets().add(outSet);
}
boolean foundDataOutput = false;
OutputSet outSet = sourceElement.getIoSpecification().getOutputSets().get(0);
for (DataOutput dataOut : outSet.getDataOutputRefs()) {
if (dataOut.getId().equals(sourceElement.getId() + "_" + da.getId() + "OutputX")) {
foundDataOutput = true;
}
}
if (!foundDataOutput) {
DataOutput d = Bpmn2Factory.eINSTANCE.createDataOutput();
d.setId(sourceElement.getId() + "_" + da.getId() + "OutputX");
d.setName(da.getId() + "OutputX");
sourceElement.getIoSpecification().getDataOutputs().add(d);
sourceElement.getIoSpecification().getOutputSets().get(0).getDataOutputRefs().add(d);
DataOutputAssociation doa = Bpmn2Factory.eINSTANCE.createDataOutputAssociation();
doa.getSourceRef().add(d);
doa.setTargetRef(da);
sourceElement.getDataOutputAssociations().add(doa);
}
}
}
}
}
}
}
}
use of org.kie.workbench.common.dmn.api.definition.v1_1.ItemDefinition in project kie-wb-common by kiegroup.
the class Bpmn2JsonUnmarshaller method revisitSendReceiveTasks.
public void revisitSendReceiveTasks(Definitions def) {
List<Message> toAddMessages = new ArrayList<Message>();
List<ItemDefinition> toAddItemDefinitions = new ArrayList<ItemDefinition>();
List<RootElement> rootElements = def.getRootElements();
for (RootElement root : rootElements) {
if (root instanceof Process) {
setSendReceiveTasksInfo((Process) root, def, toAddMessages, toAddItemDefinitions);
}
}
for (ItemDefinition idef : toAddItemDefinitions) {
def.getRootElements().add(idef);
}
for (Message msg : toAddMessages) {
def.getRootElements().add(msg);
}
}
use of org.kie.workbench.common.dmn.api.definition.v1_1.ItemDefinition 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.kie.workbench.common.dmn.api.definition.v1_1.ItemDefinition 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.kie.workbench.common.dmn.api.definition.v1_1.ItemDefinition in project kie-wb-common by kiegroup.
the class BPMNDiagramMarshallerTest 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);
assertTrue(itemDefinition.getStructureRef().equals(dataType));
assertTrue(itemDefinition.getId().endsWith(itemSubjectRefSuffix));
}
Aggregations