Search in sources :

Example 1 with DMNShape

use of org.kie.workbench.common.dmn.backend.definition.v1_1.dd.DMNShape in project kie-wb-common by kiegroup.

the class DMNMarshaller method ddExtAugmentStunner.

private void ddExtAugmentStunner(Optional<org.kie.workbench.common.dmn.backend.definition.v1_1.dd.DMNDiagram> dmnDDDiagram, Node currentNode) {
    if (!dmnDDDiagram.isPresent()) {
        return;
    }
    Stream<DMNShape> drgShapeStream = dmnDDDiagram.get().getAny().stream().filter(DMNShape.class::isInstance).map(DMNShape.class::cast);
    View content = (View) currentNode.getContent();
    if (content.getDefinition() instanceof Decision) {
        Decision d = (Decision) content.getDefinition();
        internalAugment(drgShapeStream, d.getId(), content.getBounds().getUpperLeft(), d.getDimensionsSet(), content.getBounds().getLowerRight(), d.getBackgroundSet(), d::setFontSet);
    } else if (content.getDefinition() instanceof InputData) {
        InputData d = (InputData) content.getDefinition();
        internalAugment(drgShapeStream, d.getId(), content.getBounds().getUpperLeft(), d.getDimensionsSet(), content.getBounds().getLowerRight(), d.getBackgroundSet(), d::setFontSet);
    } else if (content.getDefinition() instanceof BusinessKnowledgeModel) {
        BusinessKnowledgeModel d = (BusinessKnowledgeModel) content.getDefinition();
        internalAugment(drgShapeStream, d.getId(), content.getBounds().getUpperLeft(), d.getDimensionsSet(), content.getBounds().getLowerRight(), d.getBackgroundSet(), d::setFontSet);
    } else if (content.getDefinition() instanceof KnowledgeSource) {
        KnowledgeSource d = (KnowledgeSource) content.getDefinition();
        internalAugment(drgShapeStream, d.getId(), content.getBounds().getUpperLeft(), d.getDimensionsSet(), content.getBounds().getLowerRight(), d.getBackgroundSet(), d::setFontSet);
    } else if (content.getDefinition() instanceof TextAnnotation) {
        TextAnnotation d = (TextAnnotation) content.getDefinition();
        internalAugment(drgShapeStream, d.getId(), content.getBounds().getUpperLeft(), d.getDimensionsSet(), content.getBounds().getLowerRight(), d.getBackgroundSet(), d::setFontSet);
    }
}
Also used : DMNShape(org.kie.workbench.common.dmn.backend.definition.v1_1.dd.DMNShape) Child(org.kie.workbench.common.stunner.core.graph.content.relationship.Child) ApplicationScoped(javax.enterprise.context.ApplicationScoped) Id(org.kie.workbench.common.dmn.api.property.dmn.Id) Bound(org.kie.workbench.common.stunner.core.graph.content.Bounds.Bound) KnowledgeSource(org.kie.workbench.common.dmn.api.definition.v1_1.KnowledgeSource) BusinessKnowledgeModel(org.kie.workbench.common.dmn.api.definition.v1_1.BusinessKnowledgeModel) InputData(org.kie.workbench.common.dmn.api.definition.v1_1.InputData) TextAnnotation(org.kie.workbench.common.dmn.api.definition.v1_1.TextAnnotation) View(org.kie.workbench.common.stunner.core.graph.content.view.View) Decision(org.kie.workbench.common.dmn.api.definition.v1_1.Decision)

Example 2 with DMNShape

use of org.kie.workbench.common.dmn.backend.definition.v1_1.dd.DMNShape in project kie-wb-common by kiegroup.

the class DMNMarshaller method stunnerToDDExt.

