View Javadoc
1   package org.kuali.ole.describe.keyvalue;
2   
3   import org.kuali.ole.deliver.bo.OleCirculationDesk;
4   import org.kuali.ole.deliver.bo.OleDeliverRequestBo;
5   import org.kuali.ole.describe.bo.OleLocation;
6   import org.kuali.rice.core.api.util.ConcreteKeyValue;
7   import org.kuali.rice.core.api.util.KeyValue;
8   import org.kuali.rice.krad.service.KRADServiceLocator;
9   import org.kuali.rice.krad.uif.control.UifKeyValuesFinderBase;
10  import org.kuali.rice.krad.uif.view.ViewModel;
11  import org.kuali.rice.krad.web.form.MaintenanceDocumentForm;
12  
13  import java.util.*;
14  
15  /**
16   * The LocationKeyValuesFinder class contains a method that returns the location name as key and location code as value
17   * wrapped as a KeyValue object in a list.
18   */
19  public class LocationKeyValuesFinder extends UifKeyValuesFinderBase {
20  
21      /**
22       * This method returns the key-values in a List based on the model parameter that is passed.
23       *
24       * @param model
25       * @return options
26       */
27      @Override
28      public List<KeyValue> getKeyValues(ViewModel model) {
29          MaintenanceDocumentForm testForm = (MaintenanceDocumentForm) model;
30          List<KeyValue> options = new ArrayList<KeyValue>();
31          if (testForm.getDocument().getNewMaintainableObject().getDataObject() instanceof OleDeliverRequestBo) {
32              List<OleLocation> oleLocations = (List<OleLocation>) KRADServiceLocator.getBusinessObjectService().findAll(OleLocation.class);
33              for (int i = 0; i < oleLocations.size(); i++) {
34                  options.add(new ConcreteKeyValue(oleLocations.get(i).getLevelId(), oleLocations.get(i).getLocationCode()));
35              }
36          } else if (testForm.getDocument().getNewMaintainableObject().getDataObject() instanceof OleCirculationDesk) {
37              Map<String, String> locationMap = new HashMap<String, String>();
38              locationMap.put("levelId", "5");
39              List<OleLocation> shelvingLocations = (List<OleLocation>) KRADServiceLocator.getBusinessObjectService().findMatching(OleLocation.class, locationMap);
40              for (int i = 0; i < shelvingLocations.size(); i++) {
41                  options.add(new ConcreteKeyValue(shelvingLocations.get(i).getLocationId(), shelvingLocations.get(i).getLocationCode()));
42              }
43          } else {
44              String levelId = ((OleLocation) testForm.getDocument().getNewMaintainableObject().getDataObject()).getLevelId();
45              Collection<OleLocation> oleLocations = KRADServiceLocator.getBusinessObjectService().findAll(OleLocation.class);
46              for (OleLocation location : oleLocations) {
47                  if (location.getLevelId() != null && !location.getLevelId().equalsIgnoreCase("") && levelId != null && !levelId.equalsIgnoreCase("")) {
48                      if (Integer.parseInt(location.getLevelId()) < Integer.parseInt(levelId)) {
49                          options.add(new ConcreteKeyValue(location.getLocationId(), location.getLocationName() + " [" + location.getLocationCode() + "]"));
50                      }
51                  }
52              }
53              return options;
54          }
55          return options;
56      }
57  
58  }