Search in sources :

Example 11 with Definitions

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

the class DecisionTableEditorDefinitionEnricherTest method testModelEnrichmentWhenTopLevelDecisionTableWithInputDataAndRecursiveCustomType.

@Test
@SuppressWarnings("unchecked")
public void testModelEnrichmentWhenTopLevelDecisionTableWithInputDataAndRecursiveCustomType() {
    setupGraphWithDiagram();
    setupGraphWithInputData();
    final Definitions definitions = diagram.getDefinitions();
    final String tSmurfName = "tSmurf";
    final String tDateOfBirthName = "tDateOfBirth";
    final String tIsBlueName = "tIsBlue";
    final String tParentName = "tParent";
    final QName dateBuiltInType = new QName(QName.NULL_NS_URI, BuiltInType.DATE.getName());
    final QName booleanBuiltInType = new QName(QName.NULL_NS_URI, BuiltInType.BOOLEAN.getName());
    final QName parentCustomType = new QName(QName.NULL_NS_URI, tSmurfName);
    final ItemDefinition tSmurfCustomDataType = new ItemDefinition();
    tSmurfCustomDataType.setName(new Name(tSmurfName));
    tSmurfCustomDataType.getItemComponent().add(new ItemDefinition() {

        {
            setName(new Name(tDateOfBirthName));
            setTypeRef(dateBuiltInType);
        }
    });
    tSmurfCustomDataType.getItemComponent().add(new ItemDefinition() {

        {
            setName(new Name(tIsBlueName));
            setTypeRef(booleanBuiltInType);
        }
    });
    tSmurfCustomDataType.getItemComponent().add(new ItemDefinition() {

        {
            setName(new Name(tParentName));
            setTypeRef(parentCustomType);
        }
    });
    definitions.getItemDefinition().add(tSmurfCustomDataType);
    final QName inputData1TypeRef = new QName(QName.NULL_NS_URI, tSmurfName);
    inputData1.getVariable().setTypeRef(inputData1TypeRef);
    final Optional<DecisionTable> oModel = definition.getModelClass();
    definition.enrich(Optional.of(NODE_UUID), decision, oModel);
    final DecisionTable model = oModel.get();
    assertBasicEnrichment(model);
    final List<InputClause> input = model.getInput();
    assertThat(input.size()).isEqualTo(4);
    assertThat(input.get(0).getInputExpression()).isInstanceOf(InputClauseLiteralExpression.class);
    assertThat(input.get(0).getInputExpression().getText().getValue()).isEqualTo(INPUT_DATA_NAME_2);
    assertThat(input.get(0).getInputExpression().getTypeRef()).isEqualTo(INPUT_DATA_QNAME_2);
    assertThat(input.get(1).getInputExpression()).isInstanceOf(InputClauseLiteralExpression.class);
    assertThat(input.get(1).getInputExpression().getText().getValue()).isEqualTo(INPUT_DATA_NAME_1 + "." + tDateOfBirthName);
    assertThat(input.get(1).getInputExpression().getTypeRef()).isEqualTo(dateBuiltInType);
    assertThat(input.get(2).getInputExpression()).isInstanceOf(InputClauseLiteralExpression.class);
    assertThat(input.get(2).getInputExpression().getText().getValue()).isEqualTo(INPUT_DATA_NAME_1 + "." + tIsBlueName);
    assertThat(input.get(2).getInputExpression().getTypeRef()).isEqualTo(booleanBuiltInType);
    assertThat(input.get(3).getInputExpression()).isInstanceOf(InputClauseLiteralExpression.class);
    assertThat(input.get(3).getInputExpression().getText().getValue()).isEqualTo(INPUT_DATA_NAME_1 + "." + tParentName);
    assertThat(input.get(3).getInputExpression().getTypeRef()).isEqualTo(parentCustomType);
    assertStandardOutputClauseEnrichment(model);
    assertStandardDecisionRuleEnrichment(model);
    assertParentHierarchyEnrichment(model);
}
Also used : DecisionTable(org.kie.workbench.common.dmn.api.definition.model.DecisionTable) QName(org.kie.workbench.common.dmn.api.property.dmn.QName) Definitions(org.kie.workbench.common.dmn.api.definition.model.Definitions) ItemDefinition(org.kie.workbench.common.dmn.api.definition.model.ItemDefinition) QName(org.kie.workbench.common.dmn.api.property.dmn.QName) Name(org.kie.workbench.common.dmn.api.property.dmn.Name) InputClause(org.kie.workbench.common.dmn.api.definition.model.InputClause) Test(org.junit.Test)

