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