use of org.openforis.collect.io.metadata.parsing.ParsingError in project collect by openforis.
the class CSVDataImportJobIntegrationTest method invalidHeaderTest.
@Test
public void invalidHeaderTest() throws Exception {
EntityDefinition clusterDefn = survey.getSchema().getRootEntityDefinition("cluster");
EntityDefinition plotDefn = (EntityDefinition) clusterDefn.getChildDefinition("plot");
CSVDataImportJob process = importCSVFile(INVALID_HEADER_TEST_CSV, plotDefn.getId());
assertFalse(process.isCompleted());
assertTrue(process.isFailed());
List<DataParsingError> errors = process.getParsingErrors();
assertEquals(1, errors.size());
ParsingError headerError = errors.get(0);
assertEquals(ErrorType.WRONG_COLUMN_NAME, headerError.getErrorType());
assertTrue(Arrays.equals(new String[] { "land_usage" }, headerError.getColumns()));
}
use of org.openforis.collect.io.metadata.parsing.ParsingError in project collect by openforis.
the class CSVDataImportProcessIntegrationTest method singleEntityTest.
@Test
public void singleEntityTest() throws Exception {
{
CollectRecord record = createTestRecord(survey, "10_114");
recordDao.insert(record);
}
EntityDefinition clusterDefn = survey.getSchema().getRootEntityDefinition("cluster");
EntityDefinition plotDefn = (EntityDefinition) clusterDefn.getChildDefinition("plot");
CSVDataImportProcess process = importCSVFile(VALID_SINGLE_ENTITY_TEST_CSV, plotDefn.getId());
ReferenceDataImportStatus<ParsingError> status = process.getStatus();
assertTrue(status.isComplete());
assertTrue(status.getSkippedRows().isEmpty());
assertEquals(3, status.getProcessed());
{
CollectRecord reloadedRecord = loadRecord("10_114");
Entity reloadedCluster = reloadedRecord.getRootEntity();
{
Entity plot = reloadedCluster.findChildEntitiesByKeys("plot", "1", "A").get(0);
Entity timeStudy = (Entity) plot.getChild("time_study");
DateAttribute date = (DateAttribute) timeStudy.getChild("date");
assertEquals(new Date(2012, 2, 15), date.getValue());
}
{
Entity plot = reloadedCluster.findChildEntitiesByKeys("plot", "2", "B").get(0);
Entity timeStudy = (Entity) plot.getChild("time_study");
DateAttribute date = (DateAttribute) timeStudy.getChild("date");
assertEquals(new Date(2013, 5, 18), date.getValue());
}
}
}
use of org.openforis.collect.io.metadata.parsing.ParsingError in project collect by openforis.
the class CSVDataImportProcessIntegrationTest method nestedEntityTest.
@Test
public void nestedEntityTest() throws Exception {
CollectRecord record = createTestRecord(survey, "10_114");
recordDao.insert(record);
EntityDefinition clusterDefn = survey.getSchema().getRootEntityDefinition("cluster");
EntityDefinition plotDefn = (EntityDefinition) clusterDefn.getChildDefinition("plot");
CSVDataImportProcess process = importCSVFile(VALID_NESTED_ENTITY_TEST_CSV, plotDefn.getId());
ReferenceDataImportStatus<ParsingError> status = process.getStatus();
assertTrue(status.isComplete());
assertTrue(status.getSkippedRows().isEmpty());
assertEquals(3, status.getProcessed());
CollectRecord reloadedRecord = recordDao.load(survey, record.getId(), Step.ENTRY);
Entity reloadedCluster = reloadedRecord.getRootEntity();
{
Entity plot = reloadedCluster.findChildEntitiesByKeys("plot", "1", "A").get(0);
CodeAttribute landUse = (CodeAttribute) plot.getChild("land_use");
assertEquals("2", landUse.getValue().getCode());
}
{
Entity plot = reloadedCluster.findChildEntitiesByKeys("plot", "2", "B").get(0);
CodeAttribute landUse = (CodeAttribute) plot.getChild("land_use");
assertEquals("3", landUse.getValue().getCode());
}
}
use of org.openforis.collect.io.metadata.parsing.ParsingError in project collect by openforis.
the class CSVDataImportProcessIntegrationTest 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");
CSVDataImportProcess process = importCSVFile(INVALID_VALUES_TEST_CSV, clusterDefn.getId());
ReferenceDataImportStatus<ParsingError> status = process.getStatus();
assertFalse(status.isComplete());
assertTrue(status.isError());
List<ParsingError> errors = status.getErrors();
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 SamplingDesignImportProcessIntegrationTest method containsError.
protected boolean containsError(List<ParsingError> errors, long row, SamplingDesignFileColumn[] columns, ErrorType type) {
String[] colNames = new String[columns.length];
for (int i = 0; i < columns.length; i++) {
SamplingDesignFileColumn col = columns[i];
colNames[i] = col.getColumnName();
}
for (ParsingError error : errors) {
if (error.getErrorType() == type && error.getRow() == row && Arrays.equals(colNames, error.getColumns())) {
return true;
}
}
return false;
}
Aggregations