Example 12 with Definitions

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

the class PMMLDocumentMetadataProviderTest method setup.

@Before
public void setup() {
    this.definitions = new Definitions();
    this.provider = new PMMLDocumentMetadataProvider(graphUtils, clientServicesProxy, stateProvider);
    final Diagram diagram = mock(Diagram.class);
    final Metadata metadata = mock(Metadata.class);
    when(stateProvider.getDiagram()).thenReturn(Optional.of(diagram));
    when(diagram.getMetadata()).thenReturn(metadata);
    when(metadata.getPath()).thenReturn(dmnModelPath);
    when(graphUtils.getDefinitions(diagram)).thenReturn(definitions);
}
Also used : Definitions(org.kie.workbench.common.dmn.api.definition.model.Definitions) PMMLDocumentMetadata(org.kie.workbench.common.dmn.api.editors.included.PMMLDocumentMetadata) Metadata(org.kie.workbench.common.stunner.core.diagram.Metadata) PMMLModelMetadata(org.kie.workbench.common.dmn.api.editors.included.PMMLModelMetadata) PMMLParameterMetadata(org.kie.workbench.common.dmn.api.editors.included.PMMLParameterMetadata) Diagram(org.kie.workbench.common.stunner.core.diagram.Diagram) Before(org.junit.Before)

Example 13 with Definitions

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

the class ExpressionEditor method handleCanvasElementUpdated.

@Override
public void handleCanvasElementUpdated(final CanvasElementUpdatedEvent event) {
    final Element<?> element = event.getElement();
    if ((element instanceof Node)) {
        if (element.getContent() instanceof Definition) {
            final Definition definition = (Definition) element.getContent();
            final Optional<Definitions> definitions = Optional.ofNullable(dmnGraphUtils.getModelDefinitions());
            definitions.ifPresent(d -> {
                if (Objects.equals(d, definition.getDefinition())) {
                    view.setReturnToLinkText(returnToLinkTextSupplier.get());
                }
            });
            hasExpression.ifPresent(e -> {
                if (Objects.equals(e.asDMNModelInstrumentedBase(), definition.getDefinition())) {
                    view.setExpressionNameText(Optional.ofNullable((HasName) definition.getDefinition()));
                    view.refresh();
                }
            });
        }
    }
}
Also used : HasName(org.kie.workbench.common.dmn.api.definition.HasName) Node(org.kie.workbench.common.stunner.core.graph.Node) Definitions(org.kie.workbench.common.dmn.api.definition.model.Definitions) Definition(org.kie.workbench.common.stunner.core.graph.content.definition.Definition)

Example 14 with Definitions

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

the class WrapperUtils method getImportPrefix.

