Coverage Report - org.kuali.rice.kns.document.authorization.MaintenanceDocumentRestrictionsBase
 
Classes in this File Line Coverage Branch Coverage Complexity
MaintenanceDocumentRestrictionsBase
0%
0/22
0%
0/16
1.6
 
 1  
 /*
 2  
  * Copyright 2007 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.authorization.FieldRestriction;
 22  
 import org.kuali.rice.kns.authorization.InquiryOrMaintenanceDocumentRestrictionsBase;
 23  
 import org.kuali.rice.kns.web.ui.Field;
 24  
 
 25  
 public class MaintenanceDocumentRestrictionsBase extends
 26  
                 InquiryOrMaintenanceDocumentRestrictionsBase implements
 27  
                 MaintenanceDocumentRestrictions {
 28  
         private Set<String> readOnlyFields;
 29  
         private Set<String> readOnlySectionIds;
 30  
         
 31  0
         public MaintenanceDocumentRestrictionsBase() {
 32  0
         }
 33  
         
 34  
         public void addReadOnlyField(String fieldName) {
 35  0
                 readOnlyFields.add(fieldName);
 36  0
         }
 37  
 
 38  
         public void addReadOnlySectionId(String sectionId) {
 39  0
                 readOnlySectionIds.add(sectionId);
 40  0
         }
 41  
 
 42  
         public Set<String> getReadOnlySectionIds() {
 43  0
                 return readOnlySectionIds;
 44  
         }
 45  
 
 46  
         @Override
 47  
         public FieldRestriction getFieldRestriction(String fieldName) {
 48  0
                 FieldRestriction fieldRestriction = super
 49  
                                 .getFieldRestriction(fieldName);
 50  0
                 if (fieldRestriction == null && isReadOnlyField(fieldName)) {
 51  0
                         fieldRestriction = new FieldRestriction(fieldName, Field.READONLY);
 52  
                 }
 53  
                 // TODO: next block could probably be removed since the superclass would return null for a read-only field 
 54  0
                 if (Field.EDITABLE
 55  
                                 .equals(fieldRestriction.getKualiFieldDisplayFlag())
 56  
                                 && isReadOnlyField(fieldName)) {
 57  0
                         fieldRestriction = new FieldRestriction(fieldName,
 58  
                                         Field.READONLY);
 59  
                 }
 60  0
                 return fieldRestriction;
 61  
         }
 62  
 
 63  
         @Override
 64  
         public void clearAllRestrictions() {
 65  0
                 super.clearAllRestrictions();
 66  0
                 readOnlyFields = new HashSet<String>();
 67  0
                 readOnlySectionIds = new HashSet<String>();
 68  0
         }
 69  
 
 70  
         protected boolean isReadOnlyField(String fieldName) {
 71  0
                 String normalizedFieldName = normalizeFieldName(fieldName);
 72  0
                 return readOnlyFields.contains(normalizedFieldName);
 73  
         }
 74  
 
 75  
         /**
 76  
          * @see org.kuali.rice.kns.authorization.InquiryOrMaintenanceDocumentRestrictionsBase#hasAnyFieldRestrictions()
 77  
          */
 78  
         @Override
 79  
         public boolean hasAnyFieldRestrictions() {
 80  0
                 return super.hasAnyFieldRestrictions() || !readOnlyFields.isEmpty();
 81  
         }
 82  
 
 83  
         /**
 84  
          * @see org.kuali.rice.kns.authorization.InquiryOrMaintenanceDocumentRestrictionsBase#hasRestriction(java.lang.String)
 85  
          */
 86  
         @Override
 87  
         public boolean hasRestriction(String fieldName) {
 88  0
                 return super.hasRestriction(fieldName) || isReadOnlyField(fieldName);
 89  
         }
 90  
         
 91  
         /**
 92  
          * @see org.kuali.rice.kns.document.authorization.MaintenanceDocumentRestrictions#isReadOnlySectionId(java.lang.String)
 93  
          */
 94  
         public boolean isReadOnlySectionId(String sectionId) {
 95  0
                 return readOnlySectionIds.contains(sectionId);
 96  
         }
 97  
 }