private static DMNShape stunnerToDDExt(View<? extends DMNElement> v) {
    DMNShape result = new DMNShape();
    result.setId("dmnshape-" + v.getDefinition().getId().getValue());
    result.setDmnElementRef(v.getDefinition().getId().getValue());
    Bounds bounds = new Bounds();
    result.setBounds(bounds);
    bounds.setX(v.getBounds().getUpperLeft().getX());
    bounds.setY(v.getBounds().getUpperLeft().getY());
    if (v.getDefinition() instanceof Decision) {
        Decision d = (Decision) v.getDefinition();
        applyBounds(d.getDimensionsSet(), bounds);
        applyBackgroundStyles(d.getBackgroundSet(), result);
        result.setFontStyle(FontSetPropertyConverter.dmnFromWB(d.getFontSet()));
    } else if (v.getDefinition() instanceof InputData) {
        InputData d = (InputData) v.getDefinition();
        applyBounds(d.getDimensionsSet(), bounds);
        applyBackgroundStyles(d.getBackgroundSet(), result);
        result.setFontStyle(FontSetPropertyConverter.dmnFromWB(d.getFontSet()));
    } else if (v.getDefinition() instanceof BusinessKnowledgeModel) {
        BusinessKnowledgeModel d = (BusinessKnowledgeModel) v.getDefinition();
        applyBounds(d.getDimensionsSet(), bounds);
        applyBackgroundStyles(d.getBackgroundSet(), result);
        result.setFontStyle(FontSetPropertyConverter.dmnFromWB(d.getFontSet()));
    } else if (v.getDefinition() instanceof KnowledgeSource) {
        KnowledgeSource d = (KnowledgeSource) v.getDefinition();
        applyBounds(d.getDimensionsSet(), bounds);
        applyBackgroundStyles(d.getBackgroundSet(), result);
        result.setFontStyle(FontSetPropertyConverter.dmnFromWB(d.getFontSet()));
    } else if (v.getDefinition() instanceof TextAnnotation) {
        TextAnnotation d = (TextAnnotation) v.getDefinition();
        applyBounds(d.getDimensionsSet(), bounds);
        applyBackgroundStyles(d.getBackgroundSet(), result);
        result.setFontStyle(FontSetPropertyConverter.dmnFromWB(d.getFontSet()));
    }
    return result;
}
Also used : DMNShape(org.kie.workbench.common.dmn.backend.definition.v1_1.dd.DMNShape) KnowledgeSource(org.kie.workbench.common.dmn.api.definition.v1_1.KnowledgeSource) Bounds(org.kie.workbench.common.dmn.backend.definition.v1_1.dd.org.omg.spec.CMMN_20151109_DC.Bounds) BusinessKnowledgeModel(org.kie.workbench.common.dmn.api.definition.v1_1.BusinessKnowledgeModel) InputData(org.kie.workbench.common.dmn.api.definition.v1_1.InputData) TextAnnotation(org.kie.workbench.common.dmn.api.definition.v1_1.TextAnnotation) Decision(org.kie.workbench.common.dmn.api.definition.v1_1.Decision)

Example 3 with DMNShape

use of org.kie.workbench.common.dmn.backend.definition.v1_1.dd.DMNShape in project kie-wb-common by kiegroup.

the class DMNMarshallerTest method test_diamond.

