Search in sources :

Example 6 with ParsingError

use of org.openforis.collect.io.metadata.parsing.ParsingError in project collect by openforis.

the class CSVDataImportProcessIntegrationTest method missingRequiredColumnsTest.

@Test
public void missingRequiredColumnsTest() throws Exception {
    EntityDefinition clusterDefn = survey.getSchema().getRootEntityDefinition("cluster");
    EntityDefinition plotDefn = (EntityDefinition) clusterDefn.getChildDefinition("plot");
    CSVDataImportProcess process = importCSVFile(MISSING_REQUIRED_COLUMNS_TEST_CSV, plotDefn.getId());
    ReferenceDataImportStatus<ParsingError> status = process.getStatus();
    assertFalse(status.isComplete());
    assertTrue(status.isError());
    List<ParsingError> errors = status.getErrors();
    assertEquals(1, errors.size());
    ParsingError headerError = errors.get(0);
    assertEquals(ErrorType.MISSING_REQUIRED_COLUMNS, headerError.getErrorType());
}
Also used : EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) ParsingError(org.openforis.collect.io.metadata.parsing.ParsingError) CollectIntegrationTest(org.openforis.collect.CollectIntegrationTest) Test(org.junit.Test)

Example 7 with ParsingError

use of org.openforis.collect.io.metadata.parsing.ParsingError in project collect by openforis.

the class CSVDataImportProcessIntegrationTest 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");
    CSVDataImportProcess process = importCSVFile(MISSING_RECORD_TEST_CSV, clusterDefn.getId());
    ReferenceDataImportStatus<ParsingError> status = process.getStatus();
    assertTrue(status.isError());
    assertEquals(1, status.getSkippedRows().size());
    assertEquals(1, status.getRowsInError().size());
    assertEquals(3, status.getProcessed());
    {
        ParsingError error = status.getErrors().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());
    }
}
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)

Example 8 with ParsingError

use of org.openforis.collect.io.metadata.parsing.ParsingError in project collect by openforis.

the class CSVDataImportProcessIntegrationTest method validDeleteExistingEntitiesTest.

@Test
public void validDeleteExistingEntitiesTest() throws Exception {
    CollectRecord record = createTestRecord(survey, "10_114");
    recordDao.insert(record);
    EntityDefinition clusterDefn = survey.getSchema().getRootEntityDefinition("cluster");
    EntityDefinition plotDefn = (EntityDefinition) clusterDefn.getChildDefinition("plot");
    assertEquals(3, record.getRootEntity().getCount(plotDefn));
    CSVDataImportSettings settings = new CSVDataImportSettings();
    settings.setDeleteExistingEntities(true);
    CSVDataImportProcess process = importCSVFile(VALID_NESTED_ENTITY_TEST_CSV, plotDefn.getId(), true, settings);
    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);
    assertEquals(2, reloadedRecord.getRootEntity().getCount(plotDefn));
    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());
    }
}
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) CodeAttribute(org.openforis.idm.model.CodeAttribute) CSVDataImportSettings(org.openforis.collect.io.data.csv.CSVDataImportSettings) CollectIntegrationTest(org.openforis.collect.CollectIntegrationTest) Test(org.junit.Test)

Example 9 with ParsingError

use of org.openforis.collect.io.metadata.parsing.ParsingError in project collect by openforis.

the class CSVDataImportProcessIntegrationTest method newRecordsTest.

@Test
public void newRecordsTest() throws Exception {
    EntityDefinition clusterDefn = survey.getSchema().getRootEntityDefinition("cluster");
    CSVDataImportProcess process = importCSVFile(VALID_TEST_CSV, clusterDefn.getId(), true, true, "2.0");
    ReferenceDataImportStatus<ParsingError> status = process.getStatus();
    assertTrue(status.isComplete());
    assertEquals(3, status.getProcessed());
    {
        CollectRecord reloadedRecord = loadRecord("10_111");
        Entity cluster = reloadedRecord.getRootEntity();
        RealAttribute plotDistance = (RealAttribute) cluster.getChild("plot_distance");
        RealValue plotDistanceVal = plotDistance.getValue();
        assertEquals(Double.valueOf(200d), 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(0.3d), plotDistanceVal.getValue());
        assertEquals(kilometerUnit, plotDistanceVal.getUnit());
    }
}
Also used : RealValue(org.openforis.idm.model.RealValue) EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) CollectRecord(org.openforis.collect.model.CollectRecord) Entity(org.openforis.idm.model.Entity) ParsingError(org.openforis.collect.io.metadata.parsing.ParsingError) RealAttribute(org.openforis.idm.model.RealAttribute) CollectIntegrationTest(org.openforis.collect.CollectIntegrationTest) Test(org.junit.Test)

Example 10 with ParsingError

use of org.openforis.collect.io.metadata.parsing.ParsingError in project collect by openforis.

the class CSVDataImportProcessIntegrationTest method createMissingParentEntityTest.

@Test
public void createMissingParentEntityTest() 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 plotDefn = (EntityDefinition) clusterDefn.getChildDefinition("plot");
    EntityDefinition treeDefn = (EntityDefinition) plotDefn.getChildDefinition("tree");
    CSVDataImportProcess process = importCSVFile(MISSING_PARENT_ENTITY_TEST_CSV, treeDefn.getId(), true, false, null, true);
    ReferenceDataImportStatus<ParsingError> status = process.getStatus();
    assertTrue(status.isComplete());
    assertEquals(0, status.getRowsInError().size());
    assertEquals(4, status.getProcessed());
    {
        CollectRecord reloadedRecord = loadRecord("10_111");
        Entity cluster = reloadedRecord.getRootEntity();
        Entity plot = (Entity) cluster.getChild("plot", 0);
        assertEquals(3, plot.getCount("tree"));
        Entity tree = (Entity) plot.getChild("tree", 2);
        IntegerAttribute treeNo = (IntegerAttribute) tree.getChild("tree_no");
        assertEquals(Integer.valueOf(2), treeNo.getValue().getValue());
        IntegerAttribute stemNo = (IntegerAttribute) tree.getChild("stem_no");
        assertEquals(Integer.valueOf(2), stemNo.getValue().getValue());
        RealAttribute dbh = (RealAttribute) tree.getChild("dbh");
        assertEquals(Double.valueOf(200), dbh.getValue().getValue());
    }
}
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) RealAttribute(org.openforis.idm.model.RealAttribute) IntegerAttribute(org.openforis.idm.model.IntegerAttribute) CollectIntegrationTest(org.openforis.collect.CollectIntegrationTest) Test(org.junit.Test)

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