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