Search in sources :

Example 31 with DataModel

use of org.kie.workbench.common.services.datamodeller.core.DataModel in project kie-wb-common by kiegroup.

the class DataModelerServiceImpl method constructContent.

@Override
protected EditorModelContent constructContent(Path path, Overview overview) {
    if (logger.isDebugEnabled()) {
        logger.debug("Loading editor model from path: " + path.toURI());
    }
    Long startTime = System.currentTimeMillis();
    EditorModelContent editorModelContent = new EditorModelContent();
    try {
        KieModule module = moduleService.resolveModule(path);
        if (module == null) {
            logger.warn("File : " + path.toURI() + " do not belong to a valid module");
            return editorModelContent;
        }
        Pair<DataModel, ModelDriverResult> resultPair = loadModel(module, false);
        String className = serviceHelper.calculateClassName(module, path);
        editorModelContent.setCurrentModule(module);
        editorModelContent.setPath(path);
        editorModelContent.setCurrentModulePackages(serviceHelper.resolvePackages(module));
        editorModelContent.setDataModel(resultPair.getK1());
        editorModelContent.setDataObject(resultPair.getK1().getDataObject(className));
        editorModelContent.setDataObjectPaths(resultPair.getK2().getClassPaths());
        editorModelContent.setOriginalClassName(className);
        editorModelContent.setOriginalPackageName(NamingUtils.extractPackageName(className));
        // Read the sources for the file being edited.
        if (ioService.exists(Paths.convert(path))) {
            String source = ioService.readAllString(Paths.convert(path));
            editorModelContent.setSource(source);
        }
        if (resultPair.getK2().hasErrors()) {
            editorModelContent.setErrors(serviceHelper.toDataModelerError(resultPair.getK2().getErrors()));
        }
        editorModelContent.setOverview(overview);
        editorModelContent.setElapsedTime(System.currentTimeMillis() - startTime);
        if (logger.isDebugEnabled()) {
            logger.debug("Time elapsed when loading editor model from:" + path + " : " + editorModelContent.getElapsedTime() + " ms");
        }
        return editorModelContent;
    } catch (Exception e) {
        logger.error("Editor model couldn't be loaded from path: " + (path != null ? path.toURI() : path) + ".", e);
        throw new ServiceException("Editor model couldn't be loaded from path: " + (path != null ? path.toURI() : path) + ".", e);
    }
}
Also used : ServiceException(org.kie.workbench.common.screens.datamodeller.service.ServiceException) DataModel(org.kie.workbench.common.services.datamodeller.core.DataModel) EditorModelContent(org.kie.workbench.common.screens.datamodeller.model.EditorModelContent) ModelDriverResult(org.kie.workbench.common.services.datamodeller.driver.model.ModelDriverResult) KieModule(org.kie.workbench.common.services.shared.project.KieModule) 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)

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