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.kuali.rice.kns.web.ui.Field;
19 import org.kuali.rice.krad.datadictionary.mask.MaskFormatter;
20
21 import java.util.HashMap;
22 import java.util.Map;
23 import java.util.Set;
24
25 public class BusinessObjectRestrictionsBase implements
26 BusinessObjectRestrictions {
27 private Map<String, MaskFormatter> partiallyMaskedFields;
28 private Map<String, MaskFormatter> fullyMaskedFields;
29
30 protected Set<String> allRestrictedFields;
31
32 public BusinessObjectRestrictionsBase() {
33 clearAllRestrictions();
34 }
35
36 public boolean hasAnyFieldRestrictions() {
37 return !partiallyMaskedFields.isEmpty() || !fullyMaskedFields.isEmpty();
38 }
39
40 public boolean hasRestriction(String fieldName) {
41 return isPartiallyMaskedField(fieldName) || isFullyMaskedField(fieldName);
42 }
43
44 public void addFullyMaskedField(String fieldName,
45 MaskFormatter maskFormatter) {
46 fullyMaskedFields.put(fieldName, maskFormatter);
47 }
48
49 public void addPartiallyMaskedField(String fieldName,
50 MaskFormatter maskFormatter) {
51 partiallyMaskedFields.put(fieldName, maskFormatter);
52 }
53
54
55
56
57
58
59
60
61
62
63
64
65 public FieldRestriction getFieldRestriction(String fieldName) {
66 if (hasRestriction(fieldName)) {
67 FieldRestriction fieldRestriction = null;
68 if (isPartiallyMaskedField(fieldName)) {
69 fieldRestriction = new FieldRestriction(fieldName,
70 Field.PARTIALLY_MASKED);
71 fieldRestriction.setMaskFormatter(partiallyMaskedFields
72 .get(normalizeFieldName(fieldName)));
73 }
74 if (isFullyMaskedField(fieldName)) {
75 fieldRestriction = new FieldRestriction(fieldName, Field.MASKED);
76 fieldRestriction.setMaskFormatter(fullyMaskedFields
77 .get(normalizeFieldName(fieldName)));
78 }
79 return fieldRestriction;
80 } else {
81 return new FieldRestriction(fieldName, Field.EDITABLE);
82 }
83 }
84
85 public void clearAllRestrictions() {
86 partiallyMaskedFields = new HashMap<String, MaskFormatter>();
87 fullyMaskedFields = new HashMap<String, MaskFormatter>();
88 allRestrictedFields = null;
89 }
90
91
92
93
94
95
96
97
98
99 protected String normalizeFieldName(String fieldName) {
100 return fieldName;
101 }
102
103 protected boolean isFullyMaskedField(String fieldName) {
104 String normalizedFieldName = normalizeFieldName(fieldName);
105 return fullyMaskedFields.containsKey(normalizedFieldName);
106 }
107
108 protected boolean isPartiallyMaskedField(String fieldName) {
109 String normalizedFieldName = normalizeFieldName(fieldName);
110 return partiallyMaskedFields.containsKey(normalizedFieldName);
111 }
112 }