001/**
002 * Copyright 2005-2016 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package org.kuali.rice.kns.document.authorization;
017
018import org.kuali.rice.kns.inquiry.InquiryRestrictions;
019import org.kuali.rice.kns.web.ui.Field;
020
021import java.util.HashSet;
022import java.util.Set;
023
024public class InquiryOrMaintenanceDocumentRestrictionsBase extends
025                BusinessObjectRestrictionsBase implements InquiryOrMaintenanceDocumentRestrictions, InquiryRestrictions {
026        private Set<String> hiddenFields;
027        private Set<String> hiddenSectionIds;
028
029        public void addHiddenField(String fieldName) {
030                hiddenFields.add(fieldName);
031        }
032
033        public void addHiddenSectionId(String sectionId) {
034                hiddenSectionIds.add(sectionId);
035        }
036
037        @Override
038        public FieldRestriction getFieldRestriction(String fieldName) {
039                FieldRestriction fieldRestriction = super
040                                .getFieldRestriction(fieldName);
041                if (isHiddenField(fieldName)) {
042                        fieldRestriction = new FieldRestriction(fieldName, Field.HIDDEN);
043                }
044                return fieldRestriction;                        
045        }
046
047        /**
048         * @see org.kuali.rice.krad.authorization.BusinessObjectRestrictionsBase#hasRestriction(java.lang.String)
049         */
050        @Override
051        public boolean hasRestriction(String fieldName) {
052                return super.hasRestriction(fieldName) || isHiddenField(fieldName);
053        }
054        
055        /**
056         * @see org.kuali.rice.krad.authorization.BusinessObjectRestrictionsBase#hasAnyFieldRestrictions()
057         */
058        @Override
059        public boolean hasAnyFieldRestrictions() {
060                return super.hasAnyFieldRestrictions() || !hiddenFields.isEmpty();
061        }
062
063        @Override
064        public void clearAllRestrictions() {
065                super.clearAllRestrictions();
066                hiddenFields = new HashSet<String>();
067                hiddenSectionIds = new HashSet<String>();
068        }
069
070        /**
071         * @see org.kuali.rice.krad.authorization.InquiryOrMaintenanceDocumentRestrictions#isHiddenSectionId(java.lang.String)
072         */
073        public boolean isHiddenSectionId(String sectionId) {
074                return hiddenSectionIds.contains(sectionId);
075        }
076
077        protected boolean isHiddenField(String fieldName) {
078                String normalizedFieldName = normalizeFieldName(fieldName);
079                return hiddenFields.contains(normalizedFieldName);
080        }
081}