private static Optional<String> getImportPrefix(final Definitions definitions, final DMNElement dmnElement) {
    if (!(dmnElement instanceof NamedElement)) {
        return Optional.empty();
    }
    final NamedElement namedElement = (NamedElement) dmnElement;
    final Optional<String> name = Optional.ofNullable(namedElement.getName().getValue());
    return definitions.getImport().stream().filter(anImport -> {
        final String importName = anImport.getName().getValue();
        return name.map(n -> n.startsWith(importName + ".")).orElse(false);
    }).map(anImport -> {
        final String importNamespace = anImport.getNamespace();
        return getNsContextsByNamespace(definitions, importNamespace);
    }).findFirst();
}
Also used : TextAnnotation(org.kie.workbench.common.dmn.api.definition.model.TextAnnotation) JSIDMNDiagram(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmndi12.JSIDMNDiagram) Definitions(org.kie.workbench.common.dmn.api.definition.model.Definitions) JSIDMNDecisionServiceDividerLine(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmndi12.JSIDMNDecisionServiceDividerLine) JSITTextAnnotation(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITTextAnnotation) RectangleDimensionsSet(org.kie.workbench.common.dmn.api.property.dimensions.RectangleDimensionsSet) JSITDecisionTable(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDecisionTable) PointUtils.upperLeftBound(org.kie.workbench.common.dmn.client.marshaller.converters.dd.PointUtils.upperLeftBound) JSIPoint(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dc.JSIPoint) JSIDMNEdge(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmndi12.JSIDMNEdge) IdUtils.getShapeId(org.kie.workbench.common.dmn.client.marshaller.common.IdUtils.getShapeId) JSITContext(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITContext) View(org.kie.workbench.common.stunner.core.graph.content.view.View) DMNElement(org.kie.workbench.common.dmn.api.definition.model.DMNElement) Js(jsinterop.base.Js) JSIBounds(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dc.JSIBounds) JSIName(org.kie.workbench.common.dmn.webapp.kogito.marshaller.mapper.JSIName) Map(java.util.Map) JSITDRGElement(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDRGElement) JSITList(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITList) NamedElement(org.kie.workbench.common.dmn.api.definition.model.NamedElement) XMLConstants(javax.xml.XMLConstants) JSIDMNLabel(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmndi12.JSIDMNLabel) JSITAttachment(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.kie.JSITAttachment) BusinessKnowledgeModel(org.kie.workbench.common.dmn.api.definition.model.BusinessKnowledgeModel) StylingSet(org.kie.workbench.common.dmn.api.property.styling.StylingSet) JSITAssociation(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITAssociation) JSITFunctionDefinition(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITFunctionDefinition) StringUtils.isEmpty(org.kie.workbench.common.stunner.core.util.StringUtils.isEmpty) PointUtils.xOfBound(org.kie.workbench.common.dmn.client.marshaller.converters.dd.PointUtils.xOfBound) PointUtils.yOfBound(org.kie.workbench.common.dmn.client.marshaller.converters.dd.PointUtils.yOfBound) InputData(org.kie.workbench.common.dmn.api.definition.model.InputData) JSIDMNShape(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmndi12.JSIDMNShape) JSITRelation(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITRelation) Objects(java.util.Objects) List(java.util.List) DecisionService(org.kie.workbench.common.dmn.api.definition.model.DecisionService) JsUtils(org.kie.workbench.common.dmn.webapp.kogito.marshaller.mapper.JsUtils) JSITInvocation(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITInvocation) JSITLiteralExpression(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITLiteralExpression) JSIDMNStyle(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmndi12.JSIDMNStyle) KnowledgeSource(org.kie.workbench.common.dmn.api.definition.model.KnowledgeSource) Optional(java.util.Optional) Decision(org.kie.workbench.common.dmn.api.definition.model.Decision) JSITComponentsWidthsExtension(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.kie.JSITComponentsWidthsExtension) QName(javax.xml.namespace.QName) ColorUtils(org.kie.workbench.common.dmn.client.marshaller.converters.dd.ColorUtils) NamedElement(org.kie.workbench.common.dmn.api.definition.model.NamedElement)

Example 15 with Definitions

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

the class DefinitionsConverter method wbFromDMN.

