Search in sources :

Example 11 with DataObject

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());
}
Also used : DataObjectImpl(org.kie.workbench.common.services.datamodeller.core.impl.DataObjectImpl) ObjectProperty(org.kie.workbench.common.services.datamodeller.core.ObjectProperty) Path(org.uberfire.backend.vfs.Path) ObjectPropertyImpl(org.kie.workbench.common.services.datamodeller.core.impl.ObjectPropertyImpl) DataObject(org.kie.workbench.common.services.datamodeller.core.DataObject) MethodImpl(org.kie.workbench.common.services.datamodeller.core.impl.MethodImpl) Method(org.kie.workbench.common.services.datamodeller.core.Method) Module(org.guvnor.common.services.project.model.Module) Test(org.junit.Test)

Example 12 with DataObject

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;
}
Also used : DataObject(org.kie.workbench.common.services.datamodeller.core.DataObject) DataModel(org.kie.workbench.common.services.datamodeller.core.DataModel) ArrayList(java.util.ArrayList) KieModule(org.kie.workbench.common.services.shared.project.KieModule)

Example 13 with DataObject

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);
    }
}
Also used : Path(org.uberfire.backend.vfs.Path) DataObject(org.kie.workbench.common.services.datamodeller.core.DataObject)

Example 14 with DataObject

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);
    }
}
Also used : DataModelerError(org.kie.workbench.common.screens.datamodeller.model.DataModelerError) DataObject(org.kie.workbench.common.services.datamodeller.core.DataObject) ServiceException(org.kie.workbench.common.screens.datamodeller.service.ServiceException) GenerationResult(org.kie.workbench.common.screens.datamodeller.model.GenerationResult) ModelDriverResult(org.kie.workbench.common.services.datamodeller.driver.model.ModelDriverResult) KieModule(org.kie.workbench.common.services.shared.project.KieModule) JavaRoasterModelDriver(org.kie.workbench.common.services.datamodeller.driver.impl.JavaRoasterModelDriver) ModelDriverException(org.kie.workbench.common.services.datamodeller.driver.ModelDriverException) ServiceException(org.kie.workbench.common.screens.datamodeller.service.ServiceException) FileAlreadyExistsException(org.uberfire.java.nio.file.FileAlreadyExistsException)

Example 15 with DataObject

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());
}
Also used : DataObjectImpl(org.kie.workbench.common.services.datamodeller.core.impl.DataObjectImpl) PersistableDataObject(org.kie.workbench.common.screens.datamodeller.model.persistence.PersistableDataObject) PersistableDataObject(org.kie.workbench.common.screens.datamodeller.model.persistence.PersistableDataObject) DataObject(org.kie.workbench.common.services.datamodeller.core.DataObject) DataObjectCreatedEvent(org.kie.workbench.common.screens.datamodeller.events.DataObjectCreatedEvent) Test(org.junit.Test)

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