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 org.apache.commons.collections.CollectionUtils;
19 import org.kuali.rice.core.api.util.ConcreteKeyValue;
20 import org.kuali.rice.core.api.util.KeyValue;
21 import org.kuali.rice.coreservice.impl.namespace.NamespaceBo;
22 import org.kuali.rice.krad.service.KRADServiceLocator;
23 import org.kuali.rice.krad.uif.control.UifKeyValuesFinderBase;
24 import org.kuali.rice.krad.uif.view.ViewModel;
25
26 import java.util.ArrayList;
27 import java.util.Collection;
28 import java.util.Collections;
29 import java.util.HashMap;
30 import java.util.List;
31 import java.util.Map;
32
33
34
35
36 public class AgendaNamespaceValuesFinder extends UifKeyValuesFinderBase {
37
38 @Override
39 public List<KeyValue> getKeyValues(ViewModel model) {
40 List<KeyValue> keyValues = new ArrayList<KeyValue>();
41
42
43
44 Collection<ContextBo> contexts = KRADServiceLocator.getBusinessObjectService().findAll(ContextBo.class);
45
46 Collection<NamespaceBo> namespaceBos = KRADServiceLocator.getBusinessObjectService().findAll(NamespaceBo.class);
47 Map<String, String> namespaceCodeToName = new HashMap<String, String>();
48 if (!CollectionUtils.isEmpty(namespaceBos)) for (NamespaceBo namespaceBo : namespaceBos) {
49 namespaceCodeToName.put(namespaceBo.getCode(), namespaceBo.getName());
50 }
51
52 List<String> namespaceCodes = new ArrayList<String>();
53
54 if (!CollectionUtils.isEmpty(contexts)) for (ContextBo context : contexts) {
55 if (!namespaceCodes.contains(context.getNamespace())) {
56
57 namespaceCodes.add(context.getNamespace());
58 }
59 }
60
61 Collections.sort(namespaceCodes);
62
63 for (String namespaceCode : namespaceCodes) {
64 String namespaceName = namespaceCode;
65 if (namespaceCodeToName.containsKey(namespaceCode)) { namespaceName = namespaceCodeToName.get(namespaceCode); }
66 keyValues.add(new ConcreteKeyValue(namespaceCode, namespaceName));
67 }
68
69 return keyValues;
70 }
71 }