use of org.openforis.collect.io.metadata.parsing.ParsingError in project collect by openforis.
the class SamplingDesignImportProcessIntegrationTest method testInvalidData.
@Test
public void testInvalidData() throws Exception {
SamplingDesignImportProcess process = importCSVFile(INVALID_TEST_CSV);
SamplingDesignImportStatus status = process.getStatus();
assertTrue(status.isError());
List<ParsingError> errors = status.getErrors();
assertEquals(6, errors.size());
assertTrue(containsError(errors, 3, SamplingDesignFileColumn.LEVEL_2, ErrorType.DUPLICATE_VALUE));
assertTrue(containsError(errors, 4, SamplingDesignFileColumn.LEVEL_2, ErrorType.DUPLICATE_VALUE));
assertTrue(containsError(errors, 14, SamplingDesignFileColumn.LEVEL_2, ErrorType.EMPTY));
assertTrue(containsError(errors, 17, SamplingDesignFileColumn.LEVEL_1, ErrorType.EMPTY));
assertTrue(containsError(errors, 22, SamplingDesignFileColumn.X, ErrorType.EMPTY));
assertTrue(containsError(errors, 23, SamplingDesignFileColumn.Y, ErrorType.EMPTY));
}
use of org.openforis.collect.io.metadata.parsing.ParsingError in project collect by openforis.
the class CSVDataImportJobIntegrationTest method invalidValuesTest.
@Test
public void invalidValuesTest() throws Exception {
{
CollectRecord record = createTestRecord(survey, "10_111");
recordDao.insert(record);
}
{
CollectRecord record = createTestRecord(survey, "10_114");
recordDao.insert(record);
}
EntityDefinition clusterDefn = survey.getSchema().getRootEntityDefinition("cluster");
CSVDataImportJob process = importCSVFile(INVALID_VALUES_TEST_CSV, clusterDefn.getId());
assertFalse(process.isCompleted());
assertTrue(process.isFailed());
List<DataParsingError> errors = process.getParsingErrors();
assertEquals(4, errors.size());
{
ParsingError error = errors.get(0);
assertEquals(2, error.getRow());
assertEquals(ErrorType.INVALID_VALUE, error.getErrorType());
assertTrue(Arrays.equals(new String[] { "vehicle_location_srs" }, error.getColumns()));
}
{
ParsingError error = errors.get(1);
assertEquals(4, error.getRow());
assertEquals(ErrorType.INVALID_VALUE, error.getErrorType());
assertTrue(Arrays.equals(new String[] { "vehicle_location_x" }, error.getColumns()));
}
{
ParsingError error = errors.get(2);
assertEquals(4, error.getRow());
assertEquals(ErrorType.INVALID_VALUE, error.getErrorType());
assertTrue(Arrays.equals(new String[] { "plot_distance" }, error.getColumns()));
}
{
ParsingError error = errors.get(3);
assertEquals(5, error.getRow());
assertEquals(ErrorType.INVALID_VALUE, error.getErrorType());
assertTrue(Arrays.equals(new String[] { "vehicle_location_y" }, error.getColumns()));
}
}
use of org.openforis.collect.io.metadata.parsing.ParsingError in project collect by openforis.
the class CSVDataImportJobIntegrationTest method missingRecordTest.
// @Test
// TODO transactional process not working only in test spring context
public void missingRecordTest() throws Exception {
{
CollectRecord record = createTestRecord(survey, "10_111");
recordDao.insert(record);
}
{
CollectRecord record = createTestRecord(survey, "10_114");
recordDao.insert(record);
}
EntityDefinition clusterDefn = survey.getSchema().getRootEntityDefinition("cluster");
CSVDataImportJob process = importCSVFile(MISSING_RECORD_TEST_CSV, clusterDefn.getId());
assertTrue(process.isFailed());
assertEquals(1, process.getParsingErrors().size());
{
ParsingError error = process.getParsingErrors().get(0);
assertEquals(ErrorType.INVALID_VALUE, error.getErrorType());
assertEquals(4, error.getRow());
assertTrue(Arrays.equals(new String[] { "id" }, error.getColumns()));
}
// verify that the transaction is rolled back properly
{
CollectRecord reloadedRecord = loadRecord("10_111");
Entity cluster = reloadedRecord.getRootEntity();
RealAttribute plotDistance = (RealAttribute) cluster.getChild("plot_distance");
RealValue plotDistanceVal = plotDistance.getValue();
assertEquals(Double.valueOf(100d), plotDistanceVal.getValue());
assertEquals(meterUnit, plotDistanceVal.getUnit());
}
{
CollectRecord reloadedRecord = loadRecord("10_114");
Entity cluster = reloadedRecord.getRootEntity();
RealAttribute plotDistance = (RealAttribute) cluster.getChild("plot_distance");
RealValue plotDistanceVal = plotDistance.getValue();
assertEquals(Double.valueOf(100d), plotDistanceVal.getValue());
assertEquals(meterUnit, plotDistanceVal.getUnit());
}
}
use of org.openforis.collect.io.metadata.parsing.ParsingError in project collect by openforis.
the class SamplingDesignImportProcess method processLine.
protected boolean processLine(SamplingDesignLine line) throws ParsingException {
SamplingDesignLineValidator validator = SamplingDesignLineValidator.createInstance(survey);
validator.validate(line);
List<ParsingError> errors = validator.getErrors();
for (ParsingError error : errors) {
status.addParsingError(error);
}
checkDuplicateLine(line);
return true;
}
use of org.openforis.collect.io.metadata.parsing.ParsingError in project collect by openforis.
the class SamplingDesignImportTask method throwDuplicateLineException.
protected void throwDuplicateLineException(SamplingDesignLine line, SamplingDesignLine duplicateLine, SamplingDesignFileColumn[] columns) throws ParsingException {
String[] colNames = new String[columns.length];
for (int i = 0; i < columns.length; i++) {
SamplingDesignFileColumn column = columns[i];
colNames[i] = column.getColumnName();
}
ParsingError error = new ParsingError(ErrorType.DUPLICATE_VALUE, line.getLineNumber(), colNames);
String duplicateLineNumber = Long.toString(duplicateLine.getLineNumber());
error.setMessageArgs(new String[] { duplicateLineNumber });
throw new ParsingException(error);
}
Aggregations