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