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.apache.commons.lang.StringUtils;
19 import org.kuali.ole.module.purap.PurapConstants;
20 import org.kuali.ole.module.purap.businessobject.PurchaseOrderType;
21 import org.kuali.ole.module.purap.document.RequisitionDocument;
22 import org.kuali.ole.select.batch.service.RequisitionCreateDocumentService;
23 import org.kuali.ole.select.bo.OLEEResourceOrderRecord;
24 import org.kuali.ole.select.businessobject.OleRequisitionItem;
25 import org.kuali.ole.select.document.OleRequisitionDocument;
26 import org.kuali.ole.select.document.service.OleRequisitionDocumentService;
27 import org.kuali.ole.sys.OLEConstants;
28 import org.kuali.ole.sys.context.SpringContext;
29 import org.kuali.ole.sys.document.validation.event.DocumentSystemSaveEvent;
30 import org.kuali.rice.kew.framework.postprocessor.IDocumentEvent;
31 import org.kuali.rice.kim.api.identity.Person;
32 import org.kuali.rice.kim.api.identity.PersonService;
33 import org.kuali.rice.krad.service.DocumentService;
34 import org.kuali.rice.krad.util.GlobalVariables;
35
36 import java.sql.Date;
37 import java.text.SimpleDateFormat;
38 import java.util.HashMap;
39 import java.util.List;
40 import java.util.Map;
41
42 public class RequisitionCreateDocumentServiceImpl implements RequisitionCreateDocumentService {
43 private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(RequisitionCreateDocumentServiceImpl.class);
44
45 protected DocumentService documentService;
46 private OleRequisitionDocumentService oleRequisitionDocumentService;
47
48
49
50
51
52
53 public DocumentService getDocumentService() {
54 return documentService;
55 }
56
57
58
59
60
61
62
63 public void setDocumentService(DocumentService documentService) {
64 this.documentService = documentService;
65 }
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81 public String saveRequisitionDocuments(RequisitionDocument reqDocument) {
82 try {
83 if (LOG.isInfoEnabled()) {
84 LOG.info("Calling saveRequisitionDocuments in RequisitionCreateDocumentServiceImpl >>>>" + reqDocument.getDocumentNumber());
85 }
86 try {
87 documentService.saveDocument(reqDocument, DocumentSystemSaveEvent.class);
88 } catch (Exception e) {
89 LOG.error("Exection while saving requisition document" + e);
90 e.printStackTrace();
91 }
92 reqDocument.populateDocumentForRouting();
93
94 Person principalPerson = SpringContext.getBean(PersonService.class).getPerson(GlobalVariables.getUserSession().getPerson().getPrincipalId());
95
96
97 String purchaseOrderType = "";
98 if (reqDocument.getPurchaseOrderTypeId() != null) {
99
100 Map purchaseOrderTypeIdMap = new HashMap();
101 purchaseOrderTypeIdMap.put("purchaseOrderTypeId", reqDocument.getPurchaseOrderTypeId());
102 org.kuali.rice.krad.service.BusinessObjectService
103 businessObject = SpringContext.getBean(org.kuali.rice.krad.service.BusinessObjectService.class);
104 List<PurchaseOrderType> purchaseOrderTypeDocumentList = (List) businessObject.findMatching(PurchaseOrderType.class, purchaseOrderTypeIdMap);
105 if (purchaseOrderTypeDocumentList != null && purchaseOrderTypeDocumentList.size() > 0) {
106 PurchaseOrderType purchaseOrderTypeDoc = (PurchaseOrderType) purchaseOrderTypeDocumentList.get(0);
107 purchaseOrderType = purchaseOrderTypeDoc.getPurchaseOrderType();
108 }
109 if (LOG.isDebugEnabled())
110 LOG.debug("purchaseOrderType >>>>>>>>>>>" + purchaseOrderType);
111
112
113 getDocumentService().routeDocument(reqDocument, null, null);
114
115 LOG.debug("After Calling createWorkflowDocument >>>>>>>>>>>");
116 }
117
118 LOG.debug(IDocumentEvent.BEFORE_PROCESS);
119 if (LOG.isInfoEnabled()) {
120 LOG.info("Saved Requisition document. Document Number: " + reqDocument.getDocumentNumber());
121 }
122 } catch (Exception e) {
123 LOG.error("Error persisting document # " + reqDocument.getDocumentHeader().getDocumentNumber() + " " + e.getMessage(), e);
124 throw new RuntimeException("Error persisting document # " + reqDocument.getDocumentHeader().getDocumentNumber() + " " + e.getMessage(), e);
125 }
126 return reqDocument.getDocumentNumber();
127 }
128
129 public OleRequisitionDocument updateParamaterValue(OleRequisitionDocument requisitionDocument,List<PurchaseOrderType> purchaseOrderTypeDocumentList,OLEEResourceOrderRecord oleEResourceOrderRecord) {
130
131 if(!purchaseOrderTypeDocumentList.get(0).getPurchaseOrderType().equals(OLEConstants.APPROVAL) && !purchaseOrderTypeDocumentList.get(0).getPurchaseOrderType().equals(OLEConstants.ORD_TYPE_FIRM_FIX)) {
132 try {
133 requisitionDocument.setRecurringPaymentTypeCode(getOleRequisitionDocumentService().getParameter(OLEConstants.RECURRING_PAY_TYP));
134 SimpleDateFormat format = new SimpleDateFormat(OLEConstants.DATE_FORM_PO_BEGN_DT);
135 java.util.Date utilDate = (java.util.Date) format.parse(OLEConstants.DATE_FORM_PO_END_DT);
136 java.sql.Date poEndDate = new java.sql.Date(utilDate.getTime());
137 java.util.Date date = new java.util.Date();
138 Date poCreateDate = new Date(date.getTime());
139 requisitionDocument.setPurchaseOrderBeginDate(poCreateDate);
140 requisitionDocument.setPurchaseOrderEndDate(poEndDate);
141 } catch (Exception e) {
142 LOG.error("Error Occured hwile setting the system parameter value to requisition document :" + e.getMessage());
143 }
144 }
145 return requisitionDocument;
146 }
147
148 public void updateCopyNumber() {
149
150 }
151
152
153 public OleRequisitionDocumentService getOleRequisitionDocumentService() {
154 if(oleRequisitionDocumentService == null) {
155 return SpringContext.getBean(OleRequisitionDocumentService.class);
156 }
157
158 return oleRequisitionDocumentService;
159 }
160
161
162 }