Search in sources :

Example 11 with DriverError

use of org.kie.workbench.common.services.datamodeller.driver.model.DriverError in project kie-wb-common by kiegroup.

the class JavaRoasterModelDriver method loadDataObject.

public ModelDriverResult loadDataObject(final String source, final Path path) throws ModelDriverException {
    ModelDriverResult result = new ModelDriverResult();
    DataModel dataModel = createModel();
    result.setDataModel(dataModel);
    if (source == null || "".equals(source)) {
        logger.debug("source: " + source + " is empty.");
        result.addError(new DriverError("Source is empty", Paths.convert(path)));
        return result;
    }
    try {
        JavaType<?> javaType = Roaster.parse(source);
        if (javaType.isClass()) {
            if (javaType.getSyntaxErrors() != null && !javaType.getSyntaxErrors().isEmpty()) {
                // if a file has parsing errors it will be skipped.
                addSyntaxErrors(result, path, javaType.getSyntaxErrors());
            } else {
                try {
                    // try to load the data object.
                    Pair<DataObject, List<ObjectProperty>> pair = parseDataObject((JavaClassSource) javaType);
                    dataModel.addDataObject(pair.getK1());
                    result.setClassPath(pair.getK1().getClassName(), Paths.convert(path));
                    result.setUnmanagedProperties(pair.getK1().getClassName(), pair.getK2());
                } catch (ModelDriverException e) {
                    logger.error("An error was produced when source: " + source + " was being loaded into a DataObject.", e);
                    addModelDriverError(result, path, e);
                }
            }
        } else {
            logger.debug("No Class definition was found for source: " + source + ", it will be skipped.");
        }
    } catch (ParserException e) {
        result.addError(new DriverError(e.getMessage(), Paths.convert(path)));
    } catch (Exception e) {
        // Unexpected exception.
        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 : ParserException(org.jboss.forge.roaster.ParserException) DataObject(org.kie.workbench.common.services.datamodeller.core.DataObject) DataModel(org.kie.workbench.common.services.datamodeller.core.DataModel) List(java.util.List) ArrayList(java.util.ArrayList) ModelDriverResult(org.kie.workbench.common.services.datamodeller.driver.model.ModelDriverResult) 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)

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