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.OLEConstants;
19 import org.kuali.ole.module.purap.PurapParameterConstants;
20 import org.kuali.ole.module.purap.document.RequisitionDocument;
21 import org.kuali.ole.select.OleSelectConstant;
22 import org.kuali.ole.select.batch.service.OleRequisitionCreateDocumentService;
23 import org.kuali.ole.select.batch.service.RequisitionLoadTransactionsService;
24 import org.kuali.ole.select.businessobject.BibInfoBean;
25 import org.kuali.ole.select.service.impl.BuildVendorBibInfoBean;
26 import org.kuali.ole.sys.batch.service.BatchInputFileService;
27 import org.kuali.ole.sys.context.SpringContext;
28 import org.kuali.rice.core.api.config.property.ConfigurationService;
29 import org.kuali.rice.coreservice.api.CoreServiceApiServiceLocator;
30 import org.kuali.rice.coreservice.api.parameter.Parameter;
31 import org.kuali.rice.coreservice.api.parameter.ParameterKey;
32 import org.kuali.rice.coreservice.framework.parameter.ParameterService;
33 import org.kuali.rice.kew.api.exception.WorkflowException;
34 import org.kuali.rice.krad.UserSession;
35 import org.kuali.rice.krad.util.GlobalVariables;
36 import org.springframework.beans.factory.InitializingBean;
37
38 import java.util.ArrayList;
39 import java.util.List;
40 import java.util.Properties;
41
42 public class RequisitionLoadTransactionsServiceImpl implements RequisitionLoadTransactionsService, InitializingBean {
43 private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(RequisitionLoadTransactionsServiceImpl.class);
44
45 protected BatchInputFileService batchInputFileService;
46 protected OleRequisitionCreateDocumentService oleRequisitionCreateDocumentService;
47 protected BuildVendorBibInfoBean buildVendorBibInfoBean;
48 protected Properties properties = null;
49 protected ConfigurationService kualiConfigurationService;
50
51 protected String determinePurchaseOrderTransmissionMethod() {
52
53 return SpringContext.getBean(ParameterService.class).getParameterValueAsString(RequisitionDocument.class, PurapParameterConstants.PURAP_DEFAULT_PO_TRANSMISSION_CODE);
54 }
55
56 public BatchInputFileService getBatchInputFileService() {
57 return batchInputFileService;
58 }
59
60 public void setBatchInputFileService(BatchInputFileService batchInputFileService) {
61 this.batchInputFileService = batchInputFileService;
62 }
63
64 public OleRequisitionCreateDocumentService getOleRequisitionCreateDocumentService() {
65 return oleRequisitionCreateDocumentService;
66 }
67
68
69 public void setOleRequisitionCreateDocumentService(OleRequisitionCreateDocumentService oleRequisitionCreateDocumentService) {
70 this.oleRequisitionCreateDocumentService = oleRequisitionCreateDocumentService;
71 }
72
73 public BuildVendorBibInfoBean getBuildVendorBibInfoBean() {
74 return buildVendorBibInfoBean;
75 }
76
77 public void setBuildVendorBibInfoBean(BuildVendorBibInfoBean buildVendorBibInfoBean) {
78 this.buildVendorBibInfoBean = buildVendorBibInfoBean;
79 }
80
81 public ConfigurationService getConfigurationService() {
82 return kualiConfigurationService;
83 }
84
85 public void setConfigurationService(ConfigurationService kualiConfigurationService) {
86 this.kualiConfigurationService = kualiConfigurationService;
87 }
88
89 @Override
90 public void afterPropertiesSet() throws Exception {
91
92 }
93
94
95
96
97
98
99
100 public boolean loadRequisitionFile(String fileName) {
101
102 String userName = kualiConfigurationService.getPropertyValueAsString("userName");
103 GlobalVariables.setUserSession(new UserSession(userName));
104 try {
105 List<BibInfoBean> bibInfoBeanList = new ArrayList<BibInfoBean>();
106 bibInfoBeanList = buildVendorBibInfoBean.getBibInfoList(fileName);
107 setRequisitionParameterValue(bibInfoBeanList);
108 saveRequisitionDocument(bibInfoBeanList);
109 } catch (WorkflowException we) {
110 LOG.error("failed to create a new RequisitionDocument instance" + we, we);
111 } catch (Exception ex) {
112 LOG.error("faild to create the requisition document in RequisitionLoadTransactionsServiceImpl " + fileName, ex);
113 throw new RuntimeException("parsing error " + fileName + " " + ex.getMessage(), ex);
114 }
115
116 return true;
117
118 }
119
120 private List<BibInfoBean> setRequisitionParameterValue(List<BibInfoBean> bibInfoBeanList) {
121 for (BibInfoBean bibInfoBean : bibInfoBeanList) {
122
123 bibInfoBean.setRequisitionSource(OleSelectConstant.REQUISITON_SRC_TYPE_MANUALINGEST);
124 bibInfoBean.setRequestorType(OleSelectConstant.BATCHINGEST_REQUEST);
125 bibInfoBean.setDocStoreOperation(OleSelectConstant.DOCSTORE_OPERATION_BATCHINGEST);
126 }
127 return bibInfoBeanList;
128 }
129
130
131
132
133
134
135 public List saveRequisitionDocument(List<BibInfoBean> bibInfoBeanList) throws Exception {
136 boolean vendorRecordMappingFlag = false;
137 List reqList = new ArrayList(0);
138 String vendorRecordMappingProperty = getParameter("VENDOR_RECORD_TO_REQUISITION_MAPPING");
139 if (vendorRecordMappingProperty.equalsIgnoreCase("TRUE"))
140 vendorRecordMappingFlag = true;
141 oleRequisitionCreateDocumentService.saveRequisitionDocument(bibInfoBeanList, vendorRecordMappingFlag);
142 return (List) oleRequisitionCreateDocumentService.getReqList();
143
144 }
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167 public String getParameter(String name){
168 ParameterKey parameterKey = ParameterKey.create(OLEConstants.APPL_ID,OLEConstants.SELECT_NMSPC,OLEConstants.SELECT_CMPNT,name);
169 Parameter parameter = CoreServiceApiServiceLocator.getParameterRepositoryService().getParameter(parameterKey);
170 return parameter!=null?parameter.getValue():null;
171 }
172
173 }