}
public ActionForward zipDocuments(ActionMapping mapping, ActionForm actionForm, HttpServletRequest request,
HttpServletResponse response) {
try {
RectorateSubmissionBatch batch = getDomainObject(request, "batchOid");
Set<AcademicServiceRequest> requestsToZip = new HashSet<AcademicServiceRequest>();
for (AcademicServiceRequest document : batch.getDocumentRequestSet()) {
// Filter out canceled document requests, ticket: #248539
if (!document.isDiploma() && !document.isCancelled() && !document.isRejected()) {
requestsToZip.add(document);
}
}
if (!requestsToZip.isEmpty()) {
ByteArrayOutputStream bout = new ByteArrayOutputStream();
ZipOutputStream zip = new ZipOutputStream(bout);
for (AcademicServiceRequest document : requestsToZip) {
zip.putNextEntry(new ZipEntry(document.getLastGeneratedDocument().getFilename()));
zip.write(document.getLastGeneratedDocument().getContents());
zip.closeEntry();
}
zip.close();
response.setContentType("application/zip");
response.addHeader("Content-Disposition", "attachment; filename=documentos-" + batch.getRange() + ".zip");
ServletOutputStream writer = response.getOutputStream();
writer.write(bout.toByteArray());
writer.flush();
writer.close();
response.flushBuffer();
return null;
} else {
addActionMessage(request, "error.rectorateSubmission.noDocumentsToZip");
request.setAttribute("batchOid", batch.getExternalId());
return viewBatch(mapping, actionForm, request, response);
}
} catch (IOException e) {
throw new DomainException("error.rectorateSubmission.errorGeneratingMetadata", e);
}