use of org.kie.workbench.common.screens.datamodeller.service.ServiceException in project kie-wb-common by kiegroup.
the class DataModelerServiceImpl method updateSource.
/**
* Updates Java code provided in the source parameter with the data object values provided in the dataObject
* parameter. This method does not write any changes in the file system.
* @param source Java code to be updated.
* @param path Path to the java file. (used for error messages adf and project )
* @param dataObject Data object definition.
* @return returns a GenerationResult object with the updated Java code and the dataObject parameter as is.
*/
@Override
public GenerationResult updateSource(final String source, final Path path, final DataObject dataObject) {
GenerationResult result = new GenerationResult();
KieModule module;
try {
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);
Pair<String, List<DataModelerError>> updateResult = updateJavaSource(source, dataObject, new HashMap<String, String>(), new ArrayList<String>(), classLoader);
result.setSource(updateResult.getK1());
result.setDataObject(dataObject);
result.setErrors(updateResult.getK2());
return result;
} catch (Exception e) {
logger.error("Source file for data object: " + dataObject.getClassName() + ", couldn't be updated", e);
throw new ServiceException("Source file for data object: " + dataObject.getClassName() + ", couldn't be updated", e);
}
}
use of org.kie.workbench.common.screens.datamodeller.service.ServiceException in project kie-wb-common by kiegroup.
the class DataModelerServiceImpl method saveModel.
@Override
public GenerationResult saveModel(final DataModel dataModel, final KieModule module, final boolean overwrite, final String commitMessage) {
Long startTime = System.currentTimeMillis();
boolean onBatch = false;
try {
// Start IOService bath processing. IOService batch processing causes a blocking operation on the file system
// to it must be treated carefully.
CommentedOption option = serviceHelper.makeCommentedOption(commitMessage);
ioService.startBatch(Paths.convert(module.getRootPath()).getFileSystem());
onBatch = true;
generateModel(dataModel, module, option);
onBatch = false;
ioService.endBatch();
Long endTime = System.currentTimeMillis();
if (logger.isDebugEnabled()) {
logger.debug("Time elapsed when saving " + module.getModuleName() + ": " + (endTime - startTime) + " ms");
}
GenerationResult result = new GenerationResult();
result.setGenerationTime(endTime - startTime);
return result;
} catch (Exception e) {
logger.error("An error was produced during data model adf, dataModel: " + dataModel + ", path: " + module.getRootPath(), e);
if (onBatch) {
try {
logger.warn("IOService batch method is still on, trying to end batch processing.");
ioService.endBatch();
logger.warn("IOService batch method is was successfully finished. The user will still get the exception, but the batch processing was finished.");
} catch (Exception ex) {
logger.error("An error was produced when the IOService.endBatch processing was executed.", ex);
}
}
throw new ServiceException("Data model couldn't be generated due to the following error. " + e);
}
}
use of org.kie.workbench.common.screens.datamodeller.service.ServiceException in project kie-wb-common by kiegroup.
the class DataModelerServiceImpl method loadDataObject.
public GenerationResult loadDataObject(final Path modulePath, final String source, final Path sourcePath) {
if (logger.isDebugEnabled()) {
logger.debug("Loading data object from modulePath: " + modulePath.toURI());
}
KieModule module;
DataObject dataObject = null;
try {
module = moduleService.resolveModule(modulePath);
if (module == null) {
return new GenerationResult(null, null, new ArrayList<DataModelerError>());
}
ClassLoader classLoader = classLoaderHelper.getModuleClassLoader(module);
JavaRoasterModelDriver modelDriver = new JavaRoasterModelDriver(ioService, null, classLoader, filterHolder);
ModelDriverResult driverResult = modelDriver.loadDataObject(source, Paths.convert(sourcePath));
if (!driverResult.hasErrors()) {
if (driverResult.getDataModel().getDataObjects().size() > 0) {
dataObject = driverResult.getDataModel().getDataObjects().iterator().next();
}
return new GenerationResult(source, dataObject, new ArrayList<DataModelerError>());
} else {
return new GenerationResult(source, null, serviceHelper.toDataModelerError(driverResult.getErrors()));
}
} catch (Exception e) {
logger.error("Data object couldn't be loaded, path: " + modulePath + ", modulePath: " + modulePath + ".", e);
throw new ServiceException("Data object couldn't be loaded, path: " + modulePath + ", modulePath: " + modulePath + ".", e);
}
}
use of org.kie.workbench.common.screens.datamodeller.service.ServiceException 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.screens.datamodeller.service.ServiceException in project kie-wb-common by kiegroup.
the class DataModelerServiceImpl method validate.
@SuppressWarnings("unchecked")
@Override
public List<ValidationMessage> validate(final String source, final Path path, final DataObject dataObject) {
try {
String validationSource = null;
List<ValidationMessage> validations = new ArrayList<ValidationMessage>();
KieModule module = moduleService.resolveModule(path);
if (module == null) {
logger.warn("File : " + path.toURI() + " do not belong to a valid module");
ValidationMessage validationMessage = new ValidationMessage();
validationMessage.setPath(path);
validationMessage.setText("File do no belong to a valid module");
validationMessage.setLevel(Level.ERROR);
validations.add(new ValidationMessage());
return validations;
}
if (dataObject != null) {
// the source needs to be updated with the DataObject definition prior to validation calculation.
// we must to the same processing as if the file was about to be saved.
GenerationResult result = updateSource(source, path, dataObject);
if (!result.hasErrors()) {
validationSource = result.getSource();
} else {
// it was not possible to update the source with the data object definition.
return serviceHelper.toValidationMessage(result.getErrors());
}
} else {
validationSource = source;
}
return genericValidator.validate(path, validationSource != null ? validationSource : "");
} catch (Exception e) {
logger.error("An error was produced during validation", e);
throw new ServiceException("An error was produced during validation", e);
}
}
Aggregations