Search in sources :

Example 1 with DateAttribute

use of org.openforis.idm.model.DateAttribute 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 2 with DateAttribute

use of org.openforis.idm.model.DateAttribute 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 3 with DateAttribute

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

the class ComparisonCheckTest method testDateGreaterThanCurrentDate.

@Test
public void testDateGreaterThanCurrentDate() {
    Entity timeStudy = EntityBuilder.addEntity(cluster, "time_study");
    DateAttribute date = EntityBuilder.addValue(timeStudy, "date", new Date(3015, 10, 20));
    ValidationResults results = validate(date);
    assertTrue(containsComparisonCheck(results.getErrors()));
}
Also used : Entity(org.openforis.idm.model.Entity) Date(org.openforis.idm.model.Date) DateAttribute(org.openforis.idm.model.DateAttribute) Test(org.junit.Test)

Example 4 with DateAttribute

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

the class ComparisonCheckTest method testDateNotGreaterThanCurrentDate.

@Test
public void testDateNotGreaterThanCurrentDate() {
    Entity timeStudy = EntityBuilder.addEntity(cluster, "time_study");
    DateAttribute date = EntityBuilder.addValue(timeStudy, "date", new Date(2015, 9, 20));
    ValidationResults results = validate(date);
    assertFalse(containsComparisonCheck(results.getErrors()));
}
Also used : Entity(org.openforis.idm.model.Entity) Date(org.openforis.idm.model.Date) DateAttribute(org.openforis.idm.model.DateAttribute) Test(org.junit.Test)

Example 5 with DateAttribute

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

the class CSVDataImportJobIntegrationTest 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");
    CSVDataImportJob process = importCSVFile(VALID_SINGLE_ENTITY_TEST_CSV, plotDefn.getId());
    assertTrue(process.isCompleted());
    assertTrue(process.getParsingErrors().isEmpty());
    {
        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) Date(org.openforis.idm.model.Date) DateAttribute(org.openforis.idm.model.DateAttribute) CollectIntegrationTest(org.openforis.collect.CollectIntegrationTest) Test(org.junit.Test)

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