use of org.openforis.collect.model.RecordFilter in project collect by openforis.
the class XMLDataExportProcess method loadAllSummaries.
private List<CollectRecordSummary> loadAllSummaries() {
RecordFilter filter = new RecordFilter(survey);
filter.setRootEntityId(survey.getSchema().getRootEntityDefinition(rootEntityName).getId());
filter.setModifiedSince(modifiedSince);
List<CollectRecordSummary> summaries = recordManager.loadSummaries(filter);
return summaries;
}
use of org.openforis.collect.model.RecordFilter in project collect by openforis.
the class DataRestoreSummaryTask method findAlreadyExistingFullRecordSummary.
private CollectRecordSummary findAlreadyExistingFullRecordSummary(int entryId, Step step, CollectRecord parsedRecord) {
List<String> keyValues = parsedRecord.getRootEntityKeyValues();
Entity rootEntity = parsedRecord.getRootEntity();
int rootEntityDefId = rootEntity.getDefinition().getId();
RecordFilter filter = new RecordFilter(survey);
filter.setRootEntityId(rootEntityDefId);
filter.setKeyValues(keyValues);
List<CollectRecordSummary> oldRecordSummaries = recordManager.loadSummaries(filter);
if (oldRecordSummaries == null || oldRecordSummaries.isEmpty()) {
return null;
} else if (oldRecordSummaries.size() == 1) {
CollectRecordSummary summary = oldRecordSummaries.get(0);
CollectRecord record = recordManager.load(survey, summary.getId(), summary.getStep(), fullSummary);
CollectRecordSummary recordSummary = CollectRecordSummary.fromRecord(record);
recordSummary.setFiles(recordFileManager.getAllFiles(record));
return recordSummary;
} else {
String errorMessage = String.format("Data file: %s - multiple records found in survey %s with key(s) %s", getEntryName(entryId, step), survey.getName(), keyValues);
throw new IllegalStateException(errorMessage);
}
}
use of org.openforis.collect.model.RecordFilter in project collect by openforis.
the class DataRestoreSummaryTask method findAlreadyExistingRecordSummary.
private CollectRecordSummary findAlreadyExistingRecordSummary(int entryId, Step step, int rootEntityDefId, List<String> rootEntityKeys) {
RecordFilter filter = new RecordFilter(survey);
filter.setRootEntityId(rootEntityDefId);
filter.setKeyValues(rootEntityKeys);
List<CollectRecordSummary> summaries = recordManager.loadSummaries(filter);
switch(summaries.size()) {
case 0:
return null;
case 1:
return summaries.get(0);
default:
String errorMessage = String.format("Data file: %s - multiple records found in survey %s with key(s) %s", getEntryName(entryId, step), survey.getName(), rootEntityKeys);
throw new IllegalStateException(errorMessage);
}
}
use of org.openforis.collect.model.RecordFilter in project collect by openforis.
the class RecordController method loadRecordSummaries.
@RequestMapping(value = "survey/{surveyId}/data/records/summary", method = GET)
@ResponseBody
public Map<String, Object> loadRecordSummaries(@PathVariable("surveyId") int surveyId, @Valid RecordSummarySearchParameters params) {
CollectSurvey survey = surveyManager.getOrLoadSurveyById(surveyId);
User user = loadUser(params.getUserId(), params.getUsername());
Map<String, Object> result = new HashMap<String, Object>();
Schema schema = survey.getSchema();
EntityDefinition rootEntityDefinition = params.getRootEntityName() == null ? schema.getFirstRootEntityDefinition() : schema.getRootEntityDefinition(params.getRootEntityName());
RecordFilter filter = createRecordFilter(survey, user, userGroupManager, rootEntityDefinition.getId(), false);
filter.setKeyValues(params.getKeyValues());
filter.setCaseSensitiveKeyValues(params.isCaseSensitiveKeyValues());
if (CollectionUtils.isEmpty(filter.getQualifiers())) {
// filter by qualifiers only if not already done by user group qualifiers
filter.setQualifiers(params.getQualifierValues());
}
filter.setSummaryValues(params.getSummaryValues());
if (filter.getOwnerIds() == null && params.getOwnerIds() != null && params.getOwnerIds().length > 0) {
filter.setOwnerIds(Arrays.asList(params.getOwnerIds()));
}
filter.setOffset(params.getOffset());
filter.setMaxNumberOfRecords(params.getMaxNumberOfRows());
// load summaries
List<CollectRecordSummary> summaries = params.isFullSummary() ? recordManager.loadFullSummaries(filter, params.getSortFields()) : recordManager.loadSummaries(filter, params.getSortFields());
result.put("records", toProxies(summaries));
// count total records
int count = recordManager.countRecords(filter);
result.put("count", count);
if (params.isIncludeOwners()) {
Set<User> owners = recordManager.loadDistinctOwners(createRecordFilter(survey, user, userGroupManager, rootEntityDefinition.getId(), false));
Set<BasicUserProxy> ownerProxies = Proxies.fromSet(owners, BasicUserProxy.class);
result.put("owners", ownerProxies);
}
return result;
}
use of org.openforis.collect.model.RecordFilter in project collect by openforis.
the class RecordController method exportRecord.
@RequestMapping(value = "survey/{survey_id}/data/records/{record_id}/steps/{step}/csv_content.zip", method = GET, produces = MediaTypes.ZIP_CONTENT_TYPE)
public void exportRecord(@PathVariable(value = "survey_id") int surveyId, @PathVariable(value = "record_id") int recordId, @PathVariable(value = "step") int stepNumber, HttpServletResponse response) throws RecordPersistenceException, IOException {
CollectSurvey survey = surveyManager.getById(surveyId);
CollectRecord record = recordManager.load(survey, recordId);
RecordAccessControlManager accessControlManager = new RecordAccessControlManager();
if (accessControlManager.canEdit(sessionManager.getLoggedUser(), record)) {
CSVDataExportJob job = jobManager.createJob(CSVDataExportJob.class);
CSVDataExportParameters parameters = new CSVDataExportParameters();
RecordFilter recordFilter = createRecordFilter(survey, sessionManager.getLoggedUser(), userGroupManager, null, false);
recordFilter.setRecordId(recordId);
recordFilter.setStepGreaterOrEqual(Step.valueOf(stepNumber));
parameters.setRecordFilter(recordFilter);
parameters.setAlwaysGenerateZipFile(true);
job.setParameters(parameters);
File outputFile = File.createTempFile("record_export", ".zip");
job.setOutputFile(outputFile);
jobManager.startSurveyJob(job);
if (job.isCompleted()) {
String fileName = String.format("record_data_%s.zip", Dates.formatDate(new Date()));
Controllers.writeFileToResponse(response, outputFile, fileName, MediaTypes.ZIP_CONTENT_TYPE);
}
}
}
Aggregations