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
15
16 public class LocationValuesBuilder extends KeyValuesBase {
17
18
19
20
21
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
56 options.add(new ConcreteKeyValue(levelCode, levelCode));
57 }
58 return options;
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89 }
90 }
91