Search in sources :

Example 11 with Date

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

the class CSVDataImportProcessIntegrationTest method createTestRecord.

private CollectRecord createTestRecord(CollectSurvey survey, String id) {
    CollectRecord record = new CollectRecord(survey, "2.0", "cluster");
    Entity cluster = record.getRootEntity();
    record.setCreationDate(new GregorianCalendar(2011, 11, 31, 23, 59).getTime());
    EntityBuilder.addValue(cluster, "id", new Code(id));
    EntityBuilder.addValue(cluster, "region", new Code("001"));
    EntityBuilder.addValue(cluster, "district", new Code("002"));
    EntityBuilder.addValue(cluster, "plot_distance", 100d, meterUnit);
    EntityBuilder.addValue(cluster, "map_sheet", "map sheet 1");
    EntityBuilder.addValue(cluster, "map_sheet", "map sheet 2");
    EntityBuilder.addValue(cluster, "map_sheet", "map sheet 3");
    {
        Entity timeStudy = EntityBuilder.addEntity(cluster, "time_study");
        EntityBuilder.addValue(timeStudy, "date", new Date(2012, 1, 1));
        EntityBuilder.addValue(timeStudy, "start_time", new Time(9, 10));
        EntityBuilder.addValue(timeStudy, "end_time", new Time(12, 20));
    }
    {
        Entity timeStudy = EntityBuilder.addEntity(cluster, "time_study");
        EntityBuilder.addValue(timeStudy, "date", new Date(2012, 2, 20));
        EntityBuilder.addValue(timeStudy, "start_time", new Time(8, 15));
        EntityBuilder.addValue(timeStudy, "end_time", new Time(11, 10));
    }
    {
        Entity plot = EntityBuilder.addEntity(cluster, "plot");
        EntityBuilder.addValue(plot, "no", new Code("1"));
        EntityBuilder.addValue(plot, "subplot", "A");
        EntityBuilder.addValue(plot, "land_use", new Code("1"));
        {
            Entity tree = EntityBuilder.addEntity(plot, "tree");
            EntityBuilder.addValue(tree, "tree_no", 1);
            EntityBuilder.addValue(tree, "stem_no", 1);
            EntityBuilder.addValue(tree, "dbh", 10.5d);
        }
        {
            Entity tree = EntityBuilder.addEntity(plot, "tree");
            EntityBuilder.addValue(tree, "tree_no", 2);
            EntityBuilder.addValue(tree, "stem_no", 1);
            EntityBuilder.addValue(tree, "dbh", 20.5d);
        }
    }
    {
        Entity plot = EntityBuilder.addEntity(cluster, "plot");
        EntityBuilder.addValue(plot, "no", new Code("2"));
        EntityBuilder.addValue(plot, "subplot", "A");
        EntityBuilder.addValue(plot, "land_use", new Code("2"));
        {
            Entity tree = EntityBuilder.addEntity(plot, "tree");
            EntityBuilder.addValue(tree, "tree_no", 1);
            EntityBuilder.addValue(tree, "stem_no", 1);
            EntityBuilder.addValue(tree, "dbh", 10.5d);
        }
        {
            Entity tree = EntityBuilder.addEntity(plot, "tree");
            EntityBuilder.addValue(tree, "tree_no", 2);
            EntityBuilder.addValue(tree, "stem_no", 1);
            EntityBuilder.addValue(tree, "dbh", 20.5d);
        }
    }
    {
        Entity plot = EntityBuilder.addEntity(cluster, "plot");
        EntityBuilder.addValue(plot, "no", new Code("2"));
        EntityBuilder.addValue(plot, "subplot", "B");
        EntityBuilder.addValue(plot, "land_use", new Code("3"));
        {
            Entity tree = EntityBuilder.addEntity(plot, "tree");
            EntityBuilder.addValue(tree, "tree_no", 1);
            EntityBuilder.addValue(tree, "stem_no", 1);
            EntityBuilder.addValue(tree, "dbh", 10.5d);
        }
        {
            Entity tree = EntityBuilder.addEntity(plot, "tree");
            EntityBuilder.addValue(tree, "tree_no", 2);
            EntityBuilder.addValue(tree, "stem_no", 1);
            EntityBuilder.addValue(tree, "dbh", 20.5d);
        }
    }
    record.updateSummaryFields();
    recordManager.validate(record);
    return record;
}
Also used : CollectRecord(org.openforis.collect.model.CollectRecord) Entity(org.openforis.idm.model.Entity) GregorianCalendar(java.util.GregorianCalendar) Time(org.openforis.idm.model.Time) Code(org.openforis.idm.model.Code) Date(org.openforis.idm.model.Date)

