Search in sources :

Example 1 with RecordAccessControlManager

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);
        }
    }
}
Also used : CollectRecord(org.openforis.collect.model.CollectRecord) CSVDataExportJob(org.openforis.collect.io.data.CSVDataExportJob) CSVDataExportParameters(org.openforis.collect.io.data.csv.CSVDataExportParameters) CollectSurvey(org.openforis.collect.model.CollectSurvey) RecordAccessControlManager(org.openforis.collect.manager.RecordAccessControlManager) File(java.io.File) MultipartFile(org.springframework.web.multipart.MultipartFile) RecordFilter(org.openforis.collect.model.RecordFilter) Date(java.util.Date) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with RecordAccessControlManager

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;
}
Also used : User(org.openforis.collect.model.User) UserInGroup(org.openforis.collect.model.UserInGroup) CollectRecordSummary(org.openforis.collect.model.CollectRecordSummary) CollectSurvey(org.openforis.collect.model.CollectSurvey) RecordAccessControlManager(org.openforis.collect.manager.RecordAccessControlManager) RecordFilter(org.openforis.collect.model.RecordFilter)

Aggregations

RecordAccessControlManager (org.openforis.collect.manager.RecordAccessControlManager)2 CollectSurvey (org.openforis.collect.model.CollectSurvey)2 RecordFilter (org.openforis.collect.model.RecordFilter)2 File (java.io.File)1 Date (java.util.Date)1 CSVDataExportJob (org.openforis.collect.io.data.CSVDataExportJob)1 CSVDataExportParameters (org.openforis.collect.io.data.csv.CSVDataExportParameters)1 CollectRecord (org.openforis.collect.model.CollectRecord)1 CollectRecordSummary (org.openforis.collect.model.CollectRecordSummary)1 User (org.openforis.collect.model.User)1 UserInGroup (org.openforis.collect.model.UserInGroup)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 MultipartFile (org.springframework.web.multipart.MultipartFile)1