Coverage Report - org.kuali.rice.kns.document.authorization.BusinessObjectRestrictionsBase
 
Classes in this File Line Coverage Branch Coverage Complexity
BusinessObjectRestrictionsBase
0%
0/28
0%
0/14
1.6
 
 1  
 /*
 2  
  * Copyright 2007-2008 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.web.ui.Field;
 19  
 import org.kuali.rice.krad.datadictionary.mask.MaskFormatter;
 20  
 
 21  
 import java.util.HashMap;
 22  
 import java.util.Map;
 23  
 import java.util.Set;
 24  
 
 25  
 public class BusinessObjectRestrictionsBase implements
 26  
                 BusinessObjectRestrictions {
 27  
         private Map<String, MaskFormatter> partiallyMaskedFields;
 28  
         private Map<String, MaskFormatter> fullyMaskedFields;
 29  
 
 30  
         protected Set<String> allRestrictedFields;
 31  
 
 32  0
         public BusinessObjectRestrictionsBase() {
 33  0
                 clearAllRestrictions();
 34  0
         }
 35  
 
 36  
         public boolean hasAnyFieldRestrictions() {
 37  0
                 return !partiallyMaskedFields.isEmpty() || !fullyMaskedFields.isEmpty();
 38  
         }
 39  
 
 40  
         public boolean hasRestriction(String fieldName) {
 41  0
                 return isPartiallyMaskedField(fieldName) || isFullyMaskedField(fieldName);
 42  
         }
 43  
 
 44  
         public void addFullyMaskedField(String fieldName,
 45  
                         MaskFormatter maskFormatter) {
 46  0
                 fullyMaskedFields.put(fieldName, maskFormatter);
 47  0
         }
 48  
 
 49  
         public void addPartiallyMaskedField(String fieldName,
 50  
                         MaskFormatter maskFormatter) {
 51  0
                 partiallyMaskedFields.put(fieldName, maskFormatter);
 52  0
         }
 53  
 
 54  
         /**
 55  
          * 
 56  
          * This method returns the authorization setting for the given field name.
 57  
          * If the field name is not restricted in any way, a default full-editable
 58  
          * value is returned.
 59  
          * 
 60  
          * @param fieldName
 61  
          *            - name of field to get authorization restrictions for.
 62  
          * @return a populated FieldAuthorization class for this field
 63  
          * 
 64  
          */
 65  
         public FieldRestriction getFieldRestriction(String fieldName) {
 66  0
                 if (hasRestriction(fieldName)) {
 67  0
                         FieldRestriction fieldRestriction = null;
 68  0
                         if (isPartiallyMaskedField(fieldName)) {
 69  0
                                 fieldRestriction = new FieldRestriction(fieldName,
 70  
                                                 Field.PARTIALLY_MASKED);
 71  0
                                 fieldRestriction.setMaskFormatter(partiallyMaskedFields
 72  
                                                 .get(normalizeFieldName(fieldName)));
 73  
                         }
 74  0
                         if (isFullyMaskedField(fieldName)) {
 75  0
                                 fieldRestriction = new FieldRestriction(fieldName, Field.MASKED);
 76  0
                                 fieldRestriction.setMaskFormatter(fullyMaskedFields
 77  
                                                 .get(normalizeFieldName(fieldName)));
 78  
                         }
 79  0
                         return fieldRestriction;
 80  
                 } else {
 81  0
                         return new FieldRestriction(fieldName, Field.EDITABLE);
 82  
                 }
 83  
         }
 84  
 
 85  
         public void clearAllRestrictions() {
 86  0
                 partiallyMaskedFields = new HashMap<String, MaskFormatter>();
 87  0
                 fullyMaskedFields = new HashMap<String, MaskFormatter>();
 88  0
                 allRestrictedFields = null;
 89  0
         }
 90  
         
 91  
         
 92  
         /**
 93  
          * This method is used to convert field names on forms into a format that's compatible with field names
 94  
          * that are registered with a restriction.  The base implementation of this method just returns the string.
 95  
          * 
 96  
          * @param fieldName The field name that would be rendered on a form
 97  
          * @return
 98  
          */
 99  
         protected String normalizeFieldName(String fieldName) {
 100  0
                 return fieldName;
 101  
         }
 102  
         
 103  
         protected boolean isFullyMaskedField(String fieldName) {
 104  0
                 String normalizedFieldName = normalizeFieldName(fieldName);
 105  0
                 return fullyMaskedFields.containsKey(normalizedFieldName);
 106  
         }
 107  
         
 108  
         protected boolean isPartiallyMaskedField(String fieldName) {
 109  0
                 String normalizedFieldName = normalizeFieldName(fieldName);
 110  0
                 return partiallyMaskedFields.containsKey(normalizedFieldName);
 111  
         }
 112  
 }