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