View Javadoc

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