1 /*
2 * Copyright 2007 The Kuali Foundation
3 *
4 * Licensed under the Educational Community License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.opensource.org/licenses/ecl2.php
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 package org.kuali.ole.module.purap.document.service.impl;
17
18 import org.apache.commons.lang.StringUtils;
19 import org.apache.commons.logging.Log;
20 import org.apache.commons.logging.LogFactory;
21 import org.kuali.ole.module.purap.PurapConstants;
22 import org.kuali.ole.module.purap.businessobject.PurchaseOrderItem;
23 import org.kuali.ole.module.purap.businessobject.PurchaseOrderVendorQuote;
24 import org.kuali.ole.module.purap.document.BulkReceivingDocument;
25 import org.kuali.ole.module.purap.document.PurchaseOrderDocument;
26 import org.kuali.ole.module.purap.document.service.PrintService;
27 import org.kuali.ole.module.purap.exception.PurError;
28 import org.kuali.ole.module.purap.exception.PurapConfigurationException;
29 import org.kuali.ole.module.purap.pdf.*;
30 import org.kuali.ole.module.purap.service.ImageService;
31 import org.kuali.ole.sys.OLEConstants;
32 import org.kuali.ole.sys.context.SpringContext;
33 import org.kuali.ole.sys.service.impl.OleParameterConstants;
34 import org.kuali.rice.core.api.config.property.ConfigurationService;
35 import org.kuali.rice.coreservice.framework.parameter.ParameterService;
36 import org.kuali.rice.krad.service.BusinessObjectService;
37 import org.springframework.transaction.annotation.Transactional;
38
39 import java.io.ByteArrayOutputStream;
40 import java.util.ArrayList;
41 import java.util.Collection;
42 import java.util.List;
43
44 @Transactional
45 public class PrintServiceImpl implements PrintService {
46 private static Log LOG = LogFactory.getLog(PrintServiceImpl.class);
47 protected static final boolean TRANSMISSION_IS_RETRANSMIT = true;
48 protected static final boolean TRANSMISSION_IS_NOT_RETRANSMIT = !TRANSMISSION_IS_RETRANSMIT;
49
50 private ImageService imageService;
51 private ParameterService parameterService;
52 private BusinessObjectService businessObjectService;
53 private ConfigurationService kualiConfigurationService;
54 private PurchaseOrderParameters purchaseOrderParameters;
55
56
57 /**
58 * @see org.kuali.ole.module.purap.document.service.PrintService#generatePurchaseOrderQuoteRequestsListPdf(org.kuali.ole.module.purap.document.PurchaseOrderDocument, java.io.ByteArrayOutputStream)
59 */
60 @Override
61 public Collection generatePurchaseOrderQuoteRequestsListPdf(PurchaseOrderDocument po, ByteArrayOutputStream byteArrayOutputStream) {
62 LOG.debug("generatePurchaseOrderQuoteRequestsListPdf() started");
63 Collection errors = new ArrayList();
64
65 PurchaseOrderQuoteRequestsPdf poQuoteRequestsPdf = new PurchaseOrderQuoteRequestsPdf();
66
67 try {
68 PurchaseOrderTransmitParameters pdfParameters = getPurchaseOrderQuoteRequestsListPdfParameters(po);
69 String deliveryCampusName = pdfParameters.getCampusParameter().getCampus().getName();
70 poQuoteRequestsPdf.generatePOQuoteRequestsListPdf(po, byteArrayOutputStream, pdfParameters.getCampusParameter().getPurchasingInstitutionName());
71
72 } catch (PurError pe) {
73 LOG.error("Caught exception ", pe);
74 errors.add(pe.getMessage());
75 } catch (PurapConfigurationException pce) {
76 LOG.error("Caught exception ", pce);
77 errors.add(pce.getMessage());
78 } catch (Exception e) {
79 LOG.error("Caught exception ", e);
80 errors.add(e.getMessage());
81 }
82
83 LOG.debug("generatePurchaseOrderQuoteRequestsListPdf() ended");
84 return errors;
85 }
86
87 /**
88 * @see org.kuali.ole.module.purap.document.service.PrintService#savePurchaseOrderQuoteRequestsListPdf(org.kuali.ole.module.purap.document.PurchaseOrderDocument)
89 */
90 @Override
91 public Collection savePurchaseOrderQuoteRequestsListPdf(PurchaseOrderDocument po) {
92 return null;
93 }
94
95 /**
96 * Returns the PurchaseOrderPdfParameters given the PurchaseOrderDocument.
97 *
98 * @param po The PurchaseOrderDocument object to be used to obtain the PurchaseOrderPdfParameters.
99 * @return The PurchaseOrderPdfParameters given the PurchaseOrderDocument.
100 */
101 /*protected PurchaseOrderPdfFaxParameters getPurchaseOrderQuotePdfParameters(PurchaseOrderDocument po) {
102 String key = po.getPurapDocumentIdentifier().toString(); // key can be any string; chose to use the PO number.
103 String campusCode = po.getDeliveryCampusCode().toLowerCase();
104 String imageTempLocation = "";
105 String logoImage = "";
106 boolean useImage = true;
107 if (parameterService.parameterExists(OleParameterConstants.PURCHASING_DOCUMENT.class, PurapConstants.PDF_IMAGES_AVAILABLE_INDICATOR)) {
108 useImage = parameterService.getParameterValueAsBoolean(OleParameterConstants.PURCHASING_DOCUMENT.class, PurapConstants.PDF_IMAGES_AVAILABLE_INDICATOR);
109 }
110 // We'll get the imageTempLocation and the actual images only if the useImage is true. If useImage is false, we'll leave the
111 // images as blank space
112 if (useImage) {
113 imageTempLocation = kualiConfigurationService.getPropertyValueAsString(OLEConstants.TEMP_DIRECTORY_KEY) + "/";
114
115 if (imageTempLocation == null) {
116 LOG.debug("generatePurchaseOrderQuotePdf() ended");
117 throw new PurapConfigurationException("Application Setting IMAGE_TEMP_PATH is missing");
118 }
119 // Get logo image.
120 logoImage = imageService.getLogo(key, campusCode, imageTempLocation);
121 }
122 Map<String, Object> criteria = new HashMap<String, Object>();
123 criteria.put(OLEPropertyConstants.CAMPUS_CODE, po.getDeliveryCampusCode());
124 CampusParameter campusParameter = (CampusParameter) ((List) businessObjectService.findMatching(CampusParameter.class, criteria)).get(0);
125
126 // Get the contract manager's campus
127 ContractManager contractManager = po.getContractManager();
128 String contractManagerCampusCode = "N/A";
129 if (contractManager != null && contractManager.getContractManagerUserIdentifier() != null) {
130 Person contractManagerUser = SpringContext.getBean(PersonService.class).getPerson(contractManager.getContractManagerUserIdentifier());
131 contractManagerCampusCode = contractManagerUser.getCampusCode();
132 }
133
134 String pdfFileLocation = parameterService.getParameterValueAsString(OleParameterConstants.PURCHASING_DOCUMENT.class, PurapConstants.PDF_DIRECTORY);
135 if (pdfFileLocation == null) {
136 LOG.debug("savePurchaseOrderPdf() ended");
137 throw new PurapConfigurationException("Application Setting PDF_DIRECTORY is missing.");
138 }
139
140 PurchaseOrderPdfFaxParameters pdfParameters = new PurchaseOrderPdfFaxParameters();
141 pdfParameters.setImageTempLocation(imageTempLocation);
142 pdfParameters.setKey(key);
143 pdfParameters.setLogoImage(logoImage);
144 pdfParameters.setCampusParameter(campusParameter);
145 pdfParameters.setContractManagerCampusCode(contractManagerCampusCode);
146 pdfParameters.setPdfFileLocation(pdfFileLocation);
147 pdfParameters.setUseImage(useImage);
148 return pdfParameters;
149 }*/
150
151 /**
152 * Returns the PurchaseOrderPdfParameters given the PurchaseOrderDocument.
153 *
154 * @param po The PurchaseOrderDocument object to be used to obtain the PurchaseOrderPdfParameters.
155 * @return The PurchaseOrderPdfParameters given the PurchaseOrderDocument.
156 */
157 protected PurchaseOrderTransmitParameters getPurchaseOrderQuoteRequestsListPdfParameters(PurchaseOrderDocument po) {
158 PurchaseOrderParameters purchaseOrderParameters = getPurchaseOrderParameters();
159 purchaseOrderParameters.setPurchaseOrderPdfParameters(po);
160 return (PurchaseOrderTransmitParameters) purchaseOrderParameters;
161 /*String key = po.getPurapDocumentIdentifier().toString(); // key can be any string; chose to use the PO number.
162 String campusCode = po.getDeliveryCampusCode().toLowerCase();
163 String imageTempLocation = "";
164 String logoImage = "";
165 boolean useImage = true;
166 if (parameterService.parameterExists(OleParameterConstants.PURCHASING_DOCUMENT.class, PurapConstants.PDF_IMAGES_AVAILABLE_INDICATOR)) {
167 useImage = parameterService.getParameterValueAsBoolean(OleParameterConstants.PURCHASING_DOCUMENT.class, PurapConstants.PDF_IMAGES_AVAILABLE_INDICATOR);
168 }
169 // We'll get the imageTempLocation and the actual images only if the useImage is true. If useImage is false, we'll leave the
170 // images as blank space
171 if (useImage) {
172 imageTempLocation = kualiConfigurationService.getPropertyValueAsString(OLEConstants.TEMP_DIRECTORY_KEY) + "/";
173
174 if (imageTempLocation == null) {
175 LOG.debug("generatePurchaseOrderQuotePdf() ended");
176 throw new PurapConfigurationException("Application Setting IMAGE_TEMP_PATH is missing");
177 }
178 // Get logo image.
179 logoImage = imageService.getLogo(key, campusCode, imageTempLocation);
180 }
181 Map<String, Object> criteria = new HashMap<String, Object>();
182 criteria.put(OLEPropertyConstants.CAMPUS_CODE, po.getDeliveryCampusCode());
183 CampusParameter campusParameter = (CampusParameter) ((List) businessObjectService.findMatching(CampusParameter.class, criteria)).get(0);
184
185 // Get the contract manager's campus
186 ContractManager contractManager = po.getContractManager();
187 String contractManagerCampusCode = "";
188 if (contractManager.getContractManagerUserIdentifier() != null) {
189 Person contractManagerUser = SpringContext.getBean(PersonService.class).getPerson(contractManager.getContractManagerUserIdentifier());
190 contractManagerCampusCode = contractManagerUser.getCampusCode();
191 }
192
193 String pdfFileLocation = parameterService.getParameterValueAsString(OleParameterConstants.PURCHASING_DOCUMENT.class, PurapConstants.PDF_DIRECTORY);
194 if (pdfFileLocation == null) {
195 LOG.debug("savePurchaseOrderPdf() ended");
196 throw new PurapConfigurationException("Application Setting PDF_DIRECTORY is missing.");
197 }
198
199 PurchaseOrderPdfFaxParameters pdfParameters = new PurchaseOrderPdfFaxParameters();
200 pdfParameters.setImageTempLocation(imageTempLocation);
201 pdfParameters.setKey(key);
202 pdfParameters.setLogoImage(logoImage);
203 pdfParameters.setCampusParameter(campusParameter);
204 pdfParameters.setContractManagerCampusCode(contractManagerCampusCode);
205 pdfParameters.setPdfFileLocation(pdfFileLocation);
206 pdfParameters.setUseImage(useImage);
207 return pdfParameters;*/
208 }
209
210 /**
211 * @see org.kuali.ole.module.purap.document.service.PrintService#generatePurchaseOrderQuotePdf(org.kuali.ole.module.purap.document.PurchaseOrderDocument, org.kuali.ole.module.purap.businessobject.PurchaseOrderVendorQuote, java.io.ByteArrayOutputStream, java.lang.String)
212 */
213 @Override
214 public Collection generatePurchaseOrderQuotePdf(PurchaseOrderDocument po, PurchaseOrderVendorQuote povq, ByteArrayOutputStream byteArrayOutputStream, String environment) {
215 LOG.debug("generatePurchaseOrderQuotePdf() started");
216
217 PurchaseOrderQuotePdf poQuotePdf = new PurchaseOrderQuotePdf();
218 Collection errors = new ArrayList();
219
220 try {
221 PurchaseOrderParameters purchaseOrderParameters = getPurchaseOrderParameters();
222 purchaseOrderParameters.setPurchaseOrderPdfParameters(po, povq);
223 PurchaseOrderTransmitParameters pdfParameters = (PurchaseOrderTransmitParameters) purchaseOrderParameters;
224 String deliveryCampusName = pdfParameters.getCampusParameter().getCampus().getName();
225 poQuotePdf.generatePOQuotePDF(po, povq, deliveryCampusName, pdfParameters.getContractManagerCampusCode(), pdfParameters.getLogoImage(), byteArrayOutputStream, environment);
226 } catch (PurError pe) {
227 LOG.error("Caught exception ", pe);
228 errors.add(pe.getMessage());
229 } catch (PurapConfigurationException pce) {
230 LOG.error("Caught exception ", pce);
231 errors.add(pce.getMessage());
232 }
233 LOG.debug("generatePurchaseOrderQuotePdf() ended");
234 return errors;
235 }
236
237 /**
238 * @see org.kuali.ole.module.purap.document.service.PrintService#savePurchaseOrderQuotePdf(org.kuali.ole.module.purap.document.PurchaseOrderDocument, org.kuali.ole.module.purap.businessobject.PurchaseOrderVendorQuote, java.lang.String)
239 */
240 @Override
241 public Collection savePurchaseOrderQuotePdf(PurchaseOrderDocument po, PurchaseOrderVendorQuote povq, String environment) {
242 LOG.debug("savePurchaseOrderQuotePdf() started");
243
244 String pdfQuoteFilename = "PURAP_PO_" + po.getPurapDocumentIdentifier().toString() + "_Quote_" + povq.getPurchaseOrderVendorQuoteIdentifier().toString() + "_" + System.currentTimeMillis() + ".pdf";
245 PurchaseOrderQuotePdf poQuotePdf = new PurchaseOrderQuotePdf();
246 Collection errors = new ArrayList();
247
248 PurchaseOrderTransmitParameters pdfParameters = null;
249 try {
250 PurchaseOrderParameters purchaseOrderParameters = getPurchaseOrderParameters();
251 purchaseOrderParameters.setPurchaseOrderPdfParameters(po, povq);
252 pdfParameters = (PurchaseOrderTransmitParameters) purchaseOrderParameters;
253 String deliveryCampusName = pdfParameters.getCampusParameter().getCampus().getName();
254 poQuotePdf.savePOQuotePDF(po, povq, pdfParameters, environment);
255 } catch (PurError e) {
256 LOG.error("Caught exception ", e);
257 errors.add(e.getMessage());
258 } catch (PurapConfigurationException pce) {
259 LOG.error("Caught exception ", pce);
260 errors.add(pce.getMessage());
261 } finally {
262 try {
263 poQuotePdf.deletePdf(pdfParameters.getPdfFileLocation(), pdfQuoteFilename);
264 } catch (Throwable e) {
265 LOG.error("savePurchaseOrderQuotePdf() Error deleting Quote PDF" + pdfQuoteFilename + " - Exception was " + e.getMessage(), e);
266 errors.add(e.getMessage());
267 }
268 }
269
270 LOG.debug("savePurchaseOrderQuotePdf() ended");
271 return errors;
272 }
273
274 /**
275 * Returns the PurchaseOrderPdfParameters given the PurchaseOrderDocument.
276 *
277 * @param po The PurchaseOrderDocument object to be used to obtain the PurchaseOrderPdfParameters.
278 * @return The PurchaseOrderPdfParameters given the PurchaseOrderDocument.
279 */
280 /* protected PurchaseOrderPdfFaxParameters getPurchaseOrderPdfParameters(PurchaseOrderDocument po) {
281 String key = po.getPurapDocumentIdentifier().toString(); // key can be any string; chose to use the PO number.
282 String campusCode = po.getDeliveryCampusCode().toLowerCase();
283 String imageTempLocation = "";
284 String logoImage = "";
285 String directorSignatureImage = "";
286 String contractManagerSignatureImage = "";
287 boolean useImage = true;
288 if (parameterService.parameterExists(OleParameterConstants.PURCHASING_DOCUMENT.class, PurapConstants.PDF_IMAGES_AVAILABLE_INDICATOR)) {
289 useImage = parameterService.getParameterValueAsBoolean(OleParameterConstants.PURCHASING_DOCUMENT.class, PurapConstants.PDF_IMAGES_AVAILABLE_INDICATOR);
290 }
291 // We'll get the imageTempLocation and the actual images only if the useImage is true. If useImage is false, we'll leave the
292 // images as blank space
293 if (useImage) {
294 imageTempLocation = kualiConfigurationService.getPropertyValueAsString(OLEConstants.TEMP_DIRECTORY_KEY) + "/";
295
296 if (imageTempLocation == null) {
297 throw new PurapConfigurationException("IMAGE_TEMP_PATH is missing");
298 }
299
300 // Get images
301 if ((logoImage = imageService.getLogo(key, campusCode, imageTempLocation)) == null) {
302 throw new PurapConfigurationException("logoImage is null.");
303 }
304 if ((directorSignatureImage = imageService.getPurchasingDirectorImage(key, campusCode, imageTempLocation)) == null) {
305 throw new PurapConfigurationException("directorSignatureImage is null.");
306 }
307 if ((contractManagerSignatureImage = imageService.getContractManagerImage(key, po.getContractManagerCode(), imageTempLocation)) == null) {
308 throw new PurapConfigurationException("contractManagerSignatureImage is null.");
309 }
310 }
311
312 Map<String, Object> criteria = new HashMap<String, Object>();
313 criteria.put(OLEPropertyConstants.CAMPUS_CODE, po.getDeliveryCampusCode());
314 CampusParameter campusParameter = (CampusParameter) ((List) businessObjectService.findMatching(CampusParameter.class, criteria)).get(0);
315
316 String statusInquiryUrl = parameterService.getParameterValueAsString(OleParameterConstants.PURCHASING_DOCUMENT.class, PurapConstants.STATUS_INQUIRY_URL);
317 if (statusInquiryUrl == null) {
318 LOG.debug("generatePurchaseOrderPdf() ended");
319 throw new PurapConfigurationException("Application Setting INVOICE_STATUS_INQUIRY_URL is missing.");
320 }
321
322 StringBuffer contractLanguage = new StringBuffer();
323 criteria.put(OLEPropertyConstants.ACTIVE, true);
324 List<PurchaseOrderContractLanguage> contractLanguageList = (List<PurchaseOrderContractLanguage>) (businessObjectService.findMatching(PurchaseOrderContractLanguage.class, criteria));
325 if (!contractLanguageList.isEmpty()) {
326 int lineNumber = 1;
327 for (PurchaseOrderContractLanguage row : contractLanguageList) {
328 if (row.getCampusCode().equals(po.getDeliveryCampusCode())) {
329 contractLanguage.append(lineNumber + " " + row.getPurchaseOrderContractLanguageDescription() + "\n");
330 ++lineNumber;
331 }
332 }
333 }
334
335 String pdfFileLocation = parameterService.getParameterValueAsString(OleParameterConstants.PURCHASING_DOCUMENT.class, PurapConstants.PDF_DIRECTORY);
336 if (pdfFileLocation == null) {
337 LOG.debug("savePurchaseOrderPdf() ended");
338 throw new PurapConfigurationException("Application Setting PDF_DIRECTORY is missing.");
339 }
340
341 String pdfFileName = "PURAP_PO_" + po.getPurapDocumentIdentifier().toString() + "_" + System.currentTimeMillis() + ".pdf";
342
343 PurchaseOrderPdfFaxParameters pdfParameters = new PurchaseOrderPdfFaxParameters();
344 pdfParameters.setCampusParameter(campusParameter);
345 pdfParameters.setContractLanguage(contractLanguage.toString());
346 pdfParameters.setContractManagerSignatureImage(contractManagerSignatureImage);
347 pdfParameters.setDirectorSignatureImage(directorSignatureImage);
348 pdfParameters.setImageTempLocation(imageTempLocation);
349 pdfParameters.setKey(key);
350 pdfParameters.setLogoImage(logoImage);
351 pdfParameters.setStatusInquiryUrl(statusInquiryUrl);
352 pdfParameters.setPdfFileLocation(pdfFileLocation);
353 pdfParameters.setPdfFileName(pdfFileName);
354 pdfParameters.setUseImage(useImage);
355 return pdfParameters;
356 }*/
357
358 /**
359 * Creates purchase order pdf document given the input parameters.
360 *
361 * @param po The PurchaseOrderDocument.
362 * @param byteArrayOutputStream ByteArrayOutputStream that the action is using, where the pdf will be printed to.
363 * @param isRetransmit boolean true if this is a retransmit purchase order document.
364 * @param environment The current environment used (e.g. DEV if it is a development environment).
365 * @param retransmitItems The items selected by the user to be retransmitted.
366 * @return Collection of error strings.
367 */
368 protected Collection generatePurchaseOrderPdf(PurchaseOrderDocument po, ByteArrayOutputStream byteArrayOutputStream, boolean isRetransmit, String environment, List<PurchaseOrderItem> retransmitItems) {
369 LOG.debug("generatePurchaseOrderPdf() started");
370
371 PurchaseOrderPdf poPdf = new PurchaseOrderPdf();
372 Collection errors = new ArrayList();
373 try {
374 PurchaseOrderParameters purchaseOrderParameters = getPurchaseOrderParameters();
375 purchaseOrderParameters.setPurchaseOrderPdfParameters(po);
376 PurchaseOrderTransmitParameters pdfParameters = (PurchaseOrderTransmitParameters) purchaseOrderParameters;
377 if (LOG.isInfoEnabled()) {
378 LOG.info("PDF Parameters in PrintServiceImpl" + "pdfParameters:" + pdfParameters + "isRetransmit:"
379 + isRetransmit + "retransmitItems:" + retransmitItems);
380 }
381 poPdf.generatePdf(po, pdfParameters, byteArrayOutputStream, isRetransmit, environment, retransmitItems);
382 } catch (PurError e) {
383 LOG.error("Caught exception ", e);
384 errors.add(e.getMessage());
385 } catch (PurapConfigurationException pce) {
386 LOG.error("Caught exception ", pce);
387 errors.add(pce.getMessage());
388 }
389
390 LOG.debug("generatePurchaseOrderPdf() ended");
391 return errors;
392 }
393
394 /**
395 * @see org.kuali.ole.module.purap.document.service.PrintService#generatePurchaseOrderPdf(org.kuali.ole.module.purap.document.PurchaseOrderDocument,
396 * java.io.ByteArrayOutputStream, java.lang.String)
397 */
398 @Override
399 public Collection generatePurchaseOrderPdf(PurchaseOrderDocument po, ByteArrayOutputStream byteArrayOutputStream, String environment, List<PurchaseOrderItem> retransmitItems) {
400 if (LOG.isInfoEnabled()) {
401 LOG.info("Inside the PrintServiceImpl class" + "PO:" + po + "ByteArrayOutputStream:"
402 + byteArrayOutputStream + "environment:" + environment + "retransmitItems:" + retransmitItems);
403 }
404 return generatePurchaseOrderPdf(po, byteArrayOutputStream, TRANSMISSION_IS_NOT_RETRANSMIT, environment, retransmitItems);
405 }
406
407
408 /**
409 * @see org.kuali.ole.module.purap.document.service.PrintService#generatePurchaseOrderPdfForRetransmission(org.kuali.ole.module.purap.document.PurchaseOrderDocument,
410 * java.io.ByteArrayOutputStream, java.lang.String)
411 */
412 @Override
413 public Collection generatePurchaseOrderPdfForRetransmission(PurchaseOrderDocument po, ByteArrayOutputStream byteArrayOutputStream, String environment, List<PurchaseOrderItem> retransmitItems) {
414 return generatePurchaseOrderPdf(po, byteArrayOutputStream, TRANSMISSION_IS_RETRANSMIT, environment, retransmitItems);
415 }
416
417
418 /**
419 * Saves the purchase order pdf document.
420 *
421 * @param po The PurchaseOrderDocument.
422 * @param isRetransmit boolean true if this is a retransmit purchase order document.
423 * @param environment The current environment used (e.g. DEV if it is a development environment).
424 * @return Collection of error strings.
425 */
426 protected Collection savePurchaseOrderPdf(PurchaseOrderDocument po, boolean isRetransmit, String environment) {
427 LOG.debug("savePurchaseOrderPdf() started");
428
429 PurchaseOrderPdf poPdf = new PurchaseOrderPdf();
430 Collection errors = new ArrayList();
431
432 PurchaseOrderTransmitParameters pdfParameters = null;
433
434 try {
435 PurchaseOrderParameters purchaseOrderParameters = getPurchaseOrderParameters();
436 purchaseOrderParameters.setPurchaseOrderPdfParameters(po);
437 pdfParameters = (PurchaseOrderTransmitParameters) purchaseOrderParameters;
438 poPdf.savePdf(po, pdfParameters, isRetransmit, environment);
439 } catch (PurError e) {
440 LOG.error("Caught exception ", e);
441 errors.add(e.getMessage());
442 } catch (PurapConfigurationException pce) {
443 LOG.error("Caught exception ", pce);
444 errors.add(pce.getMessage());
445 } finally {
446 try {
447 poPdf.deletePdf(pdfParameters.getPdfFileLocation(), pdfParameters.getPdfFileName());
448 } catch (Throwable e) {
449 LOG.error("savePurchaseOrderPdf() Error deleting PDF" + pdfParameters.getPdfFileName() + " - Exception was " + e.getMessage(), e);
450 errors.add("Error while deleting the pdf after savePurchaseOrderPdf" + e.getMessage());
451 }
452 }
453
454 LOG.debug("savePurchaseOrderPdf() ended");
455 return errors;
456 }
457
458 /**
459 * @see org.kuali.ole.module.purap.document.service.PrintService#savePurchaseOrderPdf(org.kuali.ole.module.purap.document.PurchaseOrderDocument,
460 * java.lang.String)
461 */
462 @Override
463 public Collection savePurchaseOrderPdf(PurchaseOrderDocument po, String environment) {
464 return savePurchaseOrderPdf(po, TRANSMISSION_IS_NOT_RETRANSMIT, environment);
465 }
466
467 /**
468 * @see org.kuali.ole.module.purap.document.service.PrintService#savePurchaseOrderPdfForRetransmission(org.kuali.ole.module.purap.document.PurchaseOrderDocument,
469 * java.lang.String)
470 */
471 @Override
472 public Collection savePurchaseOrderPdfForRetransmission(PurchaseOrderDocument po, String environment) {
473 return savePurchaseOrderPdf(po, TRANSMISSION_IS_RETRANSMIT, environment);
474 }
475
476 @Override
477 public Collection generateBulkReceivingPDF(BulkReceivingDocument blkRecDoc,
478 ByteArrayOutputStream baosPDF) {
479
480 LOG.debug("generateBulkReceivingPDF() started");
481
482 BulkReceivingPdf recBlkTicketPDF = new BulkReceivingPdf();
483 Collection errors = new ArrayList();
484
485 String imageTempLocation = StringUtils.EMPTY;
486 String logoImage = StringUtils.EMPTY;
487
488 String key = blkRecDoc.getDocumentNumber().toString(); // key can be any string;
489 String campusCode = blkRecDoc.getDeliveryCampusCode().toLowerCase();
490
491 String environment = kualiConfigurationService.getPropertyValueAsString(OLEConstants.ENVIRONMENT_KEY);
492
493 boolean useImage = true;
494 if (parameterService.parameterExists(OleParameterConstants.PURCHASING_DOCUMENT.class, PurapConstants.PDF_IMAGES_AVAILABLE_INDICATOR)) {
495 useImage = parameterService.getParameterValueAsBoolean(OleParameterConstants.PURCHASING_DOCUMENT.class, PurapConstants.PDF_IMAGES_AVAILABLE_INDICATOR);
496 }
497
498 if (useImage) {
499 imageTempLocation = kualiConfigurationService.getPropertyValueAsString(OLEConstants.TEMP_DIRECTORY_KEY) + "/";
500
501 if (imageTempLocation == null) {
502 throw new PurapConfigurationException("IMAGE_TEMP_PATH is missing");
503 }
504
505 // Get images
506 logoImage = imageService.getLogo(key, campusCode, imageTempLocation);
507
508 if (StringUtils.isEmpty(logoImage)) {
509 throw new PurapConfigurationException("logoImage is null.");
510 }
511 }
512
513 try {
514 recBlkTicketPDF.generatePdf(blkRecDoc, baosPDF, logoImage, environment);
515 } catch (PurapConfigurationException pce) {
516 LOG.error("Caught exception ", pce);
517 errors.add(pce.getMessage());
518 }
519
520 LOG.debug("generateBulkReceivingPDF() ended");
521 return errors;
522 }
523
524 public void setParameterService(ParameterService parameterService) {
525 this.parameterService = parameterService;
526 }
527
528 public void setImageService(ImageService imageService) {
529 this.imageService = imageService;
530 }
531
532 public void setBusinessObjectService(BusinessObjectService businessObjectService) {
533 this.businessObjectService = businessObjectService;
534 }
535
536 public void setConfigurationService(ConfigurationService kualiConfigurationService) {
537 this.kualiConfigurationService = kualiConfigurationService;
538 }
539
540 public void setPurchaseOrderParameters(PurchaseOrderParameters purchaseOrderParameters) {
541 this.purchaseOrderParameters = purchaseOrderParameters;
542 }
543
544 public PurchaseOrderParameters getPurchaseOrderParameters() {
545 return SpringContext.getBean(PurchaseOrderParameters.class);
546 }
547
548 }
549