use of org.openforis.collect.model.RecordFilter in project collect by openforis.
the class RecordController method startValidationResportJob.
@RequestMapping(value = "survey/{surveyId}/data/records/validationreport", method = POST)
@ResponseBody
public JobProxy startValidationResportJob(@PathVariable("surveyId") int surveyId) {
User user = sessionManager.getLoggedUser();
Locale locale = sessionManager.getSessionState().getLocale();
CollectSurvey survey = surveyManager.getById(surveyId);
EntityDefinition rootEntityDef = survey.getSchema().getFirstRootEntityDefinition();
ValidationReportJob job = jobManager.createJob(ValidationReportJob.class);
Input input = new Input();
input.setLocale(locale);
input.setReportType(ReportType.CSV);
RecordFilter recordFilter = createRecordFilter(survey, user, userGroupManager, rootEntityDef.getId(), false);
input.setRecordFilter(recordFilter);
job.setInput(input);
this.validationReportJob = job;
jobManager.start(job);
return new JobProxy(job);
}
use of org.openforis.collect.model.RecordFilter in project collect by openforis.
the class RecordStatsGenerator method generate.
public RecordsStats generate(int surveyId, Date[] period) {
final RecordsStats stats = new RecordsStats(period);
CollectSurvey survey = surveyManager.getById(surveyId);
recordManager.visitSummaries(new RecordFilter(survey), null, new Visitor<CollectRecordSummary>() {
public void visit(CollectRecordSummary s) {
for (Entry<Step, StepSummary> entry : s.getStepSummaries().entrySet()) {
Step step = entry.getKey();
StepSummary stepSummary = entry.getValue();
if (stepSummary.getCreationDate() != null) {
PointStats pointStats = stats.getOrCreateDailyStats(stepSummary.getCreationDate());
switch(step) {
case ENTRY:
pointStats.incrementCreated();
break;
case CLEANSING:
pointStats.incrementEntered();
break;
case ANALYSIS:
pointStats.incrementCleansed();
break;
}
}
}
if (s.getModifiedDate() != null) {
PointStats pointStats = stats.getOrCreateDailyStats(s.getModifiedDate());
pointStats.incrementModified();
}
}
}, true);
stats.finalize();
return stats;
}
use of org.openforis.collect.model.RecordFilter in project collect by openforis.
the class ValidationController method validateAllRecords.
@RequestMapping(value = "/validateAllRecords.htm", method = RequestMethod.GET)
public void validateAllRecords(HttpServletRequest request, HttpServletResponse response, @RequestParam String s, @RequestParam String r) throws IOException {
final ServletOutputStream outputStream = response.getOutputStream();
try {
if (s == null || r == null) {
outputStream.println("Wrong parameters: please specify 's' (survey) and 'r' (root entity name).");
return;
}
SessionState sessionState = getSessionState(request);
final User user = sessionState.getUser();
final String sessionId = sessionState.getSessionId();
print(outputStream, "Starting validation of all records: ");
final CollectSurvey survey = surveyManager.get(s);
if (survey == null) {
print(outputStream, "Survey not found");
return;
}
RecordFilter filter = new RecordFilter(survey);
filter.setRootEntityId(survey.getSchema().getRootEntityDefinition(r).getId());
final ValidationMessageBuilder validationMessageHelper = ValidationMessageBuilder.createInstance(messageContextHolder);
recordManager.visitSummaries(filter, null, new Visitor<CollectRecordSummary>() {
public void visit(CollectRecordSummary summary) {
try {
String recordKey = validationMessageHelper.getRecordKey(summary);
long start = System.currentTimeMillis();
print(outputStream, "Start validating record: " + recordKey);
Integer id = summary.getId();
Step step = summary.getStep();
recordManager.validateAndSave(survey, user, sessionId, id, step);
long elapsedMillis = System.currentTimeMillis() - start;
print(outputStream, "Validation of record " + recordKey + " completed in " + elapsedMillis + " millis");
} catch (Exception e) {
try {
String message = "ERROR validating record " + summary.getId();
outputStream.println(message);
LOG.error(message);
} catch (IOException e1) {
}
}
}
});
print(outputStream, "End of validation of all records.");
} catch (Exception e) {
outputStream.println("ERROR - Validation of records not completed: " + e.getMessage());
LOG.error(e.getMessage(), e);
throw new RuntimeException(e);
}
}
use of org.openforis.collect.model.RecordFilter 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.RecordFilter in project collect by openforis.
the class BackupRestoreController method getLatestBackupInfo.
@RequestMapping(value = "survey/{surveyId}/backup/latest/info", method = GET)
@ResponseBody
public BackupInfo getLatestBackupInfo(@PathVariable("surveyId") int surveyId) {
CollectSurvey survey = surveyManager.getById(surveyId);
final Date date = backupStorageManager.getLastBackupDate(survey.getName());
RecordFilter filter = new RecordFilter(survey);
filter.setModifiedSince(date);
final int updatedRecordsSinceBackupDateCount = recordManager.countRecords(filter);
return new BackupInfo(date, updatedRecordsSinceBackupDateCount);
}
Aggregations