Example 12 with Date

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

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

the class DataMarshallerIntegrationTest method createTestRecord.

private CollectRecord createTestRecord(CollectSurvey survey) {
    RecordBuilder recordBuilder = record(attribute("id", "123_456"), attribute("gps_realtime", "true"), attribute("region", "001"), attribute("district", "XXX"), attribute("crew_no", 10), attribute("map_sheet", "value 1"), attribute("map_sheet", "value 2"), attribute("vehicle_location", new Coordinate(432423423d, 4324324d, "srs")), attribute("gps_model", "TomTom 1.232"), attribute("remarks", "Remarks with UTF-8 character: Í"), entity("time_study", attribute("date", new Date(2011, 2, 14)), attribute("start_time", new Time(8, 15)), attribute("end_time", new Time(15, 29))), entity("time_study", attribute("date", new Date(2011, 2, 15)), attribute("start_time", new Time(8, 32)), attribute("end_time", new Time(11, 20))), entity("plot", attribute("no", new Code("1")), entity("tree", attribute("tree_no", 1), attribute("dbh", 54.2), attribute("total_height", 2.0), attribute("bole_height", (Double) null)), entity("tree", attribute("tree_no", 2), attribute("dbh", 82.8), attribute("total_height", 3.0))), entity("plot", attribute("no", new Code("2")), entity("tree", attribute("tree_no", 1), attribute("dbh", 34.2), attribute("total_height", 2.0)), entity("tree", attribute("tree_no", 2), attribute("dbh", 85.8), attribute("total_height", 4.0))));
    CollectRecord record = recordBuilder.build(survey, "cluster", "2.0");
    User user = userManager.loadByUserName("admin");
    record.setCreatedBy(user);
    record.setModifiedBy(user);
    record.setCreationDate(new GregorianCalendar(2011, 11, 31, 23, 59).getTime());
    record.setModifiedDate(new GregorianCalendar(2012, 2, 3, 9, 30).getTime());
    record.setStep(Step.ENTRY);
    record.setState(State.REJECTED);
    record.updateSummaryFields();
    RecordUpdater recordUpdater = new RecordUpdater();
    recordUpdater.initializeRecord(record);
    Entity cluster = record.getRootEntity();
    recordUpdater.confirmError((Attribute<?, ?>) record.findNodeByPath("/cluster/district"));
    recordUpdater.approveMissingValue(cluster, "accessibility");
    NumberAttribute<?, ?> boleHeight = (NumberAttribute<?, ?>) record.findNodeByPath("/cluster/plot[1]/tree[1]/bole_height");
    recordUpdater.updateAttribute(boleHeight, FieldSymbol.BLANK_ON_FORM);
    recordUpdater.updateRemarks(boleHeight.getNumberField(), "No value specified");
    return record;
}
Also used : CollectRecord(org.openforis.collect.model.CollectRecord) Entity(org.openforis.idm.model.Entity) User(org.openforis.collect.model.User) RecordBuilder(org.openforis.idm.testfixture.RecordBuilder) GregorianCalendar(java.util.GregorianCalendar) Time(org.openforis.idm.model.Time) Code(org.openforis.idm.model.Code) Date(org.openforis.idm.model.Date) Coordinate(org.openforis.idm.model.Coordinate) NumberAttribute(org.openforis.idm.model.NumberAttribute) RecordUpdater(org.openforis.collect.model.RecordUpdater)

Example 14 with Date

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

the class ModelSerializationTest method createTestRecord.

