use of org.openforis.collect.io.metadata.parsing.ParsingError in project collect by openforis.
the class CSVDataImportProcessIntegrationTest method validEntityPositionTest.
@Test
public void validEntityPositionTest() 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");
EntityDefinition timeStudyDefn = clusterDefn.getChildDefinition("time_study", EntityDefinition.class);
CSVDataImportProcess process = importCSVFile(VALID_ENTITY_POSITION_TEST_CSV, timeStudyDefn.getId());
ReferenceDataImportStatus<ParsingError> status = process.getStatus();
assertTrue(status.isComplete());
assertTrue(status.getSkippedRows().isEmpty());
assertEquals(3, status.getProcessed());
{
CollectRecord reloadedRecord = loadRecord("10_111");
Entity cluster = reloadedRecord.getRootEntity();
{
Entity timeStudy = (Entity) cluster.getChild("time_study", 0);
DateAttribute date = (DateAttribute) timeStudy.getChild("date");
Date dateVal = date.getValue();
assertEquals(Integer.valueOf(2013), dateVal.getYear());
assertEquals(Integer.valueOf(2), dateVal.getMonth());
assertEquals(Integer.valueOf(24), dateVal.getDay());
}
{
Entity timeStudy = (Entity) cluster.getChild("time_study", 1);
DateAttribute date = (DateAttribute) timeStudy.getChild("date");
Date dateVal = date.getValue();
assertEquals(Integer.valueOf(2013), dateVal.getYear());
assertEquals(Integer.valueOf(3), dateVal.getMonth());
assertEquals(Integer.valueOf(15), dateVal.getDay());
}
}
}
use of org.openforis.collect.io.metadata.parsing.ParsingError in project collect by openforis.
the class CSVDataImportProcessIntegrationTest method validTest.
@Test
public void validTest() throws Exception {
{
CollectRecord record = createTestRecord(survey, "10_111");
recordDao.insert(record);
assertEquals(Integer.valueOf(0), record.getErrors());
}
{
CollectRecord record = createTestRecord(survey, "10_114");
recordDao.insert(record);
}
EntityDefinition clusterDefn = survey.getSchema().getRootEntityDefinition("cluster");
CSVDataImportProcess process = importCSVFile(VALID_TEST_CSV, clusterDefn.getId());
ReferenceDataImportStatus<ParsingError> status = process.getStatus();
assertTrue(status.isComplete());
assertTrue(status.getSkippedRows().isEmpty());
assertEquals(3, status.getProcessed());
{
CollectRecord reloadedRecord = loadRecord("10_111");
assertEquals(Integer.valueOf(1), reloadedRecord.getErrors());
Entity cluster = reloadedRecord.getRootEntity();
RealAttribute plotDirection = (RealAttribute) cluster.getChild("plot_direction");
RealValue plotDirectionVal = plotDirection.getValue();
assertEquals(Double.valueOf(50d), plotDirectionVal.getValue());
RealAttribute plotDistance = (RealAttribute) cluster.getChild("plot_distance");
RealValue plotDistanceVal = plotDistance.getValue();
assertEquals(Double.valueOf(200d), plotDistanceVal.getValue());
assertEquals(meterUnit, plotDistanceVal.getUnit());
TextAttribute gpsModel = (TextAttribute) cluster.getChild("gps_model");
assertEquals("GPS MAP 62S", gpsModel.getValue().getValue());
assertEquals(2, cluster.getCount("map_sheet"));
{
TextAttribute mapSheet = (TextAttribute) cluster.getChild("map_sheet", 0);
assertEquals("new map sheet 1", mapSheet.getValue().getValue());
}
{
TextAttribute mapSheet = (TextAttribute) cluster.getChild("map_sheet", 1);
assertEquals("new map sheet 2", mapSheet.getValue().getValue());
}
}
{
CollectRecord reloadedRecord = loadRecord("10_114");
Entity cluster = reloadedRecord.getRootEntity();
RealAttribute plotDirection = (RealAttribute) cluster.getChild("plot_direction");
RealValue plotDirectionVal = plotDirection.getValue();
assertEquals(Double.valueOf(40d), plotDirectionVal.getValue());
RealAttribute plotDistance = (RealAttribute) cluster.getChild("plot_distance");
RealValue plotDistanceVal = plotDistance.getValue();
assertEquals(Double.valueOf(0.3d), plotDistanceVal.getValue());
assertEquals(kilometerUnit, plotDistanceVal.getUnit());
TextAttribute gpsModel = (TextAttribute) cluster.getChild("gps_model");
assertEquals("GPS MAP 62S", gpsModel.getValue().getValue());
}
}
use of org.openforis.collect.io.metadata.parsing.ParsingError in project collect by openforis.
the class CodeListImportTask method addDifferentLabelError.
private void addDifferentLabelError(CodeListLine line, int levelIdx, String lang) {
String level = levels.get(levelIdx);
String column = level + CodeListCSVReader.LABEL_COLUMN_SUFFIX + "_" + lang;
long lineNumber = line.getLineNumber();
ParsingError error = new ParsingError(ErrorType.INVALID_VALUE, lineNumber, column, DIFFERENT_LABEL_MESSAGE_KEY);
addParsingError(lineNumber, error);
}
use of org.openforis.collect.io.metadata.parsing.ParsingError in project collect by openforis.
the class CodeListImportProcess method addDuplicateCodeError.
protected void addDuplicateCodeError(CodeListLine line, int levelIdx) {
String level = levels.get(levelIdx);
String column = level + CodeListCSVReader.CODE_COLUMN_SUFFIX;
long lineNumber = line.getLineNumber();
ParsingError error = new ParsingError(ErrorType.DUPLICATE_VALUE, lineNumber, column);
status.addParsingError(lineNumber, error);
}
use of org.openforis.collect.io.metadata.parsing.ParsingError in project collect by openforis.
the class SamplingDesignImportProcess 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