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