use of org.kie.workbench.common.services.datamodeller.core.DataModel in project kie-wb-common by kiegroup.
the class DataObjectFinderServiceImpl method getAvailableDataObjects.
@Override
public List<DataObjectFormModel> getAvailableDataObjects(Path path) {
DataModel dataModel = dataModelerService.loadModel(moduleService.resolveModule(path));
List<DataObjectFormModel> formModels = new ArrayList<>();
dataModel.getDataObjects().forEach(dataObject -> {
String modelName = dataObject.getName().substring(0, 1).toLowerCase() + dataObject.getName().substring(1);
formModels.add(new DataObjectFormModel(modelName, dataObject.getClassName()));
});
return formModels;
}
use of org.kie.workbench.common.services.datamodeller.core.DataModel in project kie-wb-common by kiegroup.
the class DataModelerServiceImpl method findPersistableClasses.
@Override
public List<String> findPersistableClasses(final Path path) {
List<String> classes = new ArrayList<String>();
KieModule module = moduleService.resolveModule(path);
if (module != null) {
DataModel dataModel = loadModel(module);
if (dataModel != null) {
for (DataObject dataObject : dataModel.getDataObjects()) {
if (dataObject.getAnnotation(Entity.class.getName()) != null) {
classes.add(dataObject.getClassName());
}
}
}
}
return classes;
}
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 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 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);
}
}
Aggregations