1 package org.kuali.ole.location.keyvalue;
2
3 import org.kuali.ole.OLEConstants;
4 import org.kuali.ole.deliver.circulationdesk.bo.OleCirculationDesk;
5 import org.kuali.ole.deliver.request.bo.OleDeliverRequestBo;
6 import org.kuali.ole.location.bo.OleLocation;
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.KRADServiceLocator;
10 import org.kuali.rice.krad.uif.control.UifKeyValuesFinderBase;
11 import org.kuali.rice.krad.uif.view.ViewModel;
12 import org.kuali.rice.krad.web.form.MaintenanceForm;
13
14 import java.util.*;
15
16
17
18
19
20 public class LocationKeyValuesFinder extends UifKeyValuesFinderBase {
21
22
23
24
25
26
27 @Override
28 public List<KeyValue> getKeyValues(ViewModel model) {
29 MaintenanceForm testForm = (MaintenanceForm) model;
30 List<KeyValue> options = new ArrayList<KeyValue>();
31 if(testForm.getDocument().getNewMaintainableObject().getDataObject() instanceof OleDeliverRequestBo){
32 List<OleLocation> oleLocations = (List<OleLocation>)KRADServiceLocator.getBusinessObjectService().findAll(OleLocation.class);
33 for(int i=0;i<oleLocations.size();i++){
34 options.add(new ConcreteKeyValue(oleLocations.get(i).getLevelId(), oleLocations.get(i).getLocationCode()));
35 }
36 }else if(testForm.getDocument().getNewMaintainableObject().getDataObject() instanceof OleCirculationDesk){
37 Map<String,String> locationMap = new HashMap<String,String>();
38 locationMap.put("levelId","5");
39 List<OleLocation> shelvingLocations = (List<OleLocation>)KRADServiceLocator.getBusinessObjectService().findMatching(OleLocation.class,locationMap);
40 for(int i=0;i<shelvingLocations.size();i++){
41 options.add(new ConcreteKeyValue(shelvingLocations.get(i).getLocationId(), shelvingLocations.get(i).getLocationCode()));
42 }
43 }
44 else {
45 String levelId = ((OleLocation)testForm.getDocument().getNewMaintainableObject().getDataObject()).getLevelId();
46 Collection<OleLocation> oleLocations = KRADServiceLocator.getBusinessObjectService().findAll(OleLocation.class);
47 for (OleLocation location : oleLocations) {
48 if(location.getLevelId() != null && !location.getLevelId().equalsIgnoreCase("") && levelId != null && !levelId.equalsIgnoreCase("")) {
49 if(Integer.parseInt(location.getLevelId()) < Integer.parseInt(levelId)){
50 options.add(new ConcreteKeyValue(location.getLocationId(),location.getLocationName()+" ["+location.getLocationCode()+"]"));
51 }
52 }
53 }
54 return options;
55 }
56 return options;
57 }
58
59 }