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