001 /**
002 * Copyright 2005-2014 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016 package org.kuali.rice.kns.document.authorization;
017
018 import org.kuali.rice.kns.web.ui.Field;
019 import org.kuali.rice.krad.datadictionary.mask.MaskFormatter;
020
021 import java.util.HashMap;
022 import java.util.Map;
023 import java.util.Set;
024
025 /**
026 * @deprecated Only used in KNS classes, use KRAD.
027 */
028 @Deprecated
029 public class BusinessObjectRestrictionsBase implements
030 BusinessObjectRestrictions {
031 private Map<String, MaskFormatter> partiallyMaskedFields;
032 private Map<String, MaskFormatter> fullyMaskedFields;
033
034 protected Set<String> allRestrictedFields;
035
036 public BusinessObjectRestrictionsBase() {
037 clearAllRestrictions();
038 }
039
040 public boolean hasAnyFieldRestrictions() {
041 return !partiallyMaskedFields.isEmpty() || !fullyMaskedFields.isEmpty();
042 }
043
044 public boolean hasRestriction(String fieldName) {
045 return isPartiallyMaskedField(fieldName) || isFullyMaskedField(fieldName);
046 }
047
048 public void addFullyMaskedField(String fieldName,
049 MaskFormatter maskFormatter) {
050 fullyMaskedFields.put(fieldName, maskFormatter);
051 }
052
053 public void addPartiallyMaskedField(String fieldName,
054 MaskFormatter maskFormatter) {
055 partiallyMaskedFields.put(fieldName, maskFormatter);
056 }
057
058 /**
059 *
060 * This method returns the authorization setting for the given field name.
061 * If the field name is not restricted in any way, a default full-editable
062 * value is returned.
063 *
064 * @param fieldName
065 * - name of field to get authorization restrictions for.
066 * @return a populated FieldAuthorization class for this field
067 *
068 */
069 public FieldRestriction getFieldRestriction(String fieldName) {
070 if (hasRestriction(fieldName)) {
071 FieldRestriction fieldRestriction = null;
072 if (isPartiallyMaskedField(fieldName)) {
073 fieldRestriction = new FieldRestriction(fieldName,
074 Field.PARTIALLY_MASKED);
075 fieldRestriction.setMaskFormatter(partiallyMaskedFields
076 .get(normalizeFieldName(fieldName)));
077 }
078 if (isFullyMaskedField(fieldName)) {
079 fieldRestriction = new FieldRestriction(fieldName, Field.MASKED);
080 fieldRestriction.setMaskFormatter(fullyMaskedFields
081 .get(normalizeFieldName(fieldName)));
082 }
083 return fieldRestriction;
084 } else {
085 return new FieldRestriction(fieldName, Field.EDITABLE);
086 }
087 }
088
089 public void clearAllRestrictions() {
090 partiallyMaskedFields = new HashMap<String, MaskFormatter>();
091 fullyMaskedFields = new HashMap<String, MaskFormatter>();
092 allRestrictedFields = null;
093 }
094
095
096 /**
097 * This method is used to convert field names on forms into a format that's compatible with field names
098 * that are registered with a restriction. The base implementation of this method just returns the string.
099 *
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 }