View Javadoc
1   /**
2    * Copyright 2005-2014 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.krad.datadictionary;
17  
18  import org.kuali.rice.krad.datadictionary.mask.MaskFormatter;
19  import org.kuali.rice.krad.datadictionary.parse.BeanTag;
20  import org.kuali.rice.krad.datadictionary.parse.BeanTagAttribute;
21  import org.kuali.rice.krad.datadictionary.uif.UifDictionaryBeanBase;
22  import org.kuali.rice.krad.datadictionary.validator.ValidationTrace;
23  
24  /**
25   * Defines a set of restrictions that are possible on an attribute
26   *
27   * @author Kuali Rice Team (rice.collab@kuali.org)
28   */
29  @BeanTag(name = "attributeSecurity")
30  public class AttributeSecurity extends UifDictionaryBeanBase {
31      private static final long serialVersionUID = -7923499408946975318L;
32  
33      private boolean readOnly = false;
34      private boolean hide = false;
35      private boolean mask = false;
36      private boolean partialMask = false;
37  
38      private MaskFormatter partialMaskFormatter;
39      private MaskFormatter maskFormatter;
40  
41      /**
42       * @return the readOnly
43       */
44      @BeanTagAttribute(name = "readOnly")
45      public boolean isReadOnly() {
46          return this.readOnly;
47      }
48  
49      /**
50       * @param readOnly the readOnly to set
51       */
52      public void setReadOnly(boolean readOnly) {
53          this.readOnly = readOnly;
54      }
55  
56      /**
57       * @return the hide
58       */
59      @BeanTagAttribute(name = "hide")
60      public boolean isHide() {
61          return this.hide;
62      }
63  
64      /**
65       * @param hide the hide to set
66       */
67      public void setHide(boolean hide) {
68          this.hide = hide;
69      }
70  
71      /**
72       * @return the mask
73       */
74      @BeanTagAttribute(name = "mask")
75      public boolean isMask() {
76          return this.mask;
77      }
78  
79      /**
80       * @param mask the mask to set
81       */
82      public void setMask(boolean mask) {
83          this.mask = mask;
84      }
85  
86      /**
87       * @return the partialMask
88       */
89      @BeanTagAttribute(name = "partialMask")
90      public boolean isPartialMask() {
91          return this.partialMask;
92      }
93  
94      /**
95       * @param partialMask the partialMask to set
96       */
97      public void setPartialMask(boolean partialMask) {
98          this.partialMask = partialMask;
99      }
100 
101     /**
102      * @return the maskFormatter
103      */
104     @BeanTagAttribute(name = "maskFormatter", type = BeanTagAttribute.AttributeType.SINGLEBEAN)
105     public MaskFormatter getMaskFormatter() {
106         return this.maskFormatter;
107     }
108 
109     /**
110      * @param maskFormatter the maskFormatter to set
111      */
112     public void setMaskFormatter(MaskFormatter maskFormatter) {
113         this.maskFormatter = maskFormatter;
114     }
115 
116     /**
117      * @return the partialMaskFormatter
118      */
119     @BeanTagAttribute(name = "partialMaskFormatter", type = BeanTagAttribute.AttributeType.SINGLEBEAN)
120     public MaskFormatter getPartialMaskFormatter() {
121         return this.partialMaskFormatter;
122     }
123 
124     /**
125      * @param partialMaskFormatter the partialMaskFormatter to set
126      */
127     public void setPartialMaskFormatter(MaskFormatter partialMaskFormatter) {
128         this.partialMaskFormatter = partialMaskFormatter;
129     }
130 
131     /**
132      * This overridden method ...
133      *
134      * @see org.kuali.rice.krad.datadictionary.DataDictionaryDefinition#completeValidation(java.lang.Class,
135      *      java.lang.Class)
136      */
137     public void completeValidation(Class rootBusinessObjectClass, Class otherBusinessObjectClass) {
138         completeValidation(rootBusinessObjectClass, otherBusinessObjectClass, new ValidationTrace());
139     }
140 
141     /**
142      * Directly validate simple fields
143      *
144      * @see org.kuali.rice.krad.datadictionary.DataDictionaryEntry#completeValidation(org.kuali.rice.krad.datadictionary.validator.ValidationTrace)
145      */
146     public void completeValidation(Class rootBusinessObjectClass, Class otherBusinessObjectClass,
147             ValidationTrace tracer) {
148         tracer.addBean(this.getClass().getSimpleName(), ValidationTrace.NO_BEAN_ID);
149 
150         if (mask && maskFormatter == null) {
151             String currentValues[] = {"mask = " + mask, "maskFormatter = " + maskFormatter};
152             tracer.createError("MaskFormatter is required", currentValues);
153         }
154         if (partialMask && partialMaskFormatter == null) {
155             String currentValues[] = {"partialMask = " + partialMask, "partialMaskFormatter = " + partialMaskFormatter};
156             tracer.createError("PartialMaskFormatter is required", currentValues);
157         }
158 
159     }
160 
161     /**
162      * Returns whether any of the restrictions defined in this class are true.
163      */
164     public boolean hasAnyRestriction() {
165         return readOnly || mask || partialMask || hide;
166     }
167 
168     /**
169      * Returns whether any of the restrictions defined in this class indicate that the attribute
170      * value potentially needs to be not shown to the user (i.e. masked, partial mask, hide). Note
171      * that readonly does not fall in this category.
172      * 
173      * @return true if the value should be hidden from the user
174      */
175     public boolean hasRestrictionThatRemovesValueFromUI() {
176         return mask || partialMask || hide;
177     }
178 
179     @Override
180     public String toString() {
181         StringBuilder builder = new StringBuilder();
182         builder.append("DataObjectAttributeSecurityBase [readOnly=").append(readOnly).append(", hide=").append(hide)
183                 .append(", mask=").append(mask).append(", partialMask=").append(partialMask).append(", ");
184         if (maskFormatter != null) {
185             builder.append("maskFormatter=").append(maskFormatter).append(", ");
186         }
187         if (partialMaskFormatter != null) {
188             builder.append("partialMaskFormatter=").append(partialMaskFormatter);
189         }
190         builder.append("]");
191         return builder.toString();
192     }
193 }