View Javadoc
1   package org.kuali.ole.service.impl;
2   
3   import org.kuali.ole.describe.bo.OleInstanceItemType;
4   import org.kuali.ole.describe.bo.OleLocation;
5   import org.kuali.ole.describe.bo.OleLocationLevel;
6   import org.kuali.ole.service.OleLocationWebService;
7   import org.kuali.rice.core.api.util.ConcreteKeyValue;
8   import org.kuali.rice.core.api.util.KeyValue;
9   import org.kuali.rice.krad.service.BusinessObjectService;
10  import org.kuali.rice.krad.service.KRADServiceLocator;
11  
12  import java.util.*;
13  
14  /**
15   * Created with IntelliJ IDEA.
16   * User: ?
17   * Date: 2/21/13
18   * Time: 10:48 PM
19   * To change this template use File | Settings | File Templates.
20   */
21  public class OleLocationWebServiceImpl implements OleLocationWebService {
22      private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(OleLocationWebServiceImpl.class);
23      @Override
24      public List<String> getItemLocation() {
25          LOG.debug(" Inside get Item Location Method of OleLocationWebServiceImpl ");
26          List<String> locationList = new ArrayList<String>();
27          List<KeyValue> options = new ArrayList<KeyValue>();
28          BusinessObjectService businessObjectService = KRADServiceLocator.getBusinessObjectService();
29          Map parentCriteria1 = new HashMap();
30          parentCriteria1.put("levelCode", "SHELVING");
31          List<OleLocationLevel> oleLocationLevel = (List<OleLocationLevel>) businessObjectService.findMatching(OleLocationLevel.class, parentCriteria1);
32          if (oleLocationLevel != null && oleLocationLevel.size() > 0) {
33              String shelvingId = oleLocationLevel.get(0).getLevelId();
34              options.add(new ConcreteKeyValue("", ""));
35              Map parentCriteria = new HashMap();
36              parentCriteria.put("levelId", shelvingId);
37              Collection<OleLocation> oleLocationCollection = businessObjectService.findMatching(OleLocation.class, parentCriteria);
38              for (OleLocation oleLocation : oleLocationCollection) {
39                  options.add(new ConcreteKeyValue(oleLocation.getFullLocationPath(), oleLocation.getFullLocationPath()));
40              }
41          }
42          Map<String, String> map = new HashMap<String, String>();
43          for (KeyValue option : options) {
44              map.put(option.getKey(), option.getValue());
45  
46          }
47          Map<String, Object> map1 = sortByLocation(map);
48  
49          // List<KeyValue> options1 = new ArrayList<KeyValue>();
50          for (Map.Entry<String, Object> entry : map1.entrySet()) {
51              locationList.add((String) entry.getValue());
52          }
53          return locationList;
54      }
55  
56      @Override
57      public List<String> getItemType() {
58          LOG.debug(" Inside get Item Type Method of OleLocationWebServiceImpl ");
59          List<String> keyValues = new ArrayList<String>();
60          Collection<OleInstanceItemType> oleInstanceItemTypes = KRADServiceLocator.getBusinessObjectService().findAll(OleInstanceItemType.class);
61          for (OleInstanceItemType oleInstanceItemType : oleInstanceItemTypes) {
62              String itemTypeCode = oleInstanceItemType.getInstanceItemTypeCode();
63              String itemTypeName = oleInstanceItemType.getInstanceItemTypeName();
64              String itemType = itemTypeCode + "," + itemTypeName;
65              keyValues.add(itemType);
66  
67          }
68          return keyValues;
69      }
70  
71      private Map<String, Object> sortByLocation(Map<String, String> parentCriteria) {
72          Map<String, Object> map = new LinkedHashMap<String, Object>();
73  
74          List<String> keyList = new ArrayList<String>(parentCriteria.keySet());
75          List<String> valueList = new ArrayList<String>(parentCriteria.values());
76          Set<String> sortedSet = new TreeSet<String>(valueList);
77  
78          Object[] sortedArray = sortedSet.toArray();
79          int size = sortedArray.length;
80  
81          for (int i = 0; i < size; i++) {
82              map.put(keyList.get(valueList.indexOf(sortedArray[i])), sortedArray[i]);
83          }
84  
85          return map;
86      }
87  }