View Javadoc
1   /*
2    * Copyright 2012 The Kuali Foundation.
3    *
4    * Licensed under the Educational Community License, Version 1.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/ecl1.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.service.impl;
17  
18  import org.kuali.ole.OleEditorResponseHandler;
19  import org.kuali.ole.OleOrderRecordHandler;
20  import org.kuali.ole.OleOrderRecords;
21  import org.kuali.ole.batch.bo.OLEBatchProcessJobDetailsBo;
22  import org.kuali.ole.pojo.OleEditorResponse;
23  import org.kuali.ole.select.businessobject.OleDocstoreResponse;
24  import org.kuali.ole.select.businessobject.OlePaymentMethod;
25  import org.kuali.ole.select.service.OleExposedWebService;
26  import org.kuali.ole.select.service.OleReqPOLoadTransactionsService;
27  import org.kuali.ole.sys.context.SpringContext;
28  import org.kuali.rice.krad.service.BusinessObjectService;
29  import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
30  
31  import java.util.HashMap;
32  import java.util.List;
33  
34  public class OleExposedWebServiceImpl implements OleExposedWebService {
35  
36      private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(OleExposedWebService.class);
37      private OleReqPOLoadTransactionsService oleReqPOLoadTransactionsService;
38  
39      @Override
40      public void createReqAndPO(String oleOrderRecordXMLContent, OLEBatchProcessJobDetailsBo job) {
41          try {
42              OleOrderRecordHandler oleOrderRecordHandler = new OleOrderRecordHandler();
43              if (LOG.isDebugEnabled()) {
44                  LOG.debug("oleOrderRecordXMLContent----------->" + oleOrderRecordXMLContent);
45              }
46              OleOrderRecords oleOrderRecords = oleOrderRecordHandler.fromXML(oleOrderRecordXMLContent);
47              OleReqPOLoadTransactionsService oleReqPOLoadTransactionsService = getOleReqPOLoadTransactionsService();
48              List reqList = oleReqPOLoadTransactionsService.saveRequisitionDocument(oleOrderRecords, job);
49              oleReqPOLoadTransactionsService.createAcquisitionDocument(reqList, oleOrderRecords, job);
50          } catch (Exception e) {
51              LOG.error("Exception while creating Req & PO"+e.getMessage());
52              throw new RuntimeException(e);
53          }
54      }
55  
56      public OleReqPOLoadTransactionsService getOleReqPOLoadTransactionsService() {
57          return oleReqPOLoadTransactionsService;
58      }
59  
60      public void setOleReqPOLoadTransactionsService(OleReqPOLoadTransactionsService oleReqPOLoadTransactionsService) {
61          this.oleReqPOLoadTransactionsService = oleReqPOLoadTransactionsService;
62      }
63  
64      @Override
65      public void addDoctoreResponse(String docstoreResponse) {
66          HashMap<String, OleEditorResponse> docstoreResponses = new HashMap<String, OleEditorResponse>();
67          OleEditorResponseHandler oleEditorResponseHandler = new OleEditorResponseHandler();
68          OleEditorResponse oleEditorResponse = oleEditorResponseHandler.fromXML(docstoreResponse);
69          docstoreResponses.put(oleEditorResponse.getTokenId(), oleEditorResponse);
70  
71          OleDocstoreResponse.getInstance().setDocstoreResponse(docstoreResponses);
72          if (LOG.isDebugEnabled()) {
73              LOG.debug("#########OleDocstoreResponse##########" + OleDocstoreResponse.getInstance().getDocstoreResponse().toString());
74          }
75      }
76  
77      @Override
78      public String getPaymentMethod() {
79  
80          StringBuffer paymentMethodbuffer = new StringBuffer();
81          BusinessObjectService businessObjectService = SpringContext.getBean(BusinessObjectService.class);
82          List<OlePaymentMethod> olePaymentMethods = (List<OlePaymentMethod>) businessObjectService.findAll(OlePaymentMethod.class);
83          if (olePaymentMethods != null && olePaymentMethods.size() > 0) {
84              for (int i = 0; i < olePaymentMethods.size(); i++) {
85                  paymentMethodbuffer.append(olePaymentMethods.get(i).getPaymentMethod() + ",");
86              }
87  
88          }
89          return paymentMethodbuffer.toString();
90      }
91  
92  }