View Javadoc

1   package org.kuali.ole.editor.keyvalue;
2   
3   import org.kuali.ole.location.bo.OleLocation;
4   import org.kuali.ole.location.bo.OleLocationLevel;
5   import org.kuali.rice.core.api.util.ConcreteKeyValue;
6   import org.kuali.rice.core.api.util.KeyValue;
7   import org.kuali.rice.krad.keyvalues.KeyValuesBase;
8   import org.kuali.rice.krad.service.BusinessObjectService;
9   import org.kuali.rice.krad.service.KRADServiceLocator;
10  
11  import java.util.*;
12  
13  /**
14   * LocationValuesBuilder used to render the values for LocationValuesBuilder dropdown control.
15   */
16  public class LocationValuesBuilder extends KeyValuesBase {
17      /**
18       * This method returns the List of ConcreteKeyValue,
19       * ConcreteKeyValue has two arguments LevelCode and
20       * LocationName.
21       * @return    List<KeyValue>
22       */
23      @Override
24      public List<KeyValue> getKeyValues() {
25          List<KeyValue> options = new ArrayList<KeyValue>();
26          BusinessObjectService businessObjectService = KRADServiceLocator.getBusinessObjectService();
27  
28          Map parentCriteria1 = new HashMap();
29          parentCriteria1.put("levelCode", "SHELVING");
30          List<OleLocationLevel> oleLocationLevel = (List<OleLocationLevel>) businessObjectService.findMatching(OleLocationLevel.class, parentCriteria1);
31          String shelvingId = oleLocationLevel.get(0).getLevelId();
32          options.add(new ConcreteKeyValue("", ""));
33          Map parentCriteria = new HashMap();
34          parentCriteria.put("levelId", shelvingId);
35          Collection<OleLocation> oleLocationCollection = businessObjectService.findMatching(OleLocation.class, parentCriteria);
36          for (OleLocation oleLocation : oleLocationCollection) {
37              String locationName = oleLocation.getLocationName();
38              String levelId = oleLocation.getLevelId();
39              String levelCode = oleLocation.getLocationCode();
40              boolean parentId = oleLocation.getParentLocationId() != null ? true : false;
41              while (parentId) {
42                  Map criteriaMap = new HashMap();
43                  criteriaMap.put("locationId", oleLocation.getParentLocationId());
44                  OleLocation location = businessObjectService.findByPrimaryKey(OleLocation.class,
45                          criteriaMap);
46                  if (locationName != null) {
47                      locationName = location.getLocationName() + "/" + locationName;
48                  }
49                  if (levelCode != null) {
50                      levelCode = location.getLocationCode() + "/" + levelCode;
51                  }
52                  parentId = location.getParentLocationId() != null ? true : false;
53                  oleLocation = location;
54              }
55              //String key = levelCode + "|" + locationName;
56              options.add(new ConcreteKeyValue(levelCode, levelCode));
57          }
58          return options;
59  /*
60          List<KeyValue> options = new ArrayList<KeyValue>();
61          BusinessObjectService businessObjectService = KRADServiceLocator.getBusinessObjectService();
62          Collection<OleLocation> oleLocationCollection = KRADServiceLocator.getBusinessObjectService().findAll(OleLocation.class);
63          options.add(new ConcreteKeyValue("", ""));
64          for (OleLocation oleLocation : oleLocationCollection) {
65              String locationName = oleLocation.getLocationName();
66              String levelId = oleLocation.getLevelId();
67              String levelCode = oleLocation.getLocationCode();
68              boolean parentId = oleLocation.getParentLocationId() != null ? true : false;
69              LOG.info("level id -->"+levelId);
70              while(parentId)  {
71                  Map parentCriteria = new HashMap();
72                  parentCriteria.put("locationId", oleLocation.getParentLocationId());
73                  OleLocation location = businessObjectService.findByPrimaryKey(OleLocation.class,
74                          parentCriteria);
75                  if(locationName!= null ) {
76                      locationName = location.getLocationName()+"-"+locationName;
77                  }
78                  if (levelCode != null ) {
79                      levelCode = location.getLocationCode() + "-" + levelCode;
80                  }
81                  parentId = location.getParentLocationId() != null ? true : false;
82                  oleLocation = location;
83              }
84              //String key = levelCode + "|" + locationName;
85              options.add(new ConcreteKeyValue(levelCode, levelCode));
86          }
87          return options;
88  */
89      }
90  }
91