001 /** 002 * Copyright 2005-2013 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.krad.datadictionary; 017 018 import org.kuali.rice.krad.datadictionary.exception.AttributeValidationException; 019 import org.kuali.rice.krad.datadictionary.mask.MaskFormatter; 020 import org.kuali.rice.krad.datadictionary.parse.BeanTag; 021 import org.kuali.rice.krad.datadictionary.parse.BeanTagAttribute; 022 import org.kuali.rice.krad.datadictionary.uif.UifDictionaryBeanBase; 023 import org.kuali.rice.krad.datadictionary.validator.ValidationTrace; 024 025 /** 026 * Defines a set of restrictions that are possible on an attribute 027 * 028 * @author Kuali Rice Team (rice.collab@kuali.org) 029 */ 030 @BeanTag(name = "attributeSecurity-bean") 031 public class AttributeSecurity extends UifDictionaryBeanBase { 032 private static final long serialVersionUID = -7923499408946975318L; 033 034 private boolean readOnly = false; 035 private boolean hide = false; 036 private boolean mask = false; 037 private boolean partialMask = false; 038 039 private MaskFormatter partialMaskFormatter; 040 private MaskFormatter maskFormatter; 041 042 /** 043 * @return the readOnly 044 */ 045 @BeanTagAttribute(name = "readOnly") 046 public boolean isReadOnly() { 047 return this.readOnly; 048 } 049 050 /** 051 * @param readOnly the readOnly to set 052 */ 053 public void setReadOnly(boolean readOnly) { 054 this.readOnly = readOnly; 055 } 056 057 /** 058 * @return the hide 059 */ 060 @BeanTagAttribute(name = "hide") 061 public boolean isHide() { 062 return this.hide; 063 } 064 065 /** 066 * @param hide the hide to set 067 */ 068 public void setHide(boolean hide) { 069 this.hide = hide; 070 } 071 072 /** 073 * @return the mask 074 */ 075 @BeanTagAttribute(name = "mask") 076 public boolean isMask() { 077 return this.mask; 078 } 079 080 /** 081 * @param mask the mask to set 082 */ 083 public void setMask(boolean mask) { 084 this.mask = mask; 085 } 086 087 /** 088 * @return the partialMask 089 */ 090 @BeanTagAttribute(name = "partialMask") 091 public boolean isPartialMask() { 092 return this.partialMask; 093 } 094 095 /** 096 * @param partialMask the partialMask to set 097 */ 098 public void setPartialMask(boolean partialMask) { 099 this.partialMask = partialMask; 100 } 101 102 /** 103 * @return the maskFormatter 104 */ 105 @BeanTagAttribute(name = "maskFormatter", type = BeanTagAttribute.AttributeType.SINGLEBEAN) 106 public MaskFormatter getMaskFormatter() { 107 return this.maskFormatter; 108 } 109 110 /** 111 * @param maskFormatter the maskFormatter to set 112 */ 113 public void setMaskFormatter(MaskFormatter maskFormatter) { 114 this.maskFormatter = maskFormatter; 115 } 116 117 /** 118 * @return the partialMaskFormatter 119 */ 120 @BeanTagAttribute(name = "partialMaskFormatter", type = BeanTagAttribute.AttributeType.SINGLEBEAN) 121 public MaskFormatter getPartialMaskFormatter() { 122 return this.partialMaskFormatter; 123 } 124 125 /** 126 * @param partialMaskFormatter the partialMaskFormatter to set 127 */ 128 public void setPartialMaskFormatter(MaskFormatter partialMaskFormatter) { 129 this.partialMaskFormatter = partialMaskFormatter; 130 } 131 132 /** 133 * This overridden method ... 134 * 135 * @see org.kuali.rice.krad.datadictionary.DataDictionaryDefinition#completeValidation(java.lang.Class, 136 * java.lang.Class) 137 */ 138 public void completeValidation(Class rootBusinessObjectClass, Class otherBusinessObjectClass) { 139 140 if (mask && maskFormatter == null) { 141 throw new AttributeValidationException("MaskFormatter is required"); 142 } 143 if (partialMask && partialMaskFormatter == null) { 144 throw new AttributeValidationException("PartialMaskFormatter is required"); 145 } 146 } 147 148 /** 149 * Directly validate simple fields 150 * 151 * @see org.kuali.rice.krad.datadictionary.DataDictionaryEntry#completeValidation(org.kuali.rice.krad.datadictionary.validator.ValidationTrace) 152 */ 153 public void completeValidation(Class rootBusinessObjectClass, Class otherBusinessObjectClass, 154 ValidationTrace tracer) { 155 tracer.addBean(this.getClass().getSimpleName(), ValidationTrace.NO_BEAN_ID); 156 157 if (mask && maskFormatter == null) { 158 String currentValues[] = {"mask = " + mask, "maskFormatter = " + maskFormatter}; 159 tracer.createError("MaskFormatter is required", currentValues); 160 } 161 if (partialMask && partialMaskFormatter == null) { 162 String currentValues[] = {"partialMask = " + partialMask, "partialMaskFormatter = " + partialMaskFormatter}; 163 tracer.createError("PartialMaskFormatter is required", currentValues); 164 } 165 166 } 167 168 /** 169 * Returns whether any of the restrictions defined in this class are true. 170 */ 171 public boolean hasAnyRestriction() { 172 return readOnly || mask || partialMask || hide; 173 } 174 175 /** 176 * Returns whether any of the restrictions defined in this class indicate that the attribute value potentially 177 * needs 178 * to be not shown to the user (i.e. masked, partial mask, hide). Note that readonly does not fall in this 179 * category. 180 * 181 * @return 182 */ 183 public boolean hasRestrictionThatRemovesValueFromUI() { 184 return mask || partialMask || hide; 185 } 186 }