<commit_before>// Copyright © 2015 HSL <https://www.hsl.fi>
// This program is dual-licensed under the EUPL v1.2 and AGPLv3 licenses.

package fi.hsl.parkandride.front;

import fi.hsl.parkandride.core.domain.User;
import fi.hsl.parkandride.core.service.AccessDeniedException;
import fi.hsl.parkandride.core.service.ReportService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.inject.Inject;
import javax.validation.constraints.NotNull;
import java.util.Collection;
import java.util.Map;
import java.util.Optional;

import static fi.hsl.parkandride.front.UrlSchema.REPORT;
import static fi.hsl.parkandride.front.UrlSchema.REPORT_ID;
import static java.util.stream.Collectors.toMap;
import static org.springframework.http.HttpHeaders.CONTENT_DISPOSITION;
import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;
import static org.springframework.http.ResponseEntity.*;
import static org.springframework.web.bind.annotation.RequestMethod.POST;

@RestController
public class ReportController {
    private static final Logger log = LoggerFactory.getLogger(ReportController.class);
    public static final String MEDIA_TYPE_EXCEL = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";

    private final Map<String, ReportService> reporters;

    @Inject
    public ReportController(Collection<ReportService> reportServices) {
        this.reporters = reportServices.stream().collect(toMap(rs -> rs.reportName(), rs -> rs));
    }

    @RequestMapping(method = POST, value = REPORT, consumes = APPLICATION_JSON_VALUE,  produces = MEDIA_TYPE_EXCEL)
    public ResponseEntity<?> report(@NotNull @PathVariable(REPORT_ID) String reportId, @RequestBody ReportParameters parameters, User currentUser) {
        log.info("report({})", reportId);
        byte[] report;
        try {
            report = Optional.ofNullable(reporters.get(reportId)).get().generateReport(currentUser, parameters);
        } catch (AccessDeniedException ade) {
            log.error("Access denied", ade);
            return status(HttpStatus.FORBIDDEN).body(new byte[0]);
        } catch (Exception e) {
            e.printStackTrace();
            log.error("Failed to generate report", e);
            return badRequest().body(new byte[0]);<commit_msg>fix(report): remove printStackTrace from report controller<commit_after>// Copyright © 2015 HSL <https://www.hsl.fi>
// This program is dual-licensed under the EUPL v1.2 and AGPLv3 licenses.

package fi.hsl.parkandride.front;

import fi.hsl.parkandride.core.domain.User;
import fi.hsl.parkandride.core.service.AccessDeniedException;
import fi.hsl.parkandride.core.service.ReportService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.inject.Inject;
import javax.validation.constraints.NotNull;
import java.util.Collection;
import java.util.Map;
import java.util.Optional;

import static fi.hsl.parkandride.front.UrlSchema.REPORT;
import static fi.hsl.parkandride.front.UrlSchema.REPORT_ID;
import static java.util.stream.Collectors.toMap;
import static org.springframework.http.HttpHeaders.CONTENT_DISPOSITION;
import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;
import static org.springframework.http.ResponseEntity.*;
import static org.springframework.web.bind.annotation.RequestMethod.POST;

@RestController
public class ReportController {
    private static final Logger log = LoggerFactory.getLogger(ReportController.class);
    public static final String MEDIA_TYPE_EXCEL = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";

    private final Map<String, ReportService> reporters;

    @Inject
    public ReportController(Collection<ReportService> reportServices) {
        this.reporters = reportServices.stream().collect(toMap(rs -> rs.reportName(), rs -> rs));
    }

    @RequestMapping(method = POST, value = REPORT, consumes = APPLICATION_JSON_VALUE,  produces = MEDIA_TYPE_EXCEL)
    public ResponseEntity<?> report(@NotNull @PathVariable(REPORT_ID) String reportId, @RequestBody ReportParameters parameters, User currentUser) {
        log.info("report({})", reportId);
        byte[] report;
        try {
            report = Optional.ofNullable(reporters.get(reportId)).get().generateReport(currentUser, parameters);
        } catch (AccessDeniedException ade) {
            log.error("Access denied", ade);
            return status(HttpStatus.FORBIDDEN).body(new byte[0]);
        } catch (Exception e) {
            log.error("Failed to generate report", e);
            return badRequest().body(new byte[0]);
{'fraction_non_alphanumeric': 0.1052932216298553, 'fraction_numerical': 0.004188880426504189, 'mean_word_length': 4.810840707964601, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 15, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3111203', 'n_tokens_mistral': 1492, 'n_tokens_neox': 1467, 'n_words': 303}