Search in sources :

Example 1 with ItemDefinition

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

the class DefinitionsConverter method wbFromDMN.

public static Definitions wbFromDMN(final org.kie.dmn.model.api.Definitions dmn, final Map<org.kie.dmn.model.api.Import, org.kie.dmn.model.api.Definitions> importDefinitions, final Map<org.kie.dmn.model.api.Import, PMMLDocumentMetadata> pmmlDocuments) {
    if (dmn == null) {
        return null;
    }
    final Id id = new Id(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.setDescription(description);
    for (Entry<String, String> kv : dmn.getNsContext().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);
        }
    }
    for (org.kie.dmn.model.api.ItemDefinition itemDef : dmn.getItemDefinition()) {
        final ItemDefinition itemDefConverted = ItemDefinitionPropertyConverter.wbFromDMN(itemDef);
        if (itemDefConverted != null) {
            itemDefConverted.setParent(result);
        }
        result.getItemDefinition().add(itemDefConverted);
    }
    for (org.kie.dmn.model.api.Import i : dmn.getImport()) {
        final org.kie.dmn.model.api.Definitions definitions = importDefinitions.get(i);
        final PMMLDocumentMetadata pmmlDocument = pmmlDocuments.get(i);
        final Import importConverted = ImportConverter.wbFromDMN(i, definitions, pmmlDocument);
        if (importConverted != null) {
            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) PMMLDocumentMetadata(org.kie.workbench.common.dmn.api.editors.included.PMMLDocumentMetadata) Definitions(org.kie.workbench.common.dmn.api.definition.model.Definitions) ItemDefinition(org.kie.workbench.common.dmn.api.definition.model.ItemDefinition) Text(org.kie.workbench.common.dmn.api.property.dmn.Text) Name(org.kie.workbench.common.dmn.api.property.dmn.Name) Id(org.kie.workbench.common.dmn.api.property.dmn.Id)

Example 2 with ItemDefinition

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

the class ImportedItemDefinitionConverter method wbFromDMN.

public static ItemDefinition wbFromDMN(final org.kie.dmn.model.api.ItemDefinition dmnItemDefinition, final String prefix) {
    final org.kie.dmn.model.api.ItemDefinition dmnItemDefinitionWithNamespace = withNamespace(dmnItemDefinition, prefix);
    final ItemDefinition wbItemDefinition = ItemDefinitionPropertyConverter.wbFromDMN(dmnItemDefinitionWithNamespace);
    allowOnlyVisualChange(wbItemDefinition);
    return wbItemDefinition;
}
Also used : ItemDefinition(org.kie.workbench.common.dmn.api.definition.model.ItemDefinition)

Example 3 with ItemDefinition

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

the class DecisionTableEditorDefinitionEnricherTest method mockTCompanyStructure.

private ItemDefinition mockTCompanyStructure() {
    final ItemDefinition tCompany = mock(ItemDefinition.class);
    final ItemDefinition name = mock(ItemDefinition.class);
    final ItemDefinition tAddress = mock(ItemDefinition.class);
    /* === ItemDefinition ===
         * - tCompany (Structure)
         *   - name     (String)
         *   - tAddress (Structure)
         * ======================
         */
    when(name.getName()).thenReturn(new Name("name"));
    when(name.getTypeRef()).thenReturn(STRING.asQName());
    when(name.getItemComponent()).thenReturn(emptyList());
    when(tAddress.getName()).thenReturn(new Name("address"));
    when(tAddress.getTypeRef()).thenReturn(T_ADDRESS_QNAME);
    when(tAddress.getItemComponent()).thenReturn(singletonList(name));
    when(tCompany.getName()).thenReturn(new Name(TYPE_COMPANY));
    when(tCompany.getTypeRef()).thenReturn(null);
    when(tCompany.getItemComponent()).thenReturn(asList(name, tAddress));
    return tCompany;
}
Also used : 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)

Example 4 with ItemDefinition

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

the class DecisionTableEditorDefinitionEnricherTest method mockTPersonStructure.

private ItemDefinition mockTPersonStructure() {
    final ItemDefinition tPerson = mock(ItemDefinition.class);
    final ItemDefinition name = mock(ItemDefinition.class);
    final ItemDefinition age = mock(ItemDefinition.class);
    /* === ItemDefinition ===
         * - tPerson (Structure)
         *   - name  (String)
         *   - age   (Number)
         * ======================
         */
    when(name.getName()).thenReturn(new Name("name"));
    when(name.getTypeRef()).thenReturn(STRING.asQName());
    when(name.getItemComponent()).thenReturn(emptyList());
    when(age.getName()).thenReturn(new Name("age"));
    when(age.getTypeRef()).thenReturn(NUMBER.asQName());
    when(age.getItemComponent()).thenReturn(emptyList());
    when(tPerson.getName()).thenReturn(new Name(TYPE_PERSON));
    when(tPerson.getTypeRef()).thenReturn(null);
    when(tPerson.getItemComponent()).thenReturn(asList(name, age));
    return tPerson;
}
Also used : 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)

Example 5 with ItemDefinition

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

the class DecisionTableEditorDefinitionEnricherTest method testComputingClauseNameWithoutModelRefWhenModelRefAlreadyMissing.

@Test
public void testComputingClauseNameWithoutModelRefWhenModelRefAlreadyMissing() {
    final ItemDefinition itemComponent = new ItemDefinition();
    itemComponent.setName(new Name("age"));
    itemComponent.setAllowOnlyVisualChange(true);
    assertEquals("age", new DecisionTableEditorDefinitionEnricher(null, null, null).computeClauseName(itemComponent));
}
Also used : 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) Test(org.junit.Test)

Aggregations

ItemDefinition (org.kie.workbench.common.dmn.api.definition.model.ItemDefinition)119 Test (org.junit.Test)86 DataType (org.kie.workbench.common.dmn.client.editors.types.common.DataType)39 QName (org.kie.workbench.common.dmn.api.property.dmn.QName)37 Name (org.kie.workbench.common.dmn.api.property.dmn.Name)36 ArrayList (java.util.ArrayList)18 Definitions (org.kie.workbench.common.dmn.api.definition.model.Definitions)16 UnaryTests (org.kie.workbench.common.dmn.api.definition.model.UnaryTests)9 Description (org.kie.workbench.common.dmn.api.property.dmn.Description)8 DecisionTable (org.kie.workbench.common.dmn.api.definition.model.DecisionTable)7 Id (org.kie.workbench.common.dmn.api.property.dmn.Id)7 JSITItemDefinition (org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITItemDefinition)7 Text (org.kie.workbench.common.dmn.api.property.dmn.Text)6 DataTypeManager (org.kie.workbench.common.dmn.client.editors.types.common.DataTypeManager)6 QName (javax.xml.namespace.QName)4 Import (org.kie.workbench.common.dmn.api.definition.model.Import)4 InputClause (org.kie.workbench.common.dmn.api.definition.model.InputClause)4 RefreshDataTypesListEvent (org.kie.workbench.common.dmn.client.editors.types.common.events.RefreshDataTypesListEvent)4 DMNGraphUtils (org.kie.workbench.common.dmn.client.graph.DMNGraphUtils)4 PMMLDocumentMetadata (org.kie.workbench.common.dmn.api.editors.included.PMMLDocumentMetadata)3