Search in sources :

Example 1 with ServiceException

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);
    }
}
Also used : ServiceException(org.kie.workbench.common.screens.datamodeller.service.ServiceException) GenerationResult(org.kie.workbench.common.screens.datamodeller.model.GenerationResult) List(java.util.List) ArrayList(java.util.ArrayList) KieModule(org.kie.workbench.common.services.shared.project.KieModule) 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 2 with ServiceException

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);
    }
}
Also used : ServiceException(org.kie.workbench.common.screens.datamodeller.service.ServiceException) CommentedOption(org.uberfire.java.nio.base.options.CommentedOption) GenerationResult(org.kie.workbench.common.screens.datamodeller.model.GenerationResult) 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 3 with ServiceException

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);
    }
}
Also used : DataModelerError(org.kie.workbench.common.screens.datamodeller.model.DataModelerError) DataObject(org.kie.workbench.common.services.datamodeller.core.DataObject) 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 4 with ServiceException

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);
    }
}
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 5 with ServiceException

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);
    }
}
Also used : ValidationMessage(org.guvnor.common.services.shared.validation.model.ValidationMessage) ServiceException(org.kie.workbench.common.screens.datamodeller.service.ServiceException) GenerationResult(org.kie.workbench.common.screens.datamodeller.model.GenerationResult) ArrayList(java.util.ArrayList) KieModule(org.kie.workbench.common.services.shared.project.KieModule) 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)

Aggregations

ServiceException (org.kie.workbench.common.screens.datamodeller.service.ServiceException)13 ModelDriverException (org.kie.workbench.common.services.datamodeller.driver.ModelDriverException)13 FileAlreadyExistsException (org.uberfire.java.nio.file.FileAlreadyExistsException)12 KieModule (org.kie.workbench.common.services.shared.project.KieModule)8 GenerationResult (org.kie.workbench.common.screens.datamodeller.model.GenerationResult)7 JavaRoasterModelDriver (org.kie.workbench.common.services.datamodeller.driver.impl.JavaRoasterModelDriver)6 ModelDriverResult (org.kie.workbench.common.services.datamodeller.driver.model.ModelDriverResult)6 Package (org.guvnor.common.services.project.model.Package)3 DataObject (org.kie.workbench.common.services.datamodeller.core.DataObject)3 Path (org.uberfire.backend.vfs.Path)3 ArrayList (java.util.ArrayList)2 DataModel (org.kie.workbench.common.services.datamodeller.core.DataModel)2 DataObjectImpl (org.kie.workbench.common.services.datamodeller.core.impl.DataObjectImpl)2 ModelDriver (org.kie.workbench.common.services.datamodeller.driver.ModelDriver)2 List (java.util.List)1 ValidationMessage (org.guvnor.common.services.shared.validation.model.ValidationMessage)1 Test (org.junit.Test)1 ModuleDataModelOracle (org.kie.soup.project.datamodel.oracle.ModuleDataModelOracle)1 FormGenerationResult (org.kie.workbench.common.forms.jbpm.server.service.formGeneration.FormGenerationResult)1 FormDefinition (org.kie.workbench.common.forms.model.FormDefinition)1