use of org.openforis.collect.model.CollectRecord in project collect by openforis.
the class RecordDaoTest method testLoadRecordSummariesOrderedByPlotCount.
// @Test
public void testLoadRecordSummariesOrderedByPlotCount() throws IOException, SurveyImportException, DataInconsistencyException, InvalidIdmlException, NonexistentIdException {
EntityDefinition rootEntity = survey.getSchema().getRootEntityDefinitions().get(0);
String rootEntityName = rootEntity.getName();
// load record summaries
int offset = 0;
int maxNumberOfRecords = 5;
String orderByFieldName = "count_plot";
String filter = null;
List<CollectRecord> list = this.recordDao.loadSummaries(survey, recordManager, rootEntityName, offset, maxNumberOfRecords, orderByFieldName, filter);
assertNotNull(list);
assertEquals(maxNumberOfRecords, list.size());
// test first record of the page
{
CollectRecord sampleRecordSummary = list.get(0);
List<Integer> entityCounts = sampleRecordSummary.getEntityCounts();
assertEquals(new Integer(1), entityCounts.get(0));
}
// test last record of the page
{
CollectRecord sampleRecordSummary = list.get(4);
List<Integer> entityCounts = sampleRecordSummary.getEntityCounts();
assertEquals(new Integer(5), entityCounts.get(0));
}
}
use of org.openforis.collect.model.CollectRecord in project collect by openforis.
the class RecordDaoTest method createAndSaveSampleRecords.
/**
* Creates sample records with different id and different number of plots.
*/
private void createAndSaveSampleRecords() {
sampleRecords = new ArrayList<CollectRecord>();
// create and save clusters
for (int i = 1; i <= numberOfSampleRecords; i++) {
CollectRecord record = createRecord(survey, i);
sampleRecords.add(record);
recordDao.saveOrUpdate(record);
}
}
use of org.openforis.collect.model.CollectRecord in project collect by openforis.
the class RecordDaoTest method createRecord.
private CollectRecord createRecord(CollectSurvey survey, int sequenceNumber) {
int skippedCount = new Double(Math.ceil((double) (Math.random() * 40))).intValue();
int missingCount = new Double(Math.ceil((double) (Math.random() * 50))).intValue();
int errorsCount = new Double(Math.ceil((double) (Math.random() * 10))).intValue();
int warningsCount = new Double(Math.ceil((double) (Math.random() * 30))).intValue();
int numberOfPlots = new Double(Math.ceil((double) (Math.random() * 20))).intValue();
int numberOfTrees = new Double(Math.ceil((double) (Math.random() * 30))).intValue();
;
CollectRecord record = new CollectRecord(recordManager, survey, "2.0");
record.setCreationDate(new GregorianCalendar(2011, 0, sequenceNumber, 8, 30).getTime());
// record.setCreatedBy("ModelDaoIntegrationTest");
record.setStep(Step.ENTRY);
record.setModifiedDate(new GregorianCalendar(2011, 1, sequenceNumber, 8, 30).getTime());
record.setSkipped(skippedCount);
record.setMissing(missingCount);
record.setErrors(errorsCount);
record.setWarnings(warningsCount);
Entity cluster = record.createRootEntity("cluster");
String keyId = Integer.toString(sequenceNumber);
EntityBuilder.addValue(cluster, "id", new Code(keyId));
EntityBuilder.addValue(cluster, "gps_realtime", Boolean.TRUE);
EntityBuilder.addValue(cluster, "region", new Code("001"));
EntityBuilder.addValue(cluster, "district", new Code("002"));
EntityBuilder.addValue(cluster, "vehicle_location", new Coordinate(432423423l, 4324324l, "srs"));
EntityBuilder.addValue(cluster, "gps_model", "TomTom 1.232");
{
Entity ts = EntityBuilder.addEntity(cluster, "time_study");
ts.addValue("date", new Date(2011, 2, 14));
ts.addValue("start_time", new Time(8, 15));
ts.addValue("end_time", new Time(15, 29));
}
{
Entity ts = EntityBuilder.addEntity(cluster, "time_study");
ts.addValue("date", new Date(2011, 2, 15));
ts.addValue("start_time", new Time(8, 32));
ts.addValue("end_time", new Time(11, 20));
}
for (int i = 0; i < numberOfPlots; i++) {
Entity plot = EntityBuilder.addEntity(cluster, "plot");
EntityBuilder.addValue(plot, "no", new Code(Integer.toString(i + 1)));
for (int j = 0; j < numberOfTrees; j++) {
Entity tree = EntityBuilder.addEntity(plot, "tree");
tree.addValue("dbh", 54.2);
tree.addValue("total_height", 2.0);
RealAttribute boleHeight = tree.addValue("bole_height", (Double) null);
boleHeight.getField().setSymbol('*');
boleHeight.getField().setRemarks("No value specified");
// .setMetadata(new CollectAttributeMetadata('*',null,"No value specified"));
}
}
// set counts
record.getEntityCounts().add(numberOfPlots);
// set keys
record.getRootEntityKeys().add(keyId);
return record;
}
use of org.openforis.collect.model.CollectRecord in project collect by openforis.
the class RecordDaoSpeedTest method testCRUD.
// @Autowired
// protected SurveyContext recordContext;
// public void testRecordSerialize() throws Exception {
// CollectSurvey survey = surveyDao.load("naforma1");
// CollectRecord r1 = recordDao.load(survey, new CollectRecordContext(), 2099);
// ModelSerializer ser = new ModelSerializer(10000);
// FileOutputStream fis = new FileOutputStream("src/it/resources/test-record.bin");
// try {
// ser.writeTo(fis, r1.getRootEntity());
// fis.flush();
// } finally {
// fis.close();
// }
// }
// public void testRecordStore() throws Exception {
// CollectSurvey survey = surveyDao.load("naforma1");
// ModelSerializer ser = new ModelSerializer(10000);
// FileInputStream fis = new FileInputStream("src/it/resources/test-record.bin");
// try {
// CollectRecord r1 = new CollectRecord(new CollectRecordContext(), survey, "2.0");
// r1.createRootEntity("cluster");
// r1.setId(2099);
// ser.mergeFrom(fis, r1.getRootEntity());
// recordDao.update(r1);
// } finally {
// fis.close();
// }
//
// }
@Test
public void testCRUD() throws Exception {
// try {
// LOAD MODEL
CollectSurvey survey = surveyDao.load("naforma1");
CollectRecord r1;
{
long t1 = System.currentTimeMillis();
r1 = recordDao.load(survey, new CollectRecordContext(), 2099);
long t = System.currentTimeMillis() - t1;
System.out.println("load " + t);
}
String s1 = r1.toString();
{
long t1 = System.currentTimeMillis();
recordDao.update(r1);
long t = System.currentTimeMillis() - t1;
System.out.println("update " + t);
}
{
long t1 = System.currentTimeMillis();
recordDao.delete(r1);
long t = System.currentTimeMillis() - t1;
System.out.println("delete " + t);
}
{
long t1 = System.currentTimeMillis();
recordDao.insert(r1);
long t = System.currentTimeMillis() - t1;
System.out.println("insert " + t);
}
CollectRecord r2 = recordDao.load(survey, new CollectRecordContext(), 2099);
String s2 = r2.toString();
Assert.assertEquals(s1, s2);
//
// // SAVE NEW
// CollectRecord record = createTestRecord(survey);
// recordDao.saveOrUpdate(record);
//
// String saved = record.toString();
// log.debug("Saving record:\n"+saved);
//
// // RELOAD
// record = recordDao.load(survey, record.getId());
// String reloaded = record.toString();
// log.debug("Reloaded as:\n"+reloaded);
//
// assertEquals(saved, reloaded);
}
use of org.openforis.collect.model.CollectRecord in project collect by openforis.
the class DataHandler method startRecord.
public void startRecord(String localName, Attributes attributes) {
String versionName = extractVersionName(attributes);
record = new CollectRecord(currentSurvey, versionName, localName, validationEnabled);
String stateAttr = attributes.getValue(ATTRIBUTE_STATE);
State state = State.fromCode(stateAttr);
record.setState(state);
Date created = Dates.parseDateTime(attributes.getValue(ATTRIBUTE_DATE_CREATED));
Date modified = Dates.parseDateTime(attributes.getValue(ATTRIBUTE_DATE_MODIFIED));
record.setCreationDate(created);
record.setModifiedDate(modified);
String createdByUserName = attributes.getValue(ATTRIBUTE_CREATED_BY);
User createdBy = fetchUser(createdByUserName);
record.setCreatedBy(createdBy);
String modifiedByUserName = attributes.getValue(ATTRIBUTE_MODIFIED_BY);
User modifiedBy = fetchUser(modifiedByUserName);
record.setModifiedBy(modifiedBy);
node = record.getRootEntity();
}
Aggregations