Search in sources :

Example 16 with TextAnnotation

use of org.kie.workbench.common.dmn.api.definition.model.TextAnnotation in project kie-wb-common by kiegroup.

the class TextAnnotationConverter method dmnFromNode.

@Override
public JSITTextAnnotation dmnFromNode(final Node<View<TextAnnotation>, ?> node, final Consumer<JSITComponentWidths> componentWidthsConsumer) {
    final TextAnnotation source = (TextAnnotation) DefinitionUtils.getElementDefinition(node);
    final JSITTextAnnotation result = new JSITTextAnnotation();
    result.setId(source.getId().getValue());
    final Optional<String> description = Optional.ofNullable(DescriptionPropertyConverter.dmnFromWB(source.getDescription()));
    description.ifPresent(result::setDescription);
    result.setText(source.getText().getValue());
    result.setTextFormat(source.getTextFormat().getValue());
    return result;
}
Also used : JSITTextAnnotation(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITTextAnnotation) TextAnnotation(org.kie.workbench.common.dmn.api.definition.model.TextAnnotation) JSITTextAnnotation(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITTextAnnotation)

Example 17 with TextAnnotation

use of org.kie.workbench.common.dmn.api.definition.model.TextAnnotation in project kie-wb-common by kiegroup.

the class AssociationConverter method dmnFromWB.

@SuppressWarnings("unchecked")
public static List<JSITAssociation> dmnFromWB(final Node<View<TextAnnotation>, ?> node) {
    final TextAnnotation ta = (TextAnnotation) DefinitionUtils.getElementDefinition(node);
    final JSITDMNElementReference ta_elementReference = new JSITDMNElementReference();
    ta_elementReference.setHref("#" + ta.getId().getValue());
    final List<JSITAssociation> result = new ArrayList<>();
    final List<Edge<?, ?>> inEdges = (List<Edge<?, ?>>) node.getInEdges();
    for (Edge<?, ?> e : inEdges) {
        final Node<?, ?> sourceNode = e.getSourceNode();
        if (sourceNode.getContent() instanceof View<?>) {
            final View<?> view = (View<?>) sourceNode.getContent();
            if (view.getDefinition() instanceof DRGElement) {
                final DRGElement drgElement = (DRGElement) view.getDefinition();
                final JSITDMNElementReference sourceRef = new JSITDMNElementReference();
                sourceRef.setHref(getHref(drgElement));
                final JSITAssociation adding = new JSITAssociation();
                adding.setId(((View<Association>) e.getContent()).getDefinition().getId().getValue());
                final Optional<String> description = Optional.ofNullable(DescriptionPropertyConverter.dmnFromWB(((View<Association>) e.getContent()).getDefinition().getDescription()));
                description.ifPresent(adding::setDescription);
                adding.setSourceRef(sourceRef);
                adding.setTargetRef(ta_elementReference);
                adding.setAssociationDirection(Js.uncheckedCast(JSITAssociationDirection.NONE.value()));
                result.add(adding);
            }
        }
    }
    final List<Edge<?, ?>> outEdges = (List<Edge<?, ?>>) node.getOutEdges();
    for (Edge<?, ?> e : outEdges) {
        final Node<?, ?> targetNode = e.getTargetNode();
        if (targetNode.getContent() instanceof View<?>) {
            final View<?> view = (View<?>) targetNode.getContent();
            if (view.getDefinition() instanceof DRGElement) {
                final DRGElement drgElement = (DRGElement) view.getDefinition();
                final JSITDMNElementReference targetRef = new JSITDMNElementReference();
                targetRef.setHref(getHref(drgElement));
                final JSITAssociation adding = new JSITAssociation();
                adding.setId(((View<Association>) e.getContent()).getDefinition().getId().getValue());
                final Optional<String> description = Optional.ofNullable(DescriptionPropertyConverter.dmnFromWB(((View<Association>) e.getContent()).getDefinition().getDescription()));
                description.ifPresent(adding::setDescription);
                adding.setSourceRef(ta_elementReference);
                adding.setTargetRef(targetRef);
                adding.setAssociationDirection(Js.uncheckedCast(JSITAssociationDirection.NONE.value()));
                result.add(adding);
            }
        }
    }
    return result;
}
Also used : JSITAssociation(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITAssociation) ArrayList(java.util.ArrayList) JSITDMNElementReference(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDMNElementReference) View(org.kie.workbench.common.stunner.core.graph.content.view.View) JSITAssociation(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITAssociation) Association(org.kie.workbench.common.dmn.api.definition.model.Association) ArrayList(java.util.ArrayList) List(java.util.List) TextAnnotation(org.kie.workbench.common.dmn.api.definition.model.TextAnnotation) Edge(org.kie.workbench.common.stunner.core.graph.Edge) DRGElement(org.kie.workbench.common.dmn.api.definition.model.DRGElement)

