use of org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDRGElement in project kie-wb-common by kiegroup.
the class DMNMarshallerTest method testAddNodeToDefinitionsIfNotPresentWhenNodeIsNotPresent.
@Test
public void testAddNodeToDefinitionsIfNotPresentWhenNodeIsNotPresent() {
final DMNMarshaller dmnMarshaller = spy(new DMNMarshaller());
final Optional<JSITDRGElement> existingNode = Optional.empty();
final JSITDefinitions definitions = mock(JSITDefinitions.class);
final JSITDRGElement node = mock(JSITDRGElement.class);
doReturn(existingNode).when(dmnMarshaller).getExistingNode(definitions, node);
doNothing().when(dmnMarshaller).addNodeToDefinitions(node, definitions);
dmnMarshaller.addNodeToDefinitionsIfNotPresent(node, definitions);
verify(dmnMarshaller).addNodeToDefinitions(node, definitions);
}
use of org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDRGElement in project kie-wb-common by kiegroup.
the class DMNMarshaller method mergeNodeRequirements.
void mergeNodeRequirements(final JSITDRGElement node, final JSITDRGElement existingDRGElement) {
if (instanceOfBusinessKnowledgeModel(node)) {
final JSITBusinessKnowledgeModel existingBkm = Js.uncheckedCast(existingDRGElement);
final JSITBusinessKnowledgeModel nodeBkm = Js.uncheckedCast(node);
existingBkm.setAuthorityRequirement(distinct(nodeBkm.getAuthorityRequirement(), existingBkm.getAuthorityRequirement()));
existingBkm.setKnowledgeRequirement(distinct(nodeBkm.getKnowledgeRequirement(), existingBkm.getKnowledgeRequirement()));
} else if (instanceOfDecision(node)) {
final JSITDecision existingDecision = Js.uncheckedCast(existingDRGElement);
final JSITDecision nodeDecision = Js.uncheckedCast(node);
existingDecision.setAuthorityRequirement(distinct(nodeDecision.getAuthorityRequirement(), existingDecision.getAuthorityRequirement()));
existingDecision.setInformationRequirement(distinct(nodeDecision.getInformationRequirement(), existingDecision.getInformationRequirement()));
existingDecision.setKnowledgeRequirement(distinct(nodeDecision.getKnowledgeRequirement(), existingDecision.getKnowledgeRequirement()));
} else if (instanceOfKnowledgeSource(node)) {
final JSITKnowledgeSource existingKnowledgeSource = Js.uncheckedCast(existingDRGElement);
final JSITKnowledgeSource nodeKnowledgeSource = Js.uncheckedCast(node);
existingKnowledgeSource.setAuthorityRequirement(distinct(nodeKnowledgeSource.getAuthorityRequirement(), existingKnowledgeSource.getAuthorityRequirement()));
}
}
use of org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDRGElement in project kie-wb-common by kiegroup.
the class DMNMarshaller method marshall.
public JSITDefinitions marshall() {
final Map<String, JSITDRGElement> nodes = new HashMap<>();
final Map<String, JSITTextAnnotation> textAnnotations = new HashMap<>();
final Node<View<DMNDiagram>, ?> dmnDiagramRoot = (Node<View<DMNDiagram>, ?>) DMNGraphUtils.findDMNDiagramRoot(dmnDiagramsSession.getDRGDiagram().getGraph());
final Definitions definitionsStunnerPojo = ((DMNDiagram) getElementDefinition(dmnDiagramRoot)).getDefinitions();
final List<String> dmnDiagramElementIds = new ArrayList<>();
final JSITDefinitions definitions = DefinitionsConverter.dmnFromWB(definitionsStunnerPojo, true);
if (Objects.isNull(definitions.getExtensionElements())) {
JSITDMNElement.JSIExtensionElements jsiExtensionElements = new JSITDMNElement.JSIExtensionElements();
definitions.setExtensionElements(jsiExtensionElements);
}
final JsArrayLike<JSIDMNDiagram> dmnDiagrams = definitions.getDMNDI().getNativeDMNDiagram();
for (int i = 0; i < dmnDiagrams.getLength(); i++) {
JSIDMNDiagram diagram = Js.uncheckedCast(dmnDiagrams.getAt(i));
final String elementDiagramId = diagram.getId();
final List<JSIDMNEdge> dmnEdges = new ArrayList<>();
final List<Node> diagramNodes = getNodeStream(dmnDiagramsSession.getDiagram(elementDiagramId));
// Setup callback for marshalling ComponentWidths
if (Objects.isNull(diagram.getExtension())) {
diagram.setExtension(new JSIDiagramElement.JSIExtension());
}
final JSITComponentsWidthsExtension componentsWidthsExtension = new JSITComponentsWidthsExtension();
final JSIDiagramElement.JSIExtension extension = diagram.getExtension();
JSITComponentsWidthsExtension wrappedComponentsWidthsExtension = WrapperUtils.getWrappedJSITComponentsWidthsExtension(componentsWidthsExtension);
extension.addAny(wrappedComponentsWidthsExtension);
final Consumer<JSITComponentWidths> componentWidthsConsumer = (cw) -> componentsWidthsExtension.addComponentWidths(cw);
// Convert relative positioning to absolute
for (final Node<?, ?> node : diagramNodes) {
PointUtils.convertToAbsoluteBounds(node);
}
// Iterate Graph processing nodes..
for (final Node<?, ?> node : diagramNodes) {
if (!(node.getContent() instanceof View<?>)) {
continue;
}
final View<?> view = (View<?>) node.getContent();
final Object viewDefinition = view.getDefinition();
if (!(viewDefinition instanceof HasContentDefinitionId)) {
continue;
}
final HasContentDefinitionId hasContentDefinitionId = (HasContentDefinitionId) viewDefinition;
final String nodeDiagramId = hasContentDefinitionId.getDiagramId();
if (!Objects.equals(nodeDiagramId, elementDiagramId)) {
continue;
}
if (viewDefinition instanceof DRGElement) {
final DRGElement drgElement = (DRGElement) viewDefinition;
if (!drgElement.isAllowOnlyVisualChange()) {
if (nodes.containsKey(drgElement.getId().getValue())) {
final JSITDRGElement currentValue = nodes.get(drgElement.getId().getValue());
mergeNodeRequirements(stunnerToDMN(withIncludedModels(node, definitionsStunnerPojo), componentWidthsConsumer), currentValue);
} else {
nodes.put(drgElement.getId().getValue(), stunnerToDMN(withIncludedModels(node, definitionsStunnerPojo), componentWidthsConsumer));
}
}
final String namespaceURI = definitionsStunnerPojo.getDefaultNamespace();
diagram.addDMNDiagramElement(WrapperUtils.getWrappedJSIDMNShape(diagram, dmnDiagramElementIds, definitionsStunnerPojo, (View<? extends DMNElement>) view, namespaceURI));
}
if (viewDefinition instanceof TextAnnotation) {
final TextAnnotation textAnnotation = (TextAnnotation) viewDefinition;
if (!textAnnotation.isAllowOnlyVisualChange()) {
textAnnotations.put(textAnnotation.getId().getValue(), textAnnotationConverter.dmnFromNode((Node<View<TextAnnotation>, ?>) node, componentWidthsConsumer));
}
final String namespaceURI = definitionsStunnerPojo.getDefaultNamespace();
diagram.addDMNDiagramElement(WrapperUtils.getWrappedJSIDMNShape(diagram, dmnDiagramElementIds, definitionsStunnerPojo, (View<? extends DMNElement>) view, namespaceURI));
final List<JSITAssociation> associations = AssociationConverter.dmnFromWB((Node<View<TextAnnotation>, ?>) node);
forEach(associations, association -> {
final JSITAssociation wrappedJSITAssociation = WrapperUtils.getWrappedJSITAssociation(Js.uncheckedCast(association));
definitions.addArtifact(wrappedJSITAssociation);
});
}
connect(diagram, dmnDiagramElementIds, definitionsStunnerPojo, dmnEdges, node, view);
}
nodes.values().forEach(node -> {
addNodeToDefinitionsIfNotPresent(node, definitions);
});
textAnnotations.values().forEach(text -> {
final boolean exists = anyMatch(definitions.getArtifact(), artifact -> Objects.equals(artifact.getId(), text.getId()));
if (!exists) {
definitions.addArtifact(WrapperUtils.getWrappedJSITTextAnnotation(text));
}
});
forEach(dmnEdges, dmnEdge -> {
final boolean exists = anyMatch(diagram.getDMNDiagramElement(), diagramElement -> {
if (JSIDMNEdge.instanceOf(diagramElement)) {
final JSIDMNEdge jsidmnEdge = Js.uncheckedCast(diagramElement);
return Objects.equals(jsidmnEdge.getDmnElementRef(), dmnEdge.getDmnElementRef());
}
return false;
});
if (!exists) {
diagram.addDMNDiagramElement(WrapperUtils.getWrappedJSIDMNEdge(Js.uncheckedCast(dmnEdge)));
}
});
// Convert absolute positioning to relative
for (final Node<?, ?> node : diagramNodes) {
PointUtils.convertToRelativeBounds(node);
}
}
;
return definitions;
}
use of org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDRGElement in project kie-wb-common by kiegroup.
the class DMNMarshallerImportsClientHelper method setInformationItem.
private void setInformationItem(final JSITDRGElement drgElement, final JSITInformationItem informationItem) {
if (JSITDecision.instanceOf(drgElement)) {
final JSITDecision decision = Js.uncheckedCast(drgElement);
decision.setVariable(informationItem);
} else if (JSITInputData.instanceOf(drgElement)) {
final JSITInputData inputData = Js.uncheckedCast(drgElement);
inputData.setVariable(informationItem);
} else if (JSITInvocable.instanceOf(drgElement)) {
final JSITInvocable invocable = Js.uncheckedCast(drgElement);
invocable.setVariable(informationItem);
}
}
use of org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDRGElement in project kie-wb-common by kiegroup.
the class DMNMarshallerImportsClientHelper method updateInformationItem.
private void updateInformationItem(final String namespace, final JSITDRGElement drgElement) {
getInformationItem(drgElement).ifPresent(informationItem -> {
final JSITInformationItem tInformationItem = new JSITInformationItem();
final String typeRef = informationItem.getTypeRef();
if (!isEmpty(typeRef) && !isBuiltInType(typeRef)) {
tInformationItem.setTypeRef(namespace + "." + typeRef);
setInformationItem(drgElement, tInformationItem);
}
});
}
Aggregations