Search in sources :

Example 6 with DataModelerError

use of org.kie.workbench.common.screens.datamodeller.model.DataModelerError in project kie-wb-common by kiegroup.

the class DataModelerServiceImpl method updateJavaSource.

private Pair<String, List<DataModelerError>> updateJavaSource(String originalSource, DataObject dataObject, Map<String, String> renames, List<String> deletions, ClassLoader classLoader) throws Exception {
    String newSource;
    ClassTypeResolver classTypeResolver;
    List<DataModelerError> errors = new ArrayList<DataModelerError>();
    if (logger.isDebugEnabled()) {
        logger.debug("Starting java source update for class: " + dataObject.getClassName());
    }
    if (logger.isDebugEnabled()) {
        logger.debug("original source is: " + originalSource);
    }
    JavaType<?> javaType = Roaster.parse(originalSource);
    if (javaType.isClass()) {
        if (javaType.getSyntaxErrors() != null && !javaType.getSyntaxErrors().isEmpty()) {
            // if a file has parsing errors it will be skipped.
            errors.addAll(serviceHelper.toDataModelerError(javaType.getSyntaxErrors(), null));
            newSource = originalSource;
        } else {
            JavaClassSource javaClassSource = (JavaClassSource) javaType;
            classTypeResolver = DriverUtils.createClassTypeResolver(javaClassSource, classLoader);
            updateJavaClassSource(dataObject, javaClassSource, renames, deletions, classTypeResolver);
            newSource = javaClassSource.toString();
        }
    } else {
        logger.debug("No Class definition was found for source: " + originalSource + ", original source won't be modified.");
        newSource = originalSource;
    }
    if (logger.isDebugEnabled()) {
        logger.debug("updated source is: " + newSource);
    }
    return new Pair<String, List<DataModelerError>>(newSource, errors);
}
Also used : DataModelerError(org.kie.workbench.common.screens.datamodeller.model.DataModelerError) ArrayList(java.util.ArrayList) JavaClassSource(org.jboss.forge.roaster.model.source.JavaClassSource) ClassTypeResolver(org.kie.soup.project.datamodel.commons.types.ClassTypeResolver) Pair(org.uberfire.commons.data.Pair)

Example 7 with DataModelerError

use of org.kie.workbench.common.screens.datamodeller.model.DataModelerError in project kie-wb-common by kiegroup.

the class DataModelerServiceHelper method toDataModelerError.

public List<DataModelerError> toDataModelerError(final List<SyntaxError> syntaxErrors, final Path file) {
    final List<DataModelerError> errors = new ArrayList<>();
    DataModelerError error;
    for (SyntaxError syntaxError : syntaxErrors) {
        error = new DataModelerError(syntaxError.getDescription(), syntaxError.isError() ? Level.ERROR : Level.WARNING, Paths.convert(file));
        error.setColumn(syntaxError.getColumn());
        error.setLine(syntaxError.getLine());
        errors.add(error);
    }
    return errors;
}
Also used : DataModelerError(org.kie.workbench.common.screens.datamodeller.model.DataModelerError) SyntaxError(org.jboss.forge.roaster.model.SyntaxError) ArrayList(java.util.ArrayList)

Example 8 with DataModelerError

use of org.kie.workbench.common.screens.datamodeller.model.DataModelerError in project kie-wb-common by kiegroup.

the class DataModelerServiceHelper method toDataModelerError.

