Search in sources :

Example 26 with DRGElement

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

the class DMNMarshallerImportsService method getDRGElements.

public void getDRGElements(final String dmnXml, final ServiceCallback<List<DRGElement>> callback) {
    final DMN12UnmarshallCallback jsCallback = dmn12 -> {
        final JSITDefinitions dmnDefinitions = Js.uncheckedCast(JsUtils.getUnwrappedElement(dmn12));
        callback.onSuccess(modelToStunnerConverter.makeNodes(dmnDefinitions, new HashMap<>(), false, (a, b) -> {
        /* Nothing. */
        }).stream().map(e -> getDRGElement(e.getNode())).filter(Optional::isPresent).map(Optional::get).collect(Collectors.toList()));
    };
    MainJs.unmarshall(dmnXml, "", jsCallback);
}
Also used : MainJs(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.MainJs) Definitions(org.kie.workbench.common.dmn.api.definition.model.Definitions) PMMLDocumentMetadata(org.kie.workbench.common.dmn.api.editors.included.PMMLDocumentMetadata) DefinitionUtils(org.kie.workbench.common.stunner.core.util.DefinitionUtils) DefinitionsConverter(org.kie.workbench.common.dmn.client.marshaller.converters.DefinitionsConverter) HashMap(java.util.HashMap) ClientRuntimeError(org.kie.workbench.common.stunner.core.client.service.ClientRuntimeError) Collectors(java.util.stream.Collectors) Inject(javax.inject.Inject) DRGElement(org.kie.workbench.common.dmn.api.definition.model.DRGElement) List(java.util.List) DMN12UnmarshallCallback(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.callbacks.DMN12UnmarshallCallback) Js(jsinterop.base.Js) JsUtils(org.kie.workbench.common.dmn.webapp.kogito.marshaller.mapper.JsUtils) JSITImport(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITImport) Map(java.util.Map) Optional(java.util.Optional) NodeEntriesFactory(org.kie.workbench.common.dmn.client.marshaller.unmarshall.nodes.NodeEntriesFactory) ApplicationScoped(javax.enterprise.context.ApplicationScoped) JSITDefinitions(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDefinitions) ServiceCallback(org.kie.workbench.common.stunner.core.client.service.ServiceCallback) Node(org.kie.workbench.common.stunner.core.graph.Node) DMN12UnmarshallCallback(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.callbacks.DMN12UnmarshallCallback) Optional(java.util.Optional) HashMap(java.util.HashMap) JSITDefinitions(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDefinitions)

Example 27 with DRGElement

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

the class DMNIncludedModelHandlerTest method testDestroy.

@Test
public void testDestroy() {
    final Decision drgElement1 = makeDecision("model1.tUUID", "string", true);
    final Decision drgElement2 = makeDecision("model1.imported person", "model1.tPerson", true);
    final InputData drgElement3 = makeInputData("local person", "model1.tPerson", false);
    final InputData drgElement4 = makeInputData("regular DRG Element", "boolean", false);
    final List<DRGElement> drgElements = asList(drgElement1, drgElement2, drgElement3, drgElement4);
    doNothing().when(handler).deleteDRGElement(any());
    when(dmnGraphUtils.getModelDRGElements()).thenReturn(drgElements);
    handler.destroy("model1");
    verify(handler).deleteDRGElement(drgElement1);
    verify(handler).deleteDRGElement(drgElement2);
}
Also used : InputData(org.kie.workbench.common.dmn.api.definition.model.InputData) Decision(org.kie.workbench.common.dmn.api.definition.model.Decision) DRGElement(org.kie.workbench.common.dmn.api.definition.model.DRGElement) Test(org.junit.Test)

Example 28 with DRGElement

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

the class DMNIncludedModelHandlerTest method testUpdateDRGElementName.

@Test
public void testUpdateDRGElementName() {
    final DRGElement drgElement = mock(DRGElement.class);
    final AbstractCanvasHandler canvasHandler = mock(AbstractCanvasHandler.class);
    final String newName = "new name";
    when(dmnGraphUtils.getCanvasHandler()).thenReturn(canvasHandler);
    doReturn(compositeCommand).when(handler).buildUpdateCommand(drgElement, newName);
    handler.updateDRGElementName(drgElement, newName);
    verify(sessionCommandManager).execute(canvasHandler, compositeCommand);
}
Also used : AbstractCanvasHandler(org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler) DRGElement(org.kie.workbench.common.dmn.api.definition.model.DRGElement) Test(org.junit.Test)

Example 29 with DRGElement

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

the class DMNIncludedModelHandlerTest method testGetNode.

