<commit_before>package nuclibook.routes;

import nuclibook.constants.P;
import nuclibook.entity_utils.ExportUtils;
import nuclibook.entity_utils.PatientUtils;
import nuclibook.entity_utils.SecurityUtils;
import nuclibook.models.Patient;
import nuclibook.server.HtmlRenderer;
import spark.Request;
import spark.Response;

import java.util.List;

public class ExportRoute extends DefaultRoute {

    @Override
    public Object handle(Request request, Response response) throws Exception {
        // necessary prelim routine
        prepareToHandle();

        String[] fileSplit = request.params(":file:").split("\\.", 2);
        String table = fileSplit[0];
        String type = fileSplit[1];

        String exportData = null;

        if (table.equals("patients")) {
            if (SecurityUtils.requirePermission(P.VIEW_PATIENT_LIST, response)) {
                if (type.equals("csv")) {
                    return ExportUtils.exportCSV(Patient.class);
                }
            }
        }

        if (exportData != null) {
            response.header("Content-Disposition", "attachment");
        }

        return exportData;<commit_msg>Prevent crash if user doesn't enter a filename<commit_after>package nuclibook.routes;

import nuclibook.constants.P;
import nuclibook.entity_utils.ExportUtils;
import nuclibook.entity_utils.PatientUtils;
import nuclibook.entity_utils.SecurityUtils;
import nuclibook.models.Patient;
import nuclibook.server.HtmlRenderer;
import spark.Request;
import spark.Response;

import java.util.List;

public class ExportRoute extends DefaultRoute {

    @Override
    public Object handle(Request request, Response response) throws Exception {
        // necessary prelim routine
        prepareToHandle();

        String[] fileSplit = request.params(":file:").split("\\.", 2);
        String table = fileSplit[0];

        try {
            String type = fileSplit[1];
        } catch (ArrayIndexOutOfBoundsException e) {
            return null;
        }

        String exportData = null;

        if (table.equals("patients")) {
            if (SecurityUtils.requirePermission(P.VIEW_PATIENT_LIST, response)) {
                if (type.equals("csv")) {
                    return ExportUtils.exportCSV(Patient.class);
                }
            }
        }

        if (exportData != null) {
            response.header("Content-Disposition", "attachment");
        }

        return exportData;
{'fraction_non_alphanumeric': 0.10139002452984465, 'fraction_numerical': 0.0024529844644317253, 'mean_word_length': 2.635958395245171, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '5993319', 'n_tokens_mistral': 682, 'n_tokens_neox': 646, 'n_words': 146}