View Javadoc
1   /**
2    * Copyright 2005-2016 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
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  /**
27   * @deprecated Only used in KNS classes, use KRAD.
28   */
29  @Deprecated
30  public class MaintenanceDocumentRestrictionsBase extends InquiryOrMaintenanceDocumentRestrictionsBase implements MaintenanceDocumentRestrictions {
31  	private Set<String> readOnlyFields;
32  	private Set<String> readOnlySectionIds;
33  	
34  	public MaintenanceDocumentRestrictionsBase() {
35  	}
36  	
37  	public void addReadOnlyField(String fieldName) {
38  		readOnlyFields.add(fieldName);
39  	}
40  
41  	public void addReadOnlySectionId(String sectionId) {
42  		readOnlySectionIds.add(sectionId);
43  	}
44  
45  	public Set<String> getReadOnlySectionIds() {
46  		return readOnlySectionIds;
47  	}
48  
49  	@Override
50  	public FieldRestriction getFieldRestriction(String fieldName) {
51  		FieldRestriction fieldRestriction = super
52  				.getFieldRestriction(fieldName);
53  		if (fieldRestriction == null && isReadOnlyField(fieldName)) {
54  			fieldRestriction = new FieldRestriction(fieldName, Field.READONLY);
55  		}
56  		// TODO: next block could probably be removed since the superclass would return null for a read-only field 
57  		if (Field.EDITABLE
58  				.equals(fieldRestriction.getKualiFieldDisplayFlag())
59  				&& isReadOnlyField(fieldName)) {
60  			fieldRestriction = new FieldRestriction(fieldName,
61  					Field.READONLY);
62  		}
63  		return fieldRestriction;
64  	}
65  
66  	@Override
67  	public void clearAllRestrictions() {
68  		super.clearAllRestrictions();
69  		readOnlyFields = new HashSet<String>();
70  		readOnlySectionIds = new HashSet<String>();
71  	}
72  
73  	protected boolean isReadOnlyField(String fieldName) {
74  		String normalizedFieldName = normalizeFieldName(fieldName);
75  		return readOnlyFields.contains(normalizedFieldName);
76  	}
77  
78  	/**
79  	 * @see org.kuali.rice.krad.authorization.InquiryOrMaintenanceDocumentRestrictionsBase#hasAnyFieldRestrictions()
80  	 */
81  	@Override
82  	public boolean hasAnyFieldRestrictions() {
83  		return super.hasAnyFieldRestrictions() || !readOnlyFields.isEmpty();
84  	}
85  
86  	/**
87  	 * @see org.kuali.rice.krad.authorization.InquiryOrMaintenanceDocumentRestrictionsBase#hasRestriction(java.lang.String)
88  	 */
89  	@Override
90  	public boolean hasRestriction(String fieldName) {
91  		return super.hasRestriction(fieldName) || isReadOnlyField(fieldName);
92  	}
93  	
94  	/**
95  	 * @see org.kuali.rice.kns.document.authorization.MaintenanceDocumentRestrictions#isReadOnlySectionId(java.lang.String)
96  	 */
97  	public boolean isReadOnlySectionId(String sectionId) {
98  		return readOnlySectionIds.contains(sectionId);
99  	}
100 }