public static Definitions wbFromDMN(final JSITDefinitions dmn, final Map<JSITImport, JSITDefinitions> importDefinitions, final Map<JSITImport, PMMLDocumentMetadata> pmmlDocuments) {
    if (Objects.isNull(dmn)) {
        return null;
    }
    final Id id = IdPropertyConverter.wbFromDMN(dmn.getId());
    final Name name = new Name(dmn.getName());
    final String namespace = dmn.getNamespace();
    final Description description = DescriptionPropertyConverter.wbFromDMN(dmn.getDescription());
    final Definitions result = new Definitions();
    result.setId(id);
    result.setName(name);
    result.setNamespace(new Text(namespace));
    result.getNsContext().putIfAbsent(DMNModelInstrumentedBase.Namespace.DEFAULT.getPrefix(), namespace);
    result.setExpressionLanguage(ExpressionLanguagePropertyConverter.wbFromDMN(dmn.getExpressionLanguage()));
    result.setTypeLanguage(dmn.getTypeLanguage());
    result.setDmnDiagramElements(getDMNDiagramElements(dmn));
    result.setDescription(description);
    final Map<String, String> namespaces = NameSpaceUtils.extractNamespacesKeyedByPrefix(dmn);
    for (Entry<String, String> kv : namespaces.entrySet()) {
        String mappedURI = kv.getValue();
        switch(mappedURI) {
            case org.kie.dmn.model.v1_1.KieDMNModelInstrumentedBase.URI_DMN:
                mappedURI = org.kie.dmn.model.v1_2.KieDMNModelInstrumentedBase.URI_DMN;
                break;
            case org.kie.dmn.model.v1_1.KieDMNModelInstrumentedBase.URI_FEEL:
                mappedURI = org.kie.dmn.model.v1_2.KieDMNModelInstrumentedBase.URI_FEEL;
                break;
            case org.kie.dmn.model.v1_1.KieDMNModelInstrumentedBase.URI_KIE:
                mappedURI = org.kie.dmn.model.v1_2.KieDMNModelInstrumentedBase.URI_KIE;
                break;
        }
        if (kv.getKey().equalsIgnoreCase(DMNModelInstrumentedBase.Namespace.DEFAULT.getPrefix())) {
            result.getNsContext().putIfAbsent(kv.getKey(), mappedURI);
        } else {
            result.getNsContext().put(kv.getKey(), mappedURI);
        }
    }
    final List<JSITItemDefinition> jsiItemDefinitions = dmn.getItemDefinition();
    for (int i = 0; i < jsiItemDefinitions.size(); i++) {
        final JSITItemDefinition jsiItemDefinition = Js.uncheckedCast(jsiItemDefinitions.get(i));
        final ItemDefinition itemDefConverted = ItemDefinitionPropertyConverter.wbFromDMN(jsiItemDefinition);
        if (Objects.nonNull(itemDefConverted)) {
            itemDefConverted.setParent(result);
            result.getItemDefinition().add(itemDefConverted);
        }
    }
    final List<JSITImport> jsiImports = dmn.getImport();
    for (int i = 0; i < jsiImports.size(); i++) {
        final JSITImport jsiImport = Js.uncheckedCast(jsiImports.get(i));
        final JSITDefinitions definitions = Js.uncheckedCast(importDefinitions.get(jsiImport));
        final PMMLDocumentMetadata pmmlDocument = pmmlDocuments.get(jsiImport);
        final Import importConverted = ImportConverter.wbFromDMN(jsiImport, definitions, pmmlDocument);
        if (Objects.nonNull(importConverted)) {
            importConverted.setParent(result);
            result.getImport().add(importConverted);
        }
    }
    return result;
}
Also used : Description(org.kie.workbench.common.dmn.api.property.dmn.Description) Import(org.kie.workbench.common.dmn.api.definition.model.Import) JSITImport(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITImport) PMMLDocumentMetadata(org.kie.workbench.common.dmn.api.editors.included.PMMLDocumentMetadata) Definitions(org.kie.workbench.common.dmn.api.definition.model.Definitions) JSITDefinitions(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDefinitions) JSITItemDefinition(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITItemDefinition) ItemDefinition(org.kie.workbench.common.dmn.api.definition.model.ItemDefinition) Text(org.kie.workbench.common.dmn.api.property.dmn.Text) JSITImport(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITImport) Name(org.kie.workbench.common.dmn.api.property.dmn.Name) QName(javax.xml.namespace.QName) JSITDefinitions(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDefinitions) Id(org.kie.workbench.common.dmn.api.property.dmn.Id) JSITItemDefinition(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITItemDefinition)

Aggregations

Definitions (org.kie.workbench.common.dmn.api.definition.model.Definitions)70 Test (org.junit.Test)41 ItemDefinition (org.kie.workbench.common.dmn.api.definition.model.ItemDefinition)24 Node (org.kie.workbench.common.stunner.core.graph.Node)23 DMNDiagram (org.kie.workbench.common.dmn.api.definition.model.DMNDiagram)22 DRGElement (org.kie.workbench.common.dmn.api.definition.model.DRGElement)19 ArrayList (java.util.ArrayList)18 Name (org.kie.workbench.common.dmn.api.property.dmn.Name)18 Decision (org.kie.workbench.common.dmn.api.definition.model.Decision)15 Import (org.kie.workbench.common.dmn.api.definition.model.Import)15 Diagram (org.kie.workbench.common.stunner.core.diagram.Diagram)14 View (org.kie.workbench.common.stunner.core.graph.content.view.View)14 List (java.util.List)13 Objects (java.util.Objects)12 Optional (java.util.Optional)12 PMMLDocumentMetadata (org.kie.workbench.common.dmn.api.editors.included.PMMLDocumentMetadata)12 Id (org.kie.workbench.common.dmn.api.property.dmn.Id)12 JSITDefinitions (org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDefinitions)12 Edge (org.kie.workbench.common.stunner.core.graph.Edge)12 Map (java.util.Map)11