Search in sources :

Example 6 with DateAttribute

use of org.openforis.idm.model.DateAttribute 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());
        }
    }
}
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 7 with DateAttribute

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

the class DateAttributeMapper method setFields.

@Override
void setFields(Node<?> node, InsertSetStep<?> insert) {
    Date value = ((DateAttribute) node).getValue();
    if (value != null) {
        insert.set(DATA.NUMBER1, toNumeric(value.getYear()));
        insert.set(DATA.NUMBER2, toNumeric(value.getMonth()));
        insert.set(DATA.NUMBER3, toNumeric(value.getDay()));
    }
}
Also used : Date(org.openforis.idm.model.Date) DateAttribute(org.openforis.idm.model.DateAttribute)

Aggregations

Date (org.openforis.idm.model.Date)7 DateAttribute (org.openforis.idm.model.DateAttribute)7 Test (org.junit.Test)6 Entity (org.openforis.idm.model.Entity)6 CollectIntegrationTest (org.openforis.collect.CollectIntegrationTest)4 CollectRecord (org.openforis.collect.model.CollectRecord)4 EntityDefinition (org.openforis.idm.metamodel.EntityDefinition)4 ParsingError (org.openforis.collect.io.metadata.parsing.ParsingError)2