View Javadoc

1   package org.kuali.ole.deliver.request.lookup;
2   
3   import org.apache.commons.lang.StringUtils;
4   import org.kuali.ole.OLEConstants;
5   
6   import org.kuali.ole.deliver.loan.bo.OleItemSearch;
7   import org.kuali.ole.deliver.request.bo.OleDeliverRequestBo;
8   import org.kuali.ole.deliver.request.service.OleDeliverRequestDocumentHelperServiceImpl;
9   import org.kuali.ole.patron.bo.OlePatronDocument;
10  import org.kuali.rice.kim.impl.identity.name.EntityNameBo;
11  import org.kuali.rice.krad.lookup.LookupableImpl;
12  import org.kuali.rice.krad.service.KRADServiceLocator;
13  import org.kuali.rice.krad.uif.UifConstants;
14  import org.kuali.rice.krad.uif.UifParameters;
15  import org.kuali.rice.krad.uif.view.LookupView;
16  import org.kuali.rice.krad.util.KRADConstants;
17  import org.kuali.rice.krad.util.KRADUtils;
18  import org.kuali.rice.krad.util.UrlFactory;
19  import org.kuali.rice.krad.web.form.LookupForm;
20  
21  import java.util.*;
22  
23  /**
24   * Created with IntelliJ IDEA.
25   * User: ?
26   * Date: 10/11/12
27   * Time: 4:01 PM
28   * To change this template use File | Settings | File Templates.
29   */
30  
31  public class OleDeliverRequestLookupableImpl extends LookupableImpl {
32      private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(OleDeliverRequestLookupableImpl.class);
33      private OleDeliverRequestDocumentHelperServiceImpl oleDeliverRequestDocumentHelperService =  new OleDeliverRequestDocumentHelperServiceImpl();
34      private String itemTitle;
35      private String borrowerName;
36      @Override
37      protected String getActionUrlHref(LookupForm lookupForm, Object dataObject, String methodToCall,
38                                        List<String> pkNames) {
39          LOG.debug("Inside getActionUrlHref()");
40          LookupView lookupView = (LookupView) lookupForm.getView();
41  
42          Properties props = new Properties();
43          props.put(KRADConstants.DISPATCH_REQUEST_PARAMETER, methodToCall);
44          Map<String, String> primaryKeyValues = KRADUtils.getPropertyKeyValuesFromDataObject(pkNames, dataObject);
45          for (String primaryKey : primaryKeyValues.keySet()) {
46              String primaryKeyValue = primaryKeyValues.get(primaryKey);
47  
48              props.put(primaryKey, primaryKeyValue);
49          }
50  
51          if (StringUtils.isNotBlank(lookupForm.getReturnLocation())) {
52              props.put(KRADConstants.RETURN_LOCATION_PARAMETER, lookupForm.getReturnLocation());
53          }
54  
55          props.put(UifParameters.DATA_OBJECT_CLASS_NAME, OleDeliverRequestBo.class.getName());
56          props.put(UifParameters.VIEW_TYPE_NAME, UifConstants.ViewType.MAINTENANCE.name());
57  
58          String maintenanceMapping = OLEConstants.OleDeliverRequest.DELIVER_REQUEST_MAINTENANCE_ACTION_LINK;
59  
60          return UrlFactory.parameterizeUrl(maintenanceMapping, props);
61      }
62  
63  
64      @Override
65      public Collection<?> performSearch(LookupForm form, Map<String, String> searchCriteria, boolean bounded) {
66          LOG.debug("Inside performSearch()");
67  
68          itemTitle =searchCriteria.get("title");
69          borrowerName=searchCriteria.get("borrowerName");
70          searchCriteria.remove("title");
71          searchCriteria.remove("borrowerName");
72          List<OleDeliverRequestBo> displayList = new ArrayList<OleDeliverRequestBo>();
73         // List<OlePatronDocument> olePatronDocumentList = new ArrayList<OlePatronDocument>();
74          List<EntityNameBo> entityNameBos = new ArrayList<EntityNameBo>();
75          if(borrowerName!=null && !borrowerName.isEmpty()){
76              Map<String,String> patronMap = new HashMap<String,String>();
77              patronMap.put("firstName",borrowerName);
78              entityNameBos = (List<EntityNameBo>)KRADServiceLocator.getBusinessObjectService().findMatching(EntityNameBo.class,patronMap);
79           if(entityNameBos.size()==0){
80              return displayList;
81           }
82         if(entityNameBos.size()>0){
83                   for(int i=0;i<entityNameBos.size();i++){
84  
85                       searchCriteria.put("borrowerId",entityNameBos.get(i).getEntityId());
86                       displayList.addAll((List<OleDeliverRequestBo>)super.performSearch(form,searchCriteria,bounded));
87                       searchCriteria.remove("borrowerId");
88                   }
89         }
90          }   if(borrowerName==null || (borrowerName!=null && borrowerName.isEmpty())){
91  
92            displayList= (List<OleDeliverRequestBo>)super.performSearch(form,searchCriteria,bounded);
93          }
94          searchCriteria.put("title",itemTitle);
95          searchCriteria.put("borrowerName",borrowerName);
96  
97          OleItemSearch oleItemSearch;
98          try{
99              for(int i=0;i<displayList.size();i++){
100                 oleItemSearch= oleDeliverRequestDocumentHelperService.getItemDetails(displayList.get(i).getItemId());
101                 if(itemTitle!=null && !itemTitle.isEmpty()&&!oleItemSearch.getTitle().toUpperCase().contains(itemTitle.toUpperCase()))
102                 {
103                     displayList.remove(i);
104                 }
105                 else{
106                     displayList.get(i).setTitle(oleItemSearch.getTitle());
107                     displayList.get(i).setCallNumber(oleItemSearch.getCallNumber());
108                     displayList.get(i).setAuthor(oleItemSearch.getAuthor());
109                 }
110             }
111         }
112         catch(Exception e){
113         }
114 
115         return displayList;
116     }
117 
118 
119 }
120 
121