View Javadoc
1   /**
2    * Copyright 2005-2015 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 org.kuali.rice.kns.inquiry.InquiryRestrictions;
19  import org.kuali.rice.kns.web.ui.Field;
20  
21  import java.util.HashSet;
22  import java.util.Set;
23  
24  /**
25   * @deprecated Only used in KNS classes, use KRAD.
26   */
27  @Deprecated
28  public class InquiryOrMaintenanceDocumentRestrictionsBase extends
29  		BusinessObjectRestrictionsBase implements InquiryOrMaintenanceDocumentRestrictions, InquiryRestrictions {
30  	private Set<String> hiddenFields;
31  	private Set<String> hiddenSectionIds;
32  
33  	public void addHiddenField(String fieldName) {
34  		hiddenFields.add(fieldName);
35  	}
36  
37  	public void addHiddenSectionId(String sectionId) {
38  		hiddenSectionIds.add(sectionId);
39  	}
40  
41  	@Override
42  	public FieldRestriction getFieldRestriction(String fieldName) {
43  		FieldRestriction fieldRestriction = super
44  				.getFieldRestriction(fieldName);
45  		if (isHiddenField(fieldName)) {
46  			fieldRestriction = new FieldRestriction(fieldName, Field.HIDDEN);
47  		}
48  		return fieldRestriction;			
49  	}
50  
51  	/**
52  	 * @see org.kuali.rice.krad.authorization.BusinessObjectRestrictionsBase#hasRestriction(java.lang.String)
53  	 */
54  	@Override
55  	public boolean hasRestriction(String fieldName) {
56  		return super.hasRestriction(fieldName) || isHiddenField(fieldName);
57  	}
58  	
59  	/**
60  	 * @see org.kuali.rice.krad.authorization.BusinessObjectRestrictionsBase#hasAnyFieldRestrictions()
61  	 */
62  	@Override
63  	public boolean hasAnyFieldRestrictions() {
64  		return super.hasAnyFieldRestrictions() || !hiddenFields.isEmpty();
65  	}
66  
67  	@Override
68  	public void clearAllRestrictions() {
69  		super.clearAllRestrictions();
70  		hiddenFields = new HashSet<String>();
71  		hiddenSectionIds = new HashSet<String>();
72  	}
73  
74  	/**
75  	 * @see org.kuali.rice.krad.authorization.InquiryOrMaintenanceDocumentRestrictions#isHiddenSectionId(java.lang.String)
76  	 */
77  	public boolean isHiddenSectionId(String sectionId) {
78  		return hiddenSectionIds.contains(sectionId);
79  	}
80  
81  	protected boolean isHiddenField(String fieldName) {
82  		String normalizedFieldName = normalizeFieldName(fieldName);
83  		return hiddenFields.contains(normalizedFieldName);
84  	}
85  }