Search in sources :

Example 6 with JavaRoasterModelDriver

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);
    }
}
Also used : ServiceException(org.kie.workbench.common.screens.datamodeller.service.ServiceException) TypeInfoResult(org.kie.workbench.common.screens.datamodeller.model.TypeInfoResult) JavaRoasterModelDriver(org.kie.workbench.common.services.datamodeller.driver.impl.JavaRoasterModelDriver) ModelDriverException(org.kie.workbench.common.services.datamodeller.driver.ModelDriverException) ServiceException(org.kie.workbench.common.screens.datamodeller.service.ServiceException) FileAlreadyExistsException(org.uberfire.java.nio.file.FileAlreadyExistsException)

Example 7 with JavaRoasterModelDriver

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;
}
Also used : AnnotationDefinition(org.kie.workbench.common.services.datamodeller.core.AnnotationDefinition) AnnotationDefinitionResponse(org.kie.workbench.common.services.datamodeller.driver.model.AnnotationDefinitionResponse) ModelDriverException(org.kie.workbench.common.services.datamodeller.driver.ModelDriverException) ClassTypeResolver(org.kie.soup.project.datamodel.commons.types.ClassTypeResolver) JavaRoasterModelDriver(org.kie.workbench.common.services.datamodeller.driver.impl.JavaRoasterModelDriver) DriverError(org.kie.workbench.common.services.datamodeller.driver.model.DriverError)

Example 8 with JavaRoasterModelDriver

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);
    }
}
Also used : Path(org.uberfire.backend.vfs.Path) ServiceException(org.kie.workbench.common.screens.datamodeller.service.ServiceException) DataModel(org.kie.workbench.common.services.datamodeller.core.DataModel) JavaRoasterModelDriver(org.kie.workbench.common.services.datamodeller.driver.impl.JavaRoasterModelDriver) ModelDriver(org.kie.workbench.common.services.datamodeller.driver.ModelDriver) ModuleDataModelOracle(org.kie.soup.project.datamodel.oracle.ModuleDataModelOracle) Package(org.guvnor.common.services.project.model.Package) ModelDriverResult(org.kie.workbench.common.services.datamodeller.driver.model.ModelDriverResult) JavaRoasterModelDriver(org.kie.workbench.common.services.datamodeller.driver.impl.JavaRoasterModelDriver) ModelDriverException(org.kie.workbench.common.services.datamodeller.driver.ModelDriverException) ServiceException(org.kie.workbench.common.screens.datamodeller.service.ServiceException) FileAlreadyExistsException(org.uberfire.java.nio.file.FileAlreadyExistsException) Pair(org.uberfire.commons.data.Pair)

Example 9 with JavaRoasterModelDriver

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);
    }
}
Also used : ServiceException(org.kie.workbench.common.screens.datamodeller.service.ServiceException) GenerationResult(org.kie.workbench.common.screens.datamodeller.model.GenerationResult) ModelDriverResult(org.kie.workbench.common.services.datamodeller.driver.model.ModelDriverResult) KieModule(org.kie.workbench.common.services.shared.project.KieModule) JavaRoasterModelDriver(org.kie.workbench.common.services.datamodeller.driver.impl.JavaRoasterModelDriver) ModelDriverException(org.kie.workbench.common.services.datamodeller.driver.ModelDriverException) ServiceException(org.kie.workbench.common.screens.datamodeller.service.ServiceException) FileAlreadyExistsException(org.uberfire.java.nio.file.FileAlreadyExistsException)

Example 10 with JavaRoasterModelDriver

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;
}
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)

Aggregations

JavaRoasterModelDriver (org.kie.workbench.common.services.datamodeller.driver.impl.JavaRoasterModelDriver)22 ModelDriverResult (org.kie.workbench.common.services.datamodeller.driver.model.ModelDriverResult)13 Test (org.junit.Test)11 Path (org.uberfire.java.nio.file.Path)10 ArrayList (java.util.ArrayList)9 List (java.util.List)9 DataObject (org.kie.workbench.common.services.datamodeller.core.DataObject)9 AnnotationDefinition (org.kie.workbench.common.services.datamodeller.core.AnnotationDefinition)8 Entity (javax.persistence.Entity)7 BufferedReader (java.io.BufferedReader)6 File (java.io.File)6 IOException (java.io.IOException)6 InputStream (java.io.InputStream)6 InputStreamReader (java.io.InputStreamReader)6 URI (java.net.URI)6 Arrays (java.util.Arrays)6 Collections (java.util.Collections)6 Matcher (java.util.regex.Matcher)6 Generated (javax.annotation.Generated)6 Instance (javax.enterprise.inject.Instance)6