Search in sources :

Example 21 with ItemDefinition

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

the class ItemDefinitionHandlerTest method testUpdate.

@Test
public void testUpdate() {
    final ItemDefinition item1 = makeItemDefinition("model1.tPerson", null, true);
    final ItemDefinition item2 = makeItemDefinition("model1.id", "number", true);
    final ItemDefinition item3 = makeItemDefinition("model1.name", "string", true);
    final ItemDefinition item4 = makeItemDefinition("person", "model1.tPerson", false);
    final List<ItemDefinition> itemDefinitions = asList(item1, item2, item3, item4);
    doNothing().when(handler).notifyPropertiesPanel(Mockito.<String>any(), Mockito.<String>any());
    when(itemDefinitionUtils.all()).thenReturn(itemDefinitions);
    handler.update("model1", "model2");
    verify(refreshDataTypesListEvent).fire(any(RefreshDataTypesListEvent.class));
    assertEquals("model2.tPerson", item1.getName().getValue());
    assertNull(item1.getTypeRef());
    verify(handler).notifyPropertiesPanel("model1.tPerson", "model2.tPerson");
    assertEquals("model2.id", item2.getName().getValue());
    assertEquals("number", item2.getTypeRef().getLocalPart());
    verify(handler).notifyPropertiesPanel("model1.id", "model2.id");
    assertEquals("model2.name", item3.getName().getValue());
    assertEquals("string", item3.getTypeRef().getLocalPart());
    verify(handler).notifyPropertiesPanel("model1.name", "model2.name");
    assertEquals("person", item4.getName().getValue());
    assertEquals("model2.tPerson", item4.getTypeRef().getLocalPart());
}
Also used : ItemDefinition(org.kie.workbench.common.dmn.api.definition.model.ItemDefinition) RefreshDataTypesListEvent(org.kie.workbench.common.dmn.client.editors.types.common.events.RefreshDataTypesListEvent) Test(org.junit.Test)

Example 22 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 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)

Example 23 with ItemDefinition

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

the class DefinitionsConverter method dmnFromWB.

