Search in sources :

Example 11 with ParsingError

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());
        }
    }
}
Also used : CollectRecord(org.openforis.collect.model.CollectRecord) EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) Entity(org.openforis.idm.model.Entity) ParsingError(org.openforis.collect.io.metadata.parsing.ParsingError) Date(org.openforis.idm.model.Date) DateAttribute(org.openforis.idm.model.DateAttribute) CollectIntegrationTest(org.openforis.collect.CollectIntegrationTest) Test(org.junit.Test)

Example 12 with ParsingError

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());
    }
}
Also used : RealValue(org.openforis.idm.model.RealValue) CollectRecord(org.openforis.collect.model.CollectRecord) EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) Entity(org.openforis.idm.model.Entity) ParsingError(org.openforis.collect.io.metadata.parsing.ParsingError) RealAttribute(org.openforis.idm.model.RealAttribute) TextAttribute(org.openforis.idm.model.TextAttribute) CollectIntegrationTest(org.openforis.collect.CollectIntegrationTest) Test(org.junit.Test)

Example 13 with ParsingError

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);
}
Also used : ParsingError(org.openforis.collect.io.metadata.parsing.ParsingError)

Example 14 with ParsingError

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);
}
Also used : ParsingError(org.openforis.collect.io.metadata.parsing.ParsingError)

Example 15 with ParsingError

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);
}
Also used : ParsingError(org.openforis.collect.io.metadata.parsing.ParsingError) ParsingException(org.openforis.collect.io.exception.ParsingException)

Aggregations

ParsingError (org.openforis.collect.io.metadata.parsing.ParsingError)46 EntityDefinition (org.openforis.idm.metamodel.EntityDefinition)19 Test (org.junit.Test)17 CollectIntegrationTest (org.openforis.collect.CollectIntegrationTest)17 CollectRecord (org.openforis.collect.model.CollectRecord)12 ParsingException (org.openforis.collect.io.exception.ParsingException)9 Entity (org.openforis.idm.model.Entity)9 CollectSurvey (org.openforis.collect.model.CollectSurvey)5 RealAttribute (org.openforis.idm.model.RealAttribute)5 DataParsingError (org.openforis.collect.io.data.CSVDataImportJob.DataParsingError)4 RealValue (org.openforis.idm.model.RealValue)4 IOException (java.io.IOException)3 NodeChangeSet (org.openforis.collect.model.NodeChangeSet)3 Survey (org.openforis.idm.metamodel.Survey)3 ArrayList (java.util.ArrayList)2 SpeciesImportProcess (org.openforis.collect.manager.speciesimport.SpeciesImportProcess)2 SpeciesImportStatus (org.openforis.collect.manager.speciesimport.SpeciesImportStatus)2 CollectRecordSummary (org.openforis.collect.model.CollectRecordSummary)2 CodeListItem (org.openforis.idm.metamodel.CodeListItem)2 SpatialReferenceSystem (org.openforis.idm.metamodel.SpatialReferenceSystem)2