@Test
public void test_diamond() throws IOException {
    // round trip test
    roundTripUnmarshalThenMarshalUnmarshal(this.getClass().getResourceAsStream("/diamond.dmn"), this::checkDiamongGraph);
    // additionally, check the marshalled is still DMN executable as expected
    DMNMarshaller m = new DMNMarshaller(new XMLEncoderDiagramMetadataMarshaller(), applicationFactoryManager);
    Graph<?, ?> g = m.unmarshall(null, this.getClass().getResourceAsStream("/diamond.dmn"));
    DiagramImpl diagram = new DiagramImpl("", null);
    diagram.setGraph(g);
    String mString = m.marshall(diagram);
    final KieServices ks = KieServices.Factory.get();
    final KieContainer kieContainer = KieHelper.getKieContainer(ks.newReleaseId("org.kie", "dmn-test_diamond", "1.0"), ks.getResources().newByteArrayResource(mString.getBytes()).setTargetPath("src/main/resources/diamond.dmn"));
    final DMNRuntime runtime = kieContainer.newKieSession().getKieRuntime(DMNRuntime.class);
    Assert.assertNotNull(runtime);
    DMNModel diamondModel = runtime.getModel("http://www.trisotech.com/definitions/_8afa6c24-55c8-43cf-8a02-fdde7fc5d1f2", "three decisions in a diamond shape");
    DMNContext dmnContext = runtime.newContext();
    dmnContext.set("My Name", "John Doe");
    DMNResult dmnResult = runtime.evaluateAll(diamondModel, dmnContext);
    assertFalse(dmnResult.getMessages().toString(), dmnResult.hasErrors());
    DMNContext result = dmnResult.getContext();
    assertEquals("Hello, John Doe.", result.get("My Decision"));
    // additionally, check DMN DD/DI for version 1.1
    org.kie.dmn.api.marshalling.v1_1.DMNMarshaller dmnMarshaller = DMNMarshallerFactory.newMarshallerWithExtensions(Arrays.asList(new DDExtensionsRegister()));
    Definitions definitions = dmnMarshaller.unmarshal(mString);
    assertNotNull(definitions.getExtensionElements());
    assertNotNull(definitions.getExtensionElements().getAny());
    assertEquals(1, definitions.getExtensionElements().getAny().size());
    org.kie.workbench.common.dmn.backend.definition.v1_1.dd.DMNDiagram ddRoot = (org.kie.workbench.common.dmn.backend.definition.v1_1.dd.DMNDiagram) definitions.getExtensionElements().getAny().get(0);
    DMNShape myname = findShapeByDMNI(ddRoot, "_4cd17e52-6253-41d6-820d-5824bf5197f3");
    assertBounds(500, 500, 100, 50, myname.getBounds());
    assertColor(255, 255, 255, myname.getBgColor());
    assertColor(0, 0, 0, myname.getBorderColor());
    assertEquals(0.5, myname.getBorderSize().getValue(), 0);
    assertDMNStyle("Open Sans", 24, 1, 255, 0, 0, myname.getFontStyle());
    DMNShape prefix = findShapeByDMNI(ddRoot, "_e920f38a-293c-41b8-adb3-69d0dc184fab");
    assertBounds(300, 400, 100, 50, prefix.getBounds());
    assertColor(0, 253, 25, prefix.getBgColor());
    assertColor(253, 0, 0, prefix.getBorderColor());
    assertEquals(1, prefix.getBorderSize().getValue(), 0);
    assertDMNStyle("Times New Roman", 8, 2.5, 70, 60, 50, prefix.getFontStyle());
    DMNShape postfix = findShapeByDMNI(ddRoot, "_f49f9c34-29d5-4e72-91d2-f4f92117c8da");
    assertBounds(700, 400, 100, 50, postfix.getBounds());
    assertColor(247, 255, 0, postfix.getBgColor());
    assertColor(0, 51, 255, postfix.getBorderColor());
    assertEquals(2, postfix.getBorderSize().getValue(), 0);
    assertDMNStyle("Arial", 10, 1.5, 50, 60, 70, postfix.getFontStyle());
    DMNShape mydecision = findShapeByDMNI(ddRoot, "_9b061fc3-8109-42e2-9fe4-fc39c90b654e");
    assertBounds(487.5, 275, 125, 75, mydecision.getBounds());
    assertColor(255, 255, 255, mydecision.getBgColor());
    assertColor(0, 0, 0, mydecision.getBorderColor());
    assertEquals(0.5, mydecision.getBorderSize().getValue(), 0);
    assertDMNStyle("Monospaced", 32, 3.5, 55, 66, 77, mydecision.getFontStyle());
}
Also used : KieServices(org.kie.api.KieServices) Matchers.anyString(org.mockito.Matchers.anyString) DMNShape(org.kie.workbench.common.dmn.backend.definition.v1_1.dd.DMNShape) XMLEncoderDiagramMetadataMarshaller(org.kie.workbench.common.stunner.core.backend.service.XMLEncoderDiagramMetadataMarshaller) DMNModel(org.kie.dmn.api.core.DMNModel) KieContainer(org.kie.api.runtime.KieContainer) DMNDiagram(org.kie.workbench.common.dmn.api.definition.v1_1.DMNDiagram) DMNResult(org.kie.dmn.api.core.DMNResult) DiagramImpl(org.kie.workbench.common.stunner.core.diagram.DiagramImpl) Definitions(org.kie.dmn.model.v1_1.Definitions) DMNContext(org.kie.dmn.api.core.DMNContext) DMNRuntime(org.kie.dmn.api.core.DMNRuntime) DDExtensionsRegister(org.kie.workbench.common.dmn.backend.definition.v1_1.dd.DDExtensionsRegister) Test(org.junit.Test)

Example 4 with DMNShape

use of org.kie.workbench.common.dmn.backend.definition.v1_1.dd.DMNShape in project kie-wb-common by kiegroup.

the class DMNMarshaller method internalAugment.

