View Javadoc
1   package org.kuali.ole.deliver.keyvalue;
2   
3   import org.apache.commons.collections.CollectionUtils;
4   import org.apache.commons.lang.StringUtils;
5   import org.kuali.ole.OLEConstants;
6   import org.kuali.ole.deliver.bo.OleCirculationDesk;
7   import org.kuali.ole.deliver.bo.OleCirculationDeskDetail;
8   import org.kuali.ole.deliver.bo.OleCirculationDeskLocation;
9   import org.kuali.ole.deliver.form.OLEPlaceRequestForm;
10  import org.kuali.ole.deliver.service.ParameterValueResolver;
11  import org.kuali.ole.describe.form.BoundwithForm;
12  import org.kuali.rice.core.api.util.ConcreteKeyValue;
13  import org.kuali.rice.core.api.util.KeyValue;
14  import org.kuali.rice.krad.service.BusinessObjectService;
15  import org.kuali.rice.krad.service.KRADServiceLocator;
16  import org.kuali.rice.krad.uif.control.UifKeyValuesFinderBase;
17  import org.kuali.rice.krad.uif.view.ViewModel;
18  import org.kuali.rice.krad.util.GlobalVariables;
19  
20  import java.util.ArrayList;
21  import java.util.HashMap;
22  import java.util.List;
23  import java.util.Map;
24  
25  /**
26   * Created by maheswarang on 2/6/15.
27   */
28  public class OlePlaceRequestCirculationDeskKeyValue extends UifKeyValuesFinderBase {
29  
30      private BusinessObjectService businessObjectService;
31  
32      @Override
33      public boolean isAddBlankOption() {
34          return false;
35      }
36  
37      public BusinessObjectService getBusinessObjectService() {
38          if(businessObjectService == null){
39              this.businessObjectService = KRADServiceLocator.getBusinessObjectService();
40          }
41          return businessObjectService;
42      }
43  
44      public void setBusinessObjectService(BusinessObjectService businessObjectService) {
45          this.businessObjectService = businessObjectService;
46      }
47  
48      @Override
49      public List<KeyValue> getKeyValues(ViewModel viewModel) {
50          OLEPlaceRequestForm olePlaceRequestForm = (OLEPlaceRequestForm) viewModel;
51          HashMap<String,String> circulationDeskMap = new HashMap<String,String>();
52          circulationDeskMap.put("circulationPickUpDeskLocation",olePlaceRequestForm.getItemLocation());
53          List<OleCirculationDeskLocation> oleCirculationDeskLocations = (List<OleCirculationDeskLocation>)getBusinessObjectService().findMatching(OleCirculationDeskLocation.class,circulationDeskMap);
54          OleCirculationDesk defaultPickUpLocation = getDefaultPickUpLocation();
55           if(defaultPickUpLocation == null){
56               defaultPickUpLocation = getOperatorDefaultPickupLocation();
57          }
58          List<KeyValue> options = new ArrayList<KeyValue>();
59          //TODO: Get drop-down values dynamically by parsing DocumentConfig.xml file
60          if(defaultPickUpLocation!=null){
61              options.add(new ConcreteKeyValue(defaultPickUpLocation.getCirculationDeskId(),defaultPickUpLocation.getCirculationDeskCode()));
62          }else{
63              options.add(new ConcreteKeyValue("",""));
64          }
65            if(oleCirculationDeskLocations!=null && oleCirculationDeskLocations.size()>0){
66            for(OleCirculationDeskLocation oleCirculationDeskLocation : oleCirculationDeskLocations){
67                if(defaultPickUpLocation!=null){
68                if(!oleCirculationDeskLocation.getCirculationDeskId().equals(defaultPickUpLocation.getCirculationDeskId())){
69                 options.add(new ConcreteKeyValue(oleCirculationDeskLocation.getCirculationDeskId(),oleCirculationDeskLocation.getOleCirculationDesk().getCirculationDeskCode()));
70                }
71                }else{
72                  options.add(new ConcreteKeyValue(oleCirculationDeskLocation.getCirculationDeskId(),oleCirculationDeskLocation.getOleCirculationDesk().getCirculationDeskCode()));
73                }
74                }
75            }
76          return options;
77      }
78  
79      private OleCirculationDesk getDefaultPickUpLocation() {
80          String parameterValue = ParameterValueResolver.getInstance().getParameter(OLEConstants.APPL_ID_OLE, OLEConstants.DLVR_NMSPC, OLEConstants.DLVR_CMPNT, OLEConstants.DEFAULT_PICK_UP_LOCATION);
81          if (StringUtils.isNotBlank(parameterValue)) {
82              Map<String, String> pickUpLocMap = new HashMap<>();
83              pickUpLocMap.put(OLEConstants.PICKUP_LOCATION, "true");
84              pickUpLocMap.put(OLEConstants.OleCirculationDesk.OLE_CIRCULATION_DESK_CD, parameterValue);
85              List<OleCirculationDesk> oleCirculationDesks = (List<OleCirculationDesk>) KRADServiceLocator.getBusinessObjectService().findMatching(OleCirculationDesk.class, pickUpLocMap);
86              if (CollectionUtils.isNotEmpty(oleCirculationDesks)) {
87                  return oleCirculationDesks.get(0);
88              }
89          }
90          return null;
91      }
92  
93  
94      private OleCirculationDesk getOperatorDefaultPickupLocation(){
95          OleCirculationDesk oleCirculationDesk = null;
96          Map<String,String> criteriaMap = new HashMap<String,String>();
97          criteriaMap.put("operatorId", GlobalVariables.getUserSession().getPrincipalId());
98          criteriaMap.put("defaultLocation","Y");
99          List<OleCirculationDeskDetail> oleCirculationDeskDetailList = (List<OleCirculationDeskDetail>)getBusinessObjectService().findMatching(OleCirculationDeskDetail.class,criteriaMap);
100         if(oleCirculationDeskDetailList.size()>0){
101           OleCirculationDeskDetail  oleCirculationDeskDetail = oleCirculationDeskDetailList.get(0);
102           if(oleCirculationDeskDetail.getOleCirculationDesk()!=null && oleCirculationDeskDetail.getOleCirculationDesk().getDefaultPickupLocation()!=null && oleCirculationDeskDetail.getOleCirculationDesk().getDefaultPickupLocation().isPickUpLocation()){
103             oleCirculationDesk = oleCirculationDeskDetail.getOleCirculationDesk().getDefaultPickupLocation();
104           }
105 
106         }
107         return oleCirculationDesk;
108     }
109 }