use of org.kie.workbench.common.dmn.api.definition.v1_1.Association in project kie-wb-common by kiegroup.
the class DMNMarshaller method unmarshall.
@Override
public Graph unmarshall(final Metadata metadata, final InputStream input) throws IOException {
org.kie.dmn.model.v1_1.Definitions dmnXml = marshaller.unmarshal(new InputStreamReader(input));
Map<String, Entry<org.kie.dmn.model.v1_1.DRGElement, Node>> elems = dmnXml.getDrgElement().stream().collect(Collectors.toMap(org.kie.dmn.model.v1_1.DRGElement::getId, dmn -> new SimpleEntry<>(dmn, dmnToStunner(dmn))));
Optional<org.kie.workbench.common.dmn.backend.definition.v1_1.dd.DMNDiagram> dmnDDDiagram = findDMNDiagram(dmnXml);
for (Entry<org.kie.dmn.model.v1_1.DRGElement, Node> kv : elems.values()) {
org.kie.dmn.model.v1_1.DRGElement elem = kv.getKey();
Node currentNode = kv.getValue();
ddExtAugmentStunner(dmnDDDiagram, currentNode);
// DMN spec table 2: Requirements connection rules
if (elem instanceof org.kie.dmn.model.v1_1.Decision) {
org.kie.dmn.model.v1_1.Decision decision = (org.kie.dmn.model.v1_1.Decision) elem;
for (org.kie.dmn.model.v1_1.InformationRequirement ir : decision.getInformationRequirement()) {
if (ir.getRequiredInput() != null) {
String reqInputID = getId(ir.getRequiredInput());
Node requiredNode = elems.get(reqInputID).getValue();
Edge myEdge = factoryManager.newElement(UUID.uuid(), org.kie.workbench.common.dmn.api.definition.v1_1.InformationRequirement.class).asEdge();
connectEdge(myEdge, requiredNode, currentNode);
setConnectionMagnets(myEdge);
}
if (ir.getRequiredDecision() != null) {
String reqInputID = getId(ir.getRequiredDecision());
Node requiredNode = elems.get(reqInputID).getValue();
Edge myEdge = factoryManager.newElement(UUID.uuid(), org.kie.workbench.common.dmn.api.definition.v1_1.InformationRequirement.class).asEdge();
connectEdge(myEdge, requiredNode, currentNode);
setConnectionMagnets(myEdge);
}
}
for (org.kie.dmn.model.v1_1.KnowledgeRequirement kr : decision.getKnowledgeRequirement()) {
String reqInputID = getId(kr.getRequiredKnowledge());
Node requiredNode = elems.get(reqInputID).getValue();
Edge myEdge = factoryManager.newElement(UUID.uuid(), org.kie.workbench.common.dmn.api.definition.v1_1.KnowledgeRequirement.class).asEdge();
connectEdge(myEdge, requiredNode, currentNode);
setConnectionMagnets(myEdge);
}
for (org.kie.dmn.model.v1_1.AuthorityRequirement kr : decision.getAuthorityRequirement()) {
String reqInputID = getId(kr.getRequiredAuthority());
Node requiredNode = elems.get(reqInputID).getValue();
Edge myEdge = factoryManager.newElement(UUID.uuid(), org.kie.workbench.common.dmn.api.definition.v1_1.AuthorityRequirement.class).asEdge();
connectEdge(myEdge, requiredNode, currentNode);
setConnectionMagnets(myEdge);
}
} else if (elem instanceof org.kie.dmn.model.v1_1.BusinessKnowledgeModel) {
org.kie.dmn.model.v1_1.BusinessKnowledgeModel bkm = (org.kie.dmn.model.v1_1.BusinessKnowledgeModel) elem;
for (org.kie.dmn.model.v1_1.KnowledgeRequirement kr : bkm.getKnowledgeRequirement()) {
String reqInputID = getId(kr.getRequiredKnowledge());
Node requiredNode = elems.get(reqInputID).getValue();
Edge myEdge = factoryManager.newElement(UUID.uuid(), org.kie.workbench.common.dmn.api.definition.v1_1.KnowledgeRequirement.class).asEdge();
connectEdge(myEdge, requiredNode, currentNode);
setConnectionMagnets(myEdge);
}
for (org.kie.dmn.model.v1_1.AuthorityRequirement kr : bkm.getAuthorityRequirement()) {
String reqInputID = getId(kr.getRequiredAuthority());
Node requiredNode = elems.get(reqInputID).getValue();
Edge myEdge = factoryManager.newElement(UUID.uuid(), org.kie.workbench.common.dmn.api.definition.v1_1.AuthorityRequirement.class).asEdge();
connectEdge(myEdge, requiredNode, currentNode);
setConnectionMagnets(myEdge);
}
} else if (elem instanceof org.kie.dmn.model.v1_1.KnowledgeSource) {
org.kie.dmn.model.v1_1.KnowledgeSource ks = (org.kie.dmn.model.v1_1.KnowledgeSource) elem;
for (org.kie.dmn.model.v1_1.AuthorityRequirement ir : ks.getAuthorityRequirement()) {
if (ir.getRequiredInput() != null) {
String reqInputID = getId(ir.getRequiredInput());
Node requiredNode = elems.get(reqInputID).getValue();
Edge myEdge = factoryManager.newElement(UUID.uuid(), org.kie.workbench.common.dmn.api.definition.v1_1.AuthorityRequirement.class).asEdge();
connectEdge(myEdge, requiredNode, currentNode);
setConnectionMagnets(myEdge);
}
if (ir.getRequiredDecision() != null) {
String reqInputID = getId(ir.getRequiredDecision());
Node requiredNode = elems.get(reqInputID).getValue();
Edge myEdge = factoryManager.newElement(UUID.uuid(), org.kie.workbench.common.dmn.api.definition.v1_1.AuthorityRequirement.class).asEdge();
connectEdge(myEdge, requiredNode, currentNode);
setConnectionMagnets(myEdge);
}
if (ir.getRequiredAuthority() != null) {
String reqInputID = getId(ir.getRequiredAuthority());
Node requiredNode = elems.get(reqInputID).getValue();
Edge myEdge = factoryManager.newElement(UUID.uuid(), org.kie.workbench.common.dmn.api.definition.v1_1.AuthorityRequirement.class).asEdge();
connectEdge(myEdge, requiredNode, currentNode);
setConnectionMagnets(myEdge);
}
}
}
}
Map<String, Node<View<TextAnnotation>, ?>> textAnnotations = dmnXml.getArtifact().stream().filter(org.kie.dmn.model.v1_1.TextAnnotation.class::isInstance).map(org.kie.dmn.model.v1_1.TextAnnotation.class::cast).collect(Collectors.toMap(org.kie.dmn.model.v1_1.TextAnnotation::getId, textAnnotationConverter::nodeFromDMN));
textAnnotations.values().forEach(n -> ddExtAugmentStunner(dmnDDDiagram, n));
List<org.kie.dmn.model.v1_1.Association> associations = dmnXml.getArtifact().stream().filter(org.kie.dmn.model.v1_1.Association.class::isInstance).map(org.kie.dmn.model.v1_1.Association.class::cast).collect(Collectors.toList());
for (org.kie.dmn.model.v1_1.Association a : associations) {
String sourceId = getId(a.getSourceRef());
Node sourceNode = Optional.ofNullable(elems.get(sourceId)).map(Entry::getValue).orElse(textAnnotations.get(sourceId));
String targetId = getId(a.getTargetRef());
Node targetNode = Optional.ofNullable(elems.get(targetId)).map(Entry::getValue).orElse(textAnnotations.get(targetId));
@SuppressWarnings("unchecked") Edge<View<Association>, ?> myEdge = (Edge<View<Association>, ?>) factoryManager.newElement(UUID.uuid(), Association.class).asEdge();
Id id = new Id(a.getId());
Description description = new Description(a.getDescription());
Association definition = new Association(id, description);
myEdge.getContent().setDefinition(definition);
connectEdge(myEdge, sourceNode, targetNode);
setConnectionMagnets(myEdge);
}
Graph graph = factoryManager.newDiagram("prova", BindableAdapterUtils.getDefinitionSetId(DMNDefinitionSet.class), metadata).getGraph();
elems.values().stream().map(kv -> kv.getValue()).forEach(graph::addNode);
textAnnotations.values().forEach(graph::addNode);
@SuppressWarnings("unchecked") Node<View<DMNDiagram>, ?> dmnDiagramRoot = findDMNDiagramRoot(graph);
Definitions definitionsStunnerPojo = DefinitionsConverter.wbFromDMN(dmnXml);
dmnDiagramRoot.getContent().getDefinition().setDefinitions(definitionsStunnerPojo);
elems.values().stream().map(kv -> kv.getValue()).forEach(node -> connectRootWithChild(dmnDiagramRoot, node));
textAnnotations.values().stream().forEach(node -> connectRootWithChild(dmnDiagramRoot, node));
return graph;
}
use of org.kie.workbench.common.dmn.api.definition.v1_1.Association in project kie-wb-common by kiegroup.
the class AssociationConverter method dmnFromWB.
public static List<org.kie.dmn.model.v1_1.Association> dmnFromWB(final Node<View<TextAnnotation>, ?> node) {
TextAnnotation ta = node.getContent().getDefinition();
org.kie.dmn.model.v1_1.DMNElementReference ta_elementReference = new org.kie.dmn.model.v1_1.DMNElementReference();
ta_elementReference.setHref(new StringBuilder("#").append(ta.getId().getValue()).toString());
List<org.kie.dmn.model.v1_1.Association> result = new ArrayList<>();
List<Edge<?, ?>> inEdges = (List<Edge<?, ?>>) node.getInEdges();
for (Edge<?, ?> e : inEdges) {
Node<?, ?> sourceNode = e.getSourceNode();
if (sourceNode.getContent() instanceof View<?>) {
View<?> view = (View<?>) sourceNode.getContent();
if (view.getDefinition() instanceof DRGElement) {
DRGElement drgElement = (DRGElement) view.getDefinition();
org.kie.dmn.model.v1_1.DMNElementReference sourceRef = new org.kie.dmn.model.v1_1.DMNElementReference();
sourceRef.setHref(new StringBuilder("#").append(drgElement.getId().getValue()).toString());
org.kie.dmn.model.v1_1.Association adding = new org.kie.dmn.model.v1_1.Association();
adding.setId(((View<Association>) e.getContent()).getDefinition().getId().getValue());
adding.setDescription(((View<Association>) e.getContent()).getDefinition().getDescription().getValue());
adding.setSourceRef(sourceRef);
adding.setTargetRef(ta_elementReference);
result.add(adding);
}
}
}
List<Edge<?, ?>> outEdges = (List<Edge<?, ?>>) node.getOutEdges();
for (Edge<?, ?> e : outEdges) {
Node<?, ?> targetNode = e.getTargetNode();
if (targetNode.getContent() instanceof View<?>) {
View<?> view = (View<?>) targetNode.getContent();
if (view.getDefinition() instanceof DRGElement) {
DRGElement drgElement = (DRGElement) view.getDefinition();
org.kie.dmn.model.v1_1.DMNElementReference targetRef = new org.kie.dmn.model.v1_1.DMNElementReference();
targetRef.setHref(new StringBuilder("#").append(drgElement.getId().getValue()).toString());
org.kie.dmn.model.v1_1.Association adding = new org.kie.dmn.model.v1_1.Association();
adding.setId(((View<Association>) e.getContent()).getDefinition().getId().getValue());
adding.setDescription(((View<Association>) e.getContent()).getDefinition().getDescription().getValue());
adding.setSourceRef(ta_elementReference);
adding.setTargetRef(targetRef);
result.add(adding);
}
}
}
return result;
}
use of org.kie.workbench.common.dmn.api.definition.v1_1.Association in project kie-wb-common by kiegroup.
the class Bpmn2JsonMarshaller method findOutgoingAssociation.
protected Association findOutgoingAssociation(BPMNPlane plane, BaseElement baseElement) {
Association result = _diagramAssociations.get(baseElement.getId());
if (result != null) {
return result;
}
if (!(plane.getBpmnElement() instanceof Process)) {
throw new IllegalArgumentException("Don't know how to get associations from a non-Process Diagram");
}
Process process = (Process) plane.getBpmnElement();
for (Artifact artifact : process.getArtifacts()) {
if (artifact instanceof Association) {
Association association = (Association) artifact;
if (association.getSourceRef() == baseElement) {
_diagramAssociations.put(baseElement.getId(), association);
return association;
}
}
}
return null;
}
use of org.kie.workbench.common.dmn.api.definition.v1_1.Association in project kie-wb-common by kiegroup.
the class Bpmn2JsonMarshaller method marshallDataObject.
protected void marshallDataObject(DataObject dataObject, BPMNPlane plane, JsonGenerator generator, float xOffset, float yOffset, Map<String, Object> flowElementProperties) throws JsonGenerationException, IOException {
Map<String, Object> properties = new LinkedHashMap<String, Object>(flowElementProperties);
putDocumentationProperty(dataObject, properties);
if (dataObject.getName() != null && dataObject.getName().length() > 0) {
properties.put(NAME, StringEscapeUtils.unescapeXml(dataObject.getName()));
} else {
// we need a name, use id instead
properties.put(NAME, dataObject.getId());
}
// overwrite name if elementname extension element is present
String elementName = Utils.getMetaDataValue(dataObject.getExtensionValues(), "elementname");
if (elementName != null) {
properties.put(NAME, elementName);
}
if (dataObject.getItemSubjectRef().getStructureRef() != null && dataObject.getItemSubjectRef().getStructureRef().length() > 0) {
if (defaultTypesList.contains(dataObject.getItemSubjectRef().getStructureRef())) {
properties.put(STANDARDTYPE, dataObject.getItemSubjectRef().getStructureRef());
} else {
properties.put(CUSTOMTYPE, dataObject.getItemSubjectRef().getStructureRef());
}
}
Association outgoingAssociaton = findOutgoingAssociation(plane, dataObject);
Association incomingAssociation = null;
Process process = (Process) plane.getBpmnElement();
for (Artifact artifact : process.getArtifacts()) {
if (artifact instanceof Association) {
Association association = (Association) artifact;
if (association.getTargetRef() == dataObject) {
incomingAssociation = association;
}
}
}
if (outgoingAssociaton != null && incomingAssociation == null) {
properties.put(INPUT_OUTPUT, "Input");
}
if (outgoingAssociaton == null && incomingAssociation != null) {
properties.put(INPUT_OUTPUT, "Output");
}
marshallProperties(properties, generator);
generator.writeObjectFieldStart("stencil");
generator.writeObjectField("id", "DataObject");
generator.writeEndObject();
generator.writeArrayFieldStart("childShapes");
generator.writeEndArray();
generator.writeArrayFieldStart("outgoing");
List<Association> associations = findOutgoingAssociations(plane, dataObject);
if (associations != null) {
for (Association as : associations) {
generator.writeStartObject();
generator.writeObjectField("resourceId", as.getId());
generator.writeEndObject();
}
}
generator.writeEndArray();
Bounds bounds = ((BPMNShape) findDiagramElement(plane, dataObject)).getBounds();
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();
}
use of org.kie.workbench.common.dmn.api.definition.v1_1.Association in project kie-wb-common by kiegroup.
the class Bpmn2JsonMarshaller method findOutgoingAssociations.
protected List<Association> findOutgoingAssociations(BPMNPlane plane, BaseElement baseElement) {
List<Association> retList = new ArrayList<Association>();
if (!(plane.getBpmnElement() instanceof Process)) {
throw new IllegalArgumentException("Don't know how to get associations from a non-Process Diagram");
}
Process process = (Process) plane.getBpmnElement();
for (Artifact artifact : process.getArtifacts()) {
if (artifact instanceof Association) {
Association association = (Association) artifact;
if (association.getSourceRef() == baseElement) {
retList.add(association);
}
}
}
return retList;
}
Aggregations