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