Example 18 with TextAnnotation

use of org.kie.workbench.common.dmn.api.definition.model.TextAnnotation in project kie-wb-common by kiegroup.

the class DMNSVGShapeDefImplTest method testNewViewInstance.

@Test
public void testNewViewInstance() {
    final BusinessKnowledgeModel businessKnowledgeModel = new BusinessKnowledgeModel();
    shapeDef.newViewInstance(viewFactory, businessKnowledgeModel);
    verify(viewFactory).businessKnowledgeModel();
    verify(viewResource).build(businessKnowledgeModel.getDimensionsSet().getWidth().getValue(), businessKnowledgeModel.getDimensionsSet().getHeight().getValue(), true);
    reset(viewResource);
    final Decision decision = new Decision();
    shapeDef.newViewInstance(viewFactory, decision);
    verify(viewFactory).decision();
    verify(viewResource).build(decision.getDimensionsSet().getWidth().getValue(), decision.getDimensionsSet().getHeight().getValue(), true);
    reset(viewResource);
    shapeDef.newViewInstance(viewFactory, new InputData());
    verify(viewFactory).inputData();
    verify(viewResource).build(businessKnowledgeModel.getDimensionsSet().getWidth().getValue(), businessKnowledgeModel.getDimensionsSet().getHeight().getValue(), true);
    reset(viewResource);
    final KnowledgeSource knowledgeSource = new KnowledgeSource();
    shapeDef.newViewInstance(viewFactory, knowledgeSource);
    verify(viewFactory).knowledgeSource();
    verify(viewResource).build(knowledgeSource.getDimensionsSet().getWidth().getValue(), knowledgeSource.getDimensionsSet().getHeight().getValue(), true);
    reset(viewResource);
    final TextAnnotation textAnnotation = new TextAnnotation();
    shapeDef.newViewInstance(viewFactory, textAnnotation);
    verify(viewFactory).textAnnotation();
    verify(viewResource).build(textAnnotation.getDimensionsSet().getWidth().getValue(), textAnnotation.getDimensionsSet().getHeight().getValue(), true);
}
Also used : KnowledgeSource(org.kie.workbench.common.dmn.api.definition.model.KnowledgeSource) BusinessKnowledgeModel(org.kie.workbench.common.dmn.api.definition.model.BusinessKnowledgeModel) InputData(org.kie.workbench.common.dmn.api.definition.model.InputData) TextAnnotation(org.kie.workbench.common.dmn.api.definition.model.TextAnnotation) Decision(org.kie.workbench.common.dmn.api.definition.model.Decision) Test(org.junit.Test)

Example 19 with TextAnnotation

use of org.kie.workbench.common.dmn.api.definition.model.TextAnnotation in project kie-wb-common by kiegroup.

the class DecisionNavigatorItemsProviderTest method testGetItems.

