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.processor.LoanProcessor;
8   import org.kuali.rice.core.api.util.ConcreteKeyValue;
9   import org.kuali.rice.core.api.util.KeyValue;
10  import org.kuali.rice.krad.keyvalues.KeyValuesBase;
11  import org.kuali.rice.krad.service.KRADServiceLocator;
12  
13  import java.util.*;
14  
15  /**
16   * Created by angelind on 7/27/15.
17   */
18  public class PickupLocationKeyValueFinder extends KeyValuesBase {
19  
20      private LoanProcessor loanProcessor = new LoanProcessor();
21  
22      @Override
23      public List<KeyValue> getKeyValues() {
24          List<KeyValue> options = new ArrayList<KeyValue>();
25          Map<String, String> userMap = new HashMap<String, String>();
26          userMap.put(OLEConstants.PICKUP_LOCATION, "true");
27          Collection<OleCirculationDesk> oleCirculationDesks = KRADServiceLocator.getBusinessObjectService().findMatching(OleCirculationDesk.class, userMap);
28          OleCirculationDesk circulationDesk = validateDefaultPickUpLocation();
29          if (circulationDesk != null) {
30              options.add(new ConcreteKeyValue(circulationDesk.getCirculationDeskId(),circulationDesk.getCirculationDeskCode()));
31              for (OleCirculationDesk oleCirculationDesk : oleCirculationDesks) {
32                  if (!circulationDesk.getCirculationDeskId().equals(oleCirculationDesk.getCirculationDeskId())) {
33                      options.add(new ConcreteKeyValue(oleCirculationDesk.getCirculationDeskId(), oleCirculationDesk.getCirculationDeskCode()));
34                  }
35              }
36          } else {
37              options = new ArrayList<KeyValue>();
38              options.add(new ConcreteKeyValue("", ""));
39              for (OleCirculationDesk oleCirculationDesk : oleCirculationDesks) {
40                  options.add(new ConcreteKeyValue(oleCirculationDesk.getCirculationDeskId(), oleCirculationDesk.getCirculationDeskCode()));
41              }
42          }
43          return options;
44      }
45  
46      private OleCirculationDesk validateDefaultPickUpLocation() {
47          String parameterValue = loanProcessor.getParameter(OLEConstants.DEFAULT_PICK_UP_LOCATION);
48          if (StringUtils.isNotBlank(parameterValue)) {
49              Map<String, String> pickUpLocMap = new HashMap<>();
50              pickUpLocMap.put(OLEConstants.PICKUP_LOCATION, "true");
51              pickUpLocMap.put(OLEConstants.OleCirculationDesk.OLE_CIRCULATION_DESK_CD, parameterValue);
52              List<OleCirculationDesk> oleCirculationDesks = (List<OleCirculationDesk>) KRADServiceLocator.getBusinessObjectService().findMatching(OleCirculationDesk.class, pickUpLocMap);
53              if (CollectionUtils.isNotEmpty(oleCirculationDesks)) {
54                  return oleCirculationDesks.get(0);
55              }
56          }
57          return null;
58      }
59  }