use of org.polymap.model2.Association in project kie-wb-common by kiegroup.
the class Bpmn2JsonUnmarshaller method createSubProcessDiagram.
private void createSubProcessDiagram(BPMNPlane plane, FlowElement flowElement, BpmnDiFactory factory) {
SubProcess sp = (SubProcess) flowElement;
for (FlowElement subProcessFlowElement : sp.getFlowElements()) {
if (subProcessFlowElement instanceof SubProcess) {
createBpmnShapeForElement(factory, plane, subProcessFlowElement);
createSubProcessDiagram(plane, subProcessFlowElement, factory);
} else if (subProcessFlowElement instanceof FlowNode) {
createBpmnShapeForElement(factory, plane, subProcessFlowElement);
if (subProcessFlowElement instanceof BoundaryEvent) {
createDockersForBoundaryEvent((BoundaryEvent) subProcessFlowElement);
}
} else if (subProcessFlowElement instanceof SequenceFlow) {
createBpmnEdgeForSequenceFlow(factory, plane, (SequenceFlow) subProcessFlowElement);
}
}
if (sp.getArtifacts() != null) {
List<Association> incompleteAssociations = new ArrayList<Association>();
for (Artifact artifact : sp.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) {
sp.getArtifacts().remove(incompleteAssociation);
}
}
}
}
use of org.polymap.model2.Association 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.polymap.model2.Association 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.polymap.model2.Association in project kie-wb-common by kiegroup.
the class Bpmn2JsonMarshaller method writeAssociations.
private void writeAssociations(Process process, String elementId, JsonGenerator generator) throws IOException {
for (Artifact artifact : process.getArtifacts()) {
if (artifact instanceof Association) {
Association association = (Association) artifact;
if (association.getSourceRef().getId().equals(elementId)) {
generator.writeStartObject();
generator.writeObjectField("resourceId", association.getId());
generator.writeEndObject();
}
}
}
}
use of org.polymap.model2.Association in project kie-wb-common by kiegroup.
the class DMNMarshallerTest method checkAssociationsGraph.
private void checkAssociationsGraph(Graph<?, Node<?, ?>> g) {
Node<?, ?> inputData = g.getNode("BD168F8B-4398-4478-8BEA-E67AA5F90FAF");
assertNodeContentDefinitionIs(inputData, InputData.class);
Node<?, ?> decision = g.getNode("A960E2D2-FBC1-4D11-AA33-064F6A0B5CB9");
assertNodeContentDefinitionIs(decision, Decision.class);
Node<?, ?> knowledgeSource = g.getNode("FB99ED65-BC43-4750-999F-7FE24690845B");
assertNodeContentDefinitionIs(knowledgeSource, KnowledgeSource.class);
Node<?, ?> bkm = g.getNode("2F07453C-854F-436F-8378-4CFCE63BB124");
assertNodeContentDefinitionIs(bkm, BusinessKnowledgeModel.class);
Node<?, ?> textAnnotation = g.getNode("7F4B8130-6F3D-4A16-9F6C-01D01DA481D2");
assertNodeContentDefinitionIs(textAnnotation, TextAnnotation.class);
Edge fromInput = assertNodeEdgesTo(inputData, textAnnotation, Association.class);
assertEquals("From Input", ((View<Association>) fromInput.getContent()).getDefinition().getDescription().getValue());
Edge fromDecision = assertNodeEdgesTo(decision, textAnnotation, Association.class);
assertEquals("From Decision", ((View<Association>) fromDecision.getContent()).getDefinition().getDescription().getValue());
Edge fromBkm = assertNodeEdgesTo(bkm, textAnnotation, Association.class);
assertEquals("From BKM", ((View<Association>) fromBkm.getContent()).getDefinition().getDescription().getValue());
Edge fromKnowledgeSource = assertNodeEdgesTo(knowledgeSource, textAnnotation, Association.class);
assertEquals("From Knowledge Source", ((View<Association>) fromKnowledgeSource.getContent()).getDefinition().getDescription().getValue());
}
Aggregations