@Test
public void testGetItems() {
    final Diagram stunnerDiagram1 = mock(Diagram.class);
    final Diagram stunnerDiagram2 = mock(Diagram.class);
    final DMNDiagramElement dmnDiagramElement1 = mock(DMNDiagramElement.class);
    final DMNDiagramElement dmnDiagramElement2 = mock(DMNDiagramElement.class);
    final DMNDiagramTuple dmnDiagramTuple1 = new DMNDiagramTuple(stunnerDiagram1, dmnDiagramElement1);
    final DMNDiagramTuple dmnDiagramTuple2 = new DMNDiagramTuple(stunnerDiagram2, dmnDiagramElement2);
    final DecisionNavigatorItem decisionNavigatorItem1 = mock(DecisionNavigatorItem.class);
    final DecisionNavigatorItem decisionNavigatorItem2 = mock(DecisionNavigatorItem.class);
    final DecisionNavigatorItem decisionNavigatorItem3 = mock(DecisionNavigatorItem.class);
    final DecisionNavigatorItem decisionNavigatorItem4 = mock(DecisionNavigatorItem.class);
    final DecisionNavigatorItem decisionNavigatorItem5 = mock(DecisionNavigatorItem.class);
    final DecisionNavigatorItem decisionNavigatorItem6 = mock(DecisionNavigatorItem.class);
    final DecisionNavigatorItem decisionNavigatorItem7 = mock(DecisionNavigatorItem.class);
    final DecisionNavigatorItem decisionNavigatorItem8 = mock(DecisionNavigatorItem.class);
    final DecisionNavigatorItem decisionNavigatorItem9 = mock(DecisionNavigatorItem.class);
    final DecisionNavigatorItem decisionNavigatorItem10 = mock(DecisionNavigatorItem.class);
    final List<DMNDiagramTuple> diagramTuples = asList(dmnDiagramTuple1, dmnDiagramTuple2);
    final Node node1 = mockNode(new Decision());
    final Node node2 = mockNode(new InputData());
    final Node node3 = mockNode(new TextAnnotation());
    final Node node4 = mockNode(new BusinessKnowledgeModel());
    final Node node5 = mockNode(new KnowledgeSource());
    final Node node6 = mockNode(new TextAnnotation());
    final Stream<Node> stunnerNodes1 = Stream.of(node1, node2, node3);
    final Stream<Node> stunnerNodes2 = Stream.of(node4, node5, node6);
    when(dmnDiagramElement1.getName()).thenReturn(new Name("DRD"));
    when(dmnDiagramElement2.getName()).thenReturn(new Name("DRG"));
    when(dmnDiagramsSession.getDMNDiagrams()).thenReturn(diagramTuples);
    when(itemFactory.makeRoot(dmnDiagramTuple1)).thenReturn(decisionNavigatorItem1);
    when(itemFactory.makeRoot(dmnDiagramTuple2)).thenReturn(decisionNavigatorItem2);
    when(itemFactory.makeItem(node1)).thenReturn(decisionNavigatorItem5);
    when(itemFactory.makeItem(node2)).thenReturn(decisionNavigatorItem6);
    when(itemFactory.makeItem(node3)).thenReturn(decisionNavigatorItem7);
    when(itemFactory.makeItem(node4)).thenReturn(decisionNavigatorItem8);
    when(itemFactory.makeItem(node5)).thenReturn(decisionNavigatorItem9);
    when(itemFactory.makeItem(node6)).thenReturn(decisionNavigatorItem10);
    when(itemFactory.makeSeparator(DRG)).thenReturn(decisionNavigatorItem3);
    when(itemFactory.makeSeparator(DRDs)).thenReturn(decisionNavigatorItem4);
    when(dmnDiagramUtils.getNodeStream(stunnerDiagram1)).thenReturn(stunnerNodes1);
    when(dmnDiagramUtils.getNodeStream(stunnerDiagram2)).thenReturn(stunnerNodes2);
    final List<DecisionNavigatorItem> actualItems = itemsProvider.getItems();
    final List<DecisionNavigatorItem> expectedItems = asList(decisionNavigatorItem3, decisionNavigatorItem2, decisionNavigatorItem4, decisionNavigatorItem1);
    assertEquals(expectedItems, actualItems);
    verify(decisionNavigatorItem1).addChild(decisionNavigatorItem5);
    verify(decisionNavigatorItem1).addChild(decisionNavigatorItem6);
    verify(decisionNavigatorItem1).addChild(decisionNavigatorItem7);
    verify(decisionNavigatorItem2).addChild(decisionNavigatorItem8);
    verify(decisionNavigatorItem2).addChild(decisionNavigatorItem9);
    verify(decisionNavigatorItem2).addChild(decisionNavigatorItem10);
}
Also used : DMNDiagramTuple(org.kie.workbench.common.dmn.client.docks.navigator.drds.DMNDiagramTuple) Node(org.kie.workbench.common.stunner.core.graph.Node) Decision(org.kie.workbench.common.dmn.api.definition.model.Decision) Diagram(org.kie.workbench.common.stunner.core.diagram.Diagram) Name(org.kie.workbench.common.dmn.api.property.dmn.Name) KnowledgeSource(org.kie.workbench.common.dmn.api.definition.model.KnowledgeSource) BusinessKnowledgeModel(org.kie.workbench.common.dmn.api.definition.model.BusinessKnowledgeModel) DMNDiagramElement(org.kie.workbench.common.dmn.api.definition.model.DMNDiagramElement) InputData(org.kie.workbench.common.dmn.api.definition.model.InputData) TextAnnotation(org.kie.workbench.common.dmn.api.definition.model.TextAnnotation) Test(org.junit.Test)

