1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.kim.impl.permission |
17 | |
|
18 | |
import javax.persistence.CascadeType |
19 | |
import javax.persistence.Column |
20 | |
import javax.persistence.Entity |
21 | |
import javax.persistence.FetchType |
22 | |
import javax.persistence.Id |
23 | |
import javax.persistence.JoinColumn |
24 | |
import javax.persistence.OneToMany |
25 | |
import javax.persistence.OneToOne |
26 | |
import javax.persistence.Table |
27 | |
import javax.persistence.Transient |
28 | |
import org.hibernate.annotations.Fetch |
29 | |
import org.hibernate.annotations.FetchMode |
30 | |
import org.hibernate.annotations.Type |
31 | |
import org.kuali.rice.kim.api.KimConstants |
32 | |
import org.kuali.rice.kim.api.permission.Permission |
33 | |
import org.kuali.rice.kim.api.permission.PermissionContract |
34 | |
import org.kuali.rice.kim.api.services.KimApiServiceLocator |
35 | |
import org.kuali.rice.kim.api.type.KimType |
36 | |
import org.kuali.rice.kim.api.type.KimTypeAttribute |
37 | |
import org.kuali.rice.kim.api.type.KimTypeInfoService |
38 | |
import org.kuali.rice.kim.impl.common.attribute.KimAttributeDataBo |
39 | |
import org.kuali.rice.kim.impl.role.RolePermissionBo |
40 | |
import org.kuali.rice.krad.bo.PersistableBusinessObjectBase |
41 | |
import org.kuali.rice.krad.service.DataDictionaryService |
42 | |
import org.kuali.rice.krad.service.KRADServiceLocatorWeb |
43 | |
import org.springframework.util.AutoPopulatingList |
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 | 0 | List<RolePermissionBo> rolePermissions = new AutoPopulatingList(RolePermissionBo.class) |
84 | |
|
85 | |
Map<String,String> getAttributes() { |
86 | 0 | 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 | 0 | if (bo == null) { |
102 | 0 | return null |
103 | |
} |
104 | |
|
105 | 0 | return Permission.Builder.create(bo).build(); |
106 | |
} |
107 | |
|
108 | |
|
109 | |
|
110 | |
|
111 | |
|
112 | |
|
113 | |
static PermissionBo from(Permission im) { |
114 | 0 | if (im == null) { |
115 | 0 | return null |
116 | |
} |
117 | |
|
118 | 0 | PermissionBo bo = new PermissionBo() |
119 | 0 | bo.id = im.id |
120 | 0 | bo.namespaceCode = im.namespaceCode |
121 | 0 | bo.name = im.name |
122 | 0 | bo.description = im.description |
123 | 0 | bo.active = im.active |
124 | 0 | bo.templateId = im.template != null ? im.template.getId() : null; |
125 | 0 | bo.template = PermissionTemplateBo.from(im.template) |
126 | 0 | bo.attributes = im.attributes |
127 | 0 | bo.versionNumber = im.versionNumber |
128 | 0 | bo.objectId = im.objectId; |
129 | |
|
130 | 0 | return bo |
131 | |
} |
132 | |
|
133 | |
PermissionTemplateBo getTemplate() { |
134 | 0 | return template; |
135 | |
} |
136 | |
|
137 | |
void setTemplate(PermissionTemplateBo template) { |
138 | 0 | this.template = template |
139 | |
} |
140 | |
|
141 | |
public String getDetailObjectsValues() { |
142 | 0 | StringBuffer detailObjectsToDisplay = new StringBuffer(); |
143 | 0 | Iterator<PermissionAttributeBo> permIter = attributeDetails.iterator(); |
144 | 0 | while (permIter.hasNext()) { |
145 | 0 | PermissionAttributeBo permissionAttributeData = permIter.next(); |
146 | 0 | detailObjectsToDisplay.append(permissionAttributeData.getAttributeValue()); |
147 | 0 | if (permIter.hasNext()) { |
148 | 0 | detailObjectsToDisplay.append(KimConstants.KimUIConstants.COMMA_SEPARATOR); |
149 | |
} |
150 | |
} |
151 | 0 | return detailObjectsToDisplay.toString(); |
152 | |
} |
153 | |
|
154 | |
String getDetailObjectsToDisplay() { |
155 | 0 | final KimType kimType = getTypeInfoService().getKimType( getTemplate().getKimTypeId() ); |
156 | |
|
157 | 0 | return attributeDetails.collect { |
158 | 0 | getKimAttributeLabelFromDD(kimType.getAttributeDefinitionById(it.kimAttributeId)) + ":" + it.attributeValue |
159 | |
}.join(",") |
160 | |
} |
161 | |
|
162 | |
private String getKimAttributeLabelFromDD( KimTypeAttribute attribute ){ |
163 | 0 | return getDataDictionaryService().getAttributeLabel(attribute.getKimAttribute().getComponentName(), attribute.getKimAttribute().getAttributeName() ); |
164 | |
} |
165 | |
|
166 | |
private DataDictionaryService dataDictionaryService; |
167 | |
private DataDictionaryService getDataDictionaryService() { |
168 | 0 | if(dataDictionaryService == null){ |
169 | 0 | dataDictionaryService = KRADServiceLocatorWeb.getDataDictionaryService(); |
170 | |
} |
171 | 0 | return dataDictionaryService; |
172 | |
} |
173 | |
|
174 | |
private KimTypeInfoService kimTypeInfoService; |
175 | |
private KimTypeInfoService getTypeInfoService() { |
176 | 0 | if(kimTypeInfoService == null){ |
177 | 0 | kimTypeInfoService = KimApiServiceLocator.getKimTypeInfoService(); |
178 | |
} |
179 | 0 | return kimTypeInfoService; |
180 | |
} |
181 | |
} |