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 java.util.HashSet; |
19 | |
import java.util.Set; |
20 | |
|
21 | |
import org.kuali.rice.kns.authorization.FieldRestriction; |
22 | |
import org.kuali.rice.kns.authorization.InquiryOrMaintenanceDocumentRestrictionsBase; |
23 | |
import org.kuali.rice.kns.web.ui.Field; |
24 | |
|
25 | |
public class MaintenanceDocumentRestrictionsBase extends |
26 | |
InquiryOrMaintenanceDocumentRestrictionsBase implements |
27 | |
MaintenanceDocumentRestrictions { |
28 | |
private Set<String> readOnlyFields; |
29 | |
private Set<String> readOnlySectionIds; |
30 | |
|
31 | 0 | public MaintenanceDocumentRestrictionsBase() { |
32 | 0 | } |
33 | |
|
34 | |
public void addReadOnlyField(String fieldName) { |
35 | 0 | readOnlyFields.add(fieldName); |
36 | 0 | } |
37 | |
|
38 | |
public void addReadOnlySectionId(String sectionId) { |
39 | 0 | readOnlySectionIds.add(sectionId); |
40 | 0 | } |
41 | |
|
42 | |
public Set<String> getReadOnlySectionIds() { |
43 | 0 | return readOnlySectionIds; |
44 | |
} |
45 | |
|
46 | |
@Override |
47 | |
public FieldRestriction getFieldRestriction(String fieldName) { |
48 | 0 | FieldRestriction fieldRestriction = super |
49 | |
.getFieldRestriction(fieldName); |
50 | 0 | if (fieldRestriction == null && isReadOnlyField(fieldName)) { |
51 | 0 | fieldRestriction = new FieldRestriction(fieldName, Field.READONLY); |
52 | |
} |
53 | |
|
54 | 0 | if (Field.EDITABLE |
55 | |
.equals(fieldRestriction.getKualiFieldDisplayFlag()) |
56 | |
&& isReadOnlyField(fieldName)) { |
57 | 0 | fieldRestriction = new FieldRestriction(fieldName, |
58 | |
Field.READONLY); |
59 | |
} |
60 | 0 | return fieldRestriction; |
61 | |
} |
62 | |
|
63 | |
@Override |
64 | |
public void clearAllRestrictions() { |
65 | 0 | super.clearAllRestrictions(); |
66 | 0 | readOnlyFields = new HashSet<String>(); |
67 | 0 | readOnlySectionIds = new HashSet<String>(); |
68 | 0 | } |
69 | |
|
70 | |
protected boolean isReadOnlyField(String fieldName) { |
71 | 0 | String normalizedFieldName = normalizeFieldName(fieldName); |
72 | 0 | return readOnlyFields.contains(normalizedFieldName); |
73 | |
} |
74 | |
|
75 | |
|
76 | |
|
77 | |
|
78 | |
@Override |
79 | |
public boolean hasAnyFieldRestrictions() { |
80 | 0 | return super.hasAnyFieldRestrictions() || !readOnlyFields.isEmpty(); |
81 | |
} |
82 | |
|
83 | |
|
84 | |
|
85 | |
|
86 | |
@Override |
87 | |
public boolean hasRestriction(String fieldName) { |
88 | 0 | return super.hasRestriction(fieldName) || isReadOnlyField(fieldName); |
89 | |
} |
90 | |
|
91 | |
|
92 | |
|
93 | |
|
94 | |
public boolean isReadOnlySectionId(String sectionId) { |
95 | 0 | return readOnlySectionIds.contains(sectionId); |
96 | |
} |
97 | |
} |