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.commons.lang.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.MaintenanceDocumentForm;
25 import org.kuali.rice.krms.impl.repository.CategoryBo;
26
27 import java.util.ArrayList;
28 import java.util.Collection;
29 import java.util.Collections;
30 import java.util.List;
31 import java.util.Map;
32
33
34
35
36 public class CategoryValuesFinder extends UifKeyValuesFinderBase {
37
38 private boolean blankOption;
39
40
41
42
43 public boolean isBlankOption() {
44 return this.blankOption;
45 }
46
47
48
49
50 public void setBlankOption(boolean blankOption) {
51 this.blankOption = blankOption;
52 }
53
54 @Override
55 public List<KeyValue> getKeyValues(ViewModel model) {
56 List<KeyValue> keyValues = new ArrayList<KeyValue>();
57
58 MaintenanceDocumentForm maintenanceForm = (MaintenanceDocumentForm) model;
59 AgendaEditor agendaEditor = ((AgendaEditor) maintenanceForm.getDocument().getNewMaintainableObject().getDataObject());
60
61
62 if (agendaEditor.getAgenda() != null && StringUtils.isNotBlank(agendaEditor.getAgenda().getContextId())) {
63
64
65
66 String namespace = agendaEditor.getNamespace();
67
68 if(blankOption){
69 keyValues.add(new ConcreteKeyValue("", ""));
70 }
71
72 Map<String, String> criteria = Collections.singletonMap("namespace", namespace);
73 Collection<CategoryBo> categories =
74 KRADServiceLocator.getBusinessObjectService().findMatchingOrderBy(
75 CategoryBo.class, criteria, "name", true
76 );
77
78 for (CategoryBo category : categories) {
79 keyValues.add(new ConcreteKeyValue(category.getId(), category.getName()));
80 }
81 }
82
83 return keyValues;
84 }
85 }