001 package org.kuali.ole.editor.keyvalue;
002
003 import org.kuali.ole.location.bo.OleLocation;
004 import org.kuali.ole.location.bo.OleLocationLevel;
005 import org.kuali.rice.core.api.util.ConcreteKeyValue;
006 import org.kuali.rice.core.api.util.KeyValue;
007 import org.kuali.rice.krad.keyvalues.KeyValuesBase;
008 import org.kuali.rice.krad.service.BusinessObjectService;
009 import org.kuali.rice.krad.service.KRADServiceLocator;
010
011 import java.util.*;
012
013 /**
014 * LocationValuesBuilder used to render the values for LocationValuesBuilder dropdown control.
015 */
016 public class LocationValuesBuilder extends KeyValuesBase {
017 /**
018 * This method returns the List of ConcreteKeyValue,
019 * ConcreteKeyValue has two arguments LevelCode and
020 * LocationName.
021 * @return List<KeyValue>
022 */
023 @Override
024 public List<KeyValue> getKeyValues() {
025 List<KeyValue> options = new ArrayList<KeyValue>();
026 BusinessObjectService businessObjectService = KRADServiceLocator.getBusinessObjectService();
027
028 Map parentCriteria1 = new HashMap();
029 parentCriteria1.put("levelCode", "SHELVING");
030 List<OleLocationLevel> oleLocationLevel = (List<OleLocationLevel>) businessObjectService.findMatching(OleLocationLevel.class, parentCriteria1);
031 String shelvingId = oleLocationLevel.get(0).getLevelId();
032 options.add(new ConcreteKeyValue("", ""));
033 Map parentCriteria = new HashMap();
034 parentCriteria.put("levelId", shelvingId);
035 Collection<OleLocation> oleLocationCollection = businessObjectService.findMatching(OleLocation.class, parentCriteria);
036 for (OleLocation oleLocation : oleLocationCollection) {
037 String locationName = oleLocation.getLocationName();
038 String levelId = oleLocation.getLevelId();
039 String levelCode = oleLocation.getLocationCode();
040 boolean parentId = oleLocation.getParentLocationId() != null ? true : false;
041 while (parentId) {
042 Map criteriaMap = new HashMap();
043 criteriaMap.put("locationId", oleLocation.getParentLocationId());
044 OleLocation location = businessObjectService.findByPrimaryKey(OleLocation.class,
045 criteriaMap);
046 if (locationName != null) {
047 locationName = location.getLocationName() + "/" + locationName;
048 }
049 if (levelCode != null) {
050 levelCode = location.getLocationCode() + "/" + levelCode;
051 }
052 parentId = location.getParentLocationId() != null ? true : false;
053 oleLocation = location;
054 }
055 //String key = levelCode + "|" + locationName;
056 options.add(new ConcreteKeyValue(levelCode, levelCode));
057 }
058 return options;
059 /*
060 List<KeyValue> options = new ArrayList<KeyValue>();
061 BusinessObjectService businessObjectService = KRADServiceLocator.getBusinessObjectService();
062 Collection<OleLocation> oleLocationCollection = KRADServiceLocator.getBusinessObjectService().findAll(OleLocation.class);
063 options.add(new ConcreteKeyValue("", ""));
064 for (OleLocation oleLocation : oleLocationCollection) {
065 String locationName = oleLocation.getLocationName();
066 String levelId = oleLocation.getLevelId();
067 String levelCode = oleLocation.getLocationCode();
068 boolean parentId = oleLocation.getParentLocationId() != null ? true : false;
069 LOG.info("level id -->"+levelId);
070 while(parentId) {
071 Map parentCriteria = new HashMap();
072 parentCriteria.put("locationId", oleLocation.getParentLocationId());
073 OleLocation location = businessObjectService.findByPrimaryKey(OleLocation.class,
074 parentCriteria);
075 if(locationName!= null ) {
076 locationName = location.getLocationName()+"-"+locationName;
077 }
078 if (levelCode != null ) {
079 levelCode = location.getLocationCode() + "-" + levelCode;
080 }
081 parentId = location.getParentLocationId() != null ? true : false;
082 oleLocation = location;
083 }
084 //String key = levelCode + "|" + locationName;
085 options.add(new ConcreteKeyValue(levelCode, levelCode));
086 }
087 return options;
088 */
089 }
090 }
091