use of org.openforis.collect.model.CollectRecord in project collect by openforis.
the class RecordManagerIntegrationTest method testRecordSummaryUpdated.
@Test
public void testRecordSummaryUpdated() {
CollectRecord record = (CollectRecord) record(attribute("id", "10_114"), attribute("region", "001"), attribute("district", "002"), entity("plot", attribute("no", "1"), entity("tree", attribute("tree_no", "1"), attribute("dbh", "10")), entity("tree", attribute("tree_no", "2"), attribute("dbh", "20")))).build(survey, "cluster", "2.0");
User user = userManager.loadAdminUser();
record.setCreatedBy(user);
record.setModifiedBy(user);
recordManager.save(record);
CollectRecord reloadedRecord = recordManager.load(survey, record.getId());
String regionQualifier = reloadedRecord.getQualifierValues().get(0);
assertEquals("001", regionQualifier);
String districtQualifier = reloadedRecord.getQualifierValues().get(1);
assertEquals("002", districtQualifier);
int treesCount = reloadedRecord.getEntityCounts().get(1);
assertEquals(2, treesCount);
}
use of org.openforis.collect.model.CollectRecord in project collect by openforis.
the class RecordManagerIntegrationTest method testUpdateCurrentStepDoesntAffectPreviousStep.
@Test
public void testUpdateCurrentStepDoesntAffectPreviousStep() throws MissingRecordKeyException, RecordPromoteException {
CollectRecord record = (CollectRecord) record(attribute("id", "10_117"), attribute("region", "002"), attribute("district", "003")).build(survey, "cluster", "2.0");
RecordUpdater recordUpdater = new RecordUpdater();
recordUpdater.initializeNewRecord(record);
User user = userManager.loadAdminUser();
record.setCreatedBy(user);
record.setModifiedBy(user);
recordManager.save(record);
recordManager.promote(record, user, true);
CollectRecord cleansingRecord = recordManager.load(survey, record.getId());
Attribute<?, Code> district = cleansingRecord.findNodeByPath("/cluster/district");
Code newDistrictValue = new Code("001");
recordUpdater.updateAttribute(district, newDistrictValue);
recordManager.save(cleansingRecord);
CollectRecord entryRecord = recordManager.load(survey, record.getId(), Step.ENTRY);
assertEquals(2, (int) entryRecord.getWorkflowSequenceNumber());
assertEquals(1, (int) entryRecord.getDataWorkflowSequenceNumber());
Attribute<?, Code> entryDistrict = entryRecord.findNodeByPath("/cluster/district");
assertEquals(new Code("003"), entryDistrict.getValue());
}
use of org.openforis.collect.model.CollectRecord in project collect by openforis.
the class ModelDaoIntegrationTest method testCRUD.
// @Test
public void testCRUD() throws Exception {
testLoadAllSurveys();
// SAVE NEW
CollectRecord saved = createTestRecord(survey, "123_456");
recordDao.insert(saved);
// RELOAD
CollectRecord reloaded = recordDao.load(survey, saved.getId(), Step.ENTRY);
assertEquals(saved.getRootEntity(), reloaded.getRootEntity());
}
use of org.openforis.collect.model.CollectRecord in project collect by openforis.
the class DataMarshallerTest method createTestRecord.
private CollectRecord createTestRecord(CollectSurvey survey) throws RecordPersistenceException {
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");
record.setCreationDate(new GregorianCalendar(2011, 11, 31, 23, 59).getTime());
record.setStep(Step.ENTRY);
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;
}
use of org.openforis.collect.model.CollectRecord in project collect by openforis.
the class RecordGenerator method createRecord.
private CollectRecord createRecord(CollectSurvey survey, User user, RecordKey recordKey) {
EntityDefinition rootEntityDef = survey.getSchema().getFirstRootEntityDefinition();
String rootEntityName = rootEntityDef.getName();
CollectRecord record = recordManager.create(survey, rootEntityName, user, null);
if (recordKey.isNotEmpty()) {
setRecordKeyValues(record, recordKey);
}
return record;
}
Aggregations