Search in sources :

Example 31 with Entity

use of org.openforis.idm.model.Entity in project collect by openforis.

the class CSVDataImportJobIntegrationTest 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);
    CSVDataImportJob process = importCSVFile(VALID_ENTITY_POSITION_TEST_CSV, timeStudyDefn.getId());
    assertEquals(Status.COMPLETED, process.getStatus());
    assertTrue(process.getParsingErrors().isEmpty());
    {
        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) Date(org.openforis.idm.model.Date) DateAttribute(org.openforis.idm.model.DateAttribute) CollectIntegrationTest(org.openforis.collect.CollectIntegrationTest) Test(org.junit.Test)

Example 32 with Entity

use of org.openforis.idm.model.Entity in project collect by openforis.

the class CSVDataImportJobIntegrationTest 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");
    CSVDataImportJob process = importCSVFile(VALID_NESTED_ENTITY_TEST_CSV, plotDefn.getId());
    assertTrue(process.isCompleted());
    assertTrue(process.getParsingErrors().isEmpty());
    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());
    }
}
Also used : CollectRecord(org.openforis.collect.model.CollectRecord) EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) Entity(org.openforis.idm.model.Entity) CodeAttribute(org.openforis.idm.model.CodeAttribute) CollectIntegrationTest(org.openforis.collect.CollectIntegrationTest) Test(org.junit.Test)

Example 33 with Entity

use of org.openforis.idm.model.Entity in project collect by openforis.

the class CSVDataImportJobIntegrationTest method newRecordsTest.

@Test
public void newRecordsTest() throws Exception {
    EntityDefinition clusterDefn = survey.getSchema().getRootEntityDefinition("cluster");
    CSVDataImportJob process = importCSVFile(VALID_TEST_CSV, clusterDefn.getId(), true, true, "2.0");
    assertTrue(process.isCompleted());
    assertTrue(process.getParsingErrors().isEmpty());
    {
        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) RealAttribute(org.openforis.idm.model.RealAttribute) CollectIntegrationTest(org.openforis.collect.CollectIntegrationTest) Test(org.junit.Test)

Example 34 with Entity

use of org.openforis.idm.model.Entity in project collect by openforis.

the class CSVDataImportJobIntegrationTest 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);
    CSVDataImportJob process = importCSVFile(VALID_NESTED_ENTITY_TEST_CSV, plotDefn.getId(), true, settings);
    assertTrue(process.isCompleted());
    assertTrue(process.getParsingErrors().isEmpty());
    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) CodeAttribute(org.openforis.idm.model.CodeAttribute) CSVDataImportSettings(org.openforis.collect.io.data.csv.CSVDataImportSettings) CollectIntegrationTest(org.openforis.collect.CollectIntegrationTest) Test(org.junit.Test)

Example 35 with Entity

use of org.openforis.idm.model.Entity 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)

Aggregations

Entity (org.openforis.idm.model.Entity)164 Test (org.junit.Test)88 CollectRecord (org.openforis.collect.model.CollectRecord)37 EntityDefinition (org.openforis.idm.metamodel.EntityDefinition)36 Code (org.openforis.idm.model.Code)35 RealAttribute (org.openforis.idm.model.RealAttribute)25 CollectIntegrationTest (org.openforis.collect.CollectIntegrationTest)23 NodeDefinition (org.openforis.idm.metamodel.NodeDefinition)19 Node (org.openforis.idm.model.Node)19 AbstractTest (org.openforis.idm.AbstractTest)18 Date (org.openforis.idm.model.Date)16 ArrayList (java.util.ArrayList)14 CodeAttribute (org.openforis.idm.model.CodeAttribute)14 Time (org.openforis.idm.model.Time)12 GregorianCalendar (java.util.GregorianCalendar)9 ParsingError (org.openforis.collect.io.metadata.parsing.ParsingError)9 AttributeDefinition (org.openforis.idm.metamodel.AttributeDefinition)9 TextAttribute (org.openforis.idm.model.TextAttribute)9 CodeAttributeDefinition (org.openforis.idm.metamodel.CodeAttributeDefinition)8 Attribute (org.openforis.idm.model.Attribute)8