use of org.kie.workbench.common.services.datamodeller.core.DataModel in project kie-wb-common by kiegroup.
the class DataModelerServiceImpl method loadModel.
private Pair<DataModel, ModelDriverResult> loadModel(final KieModule module, boolean processErrors) {
if (logger.isDebugEnabled()) {
logger.debug("Loading data model from path: " + module.getRootPath());
}
Long startTime = System.currentTimeMillis();
DataModel dataModel = null;
Path modulePath = null;
Package defaultPackage = null;
try {
modulePath = module.getRootPath();
defaultPackage = moduleService.resolveDefaultPackage(module);
if (logger.isDebugEnabled()) {
logger.debug("Current module path is: " + modulePath);
}
ClassLoader classLoader = classLoaderHelper.getModuleClassLoader(module);
ModelDriver modelDriver = new JavaRoasterModelDriver(ioService, Paths.convert(defaultPackage.getPackageMainSrcPath()), classLoader, filterHolder);
ModelDriverResult result = modelDriver.loadModel();
dataModel = result.getDataModel();
if (processErrors && result.hasErrors()) {
processErrors(module, result);
}
// by now we still use the DMO to calculate module external dependencies.
ModuleDataModelOracle moduleDataModelOracle = dataModelService.getModuleDataModel(modulePath);
ModuleDataModelOracleUtils.loadExternalDependencies(dataModel, moduleDataModelOracle, classLoader);
Long endTime = System.currentTimeMillis();
if (logger.isDebugEnabled()) {
logger.debug("Time elapsed when loading " + modulePath.getFileName() + ": " + (endTime - startTime) + " ms");
}
return new Pair<DataModel, ModelDriverResult>(dataModel, result);
} catch (Exception e) {
logger.error("Data model couldn't be loaded, path: " + modulePath + ", modulePath: " + modulePath + ".", e);
throw new ServiceException("Data model couldn't be loaded, path: " + modulePath + ", modulePath: " + modulePath + ".", e);
}
}
use of org.kie.workbench.common.services.datamodeller.core.DataModel 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.DataModel in project kie-wb-common by kiegroup.
the class DataModelerInnerTypesWeldTest method dataModelerShouldIgnoreEnumFieldsOfInnerClasses.
@Test
public void dataModelerShouldIgnoreEnumFieldsOfInnerClasses() throws Exception {
KieModule module = loadProjectFromResources("/TestInnerTypes");
DataModel dataModel = dataModelService.loadModel(module);
DataObject dataObject = dataModel.getDataObject("test.Outer");
assertNotNull("DataObject test.Outer should be loaded", dataObject);
assertEquals("Enum fields of inner classes of test.Outer DataObject should be ignored", 0, dataObject.getProperties().size());
}
use of org.kie.workbench.common.services.datamodeller.core.DataModel 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.DataModel in project kie-wb-common by kiegroup.
the class JavaRoasterModelDriverTest method createModel.
private DataModel createModel() {
DataModel dataModel = new DataModelImpl();
dataModel.addDataObject(createPojo1());
dataModel.addDataObject(createPojo2());
dataModel.addJavaEnum(createInternalEnum1());
dataModel.addDataObject(createAnnotationValuesAnnotationTest());
dataModel.addDataObject(createClassAnnotationTest());
dataModel.addDataObject(createEnumsAnnotationTest());
dataModel.addDataObject(createMarkerAnnotationTest());
dataModel.addDataObject(createPrimitivesAnnotationTest());
dataModel.addDataObject(createAnnotationsUpdateTest());
dataModel.addDataObject(createAnnotationsUpdateTestResult());
dataModel.addDataObject(createNestedClassUpdateTest());
dataModel.addDataObject(createNestedClassUpdateTestResult());
dataModel.addDataObject(createMethodsUpdateTest());
dataModel.addDataObject(createMethodsUpdateTestResult());
dataModel.addDataObject(createImportsUpdateTest());
dataModel.addDataObject(createImportsUpdateTestResult());
return dataModel;
}
Aggregations