1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole.select.batch.service.impl;
17
18 import org.kuali.ole.module.purap.PurapConstants;
19 import org.kuali.ole.module.purap.businessobject.PurchaseOrderType;
20 import org.kuali.ole.module.purap.document.RequisitionDocument;
21 import org.kuali.ole.select.batch.service.RequisitionCreateDocumentService;
22 import org.kuali.ole.sys.context.SpringContext;
23 import org.kuali.ole.sys.document.validation.event.DocumentSystemSaveEvent;
24 import org.kuali.rice.kew.framework.postprocessor.IDocumentEvent;
25 import org.kuali.rice.kim.api.identity.Person;
26 import org.kuali.rice.kim.api.identity.PersonService;
27 import org.kuali.rice.krad.service.DocumentService;
28 import org.kuali.rice.krad.util.GlobalVariables;
29 import java.util.HashMap;
30 import java.util.List;
31 import java.util.Map;
32
33 public class RequisitionCreateDocumentServiceImpl implements RequisitionCreateDocumentService {
34 private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(RequisitionCreateDocumentServiceImpl.class);
35
36 protected DocumentService documentService;
37
38
39
40
41
42
43 public DocumentService getDocumentService() {
44 return documentService;
45 }
46
47
48
49
50
51
52
53 public void setDocumentService(DocumentService documentService) {
54 this.documentService = documentService;
55 }
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71 public String saveRequisitionDocuments(RequisitionDocument reqDocument) {
72 try {
73 if (LOG.isInfoEnabled()) {
74 LOG.info("Calling saveRequisitionDocuments in RequisitionCreateDocumentServiceImpl >>>>" + reqDocument.getDocumentNumber());
75 }
76 try {
77 documentService.saveDocument(reqDocument, DocumentSystemSaveEvent.class);
78 } catch (Exception e) {
79 LOG.error("Exection while saving requisition document" + e);
80 e.printStackTrace();
81 }
82 reqDocument.populateDocumentForRouting();
83
84 Person principalPerson = SpringContext.getBean(PersonService.class).getPerson(GlobalVariables.getUserSession().getPerson().getPrincipalId());
85
86
87 String purchaseOrderType = "";
88 if (reqDocument.getPurchaseOrderTypeId() != null) {
89
90 Map purchaseOrderTypeIdMap = new HashMap();
91 purchaseOrderTypeIdMap.put("purchaseOrderTypeId", reqDocument.getPurchaseOrderTypeId());
92 org.kuali.rice.krad.service.BusinessObjectService
93 businessObject = SpringContext.getBean(org.kuali.rice.krad.service.BusinessObjectService.class);
94 List<PurchaseOrderType> purchaseOrderTypeDocumentList = (List) businessObject.findMatching(PurchaseOrderType.class, purchaseOrderTypeIdMap);
95 if (purchaseOrderTypeDocumentList != null && purchaseOrderTypeDocumentList.size() > 0) {
96 PurchaseOrderType purchaseOrderTypeDoc = (PurchaseOrderType) purchaseOrderTypeDocumentList.get(0);
97 purchaseOrderType = purchaseOrderTypeDoc.getPurchaseOrderType();
98 }
99 if (LOG.isDebugEnabled())
100 LOG.debug("purchaseOrderType >>>>>>>>>>>" + purchaseOrderType);
101
102
103 getDocumentService().routeDocument(reqDocument, null, null);
104
105 LOG.debug("After Calling createWorkflowDocument >>>>>>>>>>>");
106 }
107
108 LOG.debug(IDocumentEvent.BEFORE_PROCESS);
109 if (LOG.isInfoEnabled()) {
110 LOG.info("Saved Requisition document. Document Number: " + reqDocument.getDocumentNumber());
111 }
112 } catch (Exception e) {
113 LOG.error("Error persisting document # " + reqDocument.getDocumentHeader().getDocumentNumber() + " " + e.getMessage(), e);
114 throw new RuntimeException("Error persisting document # " + reqDocument.getDocumentHeader().getDocumentNumber() + " " + e.getMessage(), e);
115 }
116 return reqDocument.getDocumentNumber();
117 }
118
119 }