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  
24  import java.util.ArrayList;
25  import java.util.List;
26  
27  public class OleSelectDocumentServiceImpl implements OleSelectDocumentService {
28      private static transient OlePatronRecordHandler olePatronRecordHandler;
29  
30      @Override
31      public List<OLERequestorPatronDocument> getPatronDocumentListFromWebService() {
32          List<OLERequestorPatronDocument> olePatronDocumentList = new ArrayList<OLERequestorPatronDocument>();
33          OlePatronDocuments olePatronDocument = getPatronObjectsFromWebService();
34          if (olePatronDocument.getOlePatronDocuments() != null) {
35              for (int olePatron = 0; olePatron < olePatronDocument.getOlePatronDocuments().size(); olePatron++) {
36                  olePatronDocumentList.add(olePatronDocument.getOlePatronDocuments().get(olePatron));
37              }
38          }
39          return olePatronDocumentList;
40      }
41  
42      private OlePatronDocuments getPatronObjectsFromWebService() {
43          OlePatronDocuments olePatronDocuments = new OlePatronDocuments();
44  
45          OlePatronWebServiceImpl olePatronWebService = new OlePatronWebServiceImpl();
46          String patronRecords = olePatronWebService.getPatronRecords();
47          olePatronDocuments = getOlePatronRecordHandler().retrievePatronFromXML(patronRecords);
48          return olePatronDocuments;
49      }
50  
51      @Override
52      public String getPatronName(List<OLERequestorPatronDocument> olePatronDocumentList, String requestorId) {
53          StringBuffer patronName = new StringBuffer();
54          for (OLERequestorPatronDocument olePatronDocument : olePatronDocumentList) {
55              if (requestorId != null) {
56                  if (requestorId.equalsIgnoreCase(olePatronDocument.getOlePatronId())) {
57                      patronName.append(olePatronDocument.getLastName());
58                      patronName.append(", ");
59                      patronName.append(olePatronDocument.getFirstName());
60                  }
61              }
62          }
63          return patronName.toString();
64      }
65  
66      public OlePatronRecordHandler getOlePatronRecordHandler() {
67          if (null == olePatronRecordHandler) {
68              olePatronRecordHandler = new OlePatronRecordHandler();
69          }
70          return olePatronRecordHandler;
71      }
72  
73      public void setOlePatronRecordHandler(OlePatronRecordHandler olePatronRecordHandler) {
74          this.olePatronRecordHandler = olePatronRecordHandler;
75      }
76  }