use of org.kie.workbench.common.dmn.api.definition.v1_1.DRGElement in project kie-wb-common by kiegroup.
the class KnowledgeSourceConverter method dmnFromNode.
@Override
public org.kie.dmn.model.v1_1.KnowledgeSource dmnFromNode(final Node<View<KnowledgeSource>, ?> node) {
KnowledgeSource source = node.getContent().getDefinition();
org.kie.dmn.model.v1_1.KnowledgeSource result = new org.kie.dmn.model.v1_1.KnowledgeSource();
result.setId(source.getId().getValue());
result.setDescription(DescriptionPropertyConverter.dmnFromWB(source.getDescription()));
result.setName(source.getName().getValue());
result.setType(source.getType().getValue());
result.setLocationURI(source.getLocationURI().getValue());
// DMN spec table 2: Requirements connection rules
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();
if (drgElement instanceof Decision) {
org.kie.dmn.model.v1_1.AuthorityRequirement iReq = new org.kie.dmn.model.v1_1.AuthorityRequirement();
org.kie.dmn.model.v1_1.DMNElementReference ri = new org.kie.dmn.model.v1_1.DMNElementReference();
ri.setHref(new StringBuilder("#").append(drgElement.getId().getValue()).toString());
iReq.setRequiredDecision(ri);
result.getAuthorityRequirement().add(iReq);
} else if (drgElement instanceof KnowledgeSource) {
org.kie.dmn.model.v1_1.AuthorityRequirement iReq = new org.kie.dmn.model.v1_1.AuthorityRequirement();
org.kie.dmn.model.v1_1.DMNElementReference ri = new org.kie.dmn.model.v1_1.DMNElementReference();
ri.setHref(new StringBuilder("#").append(drgElement.getId().getValue()).toString());
iReq.setRequiredAuthority(ri);
result.getAuthorityRequirement().add(iReq);
} else if (drgElement instanceof InputData) {
org.kie.dmn.model.v1_1.AuthorityRequirement iReq = new org.kie.dmn.model.v1_1.AuthorityRequirement();
org.kie.dmn.model.v1_1.DMNElementReference ri = new org.kie.dmn.model.v1_1.DMNElementReference();
ri.setHref(new StringBuilder("#").append(drgElement.getId().getValue()).toString());
iReq.setRequiredInput(ri);
result.getAuthorityRequirement().add(iReq);
} else {
throw new UnsupportedOperationException("wrong model definition.");
}
}
}
}
return result;
}
use of org.kie.workbench.common.dmn.api.definition.v1_1.DRGElement in project kie-wb-common by kiegroup.
the class DMNMarshaller method marshall.
@Override
public String marshall(final Diagram<Graph, Metadata> diagram) throws IOException {
Graph<?, Node<View, ?>> g = diagram.getGraph();
Map<String, org.kie.dmn.model.v1_1.DRGElement> nodes = new HashMap<>();
Map<String, org.kie.dmn.model.v1_1.TextAnnotation> textAnnotations = new HashMap<>();
@SuppressWarnings("unchecked") Node<View<DMNDiagram>, ?> dmnDiagramRoot = (Node<View<DMNDiagram>, ?>) findDMNDiagramRoot(g);
Definitions definitionsStunnerPojo = dmnDiagramRoot.getContent().getDefinition().getDefinitions();
org.kie.dmn.model.v1_1.Definitions definitions = DefinitionsConverter.dmnFromWB(definitionsStunnerPojo);
if (definitions.getExtensionElements() == null) {
definitions.setExtensionElements(new org.kie.dmn.model.v1_1.Definitions.ExtensionElements());
}
org.kie.workbench.common.dmn.backend.definition.v1_1.dd.DMNDiagram dmnDDDMNDiagram = new org.kie.workbench.common.dmn.backend.definition.v1_1.dd.DMNDiagram();
definitions.getExtensionElements().getAny().add(dmnDDDMNDiagram);
for (Node<?, ?> node : g.nodes()) {
if (node.getContent() instanceof View<?>) {
View<?> view = (View<?>) node.getContent();
if (view.getDefinition() instanceof DRGElement) {
DRGElement n = (org.kie.workbench.common.dmn.api.definition.v1_1.DRGElement) view.getDefinition();
nodes.put(n.getId().getValue(), stunnerToDMN(node));
dmnDDDMNDiagram.getAny().add(stunnerToDDExt((View<? extends DMNElement>) view));
} else if (view.getDefinition() instanceof TextAnnotation) {
TextAnnotation textAnnotation = (TextAnnotation) view.getDefinition();
textAnnotations.put(textAnnotation.getId().getValue(), textAnnotationConverter.dmnFromNode((Node<View<TextAnnotation>, ?>) node));
dmnDDDMNDiagram.getAny().add(stunnerToDDExt((View<? extends DMNElement>) view));
List<org.kie.dmn.model.v1_1.Association> associations = AssociationConverter.dmnFromWB((Node<View<TextAnnotation>, ?>) node);
definitions.getArtifact().addAll(associations);
}
}
}
nodes.values().forEach(definitions.getDrgElement()::add);
textAnnotations.values().forEach(definitions.getArtifact()::add);
String marshalled = marshaller.marshal(definitions);
return marshalled;
}
Aggregations