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