Search in sources :

Example 1 with DataObject

use of org.kie.workbench.common.dmn.api.editors.types.DataObject 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 DataObject

use of org.kie.workbench.common.dmn.api.editors.types.DataObject 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 DataObject

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

the class DataTypeList method importDataObjects.

public void importDataObjects(final List<DataObject> selectedDataObjects) {
    removeFullQualifiedNames(selectedDataObjects);
    for (final DataObject dataObject : selectedDataObjects) {
        final DataType newDataType = createNewDataType(dataObject);
        final Optional<DataType> existing = findDataTypeByName(dataObject.getClassType());
        if (existing.isPresent()) {
            replace(existing.get(), newDataType);
        } else {
            insert(newDataType);
        }
        insertProperties(dataObject);
    }
}
Also used : DataObject(org.kie.workbench.common.dmn.api.editors.types.DataObject) DataType(org.kie.workbench.common.dmn.client.editors.types.common.DataType)

Example 4 with DataObject

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

the class ImportDataObjectModalView method addItems.

@Override
public void addItems(final List<DataObject> dataObjects) {
    final List<TreeListItem> dataObjectItems = new ArrayList<>();
    for (final DataObject data : dataObjects) {
        dataObjectItems.add(createTreeListItem(data));
    }
    treeList.populate(dataObjectItems);
    itemsContainer.appendChild(treeList.getElement());
}
Also used : DataObject(org.kie.workbench.common.dmn.api.editors.types.DataObject) ArrayList(java.util.ArrayList) TreeListItem(org.kie.workbench.common.dmn.client.editors.types.imported.treelist.TreeListItem)

Example 5 with DataObject

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

the class DataTypeListTest method testCreateNewDataTypeFromDataObject.

@Test
public void testCreateNewDataTypeFromDataObject() {
    final DataObject dataObject = mock(DataObject.class);
    final DataType dataType = mock(DataType.class);
    final String structure = "structure";
    final String classType = "classType";
    when(dataObject.getClassType()).thenReturn(classType);
    when(dataTypeManager.structure()).thenReturn(structure);
    when(dataTypeManager.fromNew()).thenReturn(dataTypeManager);
    when(dataTypeManager.withType(structure)).thenReturn(dataTypeManager);
    when(dataTypeManager.get()).thenReturn(dataType);
    final DataType actual = dataTypeList.createNewDataType(dataObject);
    assertEquals(dataType, actual);
    verify(dataType).setName(classType);
}
Also used : 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)

Aggregations

DataObject (org.kie.workbench.common.dmn.api.editors.types.DataObject)21 Test (org.junit.Test)13 TreeListItem (org.kie.workbench.common.dmn.client.editors.types.imported.treelist.TreeListItem)5 DataType (org.kie.workbench.common.dmn.client.editors.types.common.DataType)4 DataObjectProperty (org.kie.workbench.common.dmn.api.editors.types.DataObjectProperty)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Consumer (java.util.function.Consumer)1 ModuleDataModelOracle (org.kie.soup.project.datamodel.oracle.ModuleDataModelOracle)1 BuiltInType (org.kie.workbench.common.dmn.api.property.dmn.types.BuiltInType)1 KieModule (org.kie.workbench.common.services.shared.project.KieModule)1 ServiceCallback (org.kie.workbench.common.stunner.core.client.service.ServiceCallback)1