Search in sources :

Example 1 with BuiltInType

use of org.kie.workbench.common.dmn.api.property.dmn.types.BuiltInType in project kie-wb-common by kiegroup.

the class DataObjectsServiceImpl method convertDataType.

private String convertDataType(final String typeName, final List<DataObject> dataObjects, final ClassLoader classLoader) {
    for (DataObject dataObject : dataObjects) {
        if (Objects.equals(typeName, dataObject.getClassType())) {
            return typeName;
        }
    }
    try {
        final String className = PrimitiveUtilities.getClassNameForPrimitiveType(typeName);
        final Class<?> clazz = classLoader.loadClass(Objects.nonNull(className) ? className : typeName);
        final BuiltInType builtInType = determineBuiltInTypeFromClass(clazz);
        if (Objects.nonNull(builtInType)) {
            return builtInType.getName();
        }
    } catch (ClassNotFoundException cnfe) {
    // Swallow as BuiltInType.ANY is the default response
    }
    return BuiltInType.ANY.getName();
}
Also used : DataObject(org.kie.workbench.common.dmn.api.editors.types.DataObject) BuiltInType(org.kie.workbench.common.dmn.api.property.dmn.types.BuiltInType)

Example 2 with BuiltInType

use of org.kie.workbench.common.dmn.api.property.dmn.types.BuiltInType in project kie-wb-common by kiegroup.

the class DataTypePickerWidgetTest method testMakeTypeSelectorForBuiltInType.

@Test
public void testMakeTypeSelectorForBuiltInType() {
    final BuiltInType bit = BuiltInType.ANY;
    final ArgumentCaptor<String> optionTextCaptor = ArgumentCaptor.forClass(String.class);
    final ArgumentCaptor<String> optionValueCaptor = ArgumentCaptor.forClass(String.class);
    final ArgumentCaptor<QName> qNameCaptor = ArgumentCaptor.forClass(QName.class);
    final Optional<Option> oo = picker.makeTypeSelector(bit);
    verify(option).setText(optionTextCaptor.capture());
    verify(option).setValue(optionValueCaptor.capture());
    verify(qNameConverter).toWidgetValue(qNameCaptor.capture());
    final QName normalisedQName = qNameCaptor.getValue();
    assertEquals("", normalisedQName.getNamespaceURI());
    assertEquals(QName.NULL_NS_URI, normalisedQName.getPrefix());
    assertEquals(bit.getName(), normalisedQName.getLocalPart());
    assertTrue(oo.isPresent());
    assertEquals(bit.getName(), optionTextCaptor.getValue());
    assertEquals("[][Any][]", optionValueCaptor.getValue());
}
Also used : QName(org.kie.workbench.common.dmn.api.property.dmn.QName) Option(org.gwtbootstrap3.extras.select.client.ui.Option) BuiltInType(org.kie.workbench.common.dmn.api.property.dmn.types.BuiltInType) Test(org.junit.Test)

Example 3 with BuiltInType

use of org.kie.workbench.common.dmn.api.property.dmn.types.BuiltInType in project kie-wb-common by kiegroup.

the class DataTypeManagerTest method testMakeDataTypeFromBuiltInType.

@Test
public void testMakeDataTypeFromBuiltInType() {
    final BuiltInType builtInType = BuiltInType.values()[0];
    final DataType dataType = manager.from(builtInType).get();
    assertFalse(dataType.getUUID().isEmpty());
    assertEquals(NONE, dataType.getName());
    assertEquals("number", dataType.getType());
    assertEquals(emptyList(), dataType.getSubDataTypes());
    assertFalse(dataType.hasSubDataTypes());
}
Also used : BuiltInType(org.kie.workbench.common.dmn.api.property.dmn.types.BuiltInType) Test(org.junit.Test)

Example 4 with BuiltInType

use of org.kie.workbench.common.dmn.api.property.dmn.types.BuiltInType in project kie-wb-common by kiegroup.

the class DataTypeSelectViewTest method testOptionGroupSorting.