private void internalAugment(Stream<DMNShape> drgShapeStream, Id id, Bound ul, RectangleDimensionsSet dimensionsSet, Bound lr, BackgroundSet bgset, Consumer<FontSet> fontSetSetter) {
    Optional<DMNShape> drgShapeOpt = drgShapeStream.filter(shape -> shape.getDmnElementRef().equals(id.getValue())).findFirst();
    if (!drgShapeOpt.isPresent()) {
        return;
    }
    DMNShape drgShape = drgShapeOpt.get();
    ((BoundImpl) ul).setX(drgShape.getBounds().getX());
    ((BoundImpl) ul).setY(drgShape.getBounds().getY());
    dimensionsSet.setWidth(new Width(drgShape.getBounds().getWidth()));
    dimensionsSet.setHeight(new Height(drgShape.getBounds().getHeight()));
    ((BoundImpl) lr).setX(drgShape.getBounds().getX() + drgShape.getBounds().getWidth());
    ((BoundImpl) lr).setY(drgShape.getBounds().getY() + drgShape.getBounds().getHeight());
    if (null != drgShape.getBgColor()) {
        bgset.setBgColour(new BgColour(ColorUtils.wbFromDMN(drgShape.getBgColor())));
    }
    if (null != drgShape.getBorderColor()) {
        bgset.setBorderColour(new BorderColour(ColorUtils.wbFromDMN(drgShape.getBorderColor())));
    }
    if (null != drgShape.getBorderSize()) {
        bgset.setBorderSize(new BorderSize(drgShape.getBorderSize().getValue()));
    }
    if (null != drgShape.getFontStyle()) {
        fontSetSetter.accept(FontSetPropertyConverter.wbFromDMN(drgShape.getFontStyle()));
    }
}
Also used : DMNShape(org.kie.workbench.common.dmn.backend.definition.v1_1.dd.DMNShape) Arrays(java.util.Arrays) DecisionConverter(org.kie.workbench.common.dmn.backend.definition.v1_1.DecisionConverter) Edge(org.kie.workbench.common.stunner.core.graph.Edge) KnowledgeSource(org.kie.workbench.common.dmn.api.definition.v1_1.KnowledgeSource) UUID(org.kie.workbench.common.stunner.core.util.UUID) EdgeImpl(org.kie.workbench.common.stunner.core.graph.impl.EdgeImpl) Definitions(org.kie.workbench.common.dmn.api.definition.v1_1.Definitions) TextAnnotationConverter(org.kie.workbench.common.dmn.backend.definition.v1_1.TextAnnotationConverter) Bounds(org.kie.workbench.common.dmn.backend.definition.v1_1.dd.org.omg.spec.CMMN_20151109_DC.Bounds) Map(java.util.Map) DMNDiagram(org.kie.workbench.common.dmn.api.definition.v1_1.DMNDiagram) ServerMarshalling(org.jboss.errai.marshalling.server.ServerMarshalling) BgColour(org.kie.workbench.common.dmn.api.property.background.BgColour) FactoryManager(org.kie.workbench.common.stunner.core.api.FactoryManager) Diagram(org.kie.workbench.common.stunner.core.diagram.Diagram) Height(org.kie.workbench.common.dmn.api.property.dimensions.Height) InputData(org.kie.workbench.common.dmn.api.definition.v1_1.InputData) DiagramMarshaller(org.kie.workbench.common.stunner.core.definition.service.DiagramMarshaller) BusinessKnowledgeModelConverter(org.kie.workbench.common.dmn.backend.definition.v1_1.BusinessKnowledgeModelConverter) Child(org.kie.workbench.common.stunner.core.graph.content.relationship.Child) FontSet(org.kie.workbench.common.dmn.api.property.font.FontSet) Collectors(java.util.stream.Collectors) BorderColour(org.kie.workbench.common.dmn.api.property.background.BorderColour) Metadata(org.kie.workbench.common.stunner.core.diagram.Metadata) BusinessKnowledgeModel(org.kie.workbench.common.dmn.api.definition.v1_1.BusinessKnowledgeModel) List(java.util.List) Stream(java.util.stream.Stream) DDExtensionsRegister(org.kie.workbench.common.dmn.backend.definition.v1_1.dd.DDExtensionsRegister) Entry(java.util.Map.Entry) DMNMarshallerFactory(org.kie.dmn.backend.marshalling.v1_1.DMNMarshallerFactory) Optional(java.util.Optional) DMNShape(org.kie.workbench.common.dmn.backend.definition.v1_1.dd.DMNShape) ApplicationScoped(javax.enterprise.context.ApplicationScoped) Decision(org.kie.workbench.common.dmn.api.definition.v1_1.Decision) Node(org.kie.workbench.common.stunner.core.graph.Node) Width(org.kie.workbench.common.dmn.api.property.dimensions.Width) DMNDefinitionSet(org.kie.workbench.common.dmn.api.DMNDefinitionSet) RectangleDimensionsSet(org.kie.workbench.common.dmn.api.property.dimensions.RectangleDimensionsSet) DefinitionsConverter(org.kie.workbench.common.dmn.backend.definition.v1_1.DefinitionsConverter) HashMap(java.util.HashMap) DiagramMetadataMarshaller(org.kie.workbench.common.stunner.core.definition.service.DiagramMetadataMarshaller) View(org.kie.workbench.common.stunner.core.graph.content.view.View) ColorUtils(org.kie.workbench.common.dmn.backend.definition.v1_1.dd.ColorUtils) Inject(javax.inject.Inject) Id(org.kie.workbench.common.dmn.api.property.dmn.Id) Bound(org.kie.workbench.common.stunner.core.graph.content.Bounds.Bound) DRGElement(org.kie.workbench.common.dmn.api.definition.v1_1.DRGElement) Description(org.kie.workbench.common.dmn.api.property.dmn.Description) StreamSupport(java.util.stream.StreamSupport) SimpleEntry(java.util.AbstractMap.SimpleEntry) BindableAdapterUtils(org.kie.workbench.common.stunner.core.definition.adapter.binding.BindableAdapterUtils) TextAnnotation(org.kie.workbench.common.dmn.api.definition.v1_1.TextAnnotation) XMLEncoderDiagramMetadataMarshaller(org.kie.workbench.common.stunner.core.backend.service.XMLEncoderDiagramMetadataMarshaller) BorderSize(org.kie.workbench.common.dmn.api.property.background.BorderSize) AssociationConverter(org.kie.workbench.common.dmn.backend.definition.v1_1.AssociationConverter) BoundImpl(org.kie.workbench.common.stunner.core.graph.content.view.BoundImpl) IOException(java.io.IOException) InputStreamReader(java.io.InputStreamReader) Association(org.kie.workbench.common.dmn.api.definition.v1_1.Association) BackgroundSet(org.kie.workbench.common.dmn.api.property.background.BackgroundSet) FontSetPropertyConverter(org.kie.workbench.common.dmn.backend.definition.v1_1.FontSetPropertyConverter) InputDataConverter(org.kie.workbench.common.dmn.backend.definition.v1_1.InputDataConverter) ViewConnector(org.kie.workbench.common.stunner.core.graph.content.view.ViewConnector) Consumer(java.util.function.Consumer) KnowledgeSourceConverter(org.kie.workbench.common.dmn.backend.definition.v1_1.KnowledgeSourceConverter) Graph(org.kie.workbench.common.stunner.core.graph.Graph) MagnetConnection(org.kie.workbench.common.stunner.core.graph.content.view.MagnetConnection) DMNElement(org.kie.workbench.common.dmn.api.definition.v1_1.DMNElement) InputStream(java.io.InputStream) BgColour(org.kie.workbench.common.dmn.api.property.background.BgColour) BoundImpl(org.kie.workbench.common.stunner.core.graph.content.view.BoundImpl) Height(org.kie.workbench.common.dmn.api.property.dimensions.Height) BorderSize(org.kie.workbench.common.dmn.api.property.background.BorderSize) Width(org.kie.workbench.common.dmn.api.property.dimensions.Width) BorderColour(org.kie.workbench.common.dmn.api.property.background.BorderColour)