Example 20 with TextAnnotation

use of org.kie.workbench.common.dmn.api.definition.model.TextAnnotation in project kie-wb-common by kiegroup.

the class DefaultValueUtilitiesTest method testUpdateNewNodeName_KnowledgeSource.

@Test
public void testUpdateNewNodeName_KnowledgeSource() {
    // Add some existing nodes to ensure naming is not affected by existing content
    graph.addNode(makeMockNode(new BusinessKnowledgeModel()));
    graph.addNode(makeMockNode(new Decision()));
    graph.addNode(makeMockNode(new InputData()));
    graph.addNode(makeMockNode(new TextAnnotation()));
    final KnowledgeSource knowledgeSource1 = new KnowledgeSource();
    final KnowledgeSource knowledgeSource2 = new KnowledgeSource();
    final KnowledgeSource knowledgeSource3 = new KnowledgeSource();
    final KnowledgeSource knowledgeSource4 = new KnowledgeSource();
    assertUpdateNewNodeName(knowledgeSource1, knowledgeSource2, (knowledgeSource) -> knowledgeSource.getName().getValue(), () -> KnowledgeSource.class.getSimpleName() + "-1", () -> KnowledgeSource.class.getSimpleName() + "-2");
    // Update existing names manually and add two more
    knowledgeSource1.getName().setValue("knowledgeSource");
    knowledgeSource2.getName().setValue(KnowledgeSource.class.getSimpleName() + "-5");
    assertUpdateNewNodeName(knowledgeSource3, knowledgeSource4, (knowledgeSource) -> knowledgeSource.getName().getValue(), () -> KnowledgeSource.class.getSimpleName() + "-6", () -> KnowledgeSource.class.getSimpleName() + "-7");
}
Also used : KnowledgeSource(org.kie.workbench.common.dmn.api.definition.model.KnowledgeSource) BusinessKnowledgeModel(org.kie.workbench.common.dmn.api.definition.model.BusinessKnowledgeModel) InputData(org.kie.workbench.common.dmn.api.definition.model.InputData) TextAnnotation(org.kie.workbench.common.dmn.api.definition.model.TextAnnotation) Decision(org.kie.workbench.common.dmn.api.definition.model.Decision) Test(org.junit.Test)

Aggregations

TextAnnotation (org.kie.workbench.common.dmn.api.definition.model.TextAnnotation)25 BusinessKnowledgeModel (org.kie.workbench.common.dmn.api.definition.model.BusinessKnowledgeModel)14 Decision (org.kie.workbench.common.dmn.api.definition.model.Decision)14 InputData (org.kie.workbench.common.dmn.api.definition.model.InputData)14 KnowledgeSource (org.kie.workbench.common.dmn.api.definition.model.KnowledgeSource)14 Test (org.junit.Test)10 View (org.kie.workbench.common.stunner.core.graph.content.view.View)10 Node (org.kie.workbench.common.stunner.core.graph.Node)8 List (java.util.List)7 DRGElement (org.kie.workbench.common.dmn.api.definition.model.DRGElement)7 DecisionService (org.kie.workbench.common.dmn.api.definition.model.DecisionService)7 ArrayList (java.util.ArrayList)6 Association (org.kie.workbench.common.dmn.api.definition.model.Association)6 StylingSet (org.kie.workbench.common.dmn.api.property.styling.StylingSet)6 Edge (org.kie.workbench.common.stunner.core.graph.Edge)6 Objects (java.util.Objects)5 Optional (java.util.Optional)5 Consumer (java.util.function.Consumer)5 Inject (javax.inject.Inject)5 DMNElement (org.kie.workbench.common.dmn.api.definition.model.DMNElement)5