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