Search in sources :

Example 16 with DataObject

use of org.kie.workbench.common.services.datamodeller.core.DataObject in project kie-wb-common by kiegroup.

the class DataModelerServiceWeldTest method testDataModelerService.

@Test
public void testDataModelerService() throws Exception {
    KieModule module = loadProjectFromResources("/DataModelerTest1");
    final Map<String, AnnotationDefinition> systemAnnotations = dataModelService.getAnnotationDefinitions();
    DataModel dataModelOriginal = new DataModelTestUtil(systemAnnotations).createModel(Pojo1.class, Pojo2.class);
    org.kie.workbench.common.services.datamodeller.core.DataModel dataModel = dataModelService.loadModel(module);
    Map<String, DataObject> objectsMap = new HashMap<>();
    assertNotNull(dataModel);
    assertEquals(dataModelOriginal.getDataObjects().size(), dataModel.getDataObjects().size());
    for (DataObject dataObject : dataModel.getDataObjects()) {
        objectsMap.put(dataObject.getClassName(), dataObject);
    }
    for (DataObject dataObject : dataModelOriginal.getDataObjects()) {
        org.kie.workbench.common.services.datamodeller.DataModelerAssert.assertEqualsDataObject(dataObject, objectsMap.get(dataObject.getClassName()));
    }
}
Also used : AnnotationDefinition(org.kie.workbench.common.services.datamodeller.core.AnnotationDefinition) HashMap(java.util.HashMap) DataObject(org.kie.workbench.common.services.datamodeller.core.DataObject) DataModel(org.kie.workbench.common.services.datamodeller.core.DataModel) DataModel(org.kie.workbench.common.services.datamodeller.core.DataModel) KieModule(org.kie.workbench.common.services.shared.project.KieModule) Test(org.junit.Test)

Example 17 with DataObject

use of org.kie.workbench.common.services.datamodeller.core.DataObject in project kie-wb-common by kiegroup.

the class DataModelTestUtil method createDataObject.

public DataObject createDataObject(Class clazz) throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
    Class superClass = clazz.getSuperclass();
    String superClassName = null;
    if (superClass != null && !superClass.equals(Object.class)) {
        superClassName = superClass.getCanonicalName();
    }
    DataObject dataObj = createDataObject(clazz.getPackage().getName(), clazz.getSimpleName(), superClassName);
    addAnnotations(dataObj, clazz.getAnnotations());
    for (Field field : clazz.getDeclaredFields()) {
        String fieldName = field.getName();
        String fieldType = field.getType().getCanonicalName();
        ObjectProperty fieldProp = addProperty(dataObj, fieldName, fieldType, true, false, null);
        addAnnotations(fieldProp, field.getAnnotations());
    }
    return dataObj;
}
Also used : ObjectProperty(org.kie.workbench.common.services.datamodeller.core.ObjectProperty) Field(java.lang.reflect.Field) DataObject(org.kie.workbench.common.services.datamodeller.core.DataObject)

Example 18 with DataObject

use of org.kie.workbench.common.services.datamodeller.core.DataObject in project kie-wb-common by kiegroup.

the class DataModelTestUtil method createModel.

public DataModel createModel(Class... classes) throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
    DataModel dataModel = new DataModelImpl();
    for (Class clazz : classes) {
        DataObject dataObject = createDataObject(clazz);
        dataModel.addDataObject(dataObject);
    }
    return dataModel;
}
Also used : DataObject(org.kie.workbench.common.services.datamodeller.core.DataObject) DataModel(org.kie.workbench.common.services.datamodeller.core.DataModel) DataModelImpl(org.kie.workbench.common.services.datamodeller.core.impl.DataModelImpl)

Example 19 with DataObject

use of org.kie.workbench.common.services.datamodeller.core.DataObject in project kie-wb-common by kiegroup.

the class DataModelTestUtil method createDataObject.

public DataObject createDataObject(String packageName, String name, String superClassName) {
    DataObject dataObject = new DataObjectImpl(packageName, name);
    dataObject.setSuperClassName(superClassName);
    return dataObject;
}
Also used : DataObjectImpl(org.kie.workbench.common.services.datamodeller.core.impl.DataObjectImpl) DataObject(org.kie.workbench.common.services.datamodeller.core.DataObject)

Example 20 with DataObject

use of org.kie.workbench.common.services.datamodeller.core.DataObject in project kie-wb-common by kiegroup.

the class DataModelerUtils method buildSuperclassOptions.

