/** * method to stream the byte array to response object * * @param fileContents * @param fileName * @param fileContentType * @param response * @throws Exception */ protected void streamToResponse( org.kuali.kra.proposaldevelopment.bo.AttachmentDataSource attachmentDataSource, HttpServletResponse response) throws Exception { byte[] xbts = attachmentDataSource.getContent(); ByteArrayOutputStream baos = null; try { baos = new ByteArrayOutputStream(xbts.length); baos.write(xbts); WebUtils.saveMimeOutputStreamAsFile( response, attachmentDataSource.getContentType(), baos, attachmentDataSource.getFileName()); } finally { try { if (baos != null) { baos.close(); baos = null; } } catch (IOException ioEx) { LOG.error("Error while downloading attachment"); throw new RuntimeException("IOException occurred while downloading attachment", ioEx); } } }
/** * Handy method to stream the byte array to response object * * @param attachmentDataSource * @param response * @throws Exception */ public void streamToResponse( AttachmentDataSource attachmentDataSource, HttpServletResponse response) throws Exception { byte[] xbts = attachmentDataSource.getContent(); ByteArrayOutputStream baos = null; if (xbts != null) try { baos = new ByteArrayOutputStream(xbts.length); baos.write(xbts); WebUtils.saveMimeOutputStreamAsFile( response, attachmentDataSource.getContentType(), baos, attachmentDataSource.getFileName()); } finally { try { if (baos != null) { baos.close(); baos = null; } } catch (IOException ioEx) { LOG.warn(ioEx.getMessage(), ioEx); } } }
/** {@inheritDoc}* */ public void generateCorrespondenceDocumentAndAttach( ProtocolActionsCorrespondenceBase printableCorrespondence) throws PrintingException { if (printableCorrespondence.getXSLTemplates().size() > 0) { // there are templates in play, lets do some printing and attaching ProtocolBase protocol = printableCorrespondence.getProtocol(); AttachmentDataSource ads = this.printingService.print(printableCorrespondence); applySignatureInDocument(printableCorrespondence, ads); if (ads.getContent().length > 0) { // only need to do this, if there is actually printable correspondence to save // this may not be the case if a bad template is put in place, or under certain testing // conditions. buildAndAttachProtocolCorrespondence( protocol, ads.getContent(), printableCorrespondence.getProtoCorrespTypeCode()); } } }
/** * This method is used for the printing of forms in PDF format. It generates PDF forms and puts it * into {@link AttachmentDataSource} * * @param pdDoc(ProposalDevelopmentDocument) * @return {@link AttachmentDataSource} which contains all information related to the generated * PDF * @throws * @throws S2SException * @see * org.kuali.kra.s2s.service.PrintService#printForm(org.kuali.kra.proposaldevelopment.document.ProposalDevelopmentDocument) */ public org.kuali.kra.proposaldevelopment.bo.AttachmentDataSource printForm( ProposalDevelopmentDocument pdDoc) throws S2SException, PrintingException { List<Printable> printableList = null; S2sAppSubmission s2sAppSubmission = getLatestS2SAppSubmission(pdDoc); if (s2sAppSubmission != null && s2sAppSubmission.getGgTrackingId() != null) { printableList = getSubmittedPDFStream(pdDoc); } else { printableList = getPDFStream(pdDoc); } if (pdDoc.getDevelopmentProposal().getGrantsGovSelectFlag()) { return null; } AttachmentDataSource attachmentDataSource = printingService.print(printableList); attachmentDataSource.setFileName(getFileNameForFormPrinting(pdDoc)); return attachmentDataSource; }
/** * @see * org.kuali.kra.questionnaire.print.QuestionnairePrintingService#printQuestionnaireAnswer(KewPersistableBusinessObjectBase, * java.util.Map) */ public AttachmentDataSource printQuestionnaireAnswer( KraPersistableBusinessObjectBase printableBusinessObject, Map<String, Object> reportParameters) throws PrintingException { AttachmentDataSource source = null; AbstractPrint printable = getQuestionnairePrint(); if (printable != null) { printable.setPrintableBusinessObject(printableBusinessObject); printable.setReportParameters(reportParameters); source = getPrintingService().print(printable); source.setFileName( "QuestionnaireAnswer" + reportParameters.get("questionnaireId") + Constants.PDF_FILE_EXTENSION); source.setContentType(Constants.PDF_REPORT_CONTENT_TYPE); } return source; }
/** * @see * org.kuali.kra.questionnaire.print.QuestionnairePrintingService#printQuestionnaire(org.kuali.kra.document.ResearchDocumentBase, * java.util.Map) */ public AttachmentDataSource printQuestionnaire( KraPersistableBusinessObjectBase printableBusinessObject, Map<String, Object> reportParameters) throws PrintingException { /* TODO : Questionnaire is a maintenance document. questionnaireId is generated when document is approved and * saved to DB. so, pk is not in doc xml content, and passing questionnaireid will not work. * Therefore, passing documentNumber, questionnaire can be retrieved from xml content by loaddocument. * This is what I think how offshore team can get questionnaire data to generate pdf. */ AttachmentDataSource source = null; AbstractPrint printable = getQuestionnairePrint(); if (printable != null) { printable.setPrintableBusinessObject(printableBusinessObject); printable.setReportParameters(reportParameters); source = getPrintingService().print(printable); source.setFileName( "Questionnaire-" + reportParameters.get("documentNumber") + Constants.PDF_FILE_EXTENSION); source.setContentType(Constants.PDF_REPORT_CONTENT_TYPE); } return source; }
protected void saveGrantsGovXml( ProposalDevelopmentDocument pdDoc, boolean formEntryFlag, XmlObject formObject, List<AttachmentData> attachmentList, List<S2sAppAttachments> attachmentLists) throws Exception { String loggingDirectory = KraServiceLocator.getService(ConfigurationService.class) .getPropertyValueAsString(Constants.PRINT_XML_DIRECTORY); String opportunityId = pdDoc.getDevelopmentProposal().getS2sOpportunity().getOpportunityId(); String proposalnumber = pdDoc.getDevelopmentProposal().getProposalNumber(); String exportDate = StringUtils.replaceChars( (pdDoc.getDevelopmentProposal().getUpdateTimestamp().toString()), ":", "_"); exportDate = StringUtils.replaceChars(exportDate, " ", "."); if (grantsGovXmlDirectoryFile == null) { grantsGovXmlDirectoryFile = new File(loggingDirectory + proposalnumber); } File newgrantsGovXmlDirectoryFile = null; int suffix = 1; while (grantsGovXmlDirectoryFile.exists() && formEntryFlag) { grantsGovXmlDirectoryFile = new File(loggingDirectory + proposalnumber); String filename = String.valueOf(suffix); newgrantsGovXmlDirectoryFile = new File(loggingDirectory + proposalnumber + "-" + filename); if (!newgrantsGovXmlDirectoryFile.exists()) { grantsGovXmlDirectoryFile = newgrantsGovXmlDirectoryFile; break; } suffix++; } if (formEntryFlag) { grantsGovXmlDirectoryFile.mkdir(); } pdDoc.setSaveXmlFolderName(grantsGovXmlDirectoryFile.getName()); for (AttachmentData attachmentData : attachmentList) { File attachmentFile = new File(grantsGovXmlDirectoryFile, "Attachments"); attachmentFile.mkdir(); File attachedFile = new File(attachmentFile, attachmentData.getFileName()); FileOutputStream output = new FileOutputStream(attachedFile); output.write(attachmentData.getContent()); output.close(); } for (S2sAppAttachments attAppAttachments : attachmentLists) { File attachmentFile = new File(grantsGovXmlDirectoryFile, "Attachments"); attachmentFile.mkdir(); AttachmentDataSource ads = getAttributeContent(pdDoc, attAppAttachments.getContentId()); File attachedFile = new File(attachmentFile, ads.getFileName()); FileOutputStream output = new FileOutputStream(attachedFile); output.write(getAttContent(pdDoc, attAppAttachments.getContentId())); output.close(); } File xmlFile = new File( grantsGovXmlDirectoryFile, opportunityId + "." + proposalnumber + "." + exportDate + ".xml"); BufferedWriter out = new BufferedWriter(new FileWriter(xmlFile)); out.write(formObject.xmlText()); out.close(); ZipOutputStream zipOutputStream = null; FileOutputStream fileOutputStream = new FileOutputStream(grantsGovXmlDirectoryFile + ".zip"); zipOutputStream = new ZipOutputStream(fileOutputStream); addFolderToZip("", grantsGovXmlDirectoryFile.getPath(), zipOutputStream); zipOutputStream.flush(); zipOutputStream.close(); }