use of org.kie.workbench.common.services.datamodeller.core.DataObject in project kie-wb-common by kiegroup.
the class DataModelerEventTest method createEvent.
@Test
public void createEvent() {
DataObject currentDataObject = new DataObjectImpl();
ObjectProperty currentField = new ObjectPropertyImpl();
Method currentMethod = new MethodImpl();
Module currentModule = new Module();
String source = "testSource";
String contextId = "testContextId";
Path path = new PathFactory.PathImpl();
DataModelerEvent event = new DataModelerEvent().withCurrentDataObject(currentDataObject).withCurrentField(currentField).withCurrentMethod(currentMethod).withCurrentProject(currentModule).withSource(source).withContextId(contextId).withPath(path);
assertEquals(currentDataObject, event.getCurrentDataObject());
assertEquals(currentField, event.getCurrentField());
assertEquals(currentMethod, event.getCurrentMethod());
assertEquals(currentModule, event.getCurrentModule());
assertEquals(source, event.getSource());
assertEquals(contextId, event.getContextId());
assertEquals(path, event.getPath());
}
use of org.kie.workbench.common.services.datamodeller.core.DataObject 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.DataObject in project kie-wb-common by kiegroup.
the class DataModelerServiceImpl method generateModel.
private void generateModel(DataModel dataModel, KieModule module, CommentedOption option) throws Exception {
org.uberfire.java.nio.file.Path targetFile;
org.uberfire.java.nio.file.Path javaRootPath;
String newSource;
// ensure java sources directory exists.
Path modulePath = module.getRootPath();
javaRootPath = ensureModuleJavaPath(Paths.convert(modulePath));
for (DataObject dataObject : dataModel.getDataObjects()) {
targetFile = serviceHelper.calculateFilePath(dataObject.getClassName(), javaRootPath);
if (logger.isDebugEnabled()) {
logger.debug("Data object: " + dataObject.getClassName() + " java source code will be generated from scratch and written into file: " + targetFile);
}
newSource = createJavaSource(dataObject);
ioService.write(targetFile, newSource, option);
}
}
use of org.kie.workbench.common.services.datamodeller.core.DataObject in project kie-wb-common by kiegroup.
the class DataModelerServiceImpl method loadDataObject.
public GenerationResult loadDataObject(final Path modulePath, final String source, final Path sourcePath) {
if (logger.isDebugEnabled()) {
logger.debug("Loading data object from modulePath: " + modulePath.toURI());
}
KieModule module;
DataObject dataObject = null;
try {
module = moduleService.resolveModule(modulePath);
if (module == null) {
return new GenerationResult(null, null, new ArrayList<DataModelerError>());
}
ClassLoader classLoader = classLoaderHelper.getModuleClassLoader(module);
JavaRoasterModelDriver modelDriver = new JavaRoasterModelDriver(ioService, null, classLoader, filterHolder);
ModelDriverResult driverResult = modelDriver.loadDataObject(source, Paths.convert(sourcePath));
if (!driverResult.hasErrors()) {
if (driverResult.getDataModel().getDataObjects().size() > 0) {
dataObject = driverResult.getDataModel().getDataObjects().iterator().next();
}
return new GenerationResult(source, dataObject, new ArrayList<DataModelerError>());
} else {
return new GenerationResult(source, null, serviceHelper.toDataModelerError(driverResult.getErrors()));
}
} catch (Exception e) {
logger.error("Data object couldn't be loaded, path: " + modulePath + ", modulePath: " + modulePath + ".", e);
throw new ServiceException("Data object couldn't be loaded, path: " + modulePath + ", modulePath: " + modulePath + ".", e);
}
}
use of org.kie.workbench.common.services.datamodeller.core.DataObject in project kie-wb-common by kiegroup.
the class DataModelerEventObserverTest method onNonPersistableDataObjectDeletedTest.
@Test
public void onNonPersistableDataObjectDeletedTest() {
DataObject dataObject = new DataObjectImpl("package1", "NonPersistableObject");
DataObjectCreatedEvent createdEvent = new DataObjectCreatedEvent(module, dataObject);
eventObserver.onDataObjectCreated(createdEvent);
descriptorModel.getPersistenceUnit().getClasses().add(new PersistableDataObject(createdEvent.getCurrentDataObject().getClassName()));
verify(descriptorService, times(0)).save(eq(descriptorPath), eq(descriptorModel), Mockito.<Metadata>any(), anyString());
assertEquals(1, descriptorModel.getPersistenceUnit().getClasses().size());
}
Aggregations