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