View Javadoc

1   /*
2    * Copyright 2011 The Kuali Foundation.
3    * 
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    * http://www.opensource.org/licenses/ecl2.php
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
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          //properties = loadPropertiesFromClassPath("org/kuali/ole/select/batch/service/impl/bibinfo.properties");
88      }
89  
90      /**
91       * To load the XML File for the vendor.
92       *
93       * @param fileName String
94       * @return boolean
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             //bibInfoBean.setRequestSource(OleSelectConstant.REQUEST_SRC_TYPE_BATCHINGEST);
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      * Set the values for the Requisition Document and save.
128      *
129      * @param bibInfoBeanList ArrayList
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      * To load the property file for the given path.
145      *
146      * @param classPath String
147      * @return properties
148      */
149 /*    public static Properties loadPropertiesFromClassPath(String classPath) {
150         ClassPathResource classPathResource = new ClassPathResource(classPath);
151 
152         Properties properties = new Properties();
153         try {
154             properties.load(classPathResource.getInputStream());
155         }
156         catch (IOException e) {
157             throw new RuntimeException("Invalid class path: " + classPath + e,e);
158         }
159 
160         return properties;
161     }*/
162 
163 }