1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krms.impl.ui;
17
18 import org.apache.cxf.common.util.StringUtils;
19 import org.kuali.rice.core.api.util.ConcreteKeyValue;
20 import org.kuali.rice.core.api.util.KeyValue;
21 import org.kuali.rice.krad.service.KRADServiceLocator;
22 import org.kuali.rice.krad.uif.control.UifKeyValuesFinderBase;
23 import org.kuali.rice.krad.uif.view.ViewModel;
24 import org.kuali.rice.krad.web.form.MaintenanceForm;
25 import org.kuali.rice.krms.impl.repository.CategoryBo;
26 import org.kuali.rice.krms.impl.ui.AgendaEditor;
27
28 import java.util.ArrayList;
29 import java.util.Collection;
30 import java.util.Collections;
31 import java.util.List;
32 import java.util.Map;
33
34
35
36
37 public class CategoryValuesFinder extends UifKeyValuesFinderBase {
38
39 private boolean blankOption;
40
41
42
43
44 public boolean isBlankOption() {
45 return this.blankOption;
46 }
47
48
49
50
51 public void setBlankOption(boolean blankOption) {
52 this.blankOption = blankOption;
53 }
54
55 @Override
56 public List<KeyValue> getKeyValues(ViewModel model) {
57 List<KeyValue> keyValues = new ArrayList<KeyValue>();
58
59 MaintenanceForm maintenanceForm = (MaintenanceForm) model;
60 AgendaEditor agendaEditor = ((AgendaEditor) maintenanceForm.getDocument().getNewMaintainableObject().getDataObject());
61
62
63 if (agendaEditor.getAgenda() != null && !StringUtils.isEmpty(agendaEditor.getAgenda().getContextId())) {
64
65
66
67 String namespace = agendaEditor.getNamespace();
68
69 if(blankOption){
70 keyValues.add(new ConcreteKeyValue("", ""));
71 }
72
73 Map<String, String> criteria = Collections.singletonMap("namespace", namespace);
74 Collection<CategoryBo> categories =
75 KRADServiceLocator.getBusinessObjectService().findMatchingOrderBy(
76 CategoryBo.class, criteria, "name", true
77 );
78
79 for (CategoryBo category : categories) {
80 keyValues.add(new ConcreteKeyValue(category.getId(), category.getName()));
81 }
82 }
83
84 return keyValues;
85 }
86 }