1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.kim.impl.type; |
17 | |
|
18 | |
import org.apache.commons.lang.StringUtils; |
19 | |
import org.kuali.rice.kim.api.KimConstants; |
20 | |
import org.kuali.rice.kim.api.type.KimAttributeField; |
21 | |
import org.kuali.rice.kim.api.type.KimType; |
22 | |
import org.kuali.rice.kim.bo.impl.KimAttributes; |
23 | |
import org.kuali.rice.kim.framework.services.KimFrameworkServiceLocator; |
24 | |
import org.kuali.rice.kim.framework.type.KimTypeService; |
25 | |
import org.kuali.rice.kim.service.KIMServiceLocatorInternal; |
26 | |
import org.kuali.rice.kns.kim.type.DataDictionaryTypeServiceHelper; |
27 | |
|
28 | |
import java.io.Serializable; |
29 | |
import java.util.List; |
30 | |
import java.util.Map; |
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
public class KimTypeAttributesHelper implements Serializable { |
39 | |
|
40 | |
private KimType kimType; |
41 | |
private transient KimTypeService kimTypeService; |
42 | |
private List<? extends KimAttributes> attributes; |
43 | |
private transient List<KimAttributeField> definitions; |
44 | |
private transient Map<String,Object> attributeEntry; |
45 | |
|
46 | 0 | public KimTypeAttributesHelper(KimType kimType){ |
47 | 0 | this.kimType = kimType; |
48 | 0 | } |
49 | |
|
50 | |
|
51 | |
|
52 | |
|
53 | |
public List<? extends KimAttributes> getAttributes() { |
54 | 0 | return this.attributes; |
55 | |
} |
56 | |
|
57 | |
|
58 | |
|
59 | |
|
60 | |
public KimType getKimType() { |
61 | 0 | return this.kimType; |
62 | |
} |
63 | |
|
64 | |
public KimTypeService getKimTypeService(KimType kimType){ |
65 | 0 | if(this.kimTypeService==null){ |
66 | 0 | this.kimTypeService = KimFrameworkServiceLocator.getKimTypeService(kimType); |
67 | |
} |
68 | 0 | return this.kimTypeService; |
69 | |
} |
70 | |
|
71 | |
public Map<String,Object> getAttributeEntry() { |
72 | 0 | if(attributeEntry==null || attributeEntry.isEmpty()) |
73 | 0 | attributeEntry = KIMServiceLocatorInternal.getUiDocumentService().getAttributeEntries(getDefinitions()); |
74 | 0 | return attributeEntry; |
75 | |
} |
76 | |
|
77 | |
public String getKimAttributeDefnId(KimAttributeField definition){ |
78 | 0 | return definition.getId(); |
79 | |
} |
80 | |
|
81 | |
public List<KimAttributeField> getDefinitions() { |
82 | 0 | if (definitions == null || definitions.isEmpty()) { |
83 | 0 | KimTypeService kimTypeService = getKimTypeService(getKimType()); |
84 | 0 | if(kimTypeService!=null) |
85 | 0 | this.definitions = kimTypeService.getAttributeDefinitions(getKimType().getId()); |
86 | |
} |
87 | 0 | return this.definitions; |
88 | |
} |
89 | |
|
90 | |
public String getCommaDelimitedAttributesLabels(String commaDelimitedAttributesNamesList){ |
91 | 0 | String[] names = StringUtils.splitByWholeSeparator(commaDelimitedAttributesNamesList, KimConstants.KimUIConstants.COMMA_SEPARATOR); |
92 | 0 | StringBuffer commaDelimitedAttributesLabels = new StringBuffer(); |
93 | 0 | for(String name: names){ |
94 | 0 | commaDelimitedAttributesLabels.append(getAttributeEntry().get(name.trim())+KimConstants.KimUIConstants.COMMA_SEPARATOR); |
95 | |
} |
96 | 0 | if(commaDelimitedAttributesLabels.toString().endsWith(KimConstants.KimUIConstants.COMMA_SEPARATOR)) |
97 | 0 | commaDelimitedAttributesLabels.delete(commaDelimitedAttributesLabels.length()- KimConstants.KimUIConstants.COMMA_SEPARATOR.length(), commaDelimitedAttributesLabels.length()); |
98 | 0 | return commaDelimitedAttributesLabels.toString(); |
99 | |
} |
100 | |
|
101 | |
public KimAttributeField getAttributeDefinition(String attributeName){ |
102 | 0 | return DataDictionaryTypeServiceHelper.findAttributeField(attributeName, getDefinitions()); |
103 | |
} |
104 | |
|
105 | |
public String getAttributeValue(Map<String, String> aSet, String attributeName){ |
106 | 0 | if(StringUtils.isEmpty(attributeName) || aSet==null) return null; |
107 | 0 | for(String attributeNameKey: aSet.keySet()){ |
108 | 0 | if(attributeName.equals(attributeNameKey)) |
109 | 0 | return aSet.get(attributeNameKey); |
110 | |
} |
111 | 0 | return null; |
112 | |
} |
113 | |
} |