Search in sources :

Example 1 with DataObjectProperty

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

the class DataObjectsServiceImpl method convertProperty.

private DataObjectProperty convertProperty(final ModelField field, final List<DataObject> dataObjects, final ClassLoader classLoader, final Map<String, String> parametersType, final DataObject dataObject) {
    final DataObjectProperty dataObjectProperty = new DataObjectProperty();
    dataObjectProperty.setList(isList(field.getClassName(), classLoader));
    if (dataObjectProperty.isList()) {
        final String parametersKey = dataObject.getClassType() + "#" + field.getName();
        if (!parametersType.containsKey(parametersKey)) {
            dataObjectProperty.setType(convertDataType(field.getClassName(), dataObjects, classLoader));
        } else {
            final String type = parametersType.get(parametersKey);
            final String listType = convertDataType(type, dataObjects, classLoader);
            dataObjectProperty.setType(listType);
        }
    } else {
        dataObjectProperty.setType(convertDataType(field.getClassName(), dataObjects, classLoader));
    }
    dataObjectProperty.setProperty(field.getName());
    return dataObjectProperty;
}
Also used : DataObjectProperty(org.kie.workbench.common.dmn.api.editors.types.DataObjectProperty)

Example 2 with DataObjectProperty

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

the class DataTypeList method updatePropertiesReferences.

void updatePropertiesReferences(final List<DataObject> imported, final Map<String, String> renamed) {
    for (final DataObject dataObject : imported) {
        for (final DataObjectProperty property : dataObject.getProperties()) {
            String propertyType = renamed.getOrDefault(property.getType(), property.getType());
            if (!isPropertyTypePresent(propertyType, imported)) {
                propertyType = BuiltInType.ANY.getName();
            }
            property.setType(propertyType);
        }
    }
}
Also used : DataObjectProperty(org.kie.workbench.common.dmn.api.editors.types.DataObjectProperty) DataObject(org.kie.workbench.common.dmn.api.editors.types.DataObject)

Example 3 with DataObjectProperty

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

the class DataTypeListTest method testInsertProperties.

@Test
public void testInsertProperties() {
    final DataObject dataObject = mock(DataObject.class);
    final String myImportedClass = "org.MyClass";
    final DataType existingDt = mock(DataType.class);
    final DataTypeListItem dtListItem = mock(DataTypeListItem.class);
    final Optional<DataTypeListItem> dtListItemOptional = Optional.of(dtListItem);
    final DataObjectProperty property1 = mock(DataObjectProperty.class);
    final DataObjectProperty property2 = mock(DataObjectProperty.class);
    final List<DataObjectProperty> properties = Arrays.asList(property1, property2);
    final DataType property1DataType = mock(DataType.class);
    final DataType property2DataType = mock(DataType.class);
    when(dataObject.getClassType()).thenReturn(myImportedClass);
    when(dataObject.getProperties()).thenReturn(properties);
    doReturn(Optional.of(existingDt)).when(dataTypeList).findDataTypeByName(myImportedClass);
    doReturn(dtListItemOptional).when(dataTypeList).findItem(existingDt);
    doReturn(property1DataType).when(dataTypeList).createNewDataType(property1);
    doReturn(property2DataType).when(dataTypeList).createNewDataType(property2);
    dataTypeList.insertProperties(dataObject);
    verify(dtListItem).insertNestedField(property1DataType);
    verify(dtListItem).insertNestedField(property2DataType);
}
Also used : DataObjectProperty(org.kie.workbench.common.dmn.api.editors.types.DataObjectProperty) DataObject(org.kie.workbench.common.dmn.api.editors.types.DataObject) DataType(org.kie.workbench.common.dmn.client.editors.types.common.DataType) Test(org.junit.Test)

Example 4 with DataObjectProperty

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

the class DataTypeListTest method testCreateNewDataTypeFromPropertyWhenIsList.

@Test
public void testCreateNewDataTypeFromPropertyWhenIsList() {
    final DataObjectProperty dataProperty = mock(DataObjectProperty.class);
    final String propertyName = "name";
    final String propertyType = "type";
    final DataType newType = mock(DataType.class);
    when(dataProperty.getProperty()).thenReturn(propertyName);
    when(dataProperty.getType()).thenReturn(propertyType);
    when(dataProperty.isList()).thenReturn(true);
    when(dataTypeManager.fromNew()).thenReturn(dataTypeManager);
    when(dataTypeManager.asList(anyBoolean())).thenReturn(dataTypeManager);
    when(dataTypeManager.withType(propertyType)).thenReturn(dataTypeManager);
    when(dataTypeManager.get()).thenReturn(newType);
    final DataType actual = dataTypeList.createNewDataType(dataProperty);
    assertEquals(newType, actual);
    verify(dataTypeManager).asList(true);
    verify(newType).setName(propertyName);
}
Also used : DataObjectProperty(org.kie.workbench.common.dmn.api.editors.types.DataObjectProperty) DataType(org.kie.workbench.common.dmn.client.editors.types.common.DataType) Test(org.junit.Test)

Example 5 with DataObjectProperty

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

the class DataTypeListTest method testCreateNewDataTypeFromProperty.

@Test
public void testCreateNewDataTypeFromProperty() {
    final DataObjectProperty dataProperty = mock(DataObjectProperty.class);
    final String propertyName = "name";
    final String propertyType = "type";
    final DataType newType = mock(DataType.class);
    when(dataProperty.getProperty()).thenReturn(propertyName);
    when(dataProperty.getType()).thenReturn(propertyType);
    when(dataTypeManager.fromNew()).thenReturn(dataTypeManager);
    when(dataTypeManager.asList(anyBoolean())).thenReturn(dataTypeManager);
    when(dataTypeManager.withType(propertyType)).thenReturn(dataTypeManager);
    when(dataTypeManager.get()).thenReturn(newType);
    final DataType actual = dataTypeList.createNewDataType(dataProperty);
    assertEquals(newType, actual);
    verify(dataTypeManager).asList(false);
    verify(newType).setName(propertyName);
}
Also used : DataObjectProperty(org.kie.workbench.common.dmn.api.editors.types.DataObjectProperty) DataType(org.kie.workbench.common.dmn.client.editors.types.common.DataType) Test(org.junit.Test)

Aggregations

DataObjectProperty (org.kie.workbench.common.dmn.api.editors.types.DataObjectProperty)6 Test (org.junit.Test)4 DataObject (org.kie.workbench.common.dmn.api.editors.types.DataObject)3 DataType (org.kie.workbench.common.dmn.client.editors.types.common.DataType)3 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1