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