public static List<Pair<String, String>> buildSuperclassOptions(DataModel dataModel, DataObject currentDataObject) {
    List<Pair<String, String>> options = new ArrayList<Pair<String, String>>();
    if (dataModel != null) {
        SortedMap<String, String> sortedModelClasses = new TreeMap<String, String>(SortHelper.ALPHABETICAL_ORDER_COMPARATOR);
        SortedMap<String, String> sortedExternalClasses = new TreeMap<String, String>(SortHelper.ALPHABETICAL_ORDER_COMPARATOR);
        boolean isExtensible = false;
        String className;
        String classLabel;
        String currentClassName;
        // first, all data objects form this model in order
        for (DataObject internalDataObject : dataModel.getDataObjects()) {
            className = internalDataObject.getClassName();
            classLabel = getDataObjectFullLabel(internalDataObject);
            isExtensible = !internalDataObject.isAbstract() && !internalDataObject.isFinal() && !internalDataObject.isInterface();
            if (isExtensible) {
                if (currentDataObject != null && className.toLowerCase().equals(currentDataObject.getClassName().toLowerCase()))
                    continue;
                sortedModelClasses.put(classLabel, className);
            }
        }
        // Then add all external types, ordered
        for (DataObject externalDataObject : dataModel.getExternalClasses()) {
            className = externalDataObject.getClassName();
            classLabel = EXTERNAL_PREFIX + className;
            isExtensible = !externalDataObject.isAbstract() && !externalDataObject.isFinal() && !externalDataObject.isInterface();
            if (isExtensible) {
                if (currentDataObject != null && className.toLowerCase().equals(currentDataObject.getClassName().toLowerCase()))
                    continue;
                sortedExternalClasses.put(classLabel, className);
            }
        }
        if (currentDataObject != null && currentDataObject.getSuperClassName() != null) {
            currentClassName = currentDataObject.getSuperClassName();
            if (!sortedModelClasses.containsKey(currentClassName) && !sortedExternalClasses.containsKey(currentClassName)) {
                // the model was loaded but the super class is not a model class nor an external class, e.g. java.lang.Object. Still needs to be loaded.
                sortedModelClasses.put(currentClassName, currentClassName);
            }
        }
        for (Map.Entry<String, String> classNameEntry : sortedModelClasses.entrySet()) {
            options.add(new Pair(classNameEntry.getKey(), classNameEntry.getValue()));
        }
        for (Map.Entry<String, String> classNameEntry : sortedExternalClasses.entrySet()) {
            options.add(new Pair(classNameEntry.getKey(), classNameEntry.getValue()));
        }
    }
    return options;
}
Also used : DataObject(org.kie.workbench.common.services.datamodeller.core.DataObject) ArrayList(java.util.ArrayList) TreeMap(java.util.TreeMap) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap) Map(java.util.Map) SortedMap(java.util.SortedMap) Pair(org.uberfire.commons.data.Pair)

Aggregations

DataObject (org.kie.workbench.common.services.datamodeller.core.DataObject)95 Test (org.junit.Test)45 ObjectProperty (org.kie.workbench.common.services.datamodeller.core.ObjectProperty)40 DataModel (org.kie.workbench.common.services.datamodeller.core.DataModel)29 Annotation (org.kie.workbench.common.services.datamodeller.core.Annotation)28 DataObjectImpl (org.kie.workbench.common.services.datamodeller.core.impl.DataObjectImpl)21 ArrayList (java.util.ArrayList)17 AnnotationValuesAnnotation (org.kie.workbench.common.services.datamodeller.annotations.AnnotationValuesAnnotation)17 ClassAnnotation (org.kie.workbench.common.services.datamodeller.annotations.ClassAnnotation)17 EnumsAnnotation (org.kie.workbench.common.services.datamodeller.annotations.EnumsAnnotation)17 MarkerAnnotation (org.kie.workbench.common.services.datamodeller.annotations.MarkerAnnotation)17 PrimitivesAnnotation (org.kie.workbench.common.services.datamodeller.annotations.PrimitivesAnnotation)17 TestAnnotation (org.kie.workbench.common.services.datamodeller.parser.test.TestAnnotation)17 AnnotationImpl (org.kie.workbench.common.services.datamodeller.core.impl.AnnotationImpl)16 DomainEditorBaseTest (org.kie.workbench.common.screens.datamodeller.client.widgets.DomainEditorBaseTest)15 MethodImpl (org.kie.workbench.common.services.datamodeller.core.impl.MethodImpl)12 List (java.util.List)11 TypeImpl (org.kie.workbench.common.services.datamodeller.core.impl.TypeImpl)11 Method (org.kie.workbench.common.services.datamodeller.core.Method)10 Generated (javax.annotation.Generated)8