Search in sources :

Example 1 with ValidationReportProcess

use of org.openforis.collect.manager.ValidationReportProcess in project collect by openforis.

the class ValidationController method validationReport.

@RequestMapping(value = "/validationReport", method = RequestMethod.GET)
public void validationReport(HttpServletRequest request, HttpServletResponse response, @RequestParam(required = false) String surveyName, @RequestParam(required = false) Integer rootEntityId, @RequestParam(required = false, defaultValue = "en_US") String locale, String[] recordKeys, @RequestParam(required = false) Date modifiedSince) throws IOException {
    ServletOutputStream outputStream = response.getOutputStream();
    try {
        if (surveyName == null || rootEntityId == null || locale == null) {
            outputStream.println("Wrong parameters: please specify 'surveyName' (name of the survey), 'rootEntityId' (root entity id) and 'locale' string rappresentation of locale");
            return;
        }
        CollectSurvey survey = surveyManager.get(surveyName);
        if (survey == null) {
            print(outputStream, "Survey not found");
            return;
        }
        response.setContentType("text/csv");
        String outputFileName = String.format("%s_validation_report_%s.csv", surveyName, Dates.formatDateTime(new Date()));
        response.setHeader("Content-Disposition", "attachment; fileName=" + outputFileName);
        SessionState sessionState = getSessionState(request);
        User user = sessionState.getUser();
        String sessionId = sessionState.getSessionId();
        RecordFilter recordFilter = new RecordFilter(survey, rootEntityId);
        recordFilter.setKeyValues(recordKeys);
        recordFilter.setModifiedSince(modifiedSince);
        if (user.getRole() == UserRole.ENTRY_LIMITED) {
            recordFilter.setOwnerId(user.getId());
        }
        ValidationReportProcess process = new ValidationReportProcess(outputStream, recordManager, messageContextHolder, ReportType.CSV, user, sessionId, recordFilter, true, LocaleUtils.toLocale(locale));
        process.init();
        process.call();
    } catch (Exception e) {
        // outputStream.println("ERROR - Validation of records not completed: " + e.getMessage());
        LOG.error("ERROR - Validation of records not completed: " + e.getMessage(), e);
        throw new RuntimeException(e);
    }
}
Also used : SessionState(org.openforis.collect.web.session.SessionState) User(org.openforis.collect.model.User) ServletOutputStream(javax.servlet.ServletOutputStream) ValidationReportProcess(org.openforis.collect.manager.ValidationReportProcess) CollectSurvey(org.openforis.collect.model.CollectSurvey) Date(java.util.Date) RecordFilter(org.openforis.collect.model.RecordFilter) IOException(java.io.IOException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

IOException (java.io.IOException)1 Date (java.util.Date)1 ServletOutputStream (javax.servlet.ServletOutputStream)1 ValidationReportProcess (org.openforis.collect.manager.ValidationReportProcess)1 CollectSurvey (org.openforis.collect.model.CollectSurvey)1 RecordFilter (org.openforis.collect.model.RecordFilter)1 User (org.openforis.collect.model.User)1 SessionState (org.openforis.collect.web.session.SessionState)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1