1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krms.impl.repository;
17
18 import java.util.ArrayList;
19 import java.util.Collection;
20 import java.util.Collections;
21 import java.util.HashMap;
22 import java.util.List;
23 import java.util.Map;
24
25 import org.apache.commons.collections.CollectionUtils;
26 import org.kuali.rice.core.api.criteria.QueryByCriteria;
27 import org.kuali.rice.core.api.criteria.QueryResults;
28 import org.kuali.rice.core.api.util.ConcreteKeyValue;
29 import org.kuali.rice.core.api.util.KeyValue;
30 import org.kuali.rice.coreservice.impl.namespace.NamespaceBo;
31 import org.kuali.rice.kns.service.KNSServiceLocator;
32 import org.kuali.rice.krad.data.KradDataServiceLocator;
33 import org.kuali.rice.krad.service.KRADServiceLocator;
34 import org.kuali.rice.krad.uif.control.UifKeyValuesFinderBase;
35 import org.kuali.rice.krad.uif.view.ViewModel;
36
37
38
39
40 public class AgendaNamespaceValuesFinder extends UifKeyValuesFinderBase {
41
42 @Override
43 public List<KeyValue> getKeyValues(ViewModel model) {
44 List<KeyValue> keyValues = new ArrayList<KeyValue>();
45
46
47
48 QueryByCriteria contextCrit = QueryByCriteria.Builder.create().build();
49 QueryResults<ContextBo> contexts = KRADServiceLocator.getDataObjectService().findMatching(ContextBo.class, contextCrit);
50
51 QueryResults<NamespaceBo> namespaceBos = KradDataServiceLocator.getDataObjectService().findMatching(NamespaceBo.class,
52 QueryByCriteria.Builder.create().build());
53 Map<String, String> namespaceCodeToName = new HashMap<String, String>();
54 if (!namespaceBos.getResults().isEmpty()) {
55 for (NamespaceBo namespaceBo : namespaceBos.getResults()) {
56 namespaceCodeToName.put(namespaceBo.getCode(), namespaceBo.getName());
57 }
58 }
59
60 List<String> namespaceCodes = new ArrayList<String>();
61
62 if (!CollectionUtils.isEmpty(contexts.getResults())) {
63 for (ContextBo context : contexts.getResults()) {
64 if (!namespaceCodes.contains(context.getNamespace())) {
65
66 namespaceCodes.add(context.getNamespace());
67 }
68 }
69 }
70
71 Collections.sort(namespaceCodes);
72
73 for (String namespaceCode : namespaceCodes) {
74 String namespaceName = namespaceCode;
75 if (namespaceCodeToName.containsKey(namespaceCode)) {
76 namespaceName = namespaceCodeToName.get(namespaceCode);
77 }
78 keyValues.add(new ConcreteKeyValue(namespaceCode, namespaceName));
79 }
80
81 return keyValues;
82 }
83 }