Aggregations

DMNShape (org.kie.workbench.common.dmn.backend.definition.v1_1.dd.DMNShape)4 BusinessKnowledgeModel (org.kie.workbench.common.dmn.api.definition.v1_1.BusinessKnowledgeModel)3 Decision (org.kie.workbench.common.dmn.api.definition.v1_1.Decision)3 InputData (org.kie.workbench.common.dmn.api.definition.v1_1.InputData)3 KnowledgeSource (org.kie.workbench.common.dmn.api.definition.v1_1.KnowledgeSource)3 TextAnnotation (org.kie.workbench.common.dmn.api.definition.v1_1.TextAnnotation)3 ApplicationScoped (javax.enterprise.context.ApplicationScoped)2 DMNDiagram (org.kie.workbench.common.dmn.api.definition.v1_1.DMNDiagram)2 DDExtensionsRegister (org.kie.workbench.common.dmn.backend.definition.v1_1.dd.DDExtensionsRegister)2 XMLEncoderDiagramMetadataMarshaller (org.kie.workbench.common.stunner.core.backend.service.XMLEncoderDiagramMetadataMarshaller)2 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 SimpleEntry (java.util.AbstractMap.SimpleEntry)1 Arrays (java.util.Arrays)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 Optional (java.util.Optional)1