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  
30  import java.util.HashMap;
31  import java.util.List;
32  
33  public class OleExposedWebServiceImpl implements OleExposedWebService {
34  
35      private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(OleExposedWebService.class);
36      private OleReqPOLoadTransactionsService oleReqPOLoadTransactionsService;
37  
38      @Override
39      public void createReqAndPO(String oleOrderRecordXMLContent, OLEBatchProcessJobDetailsBo job) {
40          try {
41              OleOrderRecordHandler oleOrderRecordHandler = new OleOrderRecordHandler();
42              if (LOG.isDebugEnabled()) {
43                  LOG.debug("oleOrderRecordXMLContent----------->" + oleOrderRecordXMLContent);
44              }
45              OleOrderRecords oleOrderRecords = oleOrderRecordHandler.fromXML(oleOrderRecordXMLContent);
46              OleReqPOLoadTransactionsService oleReqPOLoadTransactionsService = getOleReqPOLoadTransactionsService();
47              List reqList = oleReqPOLoadTransactionsService.saveRequisitionDocument(oleOrderRecords, job);
48              oleReqPOLoadTransactionsService.createAcquisitionDocument(reqList, oleOrderRecords, job);
49          } catch (Exception e) {
50              LOG.error("Exception while creating Req & PO"+e.getMessage());
51              throw new RuntimeException(e);
52          }
53      }
54  
55      public OleReqPOLoadTransactionsService getOleReqPOLoadTransactionsService() {
56          return oleReqPOLoadTransactionsService;
57      }
58  
59      public void setOleReqPOLoadTransactionsService(OleReqPOLoadTransactionsService oleReqPOLoadTransactionsService) {
60          this.oleReqPOLoadTransactionsService = oleReqPOLoadTransactionsService;
61      }
62  
63      @Override
64      public void addDoctoreResponse(String docstoreResponse) {
65          HashMap<String, OleEditorResponse> docstoreResponses = new HashMap<String, OleEditorResponse>();
66          OleEditorResponseHandler oleEditorResponseHandler = new OleEditorResponseHandler();
67          OleEditorResponse oleEditorResponse = oleEditorResponseHandler.fromXML(docstoreResponse);
68          docstoreResponses.put(oleEditorResponse.getTokenId(), oleEditorResponse);
69  
70          OleDocstoreResponse.getInstance().setDocstoreResponse(docstoreResponses);
71          if (LOG.isDebugEnabled()) {
72              LOG.debug("#########OleDocstoreResponse##########" + OleDocstoreResponse.getInstance().getDocstoreResponse().toString());
73          }
74      }
75  
76      @Override
77      public String getPaymentMethod() {
78  
79          StringBuffer paymentMethodbuffer = new StringBuffer();
80          BusinessObjectService businessObjectService = SpringContext.getBean(BusinessObjectService.class);
81          List<OlePaymentMethod> olePaymentMethods = (List<OlePaymentMethod>) businessObjectService.findAll(OlePaymentMethod.class);
82          if (olePaymentMethods != null && olePaymentMethods.size() > 0) {
83              for (int i = 0; i < olePaymentMethods.size(); i++) {
84                  paymentMethodbuffer.append(olePaymentMethods.get(i).getPaymentMethod() + ",");
85              }
86  
87          }
88          return paymentMethodbuffer.toString();
89      }
90  
91  }