1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.kns.document.authorization;
17
18 import org.apache.commons.lang.StringUtils;
19 import org.kuali.rice.kns.web.ui.Field;
20 import org.kuali.rice.krad.datadictionary.mask.MaskFormatter;
21
22
23
24
25
26
27
28
29
30
31
32
33 public class FieldRestriction {
34
35 private String fieldName;
36 private boolean editable;
37 private boolean viewable;
38 private boolean masked;
39 private boolean partiallyMasked;
40 private MaskFormatter maskFormatter;
41 private boolean shouldBeEncrypted;
42
43
44
45 public FieldRestriction() {
46 editable = true;
47 viewable = true;
48 }
49
50
51
52
53
54
55
56
57
58
59 public FieldRestriction(String fieldName, boolean canEdit, boolean canView) {
60 this.fieldName = fieldName;
61 setEditable(canEdit);
62 setViewable(canView);
63 }
64
65
66
67
68
69
70
71
72 public FieldRestriction(String fieldName, String fieldAuthorizationFlag) {
73
74 if (!fieldAuthorizationFlag.equals(Field.EDITABLE) && !fieldAuthorizationFlag.equals(Field.READONLY)
75 && !fieldAuthorizationFlag.equals(Field.HIDDEN) && !fieldAuthorizationFlag.equals(Field.MASKED)
76 && !fieldAuthorizationFlag.equals(Field.PARTIALLY_MASKED)) {
77 throw new IllegalArgumentException("The only allowable values are " +
78 "Field.HIDDEN, Field.READONLY, Field.EDITABLE, Field.MASKED and Field.PARTIALLY_MASKED");
79 }
80
81 this.fieldName = fieldName;
82
83 if (fieldAuthorizationFlag.equals(Field.EDITABLE)) {
84 this.editable = true;
85 this.viewable = true;
86 } else if (fieldAuthorizationFlag.equals(Field.READONLY)) {
87 this.editable = false;
88 this.viewable = true;
89 } else if (fieldAuthorizationFlag.equals(Field.HIDDEN)) {
90 this.editable = false;
91 this.viewable = false;
92 } else if(fieldAuthorizationFlag.equals(Field.MASKED)){
93 this.masked = true;
94 this.viewable = true;
95 this.editable = false;
96 } else if(fieldAuthorizationFlag.equals(Field.PARTIALLY_MASKED)){
97 this.partiallyMasked = true;
98 this.viewable = true;
99 this.editable = false;
100 }
101 }
102
103
104
105
106
107
108
109
110
111 public String getKualiFieldDisplayFlag() {
112
113 if (!editable && !viewable) {
114 return Field.HIDDEN;
115 }
116 if (!editable && viewable) {
117 return Field.READONLY;
118 }
119 else {
120 return Field.EDITABLE;
121 }
122
123 }
124
125
126
127
128
129
130
131
132 public boolean isRestricted() {
133 if (!editable || !viewable) {
134 return true;
135 }
136 else {
137 return false;
138 }
139 }
140
141
142
143
144
145
146
147
148 public boolean isHidden() {
149 if (!editable && !viewable) {
150 return true;
151 }
152 else {
153 return false;
154 }
155 }
156
157
158
159
160
161
162
163
164 public boolean isReadOnly() {
165 if (!editable && viewable) {
166 return true;
167 }
168 else {
169 return false;
170 }
171 }
172
173
174
175
176
177
178 public boolean isEditable() {
179 return editable;
180 }
181
182
183
184
185
186
187
188
189
190 public void setEditable(boolean editable) {
191 if (editable && !this.viewable) {
192 this.viewable = true;
193 }
194 this.editable = editable;
195 }
196
197
198
199
200
201
202 public String getFieldName() {
203 return fieldName;
204 }
205
206
207
208
209
210
211 public void setFieldName(String fieldName) {
212 this.fieldName = fieldName;
213 }
214
215
216
217
218
219
220 public boolean isViewable() {
221 return viewable;
222 }
223
224
225
226
227
228
229
230
231
232 public void setViewable(boolean viewable) {
233 if (!viewable && this.editable) {
234 this.editable = false;
235 }
236 this.viewable = viewable;
237 }
238
239
240
241
242 public String toString() {
243 StringBuffer sb = new StringBuffer();
244 sb.append(this.fieldName);
245 sb.append(" [");
246 if (this.editable) {
247 sb.append("editable");
248 }
249 else {
250 sb.append("not editable");
251 }
252 sb.append(",");
253 if (this.viewable) {
254 sb.append("viewable");
255 }
256 else {
257 sb.append("not viewable");
258 }
259 sb.append("]");
260 return sb.toString();
261 }
262
263
264
265
266 public boolean equals(Object obj) {
267 boolean equal = false;
268
269 if (obj != null) {
270 if (this.getClass().equals(obj.getClass())) {
271 FieldRestriction other = (FieldRestriction) obj;
272
273 if (StringUtils.equals(this.fieldName, other.getFieldName())) {
274 if (this.editable == other.isEditable() && this.viewable == other.isViewable()) {
275 equal = true;
276 }
277 }
278 }
279 }
280
281 return equal;
282 }
283
284
285
286
287 public int hashCode() {
288 return toString().hashCode();
289 }
290
291
292
293
294 public boolean isMasked() {
295 return this.masked;
296 }
297
298
299
300
301 public boolean isPartiallyMasked() {
302 return this.partiallyMasked;
303 }
304
305
306
307
308
309 public boolean isShouldBeEncrypted() {
310 return this.shouldBeEncrypted;
311 }
312
313
314
315
316 public void setShouldBeEncrypted(boolean shouldBeEncrypted) {
317 this.shouldBeEncrypted = shouldBeEncrypted;
318 }
319
320
321
322
323 public MaskFormatter getMaskFormatter() {
324 return this.maskFormatter;
325 }
326
327
328
329
330 public void setMaskFormatter(MaskFormatter maskFormatter) {
331 this.maskFormatter = maskFormatter;
332 }
333
334
335 }