use of org.kie.workbench.common.services.datamodeller.driver.impl.JavaRoasterModelDriver in project kie-wb-common by kiegroup.
the class DataModelerServiceImpl method loadJavaTypeInfo.
public TypeInfoResult loadJavaTypeInfo(final String source) {
try {
JavaRoasterModelDriver modelDriver = new JavaRoasterModelDriver();
TypeInfoResult result = new TypeInfoResult();
org.kie.workbench.common.services.datamodeller.driver.TypeInfoResult driverResult = modelDriver.loadJavaTypeInfo(source);
result.setJavaTypeInfo(driverResult.getTypeInfo());
if (driverResult.hasErrors()) {
result.setErrors(serviceHelper.toDataModelerError(driverResult.getErrors()));
}
return result;
} catch (Exception e) {
logger.error("JavaTypeInfo object couldn't be loaded for source: " + source, e);
throw new ServiceException("JavaTypeInfo object couldn't be loaded for source.", e);
}
}
use of org.kie.workbench.common.services.datamodeller.driver.impl.JavaRoasterModelDriver in project kie-wb-common by kiegroup.
the class DataModelerServiceImpl method resolveDefinitionRequest.
@Override
public AnnotationDefinitionResponse resolveDefinitionRequest(AnnotationDefinitionRequest definitionRequest, KieModule kieModule) {
JavaRoasterModelDriver modelDriver = new JavaRoasterModelDriver();
ClassLoader classLoader = classLoaderHelper.getModuleClassLoader(kieModule);
ClassTypeResolver classTypeResolver = DriverUtils.createClassTypeResolver(classLoader);
AnnotationDefinitionResponse definitionResponse = new AnnotationDefinitionResponse();
try {
AnnotationDefinition annotationDefinition = modelDriver.buildAnnotationDefinition(definitionRequest.getClassName(), classTypeResolver);
definitionResponse.withAnnotationDefinition(annotationDefinition);
} catch (ModelDriverException e) {
DriverError driverError = new DriverError(e.getMessage());
definitionResponse.addError(driverError);
}
return definitionResponse;
}
use of org.kie.workbench.common.services.datamodeller.driver.impl.JavaRoasterModelDriver 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);
}
}
use of org.kie.workbench.common.services.datamodeller.driver.impl.JavaRoasterModelDriver in project kie-wb-common by kiegroup.
the class DataModelerServiceImpl method updateDataObject.
/**
* Updates data object provided in the dataObject parameter with the Java code provided in the source parameter.
* This method does not write changes in the file system.
* @param dataObject Data object definition to be updated.
* @param source Java code to use for the update.
* @param path Path to the java file. (used for error messages adf)
* @return returns a GenerationResult object with the updated data object and the source and path parameter as is.
*/
@Override
public GenerationResult updateDataObject(final DataObject dataObject, final String source, final Path path) {
// Resolve the dataobject update in memory
GenerationResult result = new GenerationResult();
KieModule module;
try {
result.setSource(source);
module = moduleService.resolveModule(path);
if (module == null) {
logger.warn("File : " + path.toURI() + " do not belong to a valid module");
result.setSource(source);
return result;
}
ClassLoader classLoader = classLoaderHelper.getModuleClassLoader(module);
JavaRoasterModelDriver modelDriver = new JavaRoasterModelDriver(ioService, Paths.convert(path), classLoader, filterHolder);
ModelDriverResult driverResult = modelDriver.loadDataObject(source, Paths.convert(path));
if (driverResult.hasErrors()) {
result.setErrors(serviceHelper.toDataModelerError(driverResult.getErrors()));
} else {
if (driverResult.getDataModel().getDataObjects().size() > 0) {
result.setDataObject(driverResult.getDataModel().getDataObjects().iterator().next());
}
}
return result;
} catch (Exception e) {
logger.error("Source file for data object: " + dataObject.getClassName() + ", couldn't be parsed", e);
throw new ServiceException("Source file for data object: " + dataObject.getClassName() + ", couldn't be parsed", e);
}
}
use of org.kie.workbench.common.services.datamodeller.driver.impl.JavaRoasterModelDriver in project kie-wb-common by kiegroup.
the class DataModelerServiceImpl method validateValuePair.
@Override
public List<ValidationMessage> validateValuePair(String annotationClassName, ElementType target, String valuePairName, String literalValue) {
// Currently we only validate the syntax but additional checks may be added.
List<ValidationMessage> validationMessages = new ArrayList<ValidationMessage>();
JavaRoasterModelDriver modelDriver = new JavaRoasterModelDriver();
Pair<AnnotationSource<JavaClassSource>, List<DriverError>> parseResult = modelDriver.parseAnnotationWithValuePair(annotationClassName, target, valuePairName, literalValue);
if (parseResult.getK2() != null && parseResult.getK2().size() > 0) {
ValidationMessage validationMessage;
for (DriverError driverError : parseResult.getK2()) {
validationMessage = new ValidationMessage();
validationMessage.setText(driverError.getMessage());
validationMessage.setColumn(driverError.getColumn());
validationMessage.setLine(driverError.getLine());
validationMessage.setLevel(Level.ERROR);
validationMessages.add(validationMessage);
}
}
return validationMessages;
}
Aggregations