1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.kuali.ole.module.purap.document.service.impl;
18
19 import org.kuali.ole.module.purap.PurapConstants;
20 import org.kuali.ole.module.purap.document.PurchaseOrderDocument;
21 import org.kuali.ole.module.purap.document.service.FaxBatchDocumentsService;
22 import org.kuali.ole.module.purap.document.service.FaxService;
23 import org.kuali.ole.module.purap.document.service.PurapService;
24 import org.kuali.ole.module.purap.document.service.PurchaseOrderService;
25 import org.kuali.ole.sys.context.SpringContext;
26 import org.kuali.rice.core.api.datetime.DateTimeService;
27 import org.kuali.rice.kew.api.exception.WorkflowException;
28 import org.kuali.rice.krad.service.DocumentService;
29 import org.kuali.rice.krad.util.GlobalVariables;
30
31 import java.util.Collection;
32 import java.util.Iterator;
33
34 public class FaxBatchDocumentsServiceImpl implements FaxBatchDocumentsService {
35 private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(FaxBatchDocumentsServiceImpl.class);
36
37 private PurchaseOrderService purchaseOrderService;
38 private FaxService faxService;
39 private PurapService purapService;
40 private DateTimeService dateTimeService;
41
42
43
44
45
46
47
48 public boolean faxPendingPurchaseOrders() {
49
50 Collection<PurchaseOrderDocument> pendingPOs = purchaseOrderService.getPendingPurchaseOrderFaxes();
51 boolean result = true;
52
53 for (Iterator<PurchaseOrderDocument> iter = pendingPOs.iterator(); iter.hasNext(); ) {
54
55 PurchaseOrderDocument po = iter.next();
56
57 if (!po.getDocumentHeader().hasWorkflowDocument()) {
58 try {
59 po = (PurchaseOrderDocument) SpringContext.getBean(DocumentService.class).getByDocumentHeaderId(po.getDocumentNumber());
60 } catch (WorkflowException e) {
61 throw new RuntimeException(e);
62 }
63 }
64
65 GlobalVariables.getMessageMap().clearErrorMessages();
66 faxService.faxPurchaseOrderPdf(po, false);
67
68 if (GlobalVariables.getMessageMap().hasErrors()) {
69 try {
70 po.updateAndSaveAppDocStatus(PurapConstants.PurchaseOrderStatuses.APPDOC_OPEN);
71 } catch (WorkflowException we) {
72 String errorMsg = "Workflow Exception caught trying to create and save PO document of type PurchaseOrderSplitDocument using source document with doc id '" + po.getDocumentNumber() + "'";
73 LOG.error(errorMsg, we);
74 throw new RuntimeException(errorMsg, we);
75 }
76
77 po.setPurchaseOrderInitialOpenTimestamp(dateTimeService.getCurrentTimestamp());
78 po.setPurchaseOrderLastTransmitTimestamp(dateTimeService.getCurrentTimestamp());
79 purapService.saveDocumentNoValidation(po);
80 } else {
81 result = false;
82 }
83 }
84
85 return result;
86 }
87
88 public void setPurchaseOrderService(PurchaseOrderService purchaseOrderService) {
89 this.purchaseOrderService = purchaseOrderService;
90 }
91
92 public void setFaxService(FaxService faxService) {
93 this.faxService = faxService;
94 }
95
96 public void setPurapService(PurapService purapService) {
97 this.purapService = purapService;
98 }
99
100 public void setDateTimeService(DateTimeService dateTimeService) {
101 this.dateTimeService = dateTimeService;
102 }
103
104 }