Search in sources :

Example 6 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)

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

Example 9 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 10 with DataModel

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

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