@Test
public void testGetNode() {
    final DRGElement drgElement = mock(DRGElement.class);
    final AbstractCanvasHandler canvasHandler = mock(AbstractCanvasHandler.class);
    final Diagram diagram = mock(Diagram.class);
    final Graph graph = mock(Graph.class);
    final Node node1 = mock(Node.class);
    final Node node2 = mock(Node.class);
    final Node node3 = mock(Node.class);
    final Definition definition1 = mock(Definition.class);
    final Definition definition2 = mock(Definition.class);
    final Definition definition3 = mock(Definition.class);
    when(definition1.getDefinition()).thenReturn(new Object());
    when(definition2.getDefinition()).thenReturn(drgElement);
    when(definition3.getDefinition()).thenReturn(new Object());
    when(node1.getContent()).thenReturn(definition1);
    when(node2.getContent()).thenReturn(definition2);
    when(node3.getContent()).thenReturn(definition3);
    when(canvasHandler.getDiagram()).thenReturn(diagram);
    when(diagram.getGraph()).thenReturn(graph);
    when(graph.nodes()).thenReturn(asList(node1, node2, node3));
    when(dmnGraphUtils.getCanvasHandler()).thenReturn(canvasHandler);
    final Node actualNode = handler.getNode(drgElement);
    assertEquals(node2, actualNode);
}
Also used : Graph(org.kie.workbench.common.stunner.core.graph.Graph) AbstractCanvasHandler(org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler) Node(org.kie.workbench.common.stunner.core.graph.Node) Definition(org.kie.workbench.common.stunner.core.graph.content.definition.Definition) DRGElement(org.kie.workbench.common.dmn.api.definition.model.DRGElement) Diagram(org.kie.workbench.common.stunner.core.diagram.Diagram) Test(org.junit.Test)

Example 30 with DRGElement

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

the class DMNMarshallerTest method testWithIncludedModelsWhenNodeAlreadyHasImports.

@Test
public void testWithIncludedModelsWhenNodeAlreadyHasImports() {
    final DMNMarshaller dmnMarshaller = spy(new DMNMarshaller());
    final Node node = mock(Node.class);
    final Definition nodeDefinition = mock(Definition.class);
    final DRGElement drgElement = mock(DRGElement.class);
    final Definitions definitionsStunnerPojo = mock(Definitions.class);
    final Import import1 = mock(Import.class);
    final Import import2 = mock(Import.class);
    final List<Import> diagramImports = new ArrayList<>(asList(import1, import2));
    final DMNDiagram nodeDiagram = mock(DMNDiagram.class);
    final Definitions nodeDiagramDefinitions = mock(Definitions.class);
    final List<Import> nodeDiagramImports = new ArrayList<>(asList(import1, import2));
    when(node.getContent()).thenReturn(nodeDefinition);
    when(nodeDefinition.getDefinition()).thenReturn(drgElement);
    when(definitionsStunnerPojo.getImport()).thenReturn(diagramImports);
    when(drgElement.getParent()).thenReturn(nodeDiagram);
    when(nodeDiagram.getDefinitions()).thenReturn(nodeDiagramDefinitions);
    when(nodeDiagramDefinitions.getImport()).thenReturn(nodeDiagramImports);
    dmnMarshaller.withIncludedModels(node, definitionsStunnerPojo);
    assertEquals(2, nodeDiagramImports.size());
    assertTrue(nodeDiagramImports.contains(import1));
    assertTrue(nodeDiagramImports.contains(import2));
}
Also used : JSIDMNDiagram(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmndi12.JSIDMNDiagram) DMNDiagram(org.kie.workbench.common.dmn.api.definition.model.DMNDiagram) Import(org.kie.workbench.common.dmn.api.definition.model.Import) Node(org.kie.workbench.common.stunner.core.graph.Node) Definitions(org.kie.workbench.common.dmn.api.definition.model.Definitions) JSITDefinitions(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDefinitions) Definition(org.kie.workbench.common.stunner.core.graph.content.definition.Definition) ArrayList(java.util.ArrayList) JSITDRGElement(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDRGElement) DRGElement(org.kie.workbench.common.dmn.api.definition.model.DRGElement) Test(org.junit.Test)

Aggregations

DRGElement (org.kie.workbench.common.dmn.api.definition.model.DRGElement)72 Test (org.junit.Test)45 Node (org.kie.workbench.common.stunner.core.graph.Node)27 ArrayList (java.util.ArrayList)25 Edge (org.kie.workbench.common.stunner.core.graph.Edge)17 View (org.kie.workbench.common.stunner.core.graph.content.view.View)17 Decision (org.kie.workbench.common.dmn.api.definition.model.Decision)16 List (java.util.List)15 Definitions (org.kie.workbench.common.dmn.api.definition.model.Definitions)15 Id (org.kie.workbench.common.dmn.api.property.dmn.Id)15 Definition (org.kie.workbench.common.stunner.core.graph.content.definition.Definition)15 InputData (org.kie.workbench.common.dmn.api.definition.model.InputData)14 Name (org.kie.workbench.common.dmn.api.property.dmn.Name)13 DecisionService (org.kie.workbench.common.dmn.api.definition.model.DecisionService)10 BusinessKnowledgeModel (org.kie.workbench.common.dmn.api.definition.model.BusinessKnowledgeModel)9 Import (org.kie.workbench.common.dmn.api.definition.model.Import)9 KnowledgeSource (org.kie.workbench.common.dmn.api.definition.model.KnowledgeSource)8 KnowledgeRequirement (org.kie.workbench.common.dmn.api.definition.model.KnowledgeRequirement)7 JSITDefinitions (org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDefinitions)7 Optional (java.util.Optional)6