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