1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
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
89
90 @Override
91 public Collection savePurchaseOrderQuoteRequestsListPdf(PurchaseOrderDocument po) {
92 return null;
93 }
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157 protected PurchaseOrderTransmitParameters getPurchaseOrderQuoteRequestsListPdfParameters(PurchaseOrderDocument po) {
158 PurchaseOrderParameters purchaseOrderParameters = getPurchaseOrderParameters();
159 purchaseOrderParameters.setPurchaseOrderPdfParameters(po);
160 return (PurchaseOrderTransmitParameters) purchaseOrderParameters;
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208 }
209
210
211
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
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
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
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
396
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
410
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
420
421
422
423
424
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
460
461
462 @Override
463 public Collection savePurchaseOrderPdf(PurchaseOrderDocument po, String environment) {
464 return savePurchaseOrderPdf(po, TRANSMISSION_IS_NOT_RETRANSMIT, environment);
465 }
466
467
468
469
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();
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
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