private CollectRecord createTestRecord(CollectSurvey survey) {
    RecordBuilder recordBuilder = record(attribute("id", new Code("123_456")), attribute("gps_realtime", "true"), attribute("region", "001"), attribute("district", "002"), attribute("crew_no", 10), attribute("map_sheet", "value 1"), attribute("map_sheet", "value 2"), attribute("vehicle_location", new Coordinate(432423423d, 4324324d, "srs")), attribute("gps_model", "TomTom 1.232"), entity("time_study", attribute("date", new Date(2011, 2, 14)), attribute("start_time", new Time(8, 15)), attribute("end_time", new Time(15, 29))), entity("time_study", attribute("date", new Date(2011, 2, 15)), attribute("start_time", new Time(8, 32)), attribute("end_time", new Time(11, 20))), entity("plot", attribute("no", new Code("1")), entity("tree", attribute("tree_no", 1), attribute("dbh", 54.2), attribute("total_height", 2.0), attribute("bole_height", (Double) null)), entity("tree", attribute("tree_no", 2), attribute("dbh", 82.8), attribute("total_height", 3.0))), entity("plot", attribute("no", new Code("2")), entity("tree", attribute("tree_no", 1), attribute("dbh", 34.2), attribute("total_height", 2.0)), entity("tree", attribute("tree_no", 2), attribute("dbh", 85.8), attribute("total_height", 4.0))));
    CollectRecord record = recordBuilder.build(survey, "cluster", "2.0");
    record.setCreationDate(new GregorianCalendar(2011, 11, 31, 23, 59).getTime());
    // record.setCreatedBy("ModelDaoIntegrationTest");
    record.setStep(Step.ENTRY);
    record.updateSummaryFields();
    updater.initializeRecord(record);
    Entity cluster = record.getRootEntity();
    updater.confirmError((Attribute<?, ?>) record.findNodeByPath("/cluster/district"));
    updater.approveMissingValue(cluster, "accessibility");
    NumberAttribute<?, ?> boleHeight = (NumberAttribute<?, ?>) record.findNodeByPath("/cluster/plot[1]/tree[1]/bole_height");
    updater.updateAttribute(boleHeight, FieldSymbol.BLANK_ON_FORM);
    updater.updateRemarks(boleHeight.getNumberField(), "No value specified");
    return record;
}
Also used : CollectRecord(org.openforis.collect.model.CollectRecord) Entity(org.openforis.idm.model.Entity) Coordinate(org.openforis.idm.model.Coordinate) RecordBuilder(org.openforis.idm.testfixture.RecordBuilder) GregorianCalendar(java.util.GregorianCalendar) NumberAttribute(org.openforis.idm.model.NumberAttribute) Time(org.openforis.idm.model.Time) Code(org.openforis.idm.model.Code) Date(org.openforis.idm.model.Date)

Example 15 with Date

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

the class CSVDataImportJobIntegrationTest method createTestRecord.

