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.type.KimType; |
20 | |
import org.kuali.rice.kim.api.type.KimTypeService; |
21 | |
import org.kuali.rice.kim.bo.impl.KimAttributes; |
22 | |
import org.kuali.rice.kim.bo.types.dto.AttributeDefinitionMap; |
23 | |
import org.kuali.rice.kim.service.KIMServiceLocatorInternal; |
24 | |
import org.kuali.rice.kim.service.KIMServiceLocatorWeb; |
25 | |
import org.kuali.rice.kim.util.KimConstants; |
26 | |
import org.kuali.rice.krad.datadictionary.AttributeDefinition; |
27 | |
import org.kuali.rice.krad.datadictionary.KimAttributeDefinition; |
28 | |
|
29 | |
import java.io.Serializable; |
30 | |
import java.util.List; |
31 | |
import java.util.Map; |
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
public class KimTypeAttributesHelper implements Serializable { |
40 | |
|
41 | |
private KimType kimType; |
42 | |
private transient KimTypeService kimTypeService; |
43 | |
private List<? extends KimAttributes> attributes; |
44 | |
private transient AttributeDefinitionMap definitions; |
45 | |
private transient Map<String,Object> attributeEntry; |
46 | |
|
47 | 0 | public KimTypeAttributesHelper(KimType kimType){ |
48 | 0 | this.kimType = kimType; |
49 | 0 | } |
50 | |
|
51 | |
|
52 | |
|
53 | |
|
54 | |
public List<? extends KimAttributes> getAttributes() { |
55 | 0 | return this.attributes; |
56 | |
} |
57 | |
|
58 | |
|
59 | |
|
60 | |
|
61 | |
public KimType getKimType() { |
62 | 0 | return this.kimType; |
63 | |
} |
64 | |
|
65 | |
public KimTypeService getKimTypeService(KimType kimType){ |
66 | 0 | if(this.kimTypeService==null){ |
67 | 0 | this.kimTypeService = KIMServiceLocatorWeb.getKimTypeService(kimType); |
68 | |
} |
69 | 0 | return this.kimTypeService; |
70 | |
} |
71 | |
|
72 | |
public Map<String,Object> getAttributeEntry() { |
73 | 0 | if(attributeEntry==null || attributeEntry.isEmpty()) |
74 | 0 | attributeEntry = KIMServiceLocatorInternal.getUiDocumentService().getAttributeEntries(getDefinitions()); |
75 | 0 | return attributeEntry; |
76 | |
} |
77 | |
|
78 | |
public String getKimAttributeDefnId(AttributeDefinition definition){ |
79 | 0 | return ((KimAttributeDefinition)definition).getKimAttrDefnId(); |
80 | |
} |
81 | |
|
82 | |
|
83 | |
|
84 | |
|
85 | |
|
86 | |
|
87 | |
public AttributeDefinitionMap getDefinitions() { |
88 | 0 | if (definitions == null || definitions.isEmpty()) { |
89 | 0 | KimTypeService kimTypeService = getKimTypeService(getKimType()); |
90 | 0 | if(kimTypeService!=null) |
91 | 0 | this.definitions = kimTypeService.getAttributeDefinitions(getKimType().getId()); |
92 | |
} |
93 | 0 | return this.definitions; |
94 | |
} |
95 | |
|
96 | |
public AttributeDefinitionMap getDefinitionsKeyedByAttributeName() { |
97 | 0 | AttributeDefinitionMap definitionsKeyedBySortCode = getDefinitions(); |
98 | 0 | AttributeDefinitionMap returnValue = new AttributeDefinitionMap(); |
99 | 0 | if (definitionsKeyedBySortCode != null) { |
100 | 0 | for (AttributeDefinition definition : definitionsKeyedBySortCode.values()) { |
101 | 0 | returnValue.put(definition.getName(), definition); |
102 | |
} |
103 | |
} |
104 | 0 | return returnValue; |
105 | |
} |
106 | |
|
107 | |
public String getCommaDelimitedAttributesLabels(String commaDelimitedAttributesNamesList){ |
108 | 0 | String[] names = StringUtils.splitByWholeSeparator(commaDelimitedAttributesNamesList, KimConstants.KimUIConstants.COMMA_SEPARATOR); |
109 | 0 | StringBuffer commaDelimitedAttributesLabels = new StringBuffer(); |
110 | 0 | for(String name: names){ |
111 | 0 | commaDelimitedAttributesLabels.append(getAttributeEntry().get(name.trim())+KimConstants.KimUIConstants.COMMA_SEPARATOR); |
112 | |
} |
113 | 0 | if(commaDelimitedAttributesLabels.toString().endsWith(KimConstants.KimUIConstants.COMMA_SEPARATOR)) |
114 | 0 | commaDelimitedAttributesLabels.delete(commaDelimitedAttributesLabels.length()-KimConstants.KimUIConstants.COMMA_SEPARATOR.length(), commaDelimitedAttributesLabels.length()); |
115 | 0 | return commaDelimitedAttributesLabels.toString(); |
116 | |
} |
117 | |
|
118 | |
public AttributeDefinition getAttributeDefinition(String attributeName){ |
119 | 0 | return getDefinitionsKeyedByAttributeName().get(attributeName); |
120 | |
} |
121 | |
|
122 | |
public String getAttributeValue(Map<String, String> aSet, String attributeName){ |
123 | 0 | if(StringUtils.isEmpty(attributeName) || aSet==null) return null; |
124 | 0 | for(String attributeNameKey: aSet.keySet()){ |
125 | 0 | if(attributeName.equals(attributeNameKey)) |
126 | 0 | return aSet.get(attributeNameKey); |
127 | |
} |
128 | 0 | return null; |
129 | |
} |
130 | |
} |