001 /*
002 * Copyright 2011 The Kuali Foundation.
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016 package org.kuali.kfs.module.purap.document.service.impl;
017
018 import java.io.ByteArrayOutputStream;
019 import java.util.ArrayList;
020 import java.util.Collection;
021 import java.util.HashMap;
022 import java.util.List;
023 import java.util.Map;
024
025 import org.apache.commons.lang.StringUtils;
026 import org.apache.commons.logging.Log;
027 import org.apache.commons.logging.LogFactory;
028 import org.kuali.kfs.module.purap.PurapConstants;
029 import org.kuali.kfs.module.purap.businessobject.PurchaseOrderContractLanguage;
030 import org.kuali.kfs.module.purap.businessobject.PurchaseOrderItem;
031 import org.kuali.kfs.module.purap.businessobject.PurchaseOrderVendorQuote;
032 import org.kuali.kfs.module.purap.dataaccess.ImageDao;
033 import org.kuali.kfs.module.purap.document.BulkReceivingDocument;
034 import org.kuali.kfs.module.purap.document.PurchaseOrderDocument;
035 import org.kuali.kfs.module.purap.document.service.PrintService;
036 import org.kuali.kfs.module.purap.exception.PurError;
037 import org.kuali.kfs.module.purap.exception.PurapConfigurationException;
038 import org.kuali.kfs.module.purap.pdf.BulkReceivingPdf;
039 import org.kuali.kfs.module.purap.pdf.PurchaseOrderParameters;
040 import org.kuali.kfs.module.purap.pdf.PurchaseOrderPdf;
041 import org.kuali.kfs.module.purap.pdf.PurchaseOrderTransmitParameters;
042 import org.kuali.kfs.module.purap.pdf.PurchaseOrderQuotePdf;
043 import org.kuali.kfs.module.purap.pdf.PurchaseOrderQuoteRequestsPdf;
044 import org.kuali.kfs.sys.KFSConstants;
045 import org.kuali.kfs.sys.KFSPropertyConstants;
046 import org.kuali.kfs.sys.context.SpringContext;
047 import org.kuali.kfs.sys.service.impl.KfsParameterConstants;
048 import org.kuali.kfs.vnd.businessobject.CampusParameter;
049 import org.kuali.kfs.vnd.businessobject.ContractManager;
050 import org.kuali.rice.kim.bo.Person;
051 import org.kuali.rice.kim.service.PersonService;
052 import org.kuali.rice.kns.service.BusinessObjectService;
053 import org.kuali.rice.kns.service.KualiConfigurationService;
054 import org.kuali.rice.kns.service.ParameterService;
055 import org.springframework.transaction.annotation.Transactional;
056
057 @Transactional
058 public class PrintServiceImpl implements PrintService {
059 private static Log LOG = LogFactory.getLog(PrintServiceImpl.class);
060 protected static final boolean TRANSMISSION_IS_RETRANSMIT = true;
061 protected static final boolean TRANSMISSION_IS_NOT_RETRANSMIT = !TRANSMISSION_IS_RETRANSMIT;
062
063 private ImageDao imageDao;
064 private ParameterService parameterService;
065 private BusinessObjectService businessObjectService;
066 private KualiConfigurationService kualiConfigurationService;
067 private PurchaseOrderParameters purchaseOrderParameters;
068
069
070
071
072 /**
073 * @see org.kuali.kfs.module.purap.document.service.PrintService#generatePurchaseOrderQuoteRequestsListPdf(org.kuali.kfs.module.purap.document.PurchaseOrderDocument, java.io.ByteArrayOutputStream)
074 */
075 public Collection generatePurchaseOrderQuoteRequestsListPdf(PurchaseOrderDocument po, ByteArrayOutputStream byteArrayOutputStream) {
076 LOG.debug("generatePurchaseOrderQuoteRequestsListPdf() started");
077 Collection errors = new ArrayList();
078
079 PurchaseOrderQuoteRequestsPdf poQuoteRequestsPdf = new PurchaseOrderQuoteRequestsPdf();
080
081 try {
082 PurchaseOrderTransmitParameters pdfParameters = getPurchaseOrderQuoteRequestsListPdfParameters(po);
083 String deliveryCampusName = pdfParameters.getCampusParameter().getCampus().getCampusName();
084 poQuoteRequestsPdf.generatePOQuoteRequestsListPdf(po, byteArrayOutputStream, pdfParameters.getCampusParameter().getPurchasingInstitutionName());
085
086 }
087 catch (PurError pe) {
088 LOG.error("Caught exception ", pe);
089 errors.add(pe.getMessage());
090 }
091 catch (PurapConfigurationException pce) {
092 LOG.error("Caught exception ", pce);
093 errors.add(pce.getMessage());
094 }
095 catch (Exception e) {
096 LOG.error("Caught exception ", e);
097 errors.add(e.getMessage());
098 }
099
100 LOG.debug("generatePurchaseOrderQuoteRequestsListPdf() ended");
101 return errors;
102 }
103
104 /**
105 * @see org.kuali.kfs.module.purap.document.service.PrintService#savePurchaseOrderQuoteRequestsListPdf(org.kuali.kfs.module.purap.document.PurchaseOrderDocument)
106 */
107 public Collection savePurchaseOrderQuoteRequestsListPdf(PurchaseOrderDocument po) {
108 return null;
109 }
110
111 /**
112 * Returns the PurchaseOrderPdfParameters given the PurchaseOrderDocument.
113 *
114 * @param po The PurchaseOrderDocument object to be used to obtain the PurchaseOrderPdfParameters.
115 * @return The PurchaseOrderPdfParameters given the PurchaseOrderDocument.
116 */
117 /*protected PurchaseOrderPdfFaxParameters getPurchaseOrderQuotePdfParameters(PurchaseOrderDocument po) {
118 String key = po.getPurapDocumentIdentifier().toString(); // key can be any string; chose to use the PO number.
119 String campusCode = po.getDeliveryCampusCode().toLowerCase();
120 String imageTempLocation = "";
121 String logoImage = "";
122 boolean useImage = true;
123 if (parameterService.parameterExists(KfsParameterConstants.PURCHASING_DOCUMENT.class, PurapConstants.PDF_IMAGES_AVAILABLE_INDICATOR)) {
124 useImage = parameterService.getIndicatorParameter(KfsParameterConstants.PURCHASING_DOCUMENT.class, PurapConstants.PDF_IMAGES_AVAILABLE_INDICATOR);
125 }
126 // We'll get the imageTempLocation and the actual images only if the useImage is true. If useImage is false, we'll leave the
127 // images as blank space
128 if (useImage) {
129 imageTempLocation = kualiConfigurationService.getPropertyString(KFSConstants.TEMP_DIRECTORY_KEY) + "/";
130
131 if (imageTempLocation == null) {
132 LOG.debug("generatePurchaseOrderQuotePdf() ended");
133 throw new PurapConfigurationException("Application Setting IMAGE_TEMP_PATH is missing");
134 }
135 // Get logo image.
136 logoImage = imageDao.getLogo(key, campusCode, imageTempLocation);
137 }
138 Map<String, Object> criteria = new HashMap<String, Object>();
139 criteria.put(KFSPropertyConstants.CAMPUS_CODE, po.getDeliveryCampusCode());
140 CampusParameter campusParameter = (CampusParameter) ((List) businessObjectService.findMatching(CampusParameter.class, criteria)).get(0);
141
142 // Get the contract manager's campus
143 ContractManager contractManager = po.getContractManager();
144 String contractManagerCampusCode = "N/A";
145 if (contractManager != null && contractManager.getContractManagerUserIdentifier() != null) {
146 Person contractManagerUser = SpringContext.getBean(PersonService.class).getPerson(contractManager.getContractManagerUserIdentifier());
147 contractManagerCampusCode = contractManagerUser.getCampusCode();
148 }
149
150 String pdfFileLocation = parameterService.getParameterValue(KfsParameterConstants.PURCHASING_DOCUMENT.class, PurapConstants.PDF_DIRECTORY);
151 if (pdfFileLocation == null) {
152 LOG.debug("savePurchaseOrderPdf() ended");
153 throw new PurapConfigurationException("Application Setting PDF_DIRECTORY is missing.");
154 }
155
156 PurchaseOrderPdfFaxParameters pdfParameters = new PurchaseOrderPdfFaxParameters();
157 pdfParameters.setImageTempLocation(imageTempLocation);
158 pdfParameters.setKey(key);
159 pdfParameters.setLogoImage(logoImage);
160 pdfParameters.setCampusParameter(campusParameter);
161 pdfParameters.setContractManagerCampusCode(contractManagerCampusCode);
162 pdfParameters.setPdfFileLocation(pdfFileLocation);
163 pdfParameters.setUseImage(useImage);
164 return pdfParameters;
165 }*/
166
167 /**
168 * Returns the PurchaseOrderPdfParameters given the PurchaseOrderDocument.
169 *
170 * @param po The PurchaseOrderDocument object to be used to obtain the PurchaseOrderPdfParameters.
171 * @return The PurchaseOrderPdfParameters given the PurchaseOrderDocument.
172 */
173 protected PurchaseOrderTransmitParameters getPurchaseOrderQuoteRequestsListPdfParameters(PurchaseOrderDocument po) {
174 PurchaseOrderParameters purchaseOrderParameters = getPurchaseOrderParameters();
175 purchaseOrderParameters.setPurchaseOrderPdfParameters(po);
176 return (PurchaseOrderTransmitParameters)purchaseOrderParameters;
177 /*String key = po.getPurapDocumentIdentifier().toString(); // key can be any string; chose to use the PO number.
178 String campusCode = po.getDeliveryCampusCode().toLowerCase();
179 String imageTempLocation = "";
180 String logoImage = "";
181 boolean useImage = true;
182 if (parameterService.parameterExists(KfsParameterConstants.PURCHASING_DOCUMENT.class, PurapConstants.PDF_IMAGES_AVAILABLE_INDICATOR)) {
183 useImage = parameterService.getIndicatorParameter(KfsParameterConstants.PURCHASING_DOCUMENT.class, PurapConstants.PDF_IMAGES_AVAILABLE_INDICATOR);
184 }
185 // We'll get the imageTempLocation and the actual images only if the useImage is true. If useImage is false, we'll leave the
186 // images as blank space
187 if (useImage) {
188 imageTempLocation = kualiConfigurationService.getPropertyString(KFSConstants.TEMP_DIRECTORY_KEY) + "/";
189
190 if (imageTempLocation == null) {
191 LOG.debug("generatePurchaseOrderQuotePdf() ended");
192 throw new PurapConfigurationException("Application Setting IMAGE_TEMP_PATH is missing");
193 }
194 // Get logo image.
195 logoImage = imageDao.getLogo(key, campusCode, imageTempLocation);
196 }
197 Map<String, Object> criteria = new HashMap<String, Object>();
198 criteria.put(KFSPropertyConstants.CAMPUS_CODE, po.getDeliveryCampusCode());
199 CampusParameter campusParameter = (CampusParameter) ((List) businessObjectService.findMatching(CampusParameter.class, criteria)).get(0);
200
201 // Get the contract manager's campus
202 ContractManager contractManager = po.getContractManager();
203 String contractManagerCampusCode = "";
204 if (contractManager.getContractManagerUserIdentifier() != null) {
205 Person contractManagerUser = SpringContext.getBean(PersonService.class).getPerson(contractManager.getContractManagerUserIdentifier());
206 contractManagerCampusCode = contractManagerUser.getCampusCode();
207 }
208
209 String pdfFileLocation = parameterService.getParameterValue(KfsParameterConstants.PURCHASING_DOCUMENT.class, PurapConstants.PDF_DIRECTORY);
210 if (pdfFileLocation == null) {
211 LOG.debug("savePurchaseOrderPdf() ended");
212 throw new PurapConfigurationException("Application Setting PDF_DIRECTORY is missing.");
213 }
214
215 PurchaseOrderPdfFaxParameters pdfParameters = new PurchaseOrderPdfFaxParameters();
216 pdfParameters.setImageTempLocation(imageTempLocation);
217 pdfParameters.setKey(key);
218 pdfParameters.setLogoImage(logoImage);
219 pdfParameters.setCampusParameter(campusParameter);
220 pdfParameters.setContractManagerCampusCode(contractManagerCampusCode);
221 pdfParameters.setPdfFileLocation(pdfFileLocation);
222 pdfParameters.setUseImage(useImage);
223 return pdfParameters;*/
224 }
225
226 /**
227 * @see org.kuali.kfs.module.purap.document.service.PrintService#generatePurchaseOrderQuotePdf(org.kuali.kfs.module.purap.document.PurchaseOrderDocument, org.kuali.kfs.module.purap.businessobject.PurchaseOrderVendorQuote, java.io.ByteArrayOutputStream, java.lang.String)
228 */
229 public Collection generatePurchaseOrderQuotePdf(PurchaseOrderDocument po, PurchaseOrderVendorQuote povq, ByteArrayOutputStream byteArrayOutputStream, String environment) {
230 LOG.debug("generatePurchaseOrderQuotePdf() started");
231
232 PurchaseOrderQuotePdf poQuotePdf = new PurchaseOrderQuotePdf();
233 Collection errors = new ArrayList();
234
235 try {
236 PurchaseOrderParameters purchaseOrderParameters = getPurchaseOrderParameters();
237 purchaseOrderParameters.setPurchaseOrderPdfParameters(po,povq);
238 PurchaseOrderTransmitParameters pdfParameters = (PurchaseOrderTransmitParameters)purchaseOrderParameters;
239 String deliveryCampusName = pdfParameters.getCampusParameter().getCampus().getCampusName();
240 poQuotePdf.generatePOQuotePDF(po, povq, deliveryCampusName, pdfParameters.getContractManagerCampusCode(), pdfParameters.getLogoImage(), byteArrayOutputStream, environment);
241 }
242 catch (PurError pe) {
243 LOG.error("Caught exception ", pe);
244 errors.add(pe.getMessage());
245 }
246 catch (PurapConfigurationException pce) {
247 LOG.error("Caught exception ", pce);
248 errors.add(pce.getMessage());
249 }
250 LOG.debug("generatePurchaseOrderQuotePdf() ended");
251 return errors;
252 }
253
254 /**
255 * @see org.kuali.kfs.module.purap.document.service.PrintService#savePurchaseOrderQuotePdf(org.kuali.kfs.module.purap.document.PurchaseOrderDocument, org.kuali.kfs.module.purap.businessobject.PurchaseOrderVendorQuote, java.lang.String)
256 */
257 public Collection savePurchaseOrderQuotePdf(PurchaseOrderDocument po, PurchaseOrderVendorQuote povq, String environment) {
258 LOG.debug("savePurchaseOrderQuotePdf() started");
259
260 String pdfQuoteFilename = "PURAP_PO_" + po.getPurapDocumentIdentifier().toString() + "_Quote_" + povq.getPurchaseOrderVendorQuoteIdentifier().toString() + "_" + System.currentTimeMillis() + ".pdf";
261 PurchaseOrderQuotePdf poQuotePdf = new PurchaseOrderQuotePdf();
262 Collection errors = new ArrayList();
263
264 PurchaseOrderTransmitParameters pdfParameters = null;
265 try {
266 PurchaseOrderParameters purchaseOrderParameters = getPurchaseOrderParameters();
267 purchaseOrderParameters.setPurchaseOrderPdfParameters(po,povq);
268 pdfParameters = (PurchaseOrderTransmitParameters)purchaseOrderParameters;
269 String deliveryCampusName = pdfParameters.getCampusParameter().getCampus().getCampusName();
270 poQuotePdf.savePOQuotePDF(po, povq, pdfParameters, environment);
271 }
272 catch (PurError e) {
273 LOG.error("Caught exception ", e);
274 errors.add(e.getMessage());
275 }
276 catch (PurapConfigurationException pce) {
277 LOG.error("Caught exception ", pce);
278 errors.add(pce.getMessage());
279 }
280 finally {
281 try {
282 poQuotePdf.deletePdf(pdfParameters.getPdfFileLocation(), pdfQuoteFilename);
283 }
284 catch (Throwable e) {
285 LOG.error("savePurchaseOrderQuotePdf() Error deleting Quote PDF" + pdfQuoteFilename + " - Exception was " + e.getMessage(), e);
286 errors.add(e.getMessage());
287 }
288 }
289
290 LOG.debug("savePurchaseOrderQuotePdf() ended");
291 return errors;
292 }
293
294 /**
295 * Returns the PurchaseOrderPdfParameters given the PurchaseOrderDocument.
296 *
297 * @param po The PurchaseOrderDocument object to be used to obtain the PurchaseOrderPdfParameters.
298 * @return The PurchaseOrderPdfParameters given the PurchaseOrderDocument.
299 */
300 /* protected PurchaseOrderPdfFaxParameters getPurchaseOrderPdfParameters(PurchaseOrderDocument po) {
301 String key = po.getPurapDocumentIdentifier().toString(); // key can be any string; chose to use the PO number.
302 String campusCode = po.getDeliveryCampusCode().toLowerCase();
303 String imageTempLocation = "";
304 String logoImage = "";
305 String directorSignatureImage = "";
306 String contractManagerSignatureImage = "";
307 boolean useImage = true;
308 if (parameterService.parameterExists(KfsParameterConstants.PURCHASING_DOCUMENT.class, PurapConstants.PDF_IMAGES_AVAILABLE_INDICATOR)) {
309 useImage = parameterService.getIndicatorParameter(KfsParameterConstants.PURCHASING_DOCUMENT.class, PurapConstants.PDF_IMAGES_AVAILABLE_INDICATOR);
310 }
311 // We'll get the imageTempLocation and the actual images only if the useImage is true. If useImage is false, we'll leave the
312 // images as blank space
313 if (useImage) {
314 imageTempLocation = kualiConfigurationService.getPropertyString(KFSConstants.TEMP_DIRECTORY_KEY) + "/";
315
316 if (imageTempLocation == null) {
317 throw new PurapConfigurationException("IMAGE_TEMP_PATH is missing");
318 }
319
320 // Get images
321 if ((logoImage = imageDao.getLogo(key, campusCode, imageTempLocation)) == null) {
322 throw new PurapConfigurationException("logoImage is null.");
323 }
324 if ((directorSignatureImage = imageDao.getPurchasingDirectorImage(key, campusCode, imageTempLocation)) == null) {
325 throw new PurapConfigurationException("directorSignatureImage is null.");
326 }
327 if ((contractManagerSignatureImage = imageDao.getContractManagerImage(key, po.getContractManagerCode(), imageTempLocation)) == null) {
328 throw new PurapConfigurationException("contractManagerSignatureImage is null.");
329 }
330 }
331
332 Map<String, Object> criteria = new HashMap<String, Object>();
333 criteria.put(KFSPropertyConstants.CAMPUS_CODE, po.getDeliveryCampusCode());
334 CampusParameter campusParameter = (CampusParameter) ((List) businessObjectService.findMatching(CampusParameter.class, criteria)).get(0);
335
336 String statusInquiryUrl = parameterService.getParameterValue(KfsParameterConstants.PURCHASING_DOCUMENT.class, PurapConstants.STATUS_INQUIRY_URL);
337 if (statusInquiryUrl == null) {
338 LOG.debug("generatePurchaseOrderPdf() ended");
339 throw new PurapConfigurationException("Application Setting INVOICE_STATUS_INQUIRY_URL is missing.");
340 }
341
342 StringBuffer contractLanguage = new StringBuffer();
343 criteria.put(KFSPropertyConstants.ACTIVE, true);
344 List<PurchaseOrderContractLanguage> contractLanguageList = (List<PurchaseOrderContractLanguage>) (businessObjectService.findMatching(PurchaseOrderContractLanguage.class, criteria));
345 if (!contractLanguageList.isEmpty()) {
346 int lineNumber = 1;
347 for (PurchaseOrderContractLanguage row : contractLanguageList) {
348 if (row.getCampusCode().equals(po.getDeliveryCampusCode())) {
349 contractLanguage.append(lineNumber + " " + row.getPurchaseOrderContractLanguageDescription() + "\n");
350 ++lineNumber;
351 }
352 }
353 }
354
355 String pdfFileLocation = parameterService.getParameterValue(KfsParameterConstants.PURCHASING_DOCUMENT.class, PurapConstants.PDF_DIRECTORY);
356 if (pdfFileLocation == null) {
357 LOG.debug("savePurchaseOrderPdf() ended");
358 throw new PurapConfigurationException("Application Setting PDF_DIRECTORY is missing.");
359 }
360
361 String pdfFileName = "PURAP_PO_" + po.getPurapDocumentIdentifier().toString() + "_" + System.currentTimeMillis() + ".pdf";
362
363 PurchaseOrderPdfFaxParameters pdfParameters = new PurchaseOrderPdfFaxParameters();
364 pdfParameters.setCampusParameter(campusParameter);
365 pdfParameters.setContractLanguage(contractLanguage.toString());
366 pdfParameters.setContractManagerSignatureImage(contractManagerSignatureImage);
367 pdfParameters.setDirectorSignatureImage(directorSignatureImage);
368 pdfParameters.setImageTempLocation(imageTempLocation);
369 pdfParameters.setKey(key);
370 pdfParameters.setLogoImage(logoImage);
371 pdfParameters.setStatusInquiryUrl(statusInquiryUrl);
372 pdfParameters.setPdfFileLocation(pdfFileLocation);
373 pdfParameters.setPdfFileName(pdfFileName);
374 pdfParameters.setUseImage(useImage);
375 return pdfParameters;
376 }*/
377
378 /**
379 * Creates purchase order pdf document given the input parameters.
380 *
381 * @param po The PurchaseOrderDocument.
382 * @param byteArrayOutputStream ByteArrayOutputStream that the action is using, where the pdf will be printed to.
383 * @param isRetransmit boolean true if this is a retransmit purchase order document.
384 * @param environment The current environment used (e.g. DEV if it is a development environment).
385 * @param retransmitItems The items selected by the user to be retransmitted.
386 * @return Collection of error strings.
387 */
388 protected Collection generatePurchaseOrderPdf(PurchaseOrderDocument po, ByteArrayOutputStream byteArrayOutputStream, boolean isRetransmit, String environment, List<PurchaseOrderItem> retransmitItems) {
389 LOG.debug("generatePurchaseOrderPdf() started");
390
391 PurchaseOrderPdf poPdf = new PurchaseOrderPdf();
392 Collection errors = new ArrayList();
393 try {
394 PurchaseOrderParameters purchaseOrderParameters = getPurchaseOrderParameters();
395 purchaseOrderParameters.setPurchaseOrderPdfParameters(po);
396 PurchaseOrderTransmitParameters pdfParameters = (PurchaseOrderTransmitParameters)purchaseOrderParameters;
397 poPdf.generatePdf(po, pdfParameters, byteArrayOutputStream, isRetransmit, environment, retransmitItems);
398 }
399 catch (PurError e) {
400 LOG.error("Caught exception ", e);
401 errors.add(e.getMessage());
402 }
403 catch (PurapConfigurationException pce) {
404 LOG.error("Caught exception ", pce);
405 errors.add(pce.getMessage());
406 }
407
408 LOG.debug("generatePurchaseOrderPdf() ended");
409 return errors;
410 }
411
412 /**
413 * @see org.kuali.kfs.module.purap.document.service.PrintService#generatePurchaseOrderPdf(org.kuali.kfs.module.purap.document.PurchaseOrderDocument,
414 * java.io.ByteArrayOutputStream, java.lang.String)
415 */
416 public Collection generatePurchaseOrderPdf(PurchaseOrderDocument po, ByteArrayOutputStream byteArrayOutputStream, String environment, List<PurchaseOrderItem> retransmitItems) {
417 return generatePurchaseOrderPdf(po, byteArrayOutputStream, TRANSMISSION_IS_NOT_RETRANSMIT, environment, retransmitItems);
418 }
419
420
421
422 /**
423 * @see org.kuali.kfs.module.purap.document.service.PrintService#generatePurchaseOrderPdfForRetransmission(org.kuali.kfs.module.purap.document.PurchaseOrderDocument,
424 * java.io.ByteArrayOutputStream, java.lang.String)
425 */
426 public Collection generatePurchaseOrderPdfForRetransmission(PurchaseOrderDocument po, ByteArrayOutputStream byteArrayOutputStream, String environment, List<PurchaseOrderItem> retransmitItems) {
427 return generatePurchaseOrderPdf(po, byteArrayOutputStream, TRANSMISSION_IS_RETRANSMIT, environment, retransmitItems);
428 }
429
430
431 /**
432 * Saves the purchase order pdf document.
433 *
434 * @param po The PurchaseOrderDocument.
435 * @param isRetransmit boolean true if this is a retransmit purchase order document.
436 * @param environment The current environment used (e.g. DEV if it is a development environment).
437 * @return Collection of error strings.
438 */
439 protected Collection savePurchaseOrderPdf(PurchaseOrderDocument po, boolean isRetransmit, String environment) {
440 LOG.debug("savePurchaseOrderPdf() started");
441
442 PurchaseOrderPdf poPdf = new PurchaseOrderPdf();
443 Collection errors = new ArrayList();
444
445 PurchaseOrderTransmitParameters pdfParameters = null;
446
447 try {
448 PurchaseOrderParameters purchaseOrderParameters = getPurchaseOrderParameters();
449 purchaseOrderParameters.setPurchaseOrderPdfParameters(po);
450 pdfParameters = (PurchaseOrderTransmitParameters)purchaseOrderParameters;
451 poPdf.savePdf(po, pdfParameters, isRetransmit, environment);
452 }
453 catch (PurError e) {
454 LOG.error("Caught exception ", e);
455 errors.add(e.getMessage());
456 }
457 catch (PurapConfigurationException pce) {
458 LOG.error("Caught exception ", pce);
459 errors.add(pce.getMessage());
460 }
461 finally {
462 try {
463 poPdf.deletePdf(pdfParameters.getPdfFileLocation(), pdfParameters.getPdfFileName());
464 }
465 catch (Throwable e) {
466 LOG.error("savePurchaseOrderPdf() Error deleting PDF" + pdfParameters.getPdfFileName() + " - Exception was " + e.getMessage(), e);
467 errors.add("Error while deleting the pdf after savePurchaseOrderPdf" + e.getMessage());
468 }
469 }
470
471 LOG.debug("savePurchaseOrderPdf() ended");
472 return errors;
473 }
474
475 /**
476 * @see org.kuali.kfs.module.purap.document.service.PrintService#savePurchaseOrderPdf(org.kuali.kfs.module.purap.document.PurchaseOrderDocument,
477 * java.lang.String)
478 */
479 public Collection savePurchaseOrderPdf(PurchaseOrderDocument po, String environment) {
480 return savePurchaseOrderPdf(po, TRANSMISSION_IS_NOT_RETRANSMIT, environment);
481 }
482
483 /**
484 * @see org.kuali.kfs.module.purap.document.service.PrintService#savePurchaseOrderPdfForRetransmission(org.kuali.kfs.module.purap.document.PurchaseOrderDocument,
485 * java.lang.String)
486 */
487 public Collection savePurchaseOrderPdfForRetransmission(PurchaseOrderDocument po, String environment) {
488 return savePurchaseOrderPdf(po, TRANSMISSION_IS_RETRANSMIT, environment);
489 }
490
491 public Collection generateBulkReceivingPDF(BulkReceivingDocument blkRecDoc,
492 ByteArrayOutputStream baosPDF) {
493
494 LOG.debug("generateBulkReceivingPDF() started");
495
496 BulkReceivingPdf recBlkTicketPDF = new BulkReceivingPdf();
497 Collection errors = new ArrayList();
498
499 String imageTempLocation = StringUtils.EMPTY;
500 String logoImage = StringUtils.EMPTY;
501
502 String key = blkRecDoc.getDocumentNumber().toString(); // key can be any string;
503 String campusCode = blkRecDoc.getDeliveryCampusCode().toLowerCase();
504
505 String environment = kualiConfigurationService.getPropertyString(KFSConstants.ENVIRONMENT_KEY);
506
507 boolean useImage = true;
508 if (parameterService.parameterExists(KfsParameterConstants.PURCHASING_DOCUMENT.class, PurapConstants.PDF_IMAGES_AVAILABLE_INDICATOR)) {
509 useImage = parameterService.getIndicatorParameter(KfsParameterConstants.PURCHASING_DOCUMENT.class, PurapConstants.PDF_IMAGES_AVAILABLE_INDICATOR);
510 }
511
512 if (useImage) {
513 imageTempLocation = kualiConfigurationService.getPropertyString(KFSConstants.TEMP_DIRECTORY_KEY) + "/";
514
515 if (imageTempLocation == null) {
516 throw new PurapConfigurationException("IMAGE_TEMP_PATH is missing");
517 }
518
519 // Get images
520 logoImage = imageDao.getLogo(key, campusCode, imageTempLocation);
521
522 if (StringUtils.isEmpty(logoImage)) {
523 throw new PurapConfigurationException("logoImage is null.");
524 }
525 }
526
527 try {
528 recBlkTicketPDF.generatePdf(blkRecDoc,baosPDF,logoImage,environment);
529 }catch (PurapConfigurationException pce) {
530 LOG.error("Caught exception ", pce);
531 errors.add(pce.getMessage());
532 }
533
534 LOG.debug("generateBulkReceivingPDF() ended");
535 return errors;
536 }
537
538 public void setParameterService(ParameterService parameterService) {
539 this.parameterService = parameterService;
540 }
541
542 public void setImageDao(ImageDao imageDao) {
543 this.imageDao = imageDao;
544 }
545
546 public void setBusinessObjectService(BusinessObjectService businessObjectService) {
547 this.businessObjectService = businessObjectService;
548 }
549
550 public void setKualiConfigurationService(KualiConfigurationService kualiConfigurationService) {
551 this.kualiConfigurationService = kualiConfigurationService;
552 }
553
554 public void setPurchaseOrderParameters(PurchaseOrderParameters purchaseOrderParameters) {
555 this.purchaseOrderParameters = purchaseOrderParameters;
556 }
557
558 public PurchaseOrderParameters getPurchaseOrderParameters() {
559 return SpringContext.getBean(PurchaseOrderParameters.class);
560 }
561
562 }
563