private CollectRecord createTestRecord(CollectSurvey survey, String id) {
    CollectRecord record = new CollectRecord(survey, "2.0", "cluster");
    Entity cluster = record.getRootEntity();
    record.setCreationDate(new GregorianCalendar(2011, 11, 31, 23, 59).getTime());
    EntityBuilder.addValue(cluster, "id", new Code(id));
    EntityBuilder.addValue(cluster, "region", new Code("001"));
    EntityBuilder.addValue(cluster, "district", new Code("002"));
    EntityBuilder.addValue(cluster, "plot_distance", 100d, meterUnit);
    EntityBuilder.addValue(cluster, "map_sheet", "map sheet 1");
    EntityBuilder.addValue(cluster, "map_sheet", "map sheet 2");
    EntityBuilder.addValue(cluster, "map_sheet", "map sheet 3");
    {
        Entity timeStudy = EntityBuilder.addEntity(cluster, "time_study");
        EntityBuilder.addValue(timeStudy, "date", new Date(2012, 1, 1));
        EntityBuilder.addValue(timeStudy, "start_time", new Time(9, 10));
        EntityBuilder.addValue(timeStudy, "end_time", new Time(12, 20));
    }
    {
        Entity timeStudy = EntityBuilder.addEntity(cluster, "time_study");
        EntityBuilder.addValue(timeStudy, "date", new Date(2012, 2, 20));
        EntityBuilder.addValue(timeStudy, "start_time", new Time(8, 15));
        EntityBuilder.addValue(timeStudy, "end_time", new Time(11, 10));
    }
    {
        Entity plot = EntityBuilder.addEntity(cluster, "plot");
        EntityBuilder.addValue(plot, "no", new Code("1"));
        EntityBuilder.addValue(plot, "subplot", "A");
        EntityBuilder.addValue(plot, "land_use", new Code("1"));
        {
            Entity tree = EntityBuilder.addEntity(plot, "tree");
            EntityBuilder.addValue(tree, "tree_no", 1);
            EntityBuilder.addValue(tree, "stem_no", 1);
            EntityBuilder.addValue(tree, "dbh", 10.5d);
        }
        {
            Entity tree = EntityBuilder.addEntity(plot, "tree");
            EntityBuilder.addValue(tree, "tree_no", 2);
            EntityBuilder.addValue(tree, "stem_no", 1);
            EntityBuilder.addValue(tree, "dbh", 20.5d);
        }
    }
    {
        Entity plot = EntityBuilder.addEntity(cluster, "plot");
        EntityBuilder.addValue(plot, "no", new Code("2"));
        EntityBuilder.addValue(plot, "subplot", "A");
        EntityBuilder.addValue(plot, "land_use", new Code("2"));
        {
            Entity tree = EntityBuilder.addEntity(plot, "tree");
            EntityBuilder.addValue(tree, "tree_no", 1);
            EntityBuilder.addValue(tree, "stem_no", 1);
            EntityBuilder.addValue(tree, "dbh", 10.5d);
        }
        {
            Entity tree = EntityBuilder.addEntity(plot, "tree");
            EntityBuilder.addValue(tree, "tree_no", 2);
            EntityBuilder.addValue(tree, "stem_no", 1);
            EntityBuilder.addValue(tree, "dbh", 20.5d);
        }
    }
    {
        Entity plot = EntityBuilder.addEntity(cluster, "plot");
        EntityBuilder.addValue(plot, "no", new Code("2"));
        EntityBuilder.addValue(plot, "subplot", "B");
        EntityBuilder.addValue(plot, "land_use", new Code("3"));
        {
            Entity tree = EntityBuilder.addEntity(plot, "tree");
            EntityBuilder.addValue(tree, "tree_no", 1);
            EntityBuilder.addValue(tree, "stem_no", 1);
            EntityBuilder.addValue(tree, "dbh", 10.5d);
        }
        {
            Entity tree = EntityBuilder.addEntity(plot, "tree");
            EntityBuilder.addValue(tree, "tree_no", 2);
            EntityBuilder.addValue(tree, "stem_no", 1);
            EntityBuilder.addValue(tree, "dbh", 20.5d);
        }
    }
    record.updateSummaryFields();
    recordManager.validate(record);
    return record;
}
Also used : CollectRecord(org.openforis.collect.model.CollectRecord) Entity(org.openforis.idm.model.Entity) GregorianCalendar(java.util.GregorianCalendar) Time(org.openforis.idm.model.Time) Code(org.openforis.idm.model.Code) Date(org.openforis.idm.model.Date)

Aggregations

Date (org.openforis.idm.model.Date)20 Entity (org.openforis.idm.model.Entity)16 CollectRecord (org.openforis.collect.model.CollectRecord)10 Code (org.openforis.idm.model.Code)10 Time (org.openforis.idm.model.Time)10 Coordinate (org.openforis.idm.model.Coordinate)8 Test (org.junit.Test)7 DateAttribute (org.openforis.idm.model.DateAttribute)7 GregorianCalendar (java.util.GregorianCalendar)6 CollectIntegrationTest (org.openforis.collect.CollectIntegrationTest)4 EntityDefinition (org.openforis.idm.metamodel.EntityDefinition)4 RealAttribute (org.openforis.idm.model.RealAttribute)4 NumberAttribute (org.openforis.idm.model.NumberAttribute)3 RecordBuilder (org.openforis.idm.testfixture.RecordBuilder)3 ParsingError (org.openforis.collect.io.metadata.parsing.ParsingError)2 RecordUpdater (org.openforis.collect.model.RecordUpdater)2 NumberFormat (java.text.NumberFormat)1 Calendar (java.util.Calendar)1 User (org.openforis.collect.model.User)1 CodeAttributeDefinition (org.openforis.idm.metamodel.CodeAttributeDefinition)1