Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.StringWriter;
import java.nio.file.Files;
Expand Down Expand Up @@ -372,31 +373,35 @@ public StreamingOutput getLatestIntegrityReport(@QueryParam("collectionID") Stri
public Response getIntegrityReportsAsZIP(@QueryParam("collectionID") String collectionID,
@QueryParam("reports") List<String> reports) {
String fileName = "IntegrityReports.zip";
HashMap<String, File> files = new HashMap<>();
Map<String, File> files = new HashMap<>();

for (String report : reports) {
String[] parts = report.split("-", 2);
files.put(report, getLatestIntegrityReportPartFile(collectionID, parts[0], parts[1]));
}

StreamingOutput streamingOutput = output -> {
ZipOutputStream zipOut = new ZipOutputStream(output);
// Add the full integrity report to the hashmap
files.put("report", integrityReportProvider.getLatestIntegrityReportReader(collectionID).getFullReport());

// Zip each file in the files hashmap
files.forEach((key, value) -> {
try {
zipOut.putNextEntry(new ZipEntry(key));
zipOut.write(Files.readAllBytes(value.toPath()));
zipOut.flush();
} catch (IOException e) {
throw new WebApplicationException(status(Status.INTERNAL_SERVER_ERROR).entity(
"Something went wrong when trying to zip the file " + key + ".").type(
MediaType.TEXT_PLAIN).build());
}
});
zipOut.close();
try (ZipOutputStream zipOut = new ZipOutputStream(output)) {
// Zip each file in the files hashmap
files.forEach((key, value) -> {
try {
zipOut.putNextEntry(new ZipEntry(key));
try (InputStream is = Files.newInputStream(value.toPath())) {
is.transferTo(zipOut);
}
zipOut.flush();
} catch (IOException e) {
throw new WebApplicationException(
status(Status.INTERNAL_SERVER_ERROR)
.entity("Internal error when trying to zip the report file " + key + ": " + e)
.type(MediaType.TEXT_PLAIN)
.build());
}
});
}
};
ResponseBuilder response = Response.ok();
response.type("application/zip");
Expand Down
2 changes: 1 addition & 1 deletion bitrepository-service/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.4.1</version>
<version>42.4.5</version>
</dependency>
<dependency>
<groupId>com.mchange</groupId>
Expand Down