}
@Override
public ActionForward printDocument(ActionMapping mapping, ActionForm actionForm, HttpServletRequest request,
HttpServletResponse response) throws IOException, FenixServiceException {
final IDocumentRequest documentRequest = getDocumentRequest(request);
try {
final List<AdministrativeOfficeDocument> documents =
AdministrativeOfficeDocument.AdministrativeOfficeDocumentCreator.create(documentRequest);
DocumentFieldsCustomization customization = getRenderedObject("document.fields.customization");
if (documentRequest.isRequestForRegistration()) {
DocumentPrintRequest.logRequest(customization.getConclusionDate(), customization.getDegreeDescription(),
customization.getGraduatedTitle(), (DocumentRequest) documentRequest);
}
if (DocumentRequestType.DEGREE_FINALIZATION_CERTIFICATE.equals(documentRequest.getDocumentRequestType())) {
documents.iterator().next().getParameters().put("degreeFinalizationDate", customization.getConclusionDate());
documents.iterator().next().getParameters().put("degreeDescription", customization.getDegreeDescription());
documents.iterator().next().getParameters().put("graduateTitle", customization.getGraduatedTitle());
} else if (DocumentRequestType.DIPLOMA_REQUEST.equals(documentRequest.getDocumentRequestType())) {
documents.iterator().next().getParameters().put("conclusionDate", customization.getConclusionDate());
documents.iterator().next().getParameters().put("degreeFilteredName", customization.getDegreeDescription());
documents.iterator().next().getParameters().put("graduateTitle", customization.getGraduatedTitle());
}
final AdministrativeOfficeDocument[] array = {};
byte[] data = ReportsUtils.exportMultipleToPdfAsByteArray(documents.toArray(array));
DocumentRequestGeneratedDocument.store(documentRequest, documents.iterator().next().getReportFileName() + ".pdf",
data);
response.setContentLength(data.length);
response.setContentType("application/pdf");
response.addHeader("Content-Disposition", "attachment; filename=" + documents.iterator().next().getReportFileName()
+ ".pdf");
final ServletOutputStream writer = response.getOutputStream();
writer.write(data);
writer.flush();
writer.close();
response.flushBuffer();
return mapping.findForward("");
} catch (DomainException e) {
addActionMessage(request, e.getKey());
if (documentRequest.isRequestForRegistration()) {
request.setAttribute("registration", ((DocumentRequest) documentRequest).getRegistration());
}
return mapping.findForward("viewRegistrationDetails");
}
}