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