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);
}
}
Aggregations