use of org.kie.workbench.common.dmn.api.definition.model.DRGElement in project kie-wb-common by kiegroup.
the class DMNDiagramsSessionTest method testDefinitionContainsDRGElement.
@Test
public void testDefinitionContainsDRGElement() {
final Node nodeWithContentDefinition = mock(Node.class);
final Definition definition = mock(Definition.class);
final DRGElement drgElement = mock(DRGElement.class);
when(nodeWithContentDefinition.getContent()).thenReturn(definition);
when(definition.getDefinition()).thenReturn(drgElement);
assertTrue(dmnDiagramsSession.definitionContainsDRGElement(nodeWithContentDefinition));
}
use of org.kie.workbench.common.dmn.api.definition.model.DRGElement in project kie-wb-common by kiegroup.
the class DocumentationLinksWidgetTest method testSetDMNModel.
@Test
public void testSetDMNModel() {
final DocumentationLinksHolder holder = mock(DocumentationLinksHolder.class);
final DocumentationLinks value = mock(DocumentationLinks.class);
when(holder.getValue()).thenReturn(value);
final DRGElement model = mock(DRGElement.class);
when(model.getLinksHolder()).thenReturn(holder);
widget.setDMNModel(model);
verify(widget).setValue(value);
verify(widget).refresh();
}
use of org.kie.workbench.common.dmn.api.definition.model.DRGElement in project kie-wb-common by kiegroup.
the class ObserverBuilderControlTest method testUpdateDMNDiagramIdFromSelectedDMNDiagram.
@Test
public void testUpdateDMNDiagramIdFromSelectedDMNDiagram() {
final DRGElement newDefinition = mock(DRGElement.class);
final Element element = mock(Element.class);
final View elementContent = mock(View.class);
final Object definition = mock(Object.class);
final String selectedDiagramId = "selected diagram id";
final DMNDiagramElement selectedDiagram = mock(DMNDiagramElement.class);
final Id id = mock(Id.class);
when(id.getValue()).thenReturn(selectedDiagramId);
when(selectedDiagram.getId()).thenReturn(id);
when(dmnDiagramsSession.getCurrentDMNDiagramElement()).thenReturn(Optional.of(selectedDiagram));
when(elementContent.getDefinition()).thenReturn(newDefinition);
when(element.getContent()).thenReturn(elementContent);
observerBuilderControl.updateElementFromDefinition(element, definition);
verify(newDefinition).setDiagramId(selectedDiagramId);
}
use of org.kie.workbench.common.dmn.api.definition.model.DRGElement in project kie-wb-common by kiegroup.
the class DMNDeepCloneProcess method clone.
/**
* <p>It defines additive fields, specific to DMN domain, to be included in the target</p>
* <p>Then, the "classic" clone operation, defined in {@link DeepCloneProcess} will be executed</p>
* <p>Note that {@link DeepCloneProcess} is already taking care of aspects related to look&feel, such as background color, font, etc.</p>
* <p>Every time we copy a node, in order to respect the name uniqueness logic, a new node will be created with a suffix {@code -X},
* where {@code X} it is an incremental numeric value</p>
*
* @param source node to be cloned
* @param target destination of the cloning operation
* @return cloned instance, i.e. target element
*/
@Override
public <S, T> T clone(final S source, final T target) {
super.clone(source, target);
if (source instanceof DRGElement) {
cloneDRGElementBasicInfo((DRGElement) source, (DRGElement) target);
}
if (source instanceof HasText) {
cloneTextElementBasicInfo((HasText) source, (HasText) target);
}
if (source instanceof HasVariable) {
final IsInformationItem sourceVariable = ((HasVariable) source).getVariable();
final IsInformationItem targetVariable = ((HasVariable) target).getVariable();
cloneTypeRefInfo(sourceVariable, targetVariable);
}
if (source instanceof Decision) {
cloneDecision((Decision) source, (Decision) target);
}
if (source instanceof BusinessKnowledgeModel) {
cloneBusinessKnowledgeModel((BusinessKnowledgeModel) source, (BusinessKnowledgeModel) target);
}
return target;
}
use of org.kie.workbench.common.dmn.api.definition.model.DRGElement 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;
}
Aggregations