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