Search in sources :

Example 6 with DriverError

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;
}
Also used : ValidationMessage(org.guvnor.common.services.shared.validation.model.ValidationMessage) ArrayList(java.util.ArrayList) AnnotationSource(org.jboss.forge.roaster.model.source.AnnotationSource) List(java.util.List) ArrayList(java.util.ArrayList) JavaRoasterModelDriver(org.kie.workbench.common.services.datamodeller.driver.impl.JavaRoasterModelDriver) DriverError(org.kie.workbench.common.services.datamodeller.driver.model.DriverError)

Example 7 with DriverError

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;
}
Also used : DataModelerError(org.kie.workbench.common.screens.datamodeller.model.DataModelerError) ArrayList(java.util.ArrayList) DriverError(org.kie.workbench.common.services.datamodeller.driver.model.DriverError)

Example 8 with DriverError

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);
}
Also used : SystemMessage(org.guvnor.messageconsole.events.SystemMessage) PublishBatchMessagesEvent(org.guvnor.messageconsole.events.PublishBatchMessagesEvent) DriverError(org.kie.workbench.common.services.datamodeller.driver.model.DriverError)

Example 9 with DriverError

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;
}
Also used : Path(org.uberfire.java.nio.file.Path) ParserException(org.jboss.forge.roaster.ParserException) FileUtils(org.kie.workbench.common.services.datamodeller.util.FileUtils) ArrayList(java.util.ArrayList) JavaClassSource(org.jboss.forge.roaster.model.source.JavaClassSource) ModelDriverException(org.kie.workbench.common.services.datamodeller.driver.ModelDriverException) ModelDriverException(org.kie.workbench.common.services.datamodeller.driver.ModelDriverException) IOException(java.io.IOException) ParserException(org.jboss.forge.roaster.ParserException) DriverError(org.kie.workbench.common.services.datamodeller.driver.model.DriverError) DataModel(org.kie.workbench.common.services.datamodeller.core.DataModel) JavaEnumSource(org.jboss.forge.roaster.model.source.JavaEnumSource) ModelDriverResult(org.kie.workbench.common.services.datamodeller.driver.model.ModelDriverResult)

Example 10 with DriverError

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);
}
Also used : ArrayList(java.util.ArrayList) AnnotationSource(org.jboss.forge.roaster.model.source.AnnotationSource) List(java.util.List) ArrayList(java.util.ArrayList) ClassTypeResolver(org.kie.soup.project.datamodel.commons.types.ClassTypeResolver) Annotation(org.kie.workbench.common.services.datamodeller.core.Annotation) ModelDriverException(org.kie.workbench.common.services.datamodeller.driver.ModelDriverException) IOException(java.io.IOException) ParserException(org.jboss.forge.roaster.ParserException) DriverError(org.kie.workbench.common.services.datamodeller.driver.model.DriverError) Pair(org.uberfire.commons.data.Pair)

Aggregations

DriverError (org.kie.workbench.common.services.datamodeller.driver.model.DriverError)11 ArrayList (java.util.ArrayList)6 ModelDriverException (org.kie.workbench.common.services.datamodeller.driver.ModelDriverException)6 IOException (java.io.IOException)4 ParserException (org.jboss.forge.roaster.ParserException)4 List (java.util.List)3 SyntaxError (org.jboss.forge.roaster.model.SyntaxError)2 AnnotationSource (org.jboss.forge.roaster.model.source.AnnotationSource)2 JavaClassSource (org.jboss.forge.roaster.model.source.JavaClassSource)2 ClassTypeResolver (org.kie.soup.project.datamodel.commons.types.ClassTypeResolver)2 DataModel (org.kie.workbench.common.services.datamodeller.core.DataModel)2 JavaRoasterModelDriver (org.kie.workbench.common.services.datamodeller.driver.impl.JavaRoasterModelDriver)2 ModelDriverResult (org.kie.workbench.common.services.datamodeller.driver.model.ModelDriverResult)2 Pair (org.uberfire.commons.data.Pair)2 ValidationMessage (org.guvnor.common.services.shared.validation.model.ValidationMessage)1 PublishBatchMessagesEvent (org.guvnor.messageconsole.events.PublishBatchMessagesEvent)1 SystemMessage (org.guvnor.messageconsole.events.SystemMessage)1 JavaClass (org.jboss.forge.roaster.model.JavaClass)1 JavaEnumSource (org.jboss.forge.roaster.model.source.JavaEnumSource)1 DataModelerError (org.kie.workbench.common.screens.datamodeller.model.DataModelerError)1