Search in sources :

Example 1 with DataModel

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;
}
Also used : DataModel(org.kie.workbench.common.services.datamodeller.core.DataModel) ArrayList(java.util.ArrayList) DataObjectFormModel(org.kie.workbench.common.forms.data.modeller.model.DataObjectFormModel)

Example 2 with DataModel

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;
}
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 3 with DataModel

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

Example 4 with DataModel

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;
}
Also used : DataObject(org.kie.workbench.common.services.datamodeller.core.DataObject) DataModel(org.kie.workbench.common.services.datamodeller.core.DataModel) DataModelImpl(org.kie.workbench.common.services.datamodeller.core.impl.DataModelImpl)

Example 5 with 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);
    }
}
Also used : Path(org.uberfire.backend.vfs.Path) ServiceException(org.kie.workbench.common.screens.datamodeller.service.ServiceException) DataModel(org.kie.workbench.common.services.datamodeller.core.DataModel) JavaRoasterModelDriver(org.kie.workbench.common.services.datamodeller.driver.impl.JavaRoasterModelDriver) ModelDriver(org.kie.workbench.common.services.datamodeller.driver.ModelDriver) ModuleDataModelOracle(org.kie.soup.project.datamodel.oracle.ModuleDataModelOracle) Package(org.guvnor.common.services.project.model.Package) ModelDriverResult(org.kie.workbench.common.services.datamodeller.driver.model.ModelDriverResult) 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) Pair(org.uberfire.commons.data.Pair)

Aggregations

DataModel (org.kie.workbench.common.services.datamodeller.core.DataModel)31 DataObject (org.kie.workbench.common.services.datamodeller.core.DataObject)25 Test (org.junit.Test)21 ObjectProperty (org.kie.workbench.common.services.datamodeller.core.ObjectProperty)14 Annotation (org.kie.workbench.common.services.datamodeller.core.Annotation)9 AnnotationImpl (org.kie.workbench.common.services.datamodeller.core.impl.AnnotationImpl)9 ArrayList (java.util.ArrayList)6 ObjectPropertyImpl (org.kie.workbench.common.services.datamodeller.core.impl.ObjectPropertyImpl)6 ModelDriverResult (org.kie.workbench.common.services.datamodeller.driver.model.ModelDriverResult)6 DataModelImpl (org.kie.workbench.common.services.datamodeller.core.impl.DataModelImpl)5 IOException (java.io.IOException)4 KieModule (org.kie.workbench.common.services.shared.project.KieModule)4 List (java.util.List)3 ModelDriverException (org.kie.workbench.common.services.datamodeller.driver.ModelDriverException)3 BufferedReader (java.io.BufferedReader)2 File (java.io.File)2 InputStream (java.io.InputStream)2 InputStreamReader (java.io.InputStreamReader)2 URI (java.net.URI)2 Arrays (java.util.Arrays)2