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