use of org.openforis.collect.model.RecordFilter in project collect by openforis.
the class RecordIndexManager method indexAllRecords.
public void indexAllRecords(CollectSurvey survey, String rootEntity) throws RecordIndexException {
cancelled = false;
RecordFilter filter = new RecordFilter(survey);
filter.setRootEntityId(survey.getSchema().getRootEntityDefinition(rootEntity).getId());
List<CollectRecordSummary> summaries = recordManager.loadSummaries(filter);
IndexWriter indexWriter = null;
try {
indexWriter = createIndexWriter();
for (CollectRecordSummary s : summaries) {
if (!cancelled) {
Integer recordId = s.getId();
deleteDocuments(indexWriter, recordId);
CollectRecord record = recordManager.load(survey, recordId, s.getStep());
index(indexWriter, record);
} else {
break;
}
}
} catch (Exception e) {
throw new RecordIndexException(e);
} finally {
close(indexWriter);
}
}
use of org.openforis.collect.model.RecordFilter in project collect by openforis.
the class RecordManager method isUnique.
/**
* Returns false if another record with the same root entity key values exists.
*/
public boolean isUnique(CollectRecord record) {
record.updateSummaryFields();
CollectSurvey survey = (CollectSurvey) record.getSurvey();
RecordFilter filter = new RecordFilter(survey, record.getRootEntityDefinitionId());
filter.setKeyValues(record.getRootEntityKeyValues());
filter.setIncludeNullConditionsForKeyValues(true);
List<CollectRecordSummary> summaries = recordDao.loadSummaries(filter);
for (CollectRecordSummary s : summaries) {
if (!s.getId().equals(record.getId())) {
return false;
}
}
return true;
}
use of org.openforis.collect.model.RecordFilter in project collect by openforis.
the class RecordManager method determineLastStep.
private Step determineLastStep(CollectSurvey survey, int recordId) {
RecordFilter filter = new RecordFilter(survey);
filter.setRecordId(recordId);
List<CollectRecordSummary> summaries = recordDao.loadSummaries(filter, null);
if (summaries.isEmpty()) {
return null;
} else {
CollectRecordSummary summary = summaries.get(0);
return summary.getStep();
}
}
use of org.openforis.collect.model.RecordFilter in project collect by openforis.
the class RecordValidationProcess method startProcessing.
@Override
@Transactional(propagation = Propagation.SUPPORTS)
public void startProcessing() throws Exception {
super.startProcessing();
validateParameters();
status.setTotal(recordManager.countRecords(new RecordFilter(survey)));
Schema schema = survey.getSchema();
List<EntityDefinition> rootEntities = schema.getRootEntityDefinitions();
for (EntityDefinition rootEntityDef : rootEntities) {
RecordFilter filter = new RecordFilter(survey, rootEntityDef.getId());
List<CollectRecordSummary> summaries = recordManager.loadSummaries(filter);
for (CollectRecordSummary summary : summaries) {
// print(outputStream, "Start validating record: " + recordKey);
if (status.isRunning()) {
Step step = summary.getStep();
Integer recordId = summary.getId();
recordManager.validateAndSave(survey, user, sessionId, recordId, step);
status.incrementProcessed();
// long elapsedMillis = System.currentTimeMillis() - start;
// print(outputStream, "Validation of record " + recordKey + " completed in " + elapsedMillis + " millis");
}
}
}
if (status.isRunning()) {
status.complete();
}
}
use of org.openforis.collect.model.RecordFilter in project collect by openforis.
the class DataQueryController method startExport.
@RequestMapping(value = "start-export.json", method = RequestMethod.POST)
@ResponseBody
public Response startExport(@Validated DataQueryForm form, @RequestParam Step recordStep) throws Exception {
CollectSurvey survey = sessionManager.getActiveSurvey();
DataQuery query = new DataQuery(survey);
form.copyTo(query);
exportJob = collectJobManager.createJob(CSVDataExportJob.class);
exportJob.setOutputFile(File.createTempFile("data-query-export", ".csv"));
CSVDataExportParameters parameters = new CSVDataExportParameters();
RecordFilter recordFilter = new RecordFilter(survey);
recordFilter.setStepGreaterOrEqual(recordStep);
parameters.setRecordFilter(recordFilter);
parameters.setEntityId(query.getEntityDefinitionId());
parameters.setAlwaysGenerateZipFile(false);
parameters.setNodeFilter(new DescendantNodeFilter(query.getAttributeDefinition(), query.getConditions()));
exportJob.setParameters(parameters);
collectJobManager.start(exportJob);
/*
csvExportItemProcessor = new CSVWriterDataQueryResultItemProcessor(query);
csvExportItemProcessor.init();
exportJob = collectJobManager.createJob(DataQueryExecutorJob.class);
exportJob.setInput(new DataQueryExecutorJobInput(query, recordStep, csvExportItemProcessor));
collectJobManager.start(exportJob);
*/
Response response = new Response();
return response;
}
Aggregations