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 java.util.HashMap;
19 import java.util.Iterator;
20 import java.util.List;
21 import java.util.Map;
22
23 import javax.persistence.Column;
24 import javax.persistence.Entity;
25 import javax.persistence.Id;
26 import javax.persistence.Table;
27 import javax.persistence.Transient;
28 import javax.persistence.Convert;
29
30 import org.apache.commons.lang.StringUtils;
31 import org.kuali.rice.krad.bo.PersistableBusinessObjectBase;
32 import org.kuali.rice.krad.data.jpa.converters.BooleanYNConverter;
33
34 @Entity
35 @Table(name = "KRIM_PERM_T")
36 public class GenericPermissionBo extends PersistableBusinessObjectBase {
37
38 private static final long serialVersionUID = 1L;
39
40 @Id
41 @Column(name = "PERM_ID")
42 protected String id;
43
44 @Column(name = "NMSPC_CD")
45 protected String namespaceCode;
46
47 @Column(name = "NM")
48 protected String name;
49
50 @Column(name = "DESC_TXT")
51 protected String description;
52
53 @Column(name = "ACTV_IND")
54 @Convert(converter = BooleanYNConverter.class)
55 protected boolean active;
56
57 @Column(name = "PERM_TMPL_ID")
58 protected String templateId;
59
60 protected String detailValues;
61
62 protected Map<String, String> details;
63
64 protected PermissionTemplateBo template = new PermissionTemplateBo();
65
66 protected List<PermissionAttributeBo> attributeDetails;
67
68
69
70
71
72 public GenericPermissionBo() {
73 }
74
75 public GenericPermissionBo(PermissionBo perm) {
76 loadFromPermission(perm);
77 }
78
79 public void loadFromPermission(PermissionBo perm) {
80 setId(perm.getId());
81 setNamespaceCode(perm.getNamespaceCode());
82 setTemplate(perm.getTemplate());
83 setAttributeDetails(perm.getAttributeDetails());
84 setDetailValues(perm.getDetailObjectsValues());
85 setName(perm.getName());
86 setTemplateId(perm.getTemplateId());
87 setDescription(perm.getDescription());
88 setActive(perm.isActive());
89 setDetails(perm.getAttributes());
90 setVersionNumber(perm.getVersionNumber());
91 setObjectId(perm.getObjectId());
92 }
93
94 public String getDetailValues() {
95
96
97
98
99
100
101
102
103
104
105
106
107 return detailValues;
108 }
109
110 public void setDetailValues(String detailValues) {
111 this.detailValues = detailValues;
112 }
113
114 public void setDetailValues(Map<String, String> detailsAttribs) {
115 StringBuffer sb = new StringBuffer();
116 if (detailsAttribs != null) {
117 Iterator<String> keyIter = detailsAttribs.keySet().iterator();
118 while (keyIter.hasNext()) {
119 String key = keyIter.next();
120 sb.append(key).append('=').append(detailsAttribs.get(key));
121 if (keyIter.hasNext()) {
122 sb.append('\n');
123 }
124 }
125 }
126 detailValues = sb.toString();
127 }
128
129 public boolean isActive() {
130 return active;
131 }
132
133 public void setActive(boolean active) {
134 this.active = active;
135 }
136
137 public String getDescription() {
138 return description;
139 }
140
141 public String getId() {
142 return id;
143 }
144
145 public String getName() {
146 return name;
147 }
148
149 public PermissionTemplateBo getTemplate() {
150 return template;
151 }
152
153 public void setDescription(String permissionDescription) {
154 this.description = permissionDescription;
155 }
156
157 public void setName(String permissionName) {
158 this.name = permissionName;
159 }
160
161 public void setDetails(Map<String, String> details) {
162 this.details = details;
163 setDetailValues(details);
164 }
165
166 public String getTemplateId() {
167 return this.templateId;
168 }
169
170 public void setTemplateId(String templateId) {
171 this.templateId = templateId;
172 }
173
174 public void setTemplate(PermissionTemplateBo template) {
175 this.template = template;
176 }
177
178 public Map<String, String> getDetails() {
179 String detailValuesTemp = this.detailValues;
180 Map<String, String> detailsTemp = new HashMap<String, String>();
181 if (detailValuesTemp != null) {
182
183 detailValuesTemp = detailValuesTemp.replace("\r\n", "\n");
184 detailValuesTemp = detailValuesTemp.replace('\r', '\n');
185 if (StringUtils.isNotBlank(detailValuesTemp)) {
186 String[] values = detailValuesTemp.split("\n");
187 for (String attrib : values) {
188 if (attrib.indexOf('=') != -1) {
189 String[] keyValueArray = attrib.split("=", 2);
190 detailsTemp.put(keyValueArray[0].trim(), keyValueArray[1].trim());
191 }
192 }
193 }
194 }
195 this.details = detailsTemp;
196 return details;
197 }
198
199 public String getNamespaceCode() {
200 return this.namespaceCode;
201 }
202
203 public void setNamespaceCode(String namespaceCode) {
204 this.namespaceCode = namespaceCode;
205 }
206
207 public void setId(String id) {
208 this.id = id;
209 }
210
211 public List<PermissionAttributeBo> getAttributeDetails() {
212 return attributeDetails;
213 }
214
215 public void setAttributeDetails(List<PermissionAttributeBo> attributeDetails) {
216 this.attributeDetails = attributeDetails;
217 }
218
219 @Override
220 public void refreshNonUpdateableReferences() {
221 }
222
223 @Override
224 public void refreshReferenceObject(String referenceObjectName) {
225 }
226
227 @Override
228 protected void prePersist() {
229 throw new UnsupportedOperationException("This object should never be persisted.");
230 }
231
232 @Override
233 protected void preUpdate() {
234 throw new UnsupportedOperationException("This object should never be persisted.");
235 }
236
237 @Override
238 protected void preRemove() {
239 throw new UnsupportedOperationException("This object should never be persisted.");
240 }
241
242 public static PermissionBo toPermissionBo(GenericPermissionBo bo) {
243 PermissionBo permission = new PermissionBo();
244 permission.setTemplateId(bo.getTemplateId());
245 permission.setId(bo.getId());
246 permission.setTemplate(bo.getTemplate());
247 permission.setActive(bo.isActive());
248 permission.setDescription(bo.getDescription());
249 permission.setName(bo.getName());
250 permission.setNamespaceCode(bo.namespaceCode);
251 permission.setAttributeDetails(bo.getAttributeDetails());
252 permission.setAttributes(bo.getDetails());
253 permission.setVersionNumber(bo.versionNumber);
254 permission.setObjectId(bo.getObjectId());
255 return permission;
256 }
257 }