Search in sources :

Example 76 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 org.kie.dmn.model.api.Definitions dmnFromWB(final Definitions wb) {
    if (wb == null) {
        return null;
    }
    final org.kie.dmn.model.api.Definitions result = new org.kie.dmn.model.v1_2.TDefinitions();
    // TODO currently DMN wb UI does not offer feature to set these required DMN properties, setting some hardcoded defaults for now.
    final String defaultId = (wb.getId() != null) ? wb.getId().getValue() : UUID.uuid();
    final String defaultName = (wb.getName() != null) ? wb.getName().getValue() : UUID.uuid(8);
    final String defaultNamespace = !StringUtils.isEmpty(wb.getNamespace().getValue()) ? wb.getNamespace().getValue() : DMNModelInstrumentedBase.Namespace.DEFAULT.getUri() + UUID.uuid();
    result.setId(defaultId);
    result.setName(defaultName);
    result.setNamespace(defaultNamespace);
    result.setDescription(DescriptionPropertyConverter.dmnFromWB(wb.getDescription()));
    result.getNsContext().putAll(wb.getNsContext());
    result.getNsContext().putIfAbsent(DMNModelInstrumentedBase.Namespace.DEFAULT.getPrefix(), defaultNamespace);
    for (ItemDefinition itemDef : wb.getItemDefinition()) {
        final org.kie.dmn.model.api.ItemDefinition itemDefConverted = ItemDefinitionPropertyConverter.dmnFromWB(itemDef);
        if (itemDefConverted != null) {
            itemDefConverted.setParent(result);
        }
        result.getItemDefinition().add(itemDefConverted);
    }
    for (Import i : wb.getImport()) {
        final org.kie.dmn.model.api.Import importConverted = ImportConverter.dmnFromWb(i);
        if (importConverted != null) {
            importConverted.setParent(result);
        }
        result.getImport().add(importConverted);
    }
    return result;
}
Also used : Import(org.kie.workbench.common.dmn.api.definition.model.Import) ItemDefinition(org.kie.workbench.common.dmn.api.definition.model.ItemDefinition)

Example 77 with ItemDefinition

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

the class ItemDefinitionPropertyConverter method dmnFromWB.

public static JSITItemDefinition dmnFromWB(final ItemDefinition wb) {
    if (Objects.isNull(wb)) {
        return null;
    }
    final JSITItemDefinition result = new JSITItemDefinition();
    result.setId(wb.getId().getValue());
    final Optional<String> description = Optional.ofNullable(DescriptionPropertyConverter.dmnFromWB(wb.getDescription()));
    description.ifPresent(result::setDescription);
    result.setName(wb.getName().getValue());
    QNamePropertyConverter.setDMNfromWB(wb.getTypeRef(), result::setTypeRef);
    result.setTypeLanguage(wb.getTypeLanguage());
    result.setIsCollection(wb.isIsCollection());
    final JSITUnaryTests utConverted = UnaryTestsPropertyConverter.dmnFromWB(wb.getAllowedValues());
    result.setAllowedValues(utConverted);
    for (ItemDefinition child : wb.getItemComponent()) {
        final JSITItemDefinition convertedChild = ItemDefinitionPropertyConverter.dmnFromWB(child);
        result.addItemComponent(convertedChild);
    }
    return result;
}
Also used : JSITUnaryTests(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITUnaryTests) 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 78 with ItemDefinition

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

the class DMNUnmarshaller method getWbImportedItemDefinitions.

private List<ItemDefinition> getWbImportedItemDefinitions(final Map<JSITImport, JSITDefinitions> importDefinitions) {
    final List<ItemDefinition> definitions = new ArrayList<>();
    final List<JSITItemDefinition> importedDefinitions = dmnMarshallerImportsHelper.getImportedItemDefinitions(importDefinitions);
    for (int i = 0; i < importedDefinitions.size(); i++) {
        final JSITItemDefinition definition = Js.uncheckedCast(importedDefinitions.get(i));
        final ItemDefinition converted = ItemDefinitionPropertyConverter.wbFromDMN(definition);
        if (converted != null) {
            converted.setAllowOnlyVisualChange(true);
            definitions.add(converted);
        }
    }
    return definitions;
}
Also used : ItemDefinition(org.kie.workbench.common.dmn.api.definition.model.ItemDefinition) JSITItemDefinition(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITItemDefinition) ArrayList(java.util.ArrayList) JSITItemDefinition(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITItemDefinition)

Example 79 with ItemDefinition

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

the class DataTypeListItemTest method testUpdateProperties.

@Test
public void testUpdateProperties() {
    final DataType dataType = spy(makeDataType());
    final String uuid = "uuid";
    final String expectedName = "name";
    final String expectedType = "type";
    final String expectedConstraint = "constraint";
    final boolean expectedList = true;
    final ItemDefinition itemDefinition = mock(ItemDefinition.class);
    when(dataType.getUUID()).thenReturn(uuid);
    when(itemDefinitionStore.get(uuid)).thenReturn(itemDefinition);
    when(view.getName()).thenReturn(expectedName);
    when(dataTypeSelectComponent.getValue()).thenReturn(expectedType);
    when(dataTypeConstraintComponent.getValue()).thenReturn(expectedConstraint);
    when(dataTypeListComponent.getValue()).thenReturn(expectedList);
    when(dataTypeManager.get()).thenReturn(dataType);
    final DataType updatedDataType = listItem.updateProperties(dataType);
    assertEquals(expectedName, updatedDataType.getName());
    assertEquals(expectedType, updatedDataType.getType());
    assertEquals(expectedConstraint, updatedDataType.getConstraint());
    assertEquals(expectedList, updatedDataType.isList());
}
Also used : ItemDefinition(org.kie.workbench.common.dmn.api.definition.model.ItemDefinition) DataType(org.kie.workbench.common.dmn.client.editors.types.common.DataType) Test(org.junit.Test)

Example 80 with ItemDefinition

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

the class DataTypeConfirmationTest method testIfDataTypeDoesNotHaveLostSubDataTypesWhenItemDefinitionItemComponentIsEmpty.

@Test
public void testIfDataTypeDoesNotHaveLostSubDataTypesWhenItemDefinitionItemComponentIsEmpty() {
    final DataType dataType = mock(DataType.class);
    final ItemDefinition itemDefinition = mock(ItemDefinition.class);
    final List<ItemDefinition> itemComponent = singletonList(mock(ItemDefinition.class));
    final Command onSuccess = mock(Command.class);
    final Command onError = mock(Command.class);
    final String uuid = "uuid";
    when(dataType.getUUID()).thenReturn(uuid);
    when(dataType.getType()).thenReturn(STRUCTURE);
    when(itemDefinitionStore.get(uuid)).thenReturn(itemDefinition);
    when(itemDefinition.getItemComponent()).thenReturn(itemComponent);
    confirmation.ifDataTypeDoesNotHaveLostSubDataTypes(dataType, onSuccess, onError);
    verify(onSuccess).execute();
}
Also used : Command(org.uberfire.mvp.Command) ItemDefinition(org.kie.workbench.common.dmn.api.definition.model.ItemDefinition) DataType(org.kie.workbench.common.dmn.client.editors.types.common.DataType) 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