Search in sources :

Example 1 with DataModelerError

use of org.kie.workbench.common.screens.datamodeller.model.DataModelerError 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 2 with DataModelerError

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

the class DataModelerServiceHelperTest method testToDataModelerErrorFromSyntaxError.

@Test
public void testToDataModelerErrorFromSyntaxError() {
    ArrayList<SyntaxError> syntaxErrors = new ArrayList<>();
    SyntaxError syntaxError;
    org.uberfire.java.nio.file.Path path = testRootPath.resolve(JAVA_FILE_FOR_ERRORS_TEST);
    for (int i = 0; i < 10; i++) {
        syntaxError = mock(SyntaxError.class);
        when(syntaxError.getDescription()).thenReturn("message" + i);
        if (i % 2 == 0) {
            when(syntaxError.isError()).thenReturn(true);
        } else {
            when(syntaxError.isError()).thenReturn(false);
        }
        when(syntaxError.getLine()).thenReturn(i);
        when(syntaxError.getColumn()).thenReturn(i);
        syntaxErrors.add(syntaxError);
    }
    List<DataModelerError> result = serviceHelper.toDataModelerError(syntaxErrors, path);
    assertEquals(syntaxErrors.size(), result.size());
    for (int i = 0; i < syntaxErrors.size(); i++) {
        assertErrorEquals(syntaxErrors.get(i), result.get(i), Paths.convert(path));
    }
}
Also used : DataModelerError(org.kie.workbench.common.screens.datamodeller.model.DataModelerError) SyntaxError(org.jboss.forge.roaster.model.SyntaxError) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 3 with DataModelerError

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

the class DataModelerServiceHelperTest method testToDataModelerErrorFromDriverError.

@Test
public void testToDataModelerErrorFromDriverError() {
    ArrayList<DriverError> driverErrors = new ArrayList<>();
    for (int i = 0; i < 10; i++) {
        driverErrors.add(new DriverError(i, "message" + i, mock(Path.class), i, i));
    }
    List<DataModelerError> result = serviceHelper.toDataModelerError(driverErrors);
    assertEquals(driverErrors.size(), result.size());
    for (int i = 0; i < driverErrors.size(); i++) {
        assertErrorEquals(driverErrors.get(i), result.get(i));
    }
}
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) Test(org.junit.Test)

Example 4 with DataModelerError

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

the class DataModelerServiceHelperTest method testToValidationMessageFromDataModelerError.

@Test
public void testToValidationMessageFromDataModelerError() {
    ArrayList<DataModelerError> dataModelerErrors = new ArrayList<>();
    DataModelerError dataModelerError;
    Level level;
    for (int i = 0; i < 10; i++) {
        level = Level.values()[i % 3];
        dataModelerError = new DataModelerError(i, "message" + i, level, mock(Path.class), i, i);
        dataModelerErrors.add(dataModelerError);
    }
    List<ValidationMessage> result = serviceHelper.toValidationMessage(dataModelerErrors);
    assertEquals(dataModelerErrors.size(), result.size());
    for (int i = 0; i < dataModelerErrors.size(); i++) {
        assertErrorEquals(dataModelerErrors.get(i), result.get(i));
    }
}
Also used : DataModelerError(org.kie.workbench.common.screens.datamodeller.model.DataModelerError) ValidationMessage(org.guvnor.common.services.shared.validation.model.ValidationMessage) ArrayList(java.util.ArrayList) Level(org.guvnor.common.services.shared.message.Level) Test(org.junit.Test)

Example 5 with DataModelerError

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

the class DataModelerServiceHelper method toValidationMessage.

public List<ValidationMessage> toValidationMessage(final List<DataModelerError> errors) {
    final List<ValidationMessage> validationMessages = new ArrayList<>();
    ValidationMessage validationMessage;
    if (errors == null) {
        return validationMessages;
    }
    for (DataModelerError error : errors) {
        validationMessage = new ValidationMessage();
        validationMessage.setPath(error.getFile());
        validationMessage.setText(error.getMessage());
        validationMessage.setColumn(error.getColumn());
        validationMessage.setLine(error.getLine());
        validationMessage.setId(error.getId());
        if (error.getLevel() != null) {
            validationMessage.setLevel(error.getLevel());
        }
        validationMessages.add(validationMessage);
    }
    return validationMessages;
}
Also used : DataModelerError(org.kie.workbench.common.screens.datamodeller.model.DataModelerError) ValidationMessage(org.guvnor.common.services.shared.validation.model.ValidationMessage) 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