use of org.openforis.collect.model.CollectRecord in project collect by openforis.
the class DataReportGeneratorIntegrationTest method testSimpleErrorReport.
@Test
public void testSimpleErrorReport() {
EntityDefinition treeDef = (EntityDefinition) survey.getSchema().getDefinitionByPath("/cluster/plot/tree");
NumberAttributeDefinition dbhDef = (NumberAttributeDefinition) survey.getSchema().getDefinitionByPath("/cluster/plot/tree/dbh");
DataQuery query = dataQuery().title("Find trees with invalid DBH").entity(treeDef).attribute(dbhDef).conditions("dbh > 20").type(invalidAttributeErrorType).severity(ErrorSeverity.ERROR).build();
dataQueryManager.save(query, adminUser);
DataQueryGroup queryGroup = new DataQueryGroup(survey);
queryGroup.setTitle("Simple query group");
queryGroup.addQuery(query);
dataQueryGroupManager.save(queryGroup, adminUser);
DataReportGeneratorJob job = jobManager.createJob(DataReportGeneratorJob.class);
job.setQueryGroup(queryGroup);
job.setRecordStep(Step.ENTRY);
job.setActiveUser(adminUser);
jobManager.start(job, false);
DataReport report = job.getReport();
DataReport reloadedReport = dataReportManager.loadById(survey, report.getId());
List<DataReportItem> items = dataReportManager.loadItems(reloadedReport, 0, 100);
assertFalse(items.isEmpty());
assertEquals(1, items.size());
DataReportItem item = items.get(0);
CollectRecord record = recordManager.load(survey, item.getRecordId());
assertEquals(Arrays.asList("10_117"), record.getRootEntityKeyValues());
assertEquals(new RealValue(30.0d, dbhDef.getDefaultUnit()), item.extractAttributeValue());
}
use of org.openforis.collect.model.CollectRecord in project collect by openforis.
the class QueryExecutorIntegrationTest method testSimpleQuery.
@Test
public void testSimpleQuery() {
// select region from tree where dbh > 20
DataQuery query = new DataQuery(survey);
EntityDefinition treeDef = (EntityDefinition) survey.getSchema().getDefinitionByPath("/cluster/plot/tree");
AttributeDefinition dbhDef = (AttributeDefinition) survey.getSchema().getDefinitionByPath("/cluster/plot/tree/dbh");
query.setEntityDefinition(treeDef);
query.setAttributeDefinition(dbhDef);
query.setConditions("dbh > 20");
final List<Node<?>> nodes = new ArrayList<Node<?>>();
DataQueryExecutorJob job = jobManager.createJob(DataQueryExecutorJob.class);
DataQueryExecutorJobInput input = new DataQueryExecutorJobInput(query, Step.ENTRY, new NodeProcessor() {
public void process(Node<?> node) {
nodes.add(node);
}
});
job.setInput(input);
jobManager.start(job, false);
assertFalse(nodes.isEmpty());
// first result
Node<?> node = nodes.get(0);
assertTrue(node instanceof Attribute);
CollectRecord record = (CollectRecord) node.getRecord();
assertEquals(Arrays.asList("10_117"), record.getRootEntityKeyValues());
}
use of org.openforis.collect.model.CollectRecord in project collect by openforis.
the class DataCleansingChainExectutorTask method execute.
@Override
@Transactional
protected void execute() throws Throwable {
CollectSurvey survey = input.chain.getSurvey();
RecordFilter filter = createRecordsFilter();
List<CollectRecordSummary> recordSummaries = recordManager.loadSummaries(filter);
datasetSize = recordSummaries.size();
lastRecordModifiedDate = null;
// Delete records in bulk if needed
Set<Integer> recordIdsToBeDeleted = new TreeSet<Integer>();
Iterator<CollectRecordSummary> it = recordSummaries.iterator();
while (it.hasNext() && isRunning()) {
CollectRecordSummary recordSummary = (CollectRecordSummary) it.next();
udpateLastRecordModifiedDate(recordSummary);
CollectRecord record = recordManager.load(survey, recordSummary.getId(), input.step, false);
boolean recordCleansed = false;
for (DataCleansingStep step : input.chain.getSteps()) {
DataCleansingStepExecutionResult stepExecutionResult = executeStep(record, step);
if (stepExecutionResult != null) {
recordCleansed = true;
if (stepExecutionResult == DataCleansingStepExecutionResult.RECORD_TO_BE_DELETED) {
recordIdsToBeDeleted.add(record.getId());
break;
}
}
}
if (recordCleansed) {
cleansedRecords++;
}
incrementProcessedItems();
}
recordManager.deleteByIds(recordIdsToBeDeleted);
}
use of org.openforis.collect.model.CollectRecord in project collect by openforis.
the class DataService method loadRecord.
@Secured(USER)
public RecordProxy loadRecord(int id, Integer stepNumber) {
SessionState sessionState = sessionManager.getSessionState();
final CollectSurvey survey = sessionState.getActiveSurvey();
Step step = stepNumber == null ? null : Step.valueOf(stepNumber);
CollectRecord record = step == null ? recordManager.load(survey, id) : recordManager.load(survey, id, step);
sessionManager.setActiveRecord(record);
return toProxy(record);
}
use of org.openforis.collect.model.CollectRecord in project collect by openforis.
the class DataService method updateActiveRecord.
@Transactional
@Secured(ENTRY_LIMITED)
public NodeChangeSetProxy updateActiveRecord(NodeUpdateRequestSetProxy requestSet) throws RecordPersistenceException, RecordIndexException {
sessionManager.checkIsActiveRecordLocked();
CollectRecord activeRecord = getActiveRecord();
NodeUpdateRequestSet reqSet = requestSet.toNodeUpdateRequestSet(codeListManager, sessionManager, activeRecord);
NodeChangeSet changeSet = updateRecord(activeRecord, reqSet);
if (!changeSet.isEmpty() && isCurrentRecordIndexable()) {
recordIndexService.temporaryIndex(activeRecord);
}
String userName = sessionManager.getSessionState().getUser().getUsername();
List<RecordEvent> events = new EventProducer().produceFor(changeSet, userName);
sessionManager.onEvents(events);
NodeChangeSetProxy result = new NodeChangeSetProxy(activeRecord, changeSet, getProxyContext());
if (requestSet.isAutoSave()) {
try {
saveActiveRecord();
result.setRecordSaved(true);
} catch (Exception e) {
result.setRecordSaved(false);
}
}
return result;
}
Aggregations