1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krad.datadictionary;
17
18 import org.kuali.rice.krad.datadictionary.exception.AttributeValidationException;
19 import org.kuali.rice.krad.datadictionary.mask.MaskFormatter;
20 import org.kuali.rice.krad.datadictionary.parse.BeanTag;
21 import org.kuali.rice.krad.datadictionary.parse.BeanTagAttribute;
22 import org.kuali.rice.krad.datadictionary.uif.UifDictionaryBeanBase;
23 import org.kuali.rice.krad.datadictionary.validator.ValidationTrace;
24
25
26
27
28
29
30 @BeanTag(name = "attributeSecurity-bean")
31 public class AttributeSecurity extends UifDictionaryBeanBase {
32 private static final long serialVersionUID = -7923499408946975318L;
33
34 private boolean readOnly = false;
35 private boolean hide = false;
36 private boolean mask = false;
37 private boolean partialMask = false;
38
39 private MaskFormatter partialMaskFormatter;
40 private MaskFormatter maskFormatter;
41
42
43
44
45 @BeanTagAttribute(name = "readOnly")
46 public boolean isReadOnly() {
47 return this.readOnly;
48 }
49
50
51
52
53 public void setReadOnly(boolean readOnly) {
54 this.readOnly = readOnly;
55 }
56
57
58
59
60 @BeanTagAttribute(name = "hide")
61 public boolean isHide() {
62 return this.hide;
63 }
64
65
66
67
68 public void setHide(boolean hide) {
69 this.hide = hide;
70 }
71
72
73
74
75 @BeanTagAttribute(name = "mask")
76 public boolean isMask() {
77 return this.mask;
78 }
79
80
81
82
83 public void setMask(boolean mask) {
84 this.mask = mask;
85 }
86
87
88
89
90 @BeanTagAttribute(name = "partialMask")
91 public boolean isPartialMask() {
92 return this.partialMask;
93 }
94
95
96
97
98 public void setPartialMask(boolean partialMask) {
99 this.partialMask = partialMask;
100 }
101
102
103
104
105 @BeanTagAttribute(name = "maskFormatter", type = BeanTagAttribute.AttributeType.SINGLEBEAN)
106 public MaskFormatter getMaskFormatter() {
107 return this.maskFormatter;
108 }
109
110
111
112
113 public void setMaskFormatter(MaskFormatter maskFormatter) {
114 this.maskFormatter = maskFormatter;
115 }
116
117
118
119
120 @BeanTagAttribute(name = "partialMaskFormatter", type = BeanTagAttribute.AttributeType.SINGLEBEAN)
121 public MaskFormatter getPartialMaskFormatter() {
122 return this.partialMaskFormatter;
123 }
124
125
126
127
128 public void setPartialMaskFormatter(MaskFormatter partialMaskFormatter) {
129 this.partialMaskFormatter = partialMaskFormatter;
130 }
131
132
133
134
135
136
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
150
151
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
170
171 public boolean hasAnyRestriction() {
172 return readOnly || mask || partialMask || hide;
173 }
174
175
176
177
178
179
180
181
182
183 public boolean hasRestrictionThatRemovesValueFromUI() {
184 return mask || partialMask || hide;
185 }
186
187
188
189
190
191
192 public <T> T copy() {
193 T copiedClass = null;
194 try {
195 copiedClass = (T)this.getClass().newInstance();
196 }
197 catch(Exception exception) {
198 throw new RuntimeException();
199 }
200
201 copyProperties(copiedClass);
202
203 return copiedClass;
204 }
205
206
207
208
209
210 protected <T> void copyProperties(T component) {
211 super.copyProperties(component);
212 AttributeSecurity attributeSecurityCopy = ((AttributeSecurity)component);
213 attributeSecurityCopy.setHide(this.hide);
214 attributeSecurityCopy.setMask(this.mask);
215 attributeSecurityCopy.setPartialMask(this.partialMask);
216 attributeSecurityCopy.setReadOnly(this.readOnly);
217 attributeSecurityCopy.setMaskFormatter(this.maskFormatter);
218 attributeSecurityCopy.setPartialMaskFormatter(this.partialMaskFormatter);
219 }
220 }