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;
}
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;
}
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;
}
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());
}
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();
}
Aggregations