Skip to content

Commit

Permalink
Put assertions into subdirectories in zip.
Browse files Browse the repository at this point in the history
  • Loading branch information
vteague committed Aug 23, 2024
1 parent 5bd2190 commit 77f0642
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public String endpointBody(final Request the_request, final Response the_respons
the_response.header("Content-Type", "application/zip");
the_response.header("Content-Disposition",
"attachment; filename*=UTF-8''assertions_" + suffix + ".zip");
getAssertions(os, suffix);
getAssertions(os, "", suffix);
os.close();

ok(the_response);
Expand Down Expand Up @@ -158,7 +158,7 @@ public String endpointBody(final Request the_request, final Response the_respons
* @param zos an output stream (to become a zip file)
* @param suffix requested file type: "csv" or "json"
*/
public static void getAssertions(final ZipOutputStream zos, String suffix)
public static void getAssertions(final ZipOutputStream zos, String directory, String suffix)
throws IOException {
final String prefix = "[getAssertions]";

Expand All @@ -180,7 +180,9 @@ public static void getAssertions(final ZipOutputStream zos, String suffix)

// Remove non-word characters for saving into .zip file; set up the zip next entry.
final String sanitizedContestName = cr.getContestName().replaceAll("[\\W]", "");
zos.putNextEntry(new ZipEntry(sanitizedContestName + "_assertions." + suffix));
// If we have a nonempty directory, add "/" to it (apparently this is platform independent).
final String dirString = directory.isBlank() ? "" : directory + "/";
zos.putNextEntry(new ZipEntry(dirString + sanitizedContestName + "_assertions." + suffix));

// Make the request.
final GetAssertionsRequest getAssertionsRequest = new GetAssertionsRequest(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,10 @@
package us.freeandfair.corla.controller;

import java.io.OutputStream;
import java.net.URISyntaxException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.io.IOException;
import org.apache.commons.csv.CSVFormat;
import org.apache.commons.csv.CSVParser;
import org.apache.commons.csv.CSVRecord;
import java.io.Reader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
Expand All @@ -33,13 +25,11 @@
import us.freeandfair.corla.report.StateReport;
import us.freeandfair.corla.model.DoSDashboard;
import us.freeandfair.corla.persistence.Persistence;
//import us.freeandfair.corla.query.CSVParser;
import us.freeandfair.corla.query.ExportQueries;

import static au.org.democracydevelopers.corla.endpoint.GetAssertions.CSV_SUFFIX;
import static au.org.democracydevelopers.corla.endpoint.GetAssertions.JSON_SUFFIX;
import static au.org.democracydevelopers.corla.endpoint.GetAssertions.getAssertions;
//import us.freeandfair.corla.query.Reader;

/**
* Find the data for a report and format it to be rendered into a presentation
Expand Down Expand Up @@ -229,11 +219,11 @@ public static void generateZip(final OutputStream os, List<String> selectedRepor
}

if ("assertions_json".equalsIgnoreCase(reportName)) {
getAssertions(zos, JSON_SUFFIX);
getAssertions(zos, "assertions-json", JSON_SUFFIX);
}

if ("assertions_csv".equalsIgnoreCase(reportName)) {
getAssertions(zos, CSV_SUFFIX);
getAssertions(zos, "assertions-csv", CSV_SUFFIX);
}
}
} catch (IOException e) {
Expand Down

0 comments on commit 77f0642

Please sign in to comment.