View Javadoc
1   /*
2    * Copyright 2013 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.document.service.impl;
17  
18  import org.kuali.ole.select.businessobject.OLERequestorPatronDocument;
19  import org.kuali.ole.select.businessobject.OlePatronDocuments;
20  import org.kuali.ole.select.businessobject.OlePatronRecordHandler;
21  import org.kuali.ole.select.document.service.OleSelectDocumentService;
22  import org.kuali.ole.service.impl.OlePatronWebServiceImpl;
23  import org.kuali.ole.sys.OLEConstants;
24  import org.kuali.ole.sys.OLEKeyConstants;
25  import org.kuali.rice.coreservice.api.CoreServiceApiServiceLocator;
26  import org.kuali.rice.coreservice.api.parameter.Parameter;
27  import org.kuali.rice.coreservice.api.parameter.ParameterKey;
28  
29  import java.util.ArrayList;
30  import java.util.List;
31  
32  public class OleSelectDocumentServiceImpl implements OleSelectDocumentService {
33      private static transient OlePatronRecordHandler olePatronRecordHandler;
34  
35      @Override
36      public List<OLERequestorPatronDocument> getPatronDocumentListFromWebService() {
37          List<OLERequestorPatronDocument> olePatronDocumentList = new ArrayList<OLERequestorPatronDocument>();
38          OlePatronDocuments olePatronDocument = getPatronObjectsFromWebService();
39          if (olePatronDocument.getOlePatronDocuments() != null) {
40              for (int olePatron = 0; olePatron < olePatronDocument.getOlePatronDocuments().size(); olePatron++) {
41                  olePatronDocumentList.add(olePatronDocument.getOlePatronDocuments().get(olePatron));
42              }
43          }
44          return olePatronDocumentList;
45      }
46  
47      private OlePatronDocuments getPatronObjectsFromWebService() {
48          OlePatronDocuments olePatronDocuments = new OlePatronDocuments();
49  
50          OlePatronWebServiceImpl olePatronWebService = new OlePatronWebServiceImpl();
51          String patronRecords = olePatronWebService.getPatronRecords();
52          olePatronDocuments = getOlePatronRecordHandler().retrievePatronFromXML(patronRecords);
53          return olePatronDocuments;
54      }
55  
56      @Override
57      public String getPatronName(List<OLERequestorPatronDocument> olePatronDocumentList, String requestorId) {
58          StringBuffer patronName = new StringBuffer();
59          for (OLERequestorPatronDocument olePatronDocument : olePatronDocumentList) {
60              if (requestorId != null) {
61                  if (requestorId.equalsIgnoreCase(olePatronDocument.getOlePatronId())) {
62                      patronName.append(olePatronDocument.getLastName());
63                      patronName.append(", ");
64                      patronName.append(olePatronDocument.getFirstName());
65                  }
66              }
67          }
68          return patronName.toString();
69      }
70  
71      public OlePatronRecordHandler getOlePatronRecordHandler() {
72          if (null == olePatronRecordHandler) {
73              olePatronRecordHandler = new OlePatronRecordHandler();
74          }
75          return olePatronRecordHandler;
76      }
77  
78      public String getSelectParameterValue(String parameterName){
79          ParameterKey parameterKey = ParameterKey.create(org.kuali.ole.OLEConstants.APPL_ID, org.kuali.ole.OLEConstants.SELECT_NMSPC, org.kuali.ole.OLEConstants.SELECT_CMPNT,parameterName);
80          Parameter parameter = CoreServiceApiServiceLocator.getParameterRepositoryService().getParameter(parameterKey);
81          return parameter!=null?parameter.getValue():null;
82      }
83  
84  
85      public void setOlePatronRecordHandler(OlePatronRecordHandler olePatronRecordHandler) {
86          this.olePatronRecordHandler = olePatronRecordHandler;
87      }
88  }