public List<DataModelerError> toDataModelerError(List<DriverError> errors) {
    final List<DataModelerError> result = new ArrayList<>();
    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 9 with DataModelerError

use of org.kie.workbench.common.screens.datamodeller.model.DataModelerError in project kie-wb-common by kiegroup.

the class DataModelerScreenPresenter method publishSystemMessages.

private void publishSystemMessages(String messageType, boolean cleanExisting, List<DataModelerError> errors) {
    PublishBatchMessagesEvent publishMessage = new PublishBatchMessagesEvent();
    publishMessage.setCleanExisting(cleanExisting);
    publishMessage.setMessageType(messageType);
    publishMessage.setUserId((sessionInfo != null && sessionInfo.getIdentity() != null) ? sessionInfo.getIdentity().getIdentifier() : null);
    publishMessage.setPlace(PublishBaseEvent.Place.TOP);
    SystemMessage systemMessage;
    for (DataModelerError error : errors) {
        systemMessage = new SystemMessage();
        systemMessage.setMessageType(messageType);
        systemMessage.setId(error.getId());
        systemMessage.setText(error.getMessage());
        systemMessage.setPath(error.getFile());
        systemMessage.setLevel(error.getLevel());
        systemMessage.setLine(error.getLine());
        systemMessage.setColumn(error.getColumn());
        publishMessage.getMessagesToPublish().add(systemMessage);
    }
    if (workbenchContext.getActiveModule().isPresent()) {
        publishMessage.setRootPath(workbenchContext.getActiveModule().get().getRootPath().toURI());
    }
    publishBatchMessagesEvent.fire(publishMessage);
}
Also used : SystemMessage(org.guvnor.messageconsole.events.SystemMessage) DataModelerError(org.kie.workbench.common.screens.datamodeller.model.DataModelerError) PublishBatchMessagesEvent(org.guvnor.messageconsole.events.PublishBatchMessagesEvent)

Example 10 with DataModelerError

use of org.kie.workbench.common.screens.datamodeller.model.DataModelerError in project kie-wb-common by kiegroup.

the class DataModelerScreenPresenterTestBase method createTestErrors.

protected List<DataModelerError> createTestErrors() {
    List<DataModelerError> errors = new ArrayList<DataModelerError>();
    errors.add(new DataModelerError(1, "error1", Level.ERROR, path, 1, 0));
    errors.add(new DataModelerError(2, "error2", Level.ERROR, path, 2, 0));
    errors.add(new DataModelerError(3, "error3", Level.ERROR, path, 3, 0));
    return errors;
}
Also used : DataModelerError(org.kie.workbench.common.screens.datamodeller.model.DataModelerError) ArrayList(java.util.ArrayList)

Aggregations

DataModelerError (org.kie.workbench.common.screens.datamodeller.model.DataModelerError)10 ArrayList (java.util.ArrayList)8 Test (org.junit.Test)3 ValidationMessage (org.guvnor.common.services.shared.validation.model.ValidationMessage)2 SyntaxError (org.jboss.forge.roaster.model.SyntaxError)2 DriverError (org.kie.workbench.common.services.datamodeller.driver.model.DriverError)2 Level (org.guvnor.common.services.shared.message.Level)1 PublishBatchMessagesEvent (org.guvnor.messageconsole.events.PublishBatchMessagesEvent)1 SystemMessage (org.guvnor.messageconsole.events.SystemMessage)1 JavaClassSource (org.jboss.forge.roaster.model.source.JavaClassSource)1 ClassTypeResolver (org.kie.soup.project.datamodel.commons.types.ClassTypeResolver)1 GenerationResult (org.kie.workbench.common.screens.datamodeller.model.GenerationResult)1 ServiceException (org.kie.workbench.common.screens.datamodeller.service.ServiceException)1 DataObject (org.kie.workbench.common.services.datamodeller.core.DataObject)1 ModelDriverException (org.kie.workbench.common.services.datamodeller.driver.ModelDriverException)1 JavaRoasterModelDriver (org.kie.workbench.common.services.datamodeller.driver.impl.JavaRoasterModelDriver)1 ModelDriverResult (org.kie.workbench.common.services.datamodeller.driver.model.ModelDriverResult)1 KieModule (org.kie.workbench.common.services.shared.project.KieModule)1 Pair (org.uberfire.commons.data.Pair)1 FileAlreadyExistsException (org.uberfire.java.nio.file.FileAlreadyExistsException)1