View Javadoc
1   package org.kuali.ole.service.impl;
2   
3   import org.kuali.ole.ingest.OlePatronRecordHandler;
4   import org.kuali.ole.deliver.bo.OlePatronDocument;
5   import org.kuali.ole.deliver.bo.OlePatronDocuments;
6   import org.kuali.ole.service.OlePatronWebService;
7   import org.kuali.rice.krad.service.BusinessObjectService;
8   import org.kuali.rice.krad.service.KRADServiceLocator;
9   
10  import java.util.ArrayList;
11  import java.util.Collection;
12  import java.util.List;
13  
14  /**
15   * Created with IntelliJ IDEA.
16   * User: ?
17   * Date: 2/19/13
18   * Time: 6:02 PM
19   * To change this template use File | Settings | File Templates.
20   */
21  public class OlePatronWebServiceImpl implements OlePatronWebService {
22  
23      private BusinessObjectService businessObjectService;
24      private OlePatronRecordHandler olePatronRecordHandler;
25  
26      /**
27       *   Returns the businessObjectService instance.
28       *   If it is not null  returns existing businessObjectService else creates new
29       * @return  businessObjectService
30       */
31      protected BusinessObjectService getBusinessObjectService() {
32          if (businessObjectService == null) {
33              businessObjectService = KRADServiceLocator.getBusinessObjectService();
34          }
35          return businessObjectService;
36      }
37  
38      public OlePatronRecordHandler getOlePatronRecordHandler() {
39          if (null == olePatronRecordHandler) {
40              olePatronRecordHandler = new OlePatronRecordHandler();
41          }
42          return olePatronRecordHandler;
43      }
44  
45      /**
46       * Sets the olePatronRecordHandler which is of type OlePatronRecordHandler
47       * @param olePatronRecordHandler(OlePatronRecordHandler)
48       */
49      public void setOlePatronRecordHandler(OlePatronRecordHandler olePatronRecordHandler) {
50          this.olePatronRecordHandler = olePatronRecordHandler;
51      }
52  
53      @Override
54      public String getPatronRecords() {
55  
56          String patronXML = new String();
57          StringBuffer patronRecords = new StringBuffer();
58          OlePatronDocuments olePatronDocuments = new OlePatronDocuments();
59  
60          List<OlePatronDocument> olePatronDocumentList = new ArrayList<OlePatronDocument>();
61          Collection<OlePatronDocument> olePatronDocumentRecords = getBusinessObjectService().findAll(OlePatronDocument.class);
62          for (OlePatronDocument olePatronDocument : olePatronDocumentRecords) {
63             olePatronDocument.setFirstName(olePatronDocument.getEntity().getNames().get(0).getFirstName());
64             olePatronDocument.setLastName(olePatronDocument.getEntity().getNames().get(0).getLastName());
65             olePatronDocument.setBorrowerType(olePatronDocument.getOleBorrowerType().getBorrowerTypeName());
66             olePatronDocumentList.add(olePatronDocument);
67             olePatronDocuments.setOlePatronDocuments(olePatronDocumentList);
68          }
69          patronXML = getOlePatronRecordHandler().generatePatronXML(olePatronDocuments);
70          return patronXML;
71      }
72  
73  }