use of org.kie.workbench.common.services.datamodeller.driver.model.DriverError 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;
}
use of org.kie.workbench.common.services.datamodeller.driver.model.DriverError in project kie-wb-common by kiegroup.
the class DataModelerServiceHelper method toDataModelerError.
public List<DataModelerError> toDataModelerError(List<DriverError> errors) {
List<DataModelerError> result = new ArrayList<DataModelerError>();
if (errors == null) {
return result;
}
for (DriverError error : errors) {
DataModelerError dataModelerError = new DataModelerError(error.getId(), error.getMessage(), Level.ERROR, error.getFile(), error.getLine(), error.getColumn());
result.add(dataModelerError);
}
return result;
}
use of org.kie.workbench.common.services.datamodeller.driver.model.DriverError in project kie-wb-common by kiegroup.
the class DataModelerServiceImpl method processErrors.
private void processErrors(KieModule module, ModelDriverResult result) {
PublishBatchMessagesEvent publishEvent = new PublishBatchMessagesEvent();
publishEvent.setCleanExisting(true);
publishEvent.setUserId(identity != null ? identity.getIdentifier() : null);
publishEvent.setMessageType("DataModeler");
SystemMessage systemMessage;
for (DriverError error : result.getErrors()) {
systemMessage = new SystemMessage();
systemMessage.setMessageType("DataModeler");
systemMessage.setLevel(Level.ERROR);
systemMessage.setId(error.getId());
systemMessage.setText(error.getMessage());
systemMessage.setColumn(error.getColumn());
systemMessage.setLine(error.getLine());
systemMessage.setPath(error.getFile());
publishEvent.getMessagesToPublish().add(systemMessage);
}
publishBatchMessagesEvent.fire(publishEvent);
}
use of org.kie.workbench.common.services.datamodeller.driver.model.DriverError in project kie-wb-common by kiegroup.
the class JavaRoasterModelDriver method loadModel.
@Override
public ModelDriverResult loadModel() throws ModelDriverException {
ModelDriverResult result = new ModelDriverResult();
DataModel dataModel;
String fileContent;
dataModel = createModel();
result.setDataModel(dataModel);
List<Path> rootPaths = new ArrayList<Path>();
rootPaths.add(javaRootPath);
Collection<FileUtils.ScanResult> scanResults = FileUtils.getInstance().scan(ioService, rootPaths, ".java", true);
if (scanResults != null) {
for (FileUtils.ScanResult scanResult : scanResults) {
logger.debug("Starting file loading into model, file: " + scanResult.getFile());
fileContent = ioService.readAllString(scanResult.getFile());
if (fileContent == null || "".equals(fileContent)) {
logger.debug("file: " + scanResult.getFile() + " is empty.");
result.addError(new DriverError("File has no content", Paths.convert(scanResult.getFile())));
continue;
}
try {
JavaType<?> javaType = Roaster.parse(fileContent);
final boolean isManaged = isManagedJavaType(javaType);
final boolean vetoed = (isManaged ? isVetoed(javaType) : false);
if (isManaged && !vetoed) {
if (javaType.getSyntaxErrors() != null && !javaType.getSyntaxErrors().isEmpty()) {
// if a file has parsing errors it will be skipped.
addSyntaxErrors(result, scanResult.getFile(), javaType.getSyntaxErrors());
} else if (javaType.isEnum()) {
loadFromJavaEnum((JavaEnumSource) javaType, scanResult.getFile(), dataModel, result);
} else {
loadFromJavaClass((JavaClassSource) javaType, scanResult.getFile(), dataModel, result);
}
} else if (vetoed) {
logger.debug("The class, {}, in the file, {}, was vetoed and will be skipped.", javaType.getQualifiedName(), scanResult.getFile());
} else {
logger.debug("File: " + scanResult.getFile() + " do not contain a managed java type, it will be skipped.");
}
} catch (ParserException e) {
result.addError(new DriverError(e.getMessage(), Paths.convert(scanResult.getFile())));
} catch (Exception e) {
// Unexpected error.
logger.error(errorMessage(MODEL_LOAD_GENERIC_ERROR, javaRootPath.toUri()), e);
throw new ModelDriverException(errorMessage(MODEL_LOAD_GENERIC_ERROR, javaRootPath.toUri()), e);
}
}
}
return result;
}
use of org.kie.workbench.common.services.datamodeller.driver.model.DriverError in project kie-wb-common by kiegroup.
the class JavaRoasterModelDriver method parseAnnotationWithValuePair.
public Pair<Annotation, List<DriverError>> parseAnnotationWithValuePair(String annotationClassName, ElementType target, String valuePairName, String literalValue, ClassLoader classLoader) {
List<DriverError> driverErrors = new ArrayList<DriverError>();
Annotation annotation = null;
Pair<AnnotationSource<JavaClassSource>, List<DriverError>> parseResult = parseAnnotationWithValuePair(annotationClassName, target, valuePairName, literalValue);
driverErrors.addAll(parseResult.getK2());
if (driverErrors.size() == 0) {
// TODO review this, we should use DriverUtils.createClassTypeResolver( javaClassSource, classLoader ); instead
ClassTypeResolver classTypeResolver = new ClassTypeResolver(Collections.emptySet(), classLoader);
try {
annotation = createAnnotation(parseResult.getK1(), classTypeResolver);
} catch (Exception e) {
driverErrors.add(new DriverError(e.getMessage()));
}
}
return new Pair<>(annotation, driverErrors);
}
Aggregations