use of org.openforis.collect.model.CollectRecord in project collect by openforis.
the class GeoDataController method processNodes.
private void processNodes(CollectSurvey survey, Integer recordOffset, Integer maxNumberOfRecords, int attributeId, NodeProcessor nodeProcessor) throws Exception {
NodeDefinition nodeDef = survey.getSchema().getDefinitionById(attributeId);
RecordFilter filter = new RecordFilter(survey);
filter.setOffset(recordOffset);
filter.setMaxNumberOfRecords(maxNumberOfRecords);
List<CollectRecordSummary> summaries = recordManager.loadSummaries(filter);
for (CollectRecordSummary summary : summaries) {
CollectRecord record = recordManager.load(survey, summary.getId(), summary.getStep(), false);
List<Node<?>> nodes = record.findNodesByPath(nodeDef.getPath());
for (Node<?> node : nodes) {
nodeProcessor.process(node);
}
}
}
use of org.openforis.collect.model.CollectRecord in project collect by openforis.
the class RecordController method newRecord.
@Transactional
@RequestMapping(value = "survey/{surveyId}/data/records", method = POST, consumes = APPLICATION_JSON_VALUE)
@ResponseBody
public RecordProxy newRecord(@PathVariable("surveyId") int surveyId, @RequestBody NewRecordParameters params) throws RecordPersistenceException {
User user = sessionManager.getLoggedUser();
if (user == null) {
user = loadUser(params.getUserId(), params.getUsername());
}
CollectSurvey survey = surveyManager.getById(surveyId);
params.setRootEntityName(ObjectUtils.defaultIfNull(params.getRootEntityName(), survey.getSchema().getFirstRootEntityDefinition().getName()));
params.setVersionName(ObjectUtils.defaultIfNull(params.getVersionName(), survey.getLatestVersion() != null ? survey.getLatestVersion().getName() : null));
params.setUserId(user.getId());
CollectRecord record = recordGenerator.generate(surveyId, params, params.getRecordKey());
return toProxy(record);
}
use of org.openforis.collect.model.CollectRecord in project collect by openforis.
the class CSVDataImportJobIntegrationTest 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);
CSVDataImportJob process = importCSVFile(VALID_ENTITY_POSITION_TEST_CSV, timeStudyDefn.getId());
assertEquals(Status.COMPLETED, process.getStatus());
assertTrue(process.getParsingErrors().isEmpty());
{
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());
}
}
}
use of org.openforis.collect.model.CollectRecord in project collect by openforis.
the class CSVDataImportJobIntegrationTest 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");
CSVDataImportJob process = importCSVFile(VALID_NESTED_ENTITY_TEST_CSV, plotDefn.getId());
assertTrue(process.isCompleted());
assertTrue(process.getParsingErrors().isEmpty());
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 CSVDataImportJobIntegrationTest method newRecordsTest.
@Test
public void newRecordsTest() throws Exception {
EntityDefinition clusterDefn = survey.getSchema().getRootEntityDefinition("cluster");
CSVDataImportJob process = importCSVFile(VALID_TEST_CSV, clusterDefn.getId(), true, true, "2.0");
assertTrue(process.isCompleted());
assertTrue(process.getParsingErrors().isEmpty());
{
CollectRecord reloadedRecord = loadRecord("10_111");
Entity cluster = reloadedRecord.getRootEntity();
RealAttribute plotDistance = (RealAttribute) cluster.getChild("plot_distance");
RealValue plotDistanceVal = plotDistance.getValue();
assertEquals(Double.valueOf(200d), plotDistanceVal.getValue());
assertEquals(meterUnit, plotDistanceVal.getUnit());
}
{
CollectRecord reloadedRecord = loadRecord("10_114");
Entity cluster = reloadedRecord.getRootEntity();
RealAttribute plotDistance = (RealAttribute) cluster.getChild("plot_distance");
RealValue plotDistanceVal = plotDistance.getValue();
assertEquals(Double.valueOf(0.3d), plotDistanceVal.getValue());
assertEquals(kilometerUnit, plotDistanceVal.getUnit());
}
}
Aggregations