Search in sources :

Example 56 with CollectRecord

use of org.openforis.collect.model.CollectRecord 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)

Example 57 with CollectRecord

use of org.openforis.collect.model.CollectRecord 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 58 with CollectRecord

use of org.openforis.collect.model.CollectRecord in project collect by openforis.

the class CSVDataImportProcessIntegrationTest method validTest.

@Test
public void validTest() throws Exception {
    {
        CollectRecord record = createTestRecord(survey, "10_111");
        recordDao.insert(record);
        assertEquals(Integer.valueOf(0), record.getErrors());
    }
    {
        CollectRecord record = createTestRecord(survey, "10_114");
        recordDao.insert(record);
    }
    EntityDefinition clusterDefn = survey.getSchema().getRootEntityDefinition("cluster");
    CSVDataImportProcess process = importCSVFile(VALID_TEST_CSV, clusterDefn.getId());
    ReferenceDataImportStatus<ParsingError> status = process.getStatus();
    assertTrue(status.isComplete());
    assertTrue(status.getSkippedRows().isEmpty());
    assertEquals(3, status.getProcessed());
    {
        CollectRecord reloadedRecord = loadRecord("10_111");
        assertEquals(Integer.valueOf(1), reloadedRecord.getErrors());
        Entity cluster = reloadedRecord.getRootEntity();
        RealAttribute plotDirection = (RealAttribute) cluster.getChild("plot_direction");
        RealValue plotDirectionVal = plotDirection.getValue();
        assertEquals(Double.valueOf(50d), plotDirectionVal.getValue());
        RealAttribute plotDistance = (RealAttribute) cluster.getChild("plot_distance");
        RealValue plotDistanceVal = plotDistance.getValue();
        assertEquals(Double.valueOf(200d), plotDistanceVal.getValue());
        assertEquals(meterUnit, plotDistanceVal.getUnit());
        TextAttribute gpsModel = (TextAttribute) cluster.getChild("gps_model");
        assertEquals("GPS MAP 62S", gpsModel.getValue().getValue());
        assertEquals(2, cluster.getCount("map_sheet"));
        {
            TextAttribute mapSheet = (TextAttribute) cluster.getChild("map_sheet", 0);
            assertEquals("new map sheet 1", mapSheet.getValue().getValue());
        }
        {
            TextAttribute mapSheet = (TextAttribute) cluster.getChild("map_sheet", 1);
            assertEquals("new map sheet 2", mapSheet.getValue().getValue());
        }
    }
    {
        CollectRecord reloadedRecord = loadRecord("10_114");
        Entity cluster = reloadedRecord.getRootEntity();
        RealAttribute plotDirection = (RealAttribute) cluster.getChild("plot_direction");
        RealValue plotDirectionVal = plotDirection.getValue();
        assertEquals(Double.valueOf(40d), plotDirectionVal.getValue());
        RealAttribute plotDistance = (RealAttribute) cluster.getChild("plot_distance");
        RealValue plotDistanceVal = plotDistance.getValue();
        assertEquals(Double.valueOf(0.3d), plotDistanceVal.getValue());
        assertEquals(kilometerUnit, plotDistanceVal.getUnit());
        TextAttribute gpsModel = (TextAttribute) cluster.getChild("gps_model");
        assertEquals("GPS MAP 62S", gpsModel.getValue().getValue());
    }
}
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) TextAttribute(org.openforis.idm.model.TextAttribute) CollectIntegrationTest(org.openforis.collect.CollectIntegrationTest) Test(org.junit.Test)

Example 59 with CollectRecord

use of org.openforis.collect.model.CollectRecord in project collect by openforis.

the class RecordIndexManagerIntegrationTest method createIndex.

private void createIndex(CollectSurvey survey, String[] gpsModels) throws Exception {
    int count = 1;
    for (String gpsModel : gpsModels) {
        CollectRecord record = createTestRecord(survey, count, Integer.toString(count++), gpsModel);
        persistedRecordIndexManager.index(record);
    }
}
Also used : CollectRecord(org.openforis.collect.model.CollectRecord)

Example 60 with CollectRecord

use of org.openforis.collect.model.CollectRecord in project collect by openforis.

the class RecordManagerIntegrationTest method testNewRecordInsert.

@Test
public void testNewRecordInsert() {
    CollectRecord record = (CollectRecord) record(attribute("id", "10_117"), attribute("region", "002"), attribute("district", "003")).build(survey, "cluster", "2.0");
    new RecordUpdater().initializeNewRecord(record);
    User user = userManager.loadAdminUser();
    record.setCreatedBy(user);
    record.setCreationDate(new Date());
    record.setModifiedBy(user);
    record.setModifiedDate(new Date());
    recordManager.save(record);
    CollectRecord reloaded = recordManager.load(survey, record.getId());
    assertEquals(record, reloaded);
}
Also used : CollectRecord(org.openforis.collect.model.CollectRecord) User(org.openforis.collect.model.User) RecordUpdater(org.openforis.collect.model.RecordUpdater) Date(java.util.Date) CollectIntegrationTest(org.openforis.collect.CollectIntegrationTest) Test(org.junit.Test)

Aggregations

CollectRecord (org.openforis.collect.model.CollectRecord)141 Entity (org.openforis.idm.model.Entity)36 Test (org.junit.Test)30 CollectSurvey (org.openforis.collect.model.CollectSurvey)29 EntityDefinition (org.openforis.idm.metamodel.EntityDefinition)29 CollectIntegrationTest (org.openforis.collect.CollectIntegrationTest)27 CollectRecordSummary (org.openforis.collect.model.CollectRecordSummary)24 Step (org.openforis.collect.model.CollectRecord.Step)23 User (org.openforis.collect.model.User)19 SessionState (org.openforis.collect.web.session.SessionState)15 RecordFilter (org.openforis.collect.model.RecordFilter)14 Transactional (org.springframework.transaction.annotation.Transactional)14 ParsingError (org.openforis.collect.io.metadata.parsing.ParsingError)12 Secured (org.springframework.security.access.annotation.Secured)12 ArrayList (java.util.ArrayList)11 Date (org.openforis.idm.model.Date)10 GregorianCalendar (java.util.GregorianCalendar)9 Code (org.openforis.idm.model.Code)9 RealAttribute (org.openforis.idm.model.RealAttribute)9 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)9