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