1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.kim.bo.role.impl; |
17 | |
|
18 | |
import java.util.Iterator; |
19 | |
import java.util.LinkedHashMap; |
20 | |
import java.util.List; |
21 | |
|
22 | |
import javax.persistence.CascadeType; |
23 | |
import javax.persistence.Column; |
24 | |
import javax.persistence.Entity; |
25 | |
import javax.persistence.FetchType; |
26 | |
import javax.persistence.Id; |
27 | |
import javax.persistence.JoinColumn; |
28 | |
import javax.persistence.OneToMany; |
29 | |
import javax.persistence.Table; |
30 | |
|
31 | |
import org.apache.log4j.Logger; |
32 | |
import org.kuali.rice.kim.bo.role.KimPermission; |
33 | |
import org.kuali.rice.kim.bo.role.dto.KimPermissionInfo; |
34 | |
import org.kuali.rice.kim.bo.types.dto.AttributeSet; |
35 | |
import org.kuali.rice.kim.bo.types.dto.KimTypeAttributeInfo; |
36 | |
import org.kuali.rice.kim.bo.types.dto.KimTypeInfo; |
37 | |
import org.kuali.rice.kim.service.KIMServiceLocator; |
38 | |
import org.kuali.rice.kim.service.KimTypeInfoService; |
39 | |
import org.kuali.rice.kim.util.KimConstants; |
40 | |
import org.kuali.rice.kns.bo.PersistableBusinessObjectBase; |
41 | |
import org.kuali.rice.kns.service.DataDictionaryService; |
42 | |
import org.kuali.rice.kns.service.KNSServiceLocator; |
43 | |
import org.kuali.rice.kns.util.TypedArrayList; |
44 | |
|
45 | |
|
46 | |
|
47 | |
|
48 | |
@SuppressWarnings("unchecked") |
49 | |
@Entity |
50 | |
@Table(name="KRIM_PERM_T") |
51 | 0 | public class KimPermissionImpl extends PersistableBusinessObjectBase implements KimPermission { |
52 | 0 | private static final Logger LOG = Logger.getLogger(KimPermissionImpl.class); |
53 | |
|
54 | |
private static final long serialVersionUID = 1L; |
55 | |
|
56 | |
@Id |
57 | |
@Column(name="PERM_ID") |
58 | |
protected String permissionId; |
59 | |
@Column(name="NMSPC_CD") |
60 | |
protected String namespaceCode; |
61 | |
@Column(name="NM") |
62 | |
protected String name; |
63 | |
@Column(name="DESC_TXT", length=400) |
64 | |
protected String description; |
65 | |
@Column(name="ACTV_IND") |
66 | |
protected boolean active; |
67 | |
|
68 | 0 | @OneToMany(targetEntity=PermissionAttributeDataImpl.class,cascade={CascadeType.ALL},fetch=FetchType.LAZY) |
69 | |
@JoinColumn(name="PERM_ID", insertable=false, updatable=false) |
70 | |
protected List<PermissionAttributeDataImpl> detailObjects = new TypedArrayList(PermissionAttributeDataImpl.class); |
71 | |
|
72 | |
protected String templateId; |
73 | |
protected KimPermissionTemplateImpl template; |
74 | |
|
75 | 0 | protected List<RolePermissionImpl> rolePermissions = new TypedArrayList(RolePermissionImpl.class); |
76 | |
|
77 | |
|
78 | |
|
79 | |
|
80 | |
public boolean isActive() { |
81 | 0 | return active; |
82 | |
} |
83 | |
|
84 | |
|
85 | |
|
86 | |
|
87 | |
public void setActive(boolean active) { |
88 | 0 | this.active = active; |
89 | 0 | } |
90 | |
|
91 | |
|
92 | |
|
93 | |
|
94 | |
public String getDescription() { |
95 | 0 | return description; |
96 | |
} |
97 | |
|
98 | |
|
99 | |
|
100 | |
|
101 | |
public String getPermissionId() { |
102 | 0 | return permissionId; |
103 | |
} |
104 | |
|
105 | |
|
106 | |
|
107 | |
|
108 | |
public String getName() { |
109 | 0 | return name; |
110 | |
} |
111 | |
|
112 | |
public void setDescription(String permissionDescription) { |
113 | 0 | this.description = permissionDescription; |
114 | 0 | } |
115 | |
|
116 | |
public void setName(String permissionName) { |
117 | 0 | this.name = permissionName; |
118 | 0 | } |
119 | |
|
120 | |
|
121 | |
|
122 | |
|
123 | |
@SuppressWarnings("unchecked") |
124 | |
@Override |
125 | |
protected LinkedHashMap toStringMapper() { |
126 | 0 | LinkedHashMap m = new LinkedHashMap(); |
127 | 0 | m.put( "permissionId", permissionId ); |
128 | 0 | m.put( "name", name ); |
129 | 0 | m.put( "details", getDetails() ); |
130 | 0 | return m; |
131 | |
} |
132 | |
|
133 | |
public KimPermissionInfo toSimpleInfo() { |
134 | 0 | KimPermissionInfo dto = new KimPermissionInfo(); |
135 | 0 | dto.setPermissionId( getPermissionId() ); |
136 | 0 | dto.setNamespaceCode( getNamespaceCode() ); |
137 | 0 | dto.setName( getName() ); |
138 | 0 | dto.setDescription( getDescription() ); |
139 | 0 | dto.setActive( isActive() ); |
140 | 0 | dto.setTemplate( getTemplate().toSimpleInfo() ); |
141 | 0 | dto.setTemplateId( getTemplateId() ); |
142 | 0 | dto.setDetails( getDetails() ); |
143 | |
|
144 | 0 | return dto; |
145 | |
} |
146 | |
|
147 | |
public List<PermissionAttributeDataImpl> getDetailObjects() { |
148 | 0 | return this.detailObjects; |
149 | |
} |
150 | |
|
151 | |
public void setDetails(List<PermissionAttributeDataImpl> detailObjects) { |
152 | 0 | this.detailObjects = detailObjects; |
153 | 0 | } |
154 | |
|
155 | |
public KimPermissionTemplateImpl getTemplate() { |
156 | 0 | return this.template; |
157 | |
} |
158 | |
|
159 | |
public void setTemplate(KimPermissionTemplateImpl template) { |
160 | 0 | this.template = template; |
161 | 0 | } |
162 | |
|
163 | |
public String getTemplateId() { |
164 | 0 | return this.templateId; |
165 | |
} |
166 | |
|
167 | |
public void setTemplateId(String templateId) { |
168 | 0 | this.templateId = templateId; |
169 | 0 | } |
170 | |
|
171 | 0 | protected transient AttributeSet detailsAsAttributeSet = null; |
172 | |
|
173 | |
public AttributeSet getDetails() { |
174 | 0 | if ( detailsAsAttributeSet == null ) { |
175 | 0 | KimTypeInfo kimType = getTypeInfoService().getKimType( getTemplate().getKimTypeId() ); |
176 | 0 | AttributeSet m = new AttributeSet(); |
177 | 0 | for ( PermissionAttributeDataImpl data : getDetailObjects() ) { |
178 | 0 | KimTypeAttributeInfo attribute = null; |
179 | 0 | if ( kimType != null ) { |
180 | 0 | attribute = kimType.getAttributeDefinition( data.getKimAttributeId() ); |
181 | |
} else { |
182 | 0 | LOG.warn( "Unable to get KimTypeInfo for permission: " + this + "\nKim Type ID: " + getTemplate().kimTypeId ); |
183 | |
} |
184 | 0 | if ( attribute != null ) { |
185 | 0 | m.put( attribute.getAttributeName(), data.getAttributeValue() ); |
186 | |
} else { |
187 | 0 | LOG.warn( "Unable to get attribute for ID: " + data.getKimAttributeId() + " from KimTypeInfo: " + kimType ); |
188 | 0 | m.put( data.getKimAttribute().getAttributeName(), data.getAttributeValue() ); |
189 | |
} |
190 | 0 | } |
191 | 0 | detailsAsAttributeSet = m; |
192 | |
} |
193 | 0 | return detailsAsAttributeSet; |
194 | |
} |
195 | |
|
196 | |
public boolean hasDetails() { |
197 | 0 | return !getDetailObjects().isEmpty(); |
198 | |
} |
199 | |
|
200 | |
public String getNamespaceCode() { |
201 | 0 | return this.namespaceCode; |
202 | |
} |
203 | |
|
204 | |
public void setNamespaceCode(String namespaceCode) { |
205 | 0 | this.namespaceCode = namespaceCode; |
206 | 0 | } |
207 | |
|
208 | |
public void setPermissionId(String permissionId) { |
209 | 0 | this.permissionId = permissionId; |
210 | 0 | } |
211 | |
|
212 | |
public void setDetailObjects(List<PermissionAttributeDataImpl> detailObjects) { |
213 | 0 | this.detailObjects = detailObjects; |
214 | 0 | } |
215 | |
|
216 | |
|
217 | |
|
218 | |
|
219 | |
public List<RolePermissionImpl> getRolePermissions() { |
220 | 0 | return this.rolePermissions; |
221 | |
} |
222 | |
|
223 | |
|
224 | |
|
225 | |
|
226 | |
public void setRolePermissions(List<RolePermissionImpl> rolePermissions) { |
227 | 0 | this.rolePermissions = rolePermissions; |
228 | 0 | } |
229 | |
|
230 | |
public String getDetailObjectsValues(){ |
231 | 0 | StringBuffer detailObjectsToDisplay = new StringBuffer(); |
232 | 0 | Iterator<PermissionAttributeDataImpl> permIter = getDetailObjects().iterator(); |
233 | 0 | while ( permIter.hasNext() ) { |
234 | 0 | PermissionAttributeDataImpl permissionAttributeData = permIter.next(); |
235 | 0 | detailObjectsToDisplay.append( permissionAttributeData.getAttributeValue() ); |
236 | 0 | if ( permIter.hasNext() ) { |
237 | 0 | detailObjectsToDisplay.append( KimConstants.KimUIConstants.COMMA_SEPARATOR ); |
238 | |
} |
239 | 0 | } |
240 | 0 | return detailObjectsToDisplay.toString(); |
241 | |
} |
242 | |
|
243 | |
public String getDetailObjectsToDisplay() { |
244 | 0 | KimTypeInfo kimType = getTypeInfoService().getKimType( getTemplate().getKimTypeId() ); |
245 | 0 | StringBuffer detailObjectsToDisplay = new StringBuffer(); |
246 | 0 | Iterator<PermissionAttributeDataImpl> permIter = getDetailObjects().iterator(); |
247 | 0 | while ( permIter.hasNext() ) { |
248 | 0 | PermissionAttributeDataImpl permissionAttributeData = permIter.next(); |
249 | 0 | detailObjectsToDisplay.append( getKimAttributeLabelFromDD(kimType.getAttributeDefinition(permissionAttributeData.getKimAttributeId()))); |
250 | 0 | detailObjectsToDisplay.append( KimConstants.KimUIConstants.NAME_VALUE_SEPARATOR ); |
251 | 0 | detailObjectsToDisplay.append( permissionAttributeData.getAttributeValue() ); |
252 | 0 | if ( permIter.hasNext() ) { |
253 | 0 | detailObjectsToDisplay.append( KimConstants.KimUIConstants.COMMA_SEPARATOR ); |
254 | |
} |
255 | 0 | } |
256 | 0 | return detailObjectsToDisplay.toString(); |
257 | |
} |
258 | |
|
259 | |
protected String getKimAttributeLabelFromDD( KimTypeAttributeInfo attribute ){ |
260 | 0 | return getDataDictionaryService().getAttributeLabel(attribute.getComponentName(), attribute.getAttributeName() ); |
261 | |
} |
262 | |
|
263 | |
private transient static DataDictionaryService dataDictionaryService; |
264 | |
|
265 | |
protected DataDictionaryService getDataDictionaryService() { |
266 | 0 | if(dataDictionaryService == null){ |
267 | 0 | dataDictionaryService = KNSServiceLocator.getDataDictionaryService(); |
268 | |
} |
269 | 0 | return dataDictionaryService; |
270 | |
} |
271 | |
|
272 | |
private transient static KimTypeInfoService kimTypeInfoService; |
273 | |
protected KimTypeInfoService getTypeInfoService() { |
274 | 0 | if(kimTypeInfoService == null){ |
275 | 0 | kimTypeInfoService = KIMServiceLocator.getTypeInfoService(); |
276 | |
} |
277 | 0 | return kimTypeInfoService; |
278 | |
} |
279 | |
} |