1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
package org.kuali.rice.kim.impl.permission |
18 | |
|
19 | |
import javax.persistence.CascadeType |
20 | |
import javax.persistence.Column |
21 | |
import javax.persistence.Entity |
22 | |
import javax.persistence.FetchType |
23 | |
import javax.persistence.Id |
24 | |
import javax.persistence.JoinColumn |
25 | |
import javax.persistence.OneToMany |
26 | |
import javax.persistence.OneToOne |
27 | |
import javax.persistence.Table |
28 | |
import javax.persistence.Transient |
29 | |
import org.hibernate.annotations.Fetch |
30 | |
import org.hibernate.annotations.FetchMode |
31 | |
import org.hibernate.annotations.Type |
32 | |
import org.kuali.rice.kim.api.services.KimApiServiceLocator |
33 | |
import org.kuali.rice.kim.api.type.KimType |
34 | |
import org.kuali.rice.kim.api.type.KimTypeAttribute |
35 | |
import org.kuali.rice.kim.api.type.KimTypeInfoService |
36 | |
import org.kuali.rice.kim.api.permission.Permission |
37 | |
import org.kuali.rice.kim.api.permission.PermissionContract |
38 | |
import org.kuali.rice.kim.impl.common.attribute.KimAttributeDataBo |
39 | |
import org.kuali.rice.kim.impl.role.RolePermissionBo |
40 | |
import org.kuali.rice.kim.util.KimConstants |
41 | |
import org.kuali.rice.krad.bo.PersistableBusinessObjectBase |
42 | |
import org.kuali.rice.krad.service.DataDictionaryService; |
43 | |
import org.kuali.rice.krad.service.KRADServiceLocatorWeb |
44 | |
|
45 | |
@Entity |
46 | |
@Table(name = "KRIM_PERM_T") |
47 | |
public class PermissionBo extends PersistableBusinessObjectBase implements PermissionContract { |
48 | |
private static final long serialVersionUID = 1L; |
49 | |
|
50 | |
@Id |
51 | |
@Column(name = "PERM_ID") |
52 | |
String id |
53 | |
|
54 | |
@Column(name = "NMSPC_CD") |
55 | |
String namespaceCode |
56 | |
|
57 | |
@Column(name = "NM") |
58 | |
String name |
59 | |
|
60 | |
@Column(name = "DESC_TXT", length = 400) |
61 | |
String description; |
62 | |
|
63 | |
@Column(name = "PERM_TMPL_ID") |
64 | |
String templateId |
65 | |
|
66 | |
@Column(name = "ACTV_IND") |
67 | |
@Type(type = "yes_no") |
68 | |
boolean active |
69 | |
|
70 | |
@OneToOne(targetEntity = PermissionTemplateBo.class, cascade = [], fetch = FetchType.EAGER) |
71 | |
@JoinColumn(name = "PERM_TMPL_ID", insertable = false, updatable = false) |
72 | |
PermissionTemplateBo template; |
73 | |
|
74 | |
@OneToMany(targetEntity = PermissionAttributeBo.class, cascade = [CascadeType.ALL], fetch = FetchType.EAGER, mappedBy = "id") |
75 | |
@Fetch(value = FetchMode.SELECT) |
76 | |
List<PermissionAttributeBo> attributeDetails |
77 | |
|
78 | |
@Transient |
79 | |
Map<String,String> attributes; |
80 | |
|
81 | |
@OneToMany(targetEntity = RolePermissionBo.class, cascade = [CascadeType.ALL], fetch = FetchType.EAGER, mappedBy = "id") |
82 | |
@Fetch(value = FetchMode.SELECT) |
83 | |
List<RolePermissionBo> rolePermissions |
84 | |
|
85 | |
Map<String,String> getAttributes() { |
86 | 2 | return attributeDetails != null ? KimAttributeDataBo.toAttributes(attributeDetails) : attributes |
87 | |
} |
88 | |
|
89 | |
|
90 | |
|
91 | |
Map<String,String> getDetails() { |
92 | 0 | return attributeDetails != null ? KimAttributeDataBo.toAttributes(attributeDetails) : attributes |
93 | |
} |
94 | |
|
95 | |
|
96 | |
|
97 | |
|
98 | |
|
99 | |
|
100 | |
static Permission to(PermissionBo bo) { |
101 | 1 | if (bo == null) { |
102 | 0 | return null |
103 | |
} |
104 | |
|
105 | 1 | return Permission.Builder.create(bo).build(); |
106 | |
} |
107 | |
|
108 | |
|
109 | |
|
110 | |
|
111 | |
|
112 | |
|
113 | |
static PermissionBo from(Permission im) { |
114 | 1 | if (im == null) { |
115 | 0 | return null |
116 | |
} |
117 | |
|
118 | 1 | PermissionBo bo = new PermissionBo() |
119 | 1 | bo.id = im.id |
120 | 1 | bo.namespaceCode = im.namespaceCode |
121 | 1 | bo.name = im.name |
122 | 1 | bo.description = im.description |
123 | 1 | bo.active = im.active |
124 | 1 | bo.templateId = im.template.getId() |
125 | 1 | bo.template = PermissionTemplateBo.from(im.template) |
126 | 1 | bo.attributes = im.attributes |
127 | 1 | bo.versionNumber = im.versionNumber |
128 | 1 | bo.objectId = im.objectId; |
129 | |
|
130 | 1 | return bo |
131 | |
} |
132 | |
|
133 | |
PermissionTemplateBo getTemplate() { |
134 | 1 | return template; |
135 | |
} |
136 | |
|
137 | |
public String getDetailObjectsValues() { |
138 | 0 | StringBuffer detailObjectsToDisplay = new StringBuffer(); |
139 | 0 | Iterator<PermissionAttributeBo> permIter = attributeDetails.iterator(); |
140 | 0 | while (permIter.hasNext()) { |
141 | 0 | PermissionAttributeBo permissionAttributeData = permIter.next(); |
142 | 0 | detailObjectsToDisplay.append(permissionAttributeData.getAttributeValue()); |
143 | 0 | if (permIter.hasNext()) { |
144 | 0 | detailObjectsToDisplay.append(KimConstants.KimUIConstants.COMMA_SEPARATOR); |
145 | |
} |
146 | |
} |
147 | 0 | return detailObjectsToDisplay.toString(); |
148 | |
} |
149 | |
|
150 | |
String getDetailObjectsToDisplay() { |
151 | 0 | final KimType kimType = getTypeInfoService().getKimType( getTemplate().getKimTypeId() ); |
152 | |
|
153 | 0 | return attributeDetails.collect { |
154 | 0 | getKimAttributeLabelFromDD(kimType.getAttributeDefinitionById(it.kimAttributeId)) + ":" + it.attributeValue |
155 | |
}.join(",") |
156 | |
} |
157 | |
|
158 | |
private String getKimAttributeLabelFromDD( KimTypeAttribute attribute ){ |
159 | 0 | return getDataDictionaryService().getAttributeLabel(attribute.getKimAttribute().getComponentName(), attribute.getKimAttribute().getAttributeName() ); |
160 | |
} |
161 | |
|
162 | |
private DataDictionaryService dataDictionaryService; |
163 | |
private DataDictionaryService getDataDictionaryService() { |
164 | 0 | if(dataDictionaryService == null){ |
165 | 0 | dataDictionaryService = KRADServiceLocatorWeb.getDataDictionaryService(); |
166 | |
} |
167 | 0 | return dataDictionaryService; |
168 | |
} |
169 | |
|
170 | |
private KimTypeInfoService kimTypeInfoService; |
171 | |
private KimTypeInfoService getTypeInfoService() { |
172 | 0 | if(kimTypeInfoService == null){ |
173 | 0 | kimTypeInfoService = KimApiServiceLocator.getKimTypeInfoService(); |
174 | |
} |
175 | 0 | return kimTypeInfoService; |
176 | |
} |
177 | |
} |