001package org.kuali.ole.deliver.service; 002 003import org.apache.log4j.Logger; 004import org.kuali.ole.deliver.api.OleDeliverRequestDefinition; 005import org.kuali.ole.deliver.api.OlePatronDefinition; 006import org.kuali.ole.deliver.bo.OleDeliverRequestBo; 007import org.kuali.ole.deliver.bo.OlePatronLoanDocument; 008import org.kuali.ole.deliver.bo.OlePatronLoanDocuments; 009import org.kuali.ole.deliver.bo.OleRenewalLoanDocument; 010import org.kuali.ole.service.OlePatronService; 011import org.kuali.ole.service.OlePatronServiceImpl; 012 013import java.util.ArrayList; 014import java.util.List; 015 016/** 017 * Created with IntelliJ IDEA. 018 * User: ? 019 * Date: 10/26/12 020 * Time: 7:47 PM 021 * To change this template use File | Settings | File Templates. 022 */ 023public class OleMyAccountProcess { 024 025 private static final Logger LOG = Logger.getLogger(OleMyAccountProcess.class); 026 027 028 public List<OleRenewalLoanDocument> oleRenewalLoanDocumentList; 029 private OlePatronService olePatronService; 030 OleDeliverRequestDocumentHelperServiceImpl service = new OleDeliverRequestDocumentHelperServiceImpl(); 031 032 public OlePatronService getOlePatronService() { 033 034 if (olePatronService == null) 035 olePatronService = new OlePatronServiceImpl(); 036 return olePatronService; 037 } 038 039 public OleMyAccountProcess() { 040 oleRenewalLoanDocumentList = new ArrayList<OleRenewalLoanDocument>(); 041 } 042 043 /** 044 * this method performs to find the patron information using by patron id 045 * 046 * @param patronId 047 * @return 048 */ 049 public OlePatronDefinition getPatronInfo(String patronId) { 050 LOG.debug("Inside the getPatronInfo method"); 051 OlePatronDefinition olePatronDefinition = getOlePatronService().getPatron(patronId); 052 return olePatronDefinition; 053 } 054 055 /** 056 * this method performs to find the patron checkout items by using patron barcode 057 * 058 * @param patronBarcode 059 * @return 060 */ 061 public List<OleRenewalLoanDocument> getPatronLoanedItems(String patronBarcode) { 062 LOG.debug("Inside the getPatronLoanedItems method"); 063 OlePatronLoanDocuments olePatronLoanDocuments = getOlePatronService().getPatronLoanedItems(patronBarcode); 064 List<OleRenewalLoanDocument> oleRenewalLoanDocumentList = convertRenewalLoanDocuments(olePatronLoanDocuments); 065 return oleRenewalLoanDocumentList; 066 067 } 068 069 public List<OleDeliverRequestDefinition> getPatronRequestItems(String patronId) { 070 LOG.debug("Inside the getPatronRequestItems method"); 071 List<OleDeliverRequestDefinition> oleDeliverRequestDefinition = getOlePatronService().getPatronRequestItems(patronId); 072 return oleDeliverRequestDefinition; 073 074 } 075 076 public void cancelRequest(List<OleDeliverRequestDefinition> oleDeliverRequestDefinition) { 077 LOG.debug("Inside the cancelRequest method"); 078 for (OleDeliverRequestDefinition oleDeliverRequestDefinitions : oleDeliverRequestDefinition) { 079 OleDeliverRequestBo oleDeliverRequestBo = OleDeliverRequestBo.from(oleDeliverRequestDefinitions); 080 service.cancelDocument(oleDeliverRequestBo); 081 } 082 } 083 084 /** 085 * this method performs to renewal the itmes 086 * 087 * @param oleRenewalLoanDocumentList 088 * @return 089 */ 090 public List<OleRenewalLoanDocument> performRenewalItem(List<OleRenewalLoanDocument> oleRenewalLoanDocumentList) { 091 LOG.debug("Inside the performRenewalItem method"); 092 OlePatronLoanDocuments olePatronLoanDocuments = convertOlePatronLoanDocuments(oleRenewalLoanDocumentList); 093 olePatronLoanDocuments = getOlePatronService().performRenewalItems(olePatronLoanDocuments); 094 oleRenewalLoanDocumentList = null; 095 oleRenewalLoanDocumentList = convertRenewalLoanDocuments(olePatronLoanDocuments); 096 return oleRenewalLoanDocumentList; 097 } 098 099 /** 100 * this method performs to convert list of OleRenewalLoanDocument to OlePatronLoanDocuments 101 * 102 * @param oleRenewalLoanDocumentList 103 * @return 104 */ 105 private OlePatronLoanDocuments convertOlePatronLoanDocuments(List<OleRenewalLoanDocument> oleRenewalLoanDocumentList) { 106 LOG.debug("Inside the convertOlePatronLoanDocuments method"); 107 List<OlePatronLoanDocument> olePatronLoanItemList = new ArrayList<OlePatronLoanDocument>(); 108 for (int i = 0; i < oleRenewalLoanDocumentList.size(); i++) { 109 OleRenewalLoanDocument oleRenewalLoanDocument = oleRenewalLoanDocumentList.get(i); 110 OlePatronLoanDocument olePatronLoanDocument = OlePatronLoanDocuments.to(oleRenewalLoanDocument); 111 olePatronLoanItemList.add(olePatronLoanDocument); 112 } 113 OlePatronLoanDocuments olePatronLoanDocuments = getOlePatronLoanDocuments(olePatronLoanItemList); 114 return olePatronLoanDocuments; 115 } 116 117 /** 118 * this method performs to convert OlePatronLoanDocuments to list of OleRenewalLoanDocument 119 * 120 * @param olePatronLoanDocuments 121 * @return 122 */ 123 private List<OleRenewalLoanDocument> convertRenewalLoanDocuments(OlePatronLoanDocuments olePatronLoanDocuments) { 124 LOG.debug("Inside the convertRenewalLoanDocuments method"); 125 List<OleRenewalLoanDocument> oleRenewalLoanDocumentList = new ArrayList<OleRenewalLoanDocument>(); 126 if (olePatronLoanDocuments != null) 127 for (int i = 0; i < olePatronLoanDocuments.getOlePatronLoanDocuments().size(); i++) { 128 OlePatronLoanDocument olePatronLoanDocument = (OlePatronLoanDocument) olePatronLoanDocuments.getOlePatronLoanDocuments().get(i); 129 OleRenewalLoanDocument oleRenewalLoanDocument = new OleRenewalLoanDocument(); 130 oleRenewalLoanDocument.setItemBarcode(olePatronLoanDocument.getItemBarcode()); 131 oleRenewalLoanDocument.setCallNumber(olePatronLoanDocument.getCallNumber()); 132 oleRenewalLoanDocument.setDueDate(olePatronLoanDocument.getDueDate()); 133 oleRenewalLoanDocument.setLocation(olePatronLoanDocument.getLocation()); 134 oleRenewalLoanDocument.setTitle(olePatronLoanDocument.getTitle()); 135 oleRenewalLoanDocument.setAuthor(olePatronLoanDocument.getAuthor()); 136 oleRenewalLoanDocument.setMessageInfo(olePatronLoanDocument.getMessageInfo()); 137 oleRenewalLoanDocumentList.add(oleRenewalLoanDocument); 138 } 139 return oleRenewalLoanDocumentList; 140 } 141 142 /** 143 * this method performs to convert OlePatronLoanDocument to list of OleRenewalLoanDocument 144 * 145 * @param olePatronLoanItemList 146 * @return 147 */ 148 private OlePatronLoanDocuments getOlePatronLoanDocuments(List<OlePatronLoanDocument> olePatronLoanItemList) { 149 LOG.debug("Inside the getOlePatronLoanDocuments method"); 150 OleRenewalLoanDocument oleRenewalLoanDocument = new OleRenewalLoanDocument(); 151 if (olePatronLoanItemList.size() != 0) { 152 oleRenewalLoanDocument.setOlePatronLoanDocuments(olePatronLoanItemList); 153 OlePatronLoanDocuments olePatronLoanDocuments = OlePatronLoanDocuments.Builder.create(oleRenewalLoanDocument).build(); 154 return olePatronLoanDocuments; 155 } 156 157 return null; 158 159 } 160 161}