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