Search in sources :

Example 91 with CollectRecord

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

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

the class CSVDataImportProcessIntegrationTest 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");
    CSVDataImportProcess process = importCSVFile(VALID_NESTED_ENTITY_TEST_CSV, plotDefn.getId());
    ReferenceDataImportStatus<ParsingError> status = process.getStatus();
    assertTrue(status.isComplete());
    assertTrue(status.getSkippedRows().isEmpty());
    assertEquals(3, status.getProcessed());
    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) ParsingError(org.openforis.collect.io.metadata.parsing.ParsingError) CodeAttribute(org.openforis.idm.model.CodeAttribute) CollectIntegrationTest(org.openforis.collect.CollectIntegrationTest) Test(org.junit.Test)

Example 93 with CollectRecord

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

the class CSVDataImportProcessIntegrationTest method invalidValuesTest.

@Test
public void invalidValuesTest() 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(INVALID_VALUES_TEST_CSV, clusterDefn.getId());
    ReferenceDataImportStatus<ParsingError> status = process.getStatus();
    assertFalse(status.isComplete());
    assertTrue(status.isError());
    List<ParsingError> errors = status.getErrors();
    assertEquals(4, errors.size());
    {
        ParsingError error = errors.get(0);
        assertEquals(2, error.getRow());
        assertEquals(ErrorType.INVALID_VALUE, error.getErrorType());
        assertTrue(Arrays.equals(new String[] { "vehicle_location_srs" }, error.getColumns()));
    }
    {
        ParsingError error = errors.get(1);
        assertEquals(4, error.getRow());
        assertEquals(ErrorType.INVALID_VALUE, error.getErrorType());
        assertTrue(Arrays.equals(new String[] { "vehicle_location_x" }, error.getColumns()));
    }
    {
        ParsingError error = errors.get(2);
        assertEquals(4, error.getRow());
        assertEquals(ErrorType.INVALID_VALUE, error.getErrorType());
        assertTrue(Arrays.equals(new String[] { "plot_distance" }, error.getColumns()));
    }
    {
        ParsingError error = errors.get(3);
        assertEquals(5, error.getRow());
        assertEquals(ErrorType.INVALID_VALUE, error.getErrorType());
        assertTrue(Arrays.equals(new String[] { "vehicle_location_y" }, error.getColumns()));
    }
}
Also used : CollectRecord(org.openforis.collect.model.CollectRecord) EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) ParsingError(org.openforis.collect.io.metadata.parsing.ParsingError) CollectIntegrationTest(org.openforis.collect.CollectIntegrationTest) Test(org.junit.Test)

Example 94 with CollectRecord

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

the class RecordIndexManagerIntegrationTest method createTestRecord.

private CollectRecord createTestRecord(CollectSurvey survey, int internalId, String id, String gpsModel) {
    CollectRecord record = new CollectRecord(survey, "2.0", "cluster");
    record.setId(internalId);
    Entity cluster = record.getRootEntity();
    record.setCreationDate(new GregorianCalendar(2011, 11, 31, 23, 59).getTime());
    record.setStep(Step.ENTRY);
    EntityBuilder.addValue(cluster, "id", new Code(id));
    EntityBuilder.addValue(cluster, "gps_model", gpsModel);
    return record;
}
Also used : CollectRecord(org.openforis.collect.model.CollectRecord) Entity(org.openforis.idm.model.Entity) GregorianCalendar(java.util.GregorianCalendar) Code(org.openforis.idm.model.Code)

Example 95 with CollectRecord

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

the class RecordManagerIntegrationTest method testPublish.

@Test
public void testPublish() throws MissingRecordKeyException, RecordPromoteException {
    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.setModifiedBy(user);
    recordManager.save(record);
    recordManager.promote(record, user, true);
    CollectRecord promotedRecord = recordManager.load(survey, record.getId());
    assertEquals(record, promotedRecord);
    List<CollectRecordSummary> fullSummaries = recordDao.loadFullSummaries(new RecordFilter(survey), null);
    assertEquals(1, fullSummaries.size());
    CollectRecordSummary recordSummary = fullSummaries.get(0);
    assertEquals(2, recordSummary.getStepSummaries().size());
}
Also used : CollectRecord(org.openforis.collect.model.CollectRecord) User(org.openforis.collect.model.User) CollectRecordSummary(org.openforis.collect.model.CollectRecordSummary) RecordUpdater(org.openforis.collect.model.RecordUpdater) RecordFilter(org.openforis.collect.model.RecordFilter) 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