View Javadoc

1   package org.kuali.ole.location.keyvalue;
2   
3   import org.kuali.ole.location.bo.OleLocation;
4   import org.kuali.rice.core.api.util.ConcreteKeyValue;
5   import org.kuali.rice.core.api.util.KeyValue;
6   import org.kuali.rice.krad.service.KRADServiceLocator;
7   import org.kuali.rice.krad.uif.control.UifKeyValuesFinderBase;
8   import org.kuali.rice.krad.uif.view.ViewModel;
9   import org.kuali.rice.krad.web.form.MaintenanceForm;
10  
11  import java.util.*;
12  
13  /**
14   * The LocationKeyValuesFinder class contains a method that returns the location name as key and location code as value
15   * wrapped as a KeyValue object in a list.
16   */
17  public class LocationKeyValuesFinder extends UifKeyValuesFinderBase {
18  
19      /**
20       * This method returns the key-values in a List based on the model parameter that is passed.
21       * @param model
22       * @return options
23       */
24      @Override
25      public List<KeyValue> getKeyValues(ViewModel model) {
26          MaintenanceForm testForm = (MaintenanceForm) model;
27          List<KeyValue> options = new ArrayList<KeyValue>();
28          String levelId = ((OleLocation)testForm.getDocument().getNewMaintainableObject().getDataObject()).getLevelId();
29          Collection<OleLocation> oleLocations = KRADServiceLocator.getBusinessObjectService().findAll(OleLocation.class);
30          for (OleLocation location : oleLocations) {
31              if(location.getLevelId() != null && !location.getLevelId().equalsIgnoreCase("") && levelId != null && !levelId.equalsIgnoreCase("")) {
32                  if(Integer.parseInt(location.getLevelId()) < Integer.parseInt(levelId)){
33                      options.add(new ConcreteKeyValue(location.getLocationId(),location.getLocationName()+" ["+location.getLocationCode()+"]"));
34                  }
35              }
36          }
37          return options;
38      }
39  
40  }