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