1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.krad.keyvalues; |
17 | |
|
18 | |
import org.apache.log4j.Logger; |
19 | |
import org.kuali.rice.core.util.ConcreteKeyValue; |
20 | |
import org.kuali.rice.core.util.KeyValue; |
21 | |
import org.kuali.rice.kim.api.services.KimApiServiceLocator; |
22 | |
import org.kuali.rice.kim.api.type.KimType; |
23 | |
import org.kuali.rice.kim.api.type.KimTypeService; |
24 | |
import org.kuali.rice.kim.service.KIMServiceLocatorWeb; |
25 | |
|
26 | |
import java.util.ArrayList; |
27 | |
import java.util.Collections; |
28 | |
import java.util.List; |
29 | |
import java.util.Map; |
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | 0 | public class KimAttributeValuesFinder extends KeyValuesBase { |
35 | |
|
36 | 0 | private static final Logger LOG = Logger.getLogger( KimAttributeValuesFinder.class ); |
37 | |
|
38 | |
protected String kimTypeId; |
39 | |
protected String kimAttributeName; |
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
@Override |
45 | |
public List<KeyValue> getKeyValues() { |
46 | 0 | KimType kimType = KimApiServiceLocator.getKimTypeInfoService().getKimType(kimTypeId); |
47 | 0 | if ( kimType != null ) { |
48 | 0 | KimTypeService service = KIMServiceLocatorWeb.getKimTypeService(kimType); |
49 | 0 | if ( service != null ) { |
50 | 0 | return toKeyValues(service.getAttributeValidValues(kimTypeId,kimAttributeName)); |
51 | |
} |
52 | 0 | LOG.error( "Unable to get type service " + kimType.getServiceName() ); |
53 | 0 | } else { |
54 | 0 | LOG.error( "Unable to obtain KIM type for kimTypeId=" + kimTypeId ); |
55 | |
} |
56 | 0 | return Collections.emptyList(); |
57 | |
} |
58 | |
|
59 | |
private static List<KeyValue> toKeyValues(Map<String, String> m) { |
60 | 0 | if (m == null) { |
61 | 0 | return Collections.emptyList(); |
62 | |
} |
63 | |
|
64 | 0 | final List<KeyValue> kv = new ArrayList<KeyValue>(); |
65 | 0 | for (Map.Entry<String, String> e : m.entrySet()) { |
66 | 0 | kv.add(new ConcreteKeyValue(e)); |
67 | |
} |
68 | |
|
69 | 0 | return Collections.unmodifiableList(kv); |
70 | |
} |
71 | |
|
72 | |
|
73 | |
|
74 | |
|
75 | |
public String getKimAttributeName() { |
76 | 0 | return this.kimAttributeName; |
77 | |
} |
78 | |
|
79 | |
|
80 | |
|
81 | |
|
82 | |
public void setKimAttributeName(String kimAttributeName) { |
83 | 0 | this.kimAttributeName = kimAttributeName; |
84 | 0 | } |
85 | |
|
86 | |
|
87 | |
|
88 | |
|
89 | |
public String getKimTypeId() { |
90 | 0 | return this.kimTypeId; |
91 | |
} |
92 | |
|
93 | |
|
94 | |
|
95 | |
|
96 | |
public void setKimTypeId(String kimTypeId) { |
97 | 0 | this.kimTypeId = kimTypeId; |
98 | 0 | } |
99 | |
|
100 | |
} |