use of org.openforis.collect.manager.RecordAccessControlManager 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);
}
}
}
use of org.openforis.collect.manager.RecordAccessControlManager in project collect by openforis.
the class RecordController method canDeleteRecords.
private boolean canDeleteRecords(int surveyId, Set<Integer> recordIds) {
CollectSurvey survey = surveyManager.getById(surveyId);
RecordFilter filter = new RecordFilter(survey);
filter.setRecordIds(recordIds);
List<CollectRecordSummary> recordSummaries = recordManager.loadSummaries(filter);
User loggedUser = sessionManager.getLoggedUser();
RecordAccessControlManager recordAccessControlManager = new RecordAccessControlManager();
UserInGroup userInSurveyGroup = userGroupManager.findUserInGroupOrDescendants(survey.getUserGroup(), loggedUser);
boolean canDeleteRecords = userInSurveyGroup != null && recordAccessControlManager.canDeleteRecords(loggedUser, userInSurveyGroup.getRole(), recordSummaries);
return canDeleteRecords;
}
Aggregations