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());
}
}
}
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());
}
}
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()));
}
}
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;
}
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());
}
Aggregations