@Test
@SuppressWarnings("unchecked")
public void testOptionGroupSorting() {
    final HTMLOptGroupElement groupElement = mock(HTMLOptGroupElement.class);
    final HTMLOptionElement optionElement = mock(HTMLOptionElement.class);
    final DataType customDataType1 = makeDataType("b");
    final DataType customDataType2 = makeDataType("a");
    final List<DataType> customDataTypes = new Lists.Builder().add(customDataType1).add(customDataType2).build();
    doReturn(groupElement).when(view).makeHTMLOptGroupElement();
    doReturn(optionElement).when(view).makeHTMLOptionElement();
    when(translationService.format(DataTypeSelectView_DefaultTitle)).thenReturn("Default");
    when(translationService.format(DataTypeSelectView_CustomTitle)).thenReturn("Custom");
    when(dataTypeStore.getTopLevelDataTypes()).thenReturn(customDataTypes);
    doAnswer(i -> {
        final BuiltInType bit = (BuiltInType) i.getArguments()[0];
        final DataTypeManager dtm = mock(DataTypeManager.class);
        final DataType dt = makeDataType(bit.getName());
        when(dtm.get()).thenReturn(dt);
        return dtm;
    }).when(dataTypeManager).from(any(BuiltInType.class));
    doAnswer(i -> dataTypeUtils.defaultDataTypes()).when(presenter).getDefaultDataTypes();
    doAnswer(i -> dataTypeUtils.customDataTypes()).when(presenter).getCustomDataTypes();
    view.setupDropdownItems();
    final int visibleItems = BuiltInType.values().length - 1;
    // Check all items were added to the group minus the UNDEFINED item
    verify(view, times(visibleItems + customDataTypes.size())).makeOption(dataTypeCaptor.capture(), any(Function.class));
    final List<DataType> dataTypes = dataTypeCaptor.getAllValues();
    // Check the items were sorted correctly
    assertEquals("Any", dataTypes.get(0).getType());
    assertEquals("boolean", dataTypes.get(1).getType());
    assertEquals("context", dataTypes.get(2).getType());
    assertEquals("date", dataTypes.get(3).getType());
    assertEquals("date and time", dataTypes.get(4).getType());
    assertEquals("days and time duration", dataTypes.get(5).getType());
    assertEquals("number", dataTypes.get(6).getType());
    assertEquals("string", dataTypes.get(7).getType());
    assertEquals("time", dataTypes.get(8).getType());
    assertEquals("years and months duration", dataTypes.get(9).getType());
    final int customDataTypesOffset = visibleItems;
    assertEquals("a", dataTypes.get(customDataTypesOffset).getType());
    assertEquals("b", dataTypes.get(customDataTypesOffset + 1).getType());
}
Also used : Function(java.util.function.Function) HTMLOptGroupElement(elemental2.dom.HTMLOptGroupElement) DataTypeManager(org.kie.workbench.common.dmn.client.editors.types.common.DataTypeManager) Lists(org.kie.soup.commons.util.Lists) HTMLOptionElement(elemental2.dom.HTMLOptionElement) DataType(org.kie.workbench.common.dmn.client.editors.types.common.DataType) BuiltInType(org.kie.workbench.common.dmn.api.property.dmn.types.BuiltInType) Test(org.junit.Test)

Aggregations

BuiltInType (org.kie.workbench.common.dmn.api.property.dmn.types.BuiltInType)4 Test (org.junit.Test)3 HTMLOptGroupElement (elemental2.dom.HTMLOptGroupElement)1 HTMLOptionElement (elemental2.dom.HTMLOptionElement)1 Function (java.util.function.Function)1 Option (org.gwtbootstrap3.extras.select.client.ui.Option)1 Lists (org.kie.soup.commons.util.Lists)1 DataObject (org.kie.workbench.common.dmn.api.editors.types.DataObject)1 QName (org.kie.workbench.common.dmn.api.property.dmn.QName)1 DataType (org.kie.workbench.common.dmn.client.editors.types.common.DataType)1 DataTypeManager (org.kie.workbench.common.dmn.client.editors.types.common.DataTypeManager)1