public static JSITDefinitions dmnFromWB(final Definitions wb, final boolean ignoreImportedItemDefinition) {
    if (Objects.isNull(wb)) {
        return null;
    }
    final JSITDefinitions result = new JSITDefinitions();
    // TODO currently DMN wb UI does not offer feature to set these required DMN properties, setting some hardcoded defaults for now.
    final String defaultId = Objects.nonNull(wb.getId()) ? wb.getId().getValue() : UUID.uuid();
    final String defaultName = Objects.nonNull(wb.getName()) ? wb.getName().getValue() : UUID.uuid(8);
    final JSIDMNDI dmnDMNDI = new JSIDMNDI();
    final String defaultNamespace = !StringUtils.isEmpty(wb.getNamespace().getValue()) ? wb.getNamespace().getValue() : DMNModelInstrumentedBase.Namespace.DEFAULT.getUri() + UUID.uuid();
    result.setDMNDI(dmnDMNDI);
    result.setId(defaultId);
    result.setName(defaultName);
    result.setNamespace(defaultNamespace);
    final List<DMNDiagramElement> dmnDiagramElements = wb.getDiagramElements();
    final List<JSIDMNDiagram> jsidmnDiagrams = getJSIDMNDiagrams(dmnDiagramElements);
    dmnDMNDI.setDMNDiagram(jsidmnDiagrams);
    final Optional<String> description = Optional.ofNullable(DescriptionPropertyConverter.dmnFromWB(wb.getDescription()));
    description.ifPresent(result::setDescription);
    final String typeLanguage = wb.getTypeLanguage();
    final String expressionLanguage = ExpressionLanguagePropertyConverter.dmnFromWB(wb.getExpressionLanguage());
    if (!StringUtils.isEmpty(typeLanguage)) {
        result.setTypeLanguage(typeLanguage);
    }
    if (!StringUtils.isEmpty(expressionLanguage)) {
        result.setExpressionLanguage(expressionLanguage);
    }
    final Map<QName, String> otherAttributes = new HashMap<>();
    wb.getNsContext().forEach((k, v) -> {
        // See https://github.com/highsource/jsonix/issues/227
        if (!Objects.equals(k, DMNModelInstrumentedBase.Namespace.DEFAULT.getPrefix())) {
            otherAttributes.put(new QName(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, k, XMLConstants.DEFAULT_NS_PREFIX), v);
        }
    });
    result.setOtherAttributes(otherAttributes);
    // Add because it is present in the original JSON when unmarshalling
    if (Objects.isNull(result.getItemDefinition())) {
        result.setItemDefinition(new ArrayList<>());
    }
    for (ItemDefinition itemDef : wb.getItemDefinition()) {
        if (ignoreImportedItemDefinition) {
            if (itemDef.isAllowOnlyVisualChange()) {
                continue;
            }
        }
        final JSITItemDefinition itemDefConverted = ItemDefinitionPropertyConverter.dmnFromWB(itemDef);
        result.addItemDefinition(itemDefConverted);
    }
    // Add because it is present in the original JSON when unmarshalling
    if (Objects.isNull(result.getImport())) {
        result.setImport(new ArrayList<>());
    }
    // Add because it is present in the original JSON when unmarshalling
    if (Objects.isNull(result.getDrgElement())) {
        result.setDrgElement(new ArrayList<>());
    }
    // Add because it is present in the original JSON when unmarshalling
    if (Objects.isNull(result.getArtifact())) {
        result.setArtifact(new ArrayList<>());
    }
    for (Import i : wb.getImport()) {
        final JSITImport importConverted = ImportConverter.dmnFromWb(i);
        result.addImport(importConverted);
    }
    return result;
}
Also used : Import(org.kie.workbench.common.dmn.api.definition.model.Import) JSITImport(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITImport) HashMap(java.util.HashMap) QName(javax.xml.namespace.QName) JSITItemDefinition(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITItemDefinition) ItemDefinition(org.kie.workbench.common.dmn.api.definition.model.ItemDefinition) JSITImport(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITImport) JSITDefinitions(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDefinitions) JSIDMNDiagram(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmndi12.JSIDMNDiagram) JSIDMNDI(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmndi12.JSIDMNDI) DMNDiagramElement(org.kie.workbench.common.dmn.api.definition.model.DMNDiagramElement) JSITItemDefinition(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITItemDefinition)

Example 24 with ItemDefinition

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

the class ImportedItemDefinitionPropertyConverter method wbFromDMN.

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

Example 25 with ItemDefinition

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

the class ItemDefinitionPropertyConverter method wbFromDMN.

public static ItemDefinition wbFromDMN(final JSITItemDefinition dmn) {
    if (Objects.isNull(dmn)) {
        return null;
    }
    final Id id = IdPropertyConverter.wbFromDMN(dmn.getId());
    final Name name = new Name(dmn.getName());
    final Description description = wbDescriptionFromDMN(dmn);
    final QName typeRef = wbTypeRefFromDMN(dmn);
    final String typeLanguage = dmn.getTypeLanguage();
    final boolean isCollection = dmn.getIsCollection();
    final ItemDefinition wb = new ItemDefinition(id, description, name, typeRef, null, null, typeLanguage, isCollection, false);
    setUnaryTests(wb, dmn);
    setItemComponent(wb, dmn);
    return wb;
}
Also used : Description(org.kie.workbench.common.dmn.api.property.dmn.Description) QName(org.kie.workbench.common.dmn.api.property.dmn.QName) JSITItemDefinition(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITItemDefinition) ItemDefinition(org.kie.workbench.common.dmn.api.definition.model.ItemDefinition) Id(org.kie.workbench.common.dmn.api.property.dmn.Id) QName(org.kie.workbench.common.dmn.api.property.dmn.QName) Name(org.kie.workbench.common.dmn.api.property.dmn.Name)

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