1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.student.r1.common.assembly.data;
17
18 import java.io.Serializable;
19 import java.util.ArrayList;
20 import java.util.HashMap;
21 import java.util.LinkedHashMap;
22 import java.util.List;
23 import java.util.Map;
24 import java.util.Map.Entry;
25
26 public class Metadata implements Serializable {
27
28 private static final long serialVersionUID = 1L;
29
30 public enum WriteAccess {
31 ON_CREATE,
32 ALWAYS, NEVER, WHEN_NULL, REQUIRED
33 }
34
35 private String name;
36 private String labelKey;
37 private WriteAccess writeAccess;
38
39 private boolean canUnmask = false;
40 private boolean canView = true;
41 private boolean canEdit = true;
42 private boolean dynamic = false;
43
44 protected String partialMaskFormatter;
45 protected String maskFormatter;
46
47 private boolean onChangeRefreshMetadata;
48
49 private Data.DataType dataType;
50
51 private Data.Value defaultValue;
52
53 private String defaultValuePath;
54
55
56
57 private List<ConstraintMetadata> constraints;
58
59 private LookupMetadata initialLookup;
60
61 private String lookupContextPath;
62
63 private List<LookupMetadata> additionalLookups;
64
65 private Map<String, Metadata> childProperties;
66
67 public Metadata() {
68
69 }
70
71
72
73
74
75
76
77 public Metadata(Metadata toClone) {
78 this.additionalLookups = toClone.additionalLookups;
79 this.canEdit = toClone.canEdit;
80 this.canUnmask = toClone.canUnmask;
81 this.canView = toClone.canView;
82 if(toClone.childProperties != null) {
83 this.childProperties = new HashMap<String, Metadata>();
84 for(Map.Entry<String, Metadata> childProperty : toClone.childProperties.entrySet()) {
85 this.childProperties.put(childProperty.getKey(), new Metadata(childProperty.getValue()));
86 }
87
88 }
89 this.constraints = toClone.constraints;
90 this.dataType = toClone.dataType;
91 this.defaultValue = toClone.defaultValue;
92 this.defaultValuePath = toClone.defaultValuePath;
93 this.dynamic = toClone.dynamic;
94 this.initialLookup = toClone.initialLookup;
95 this.labelKey = toClone.labelKey;
96 this.lookupContextPath = toClone.lookupContextPath;
97 this.maskFormatter = toClone.maskFormatter;
98 this.name = toClone.name;
99 this.onChangeRefreshMetadata = toClone.onChangeRefreshMetadata;
100 this.partialMaskFormatter = toClone.partialMaskFormatter;
101 this.writeAccess = toClone.writeAccess;
102 }
103
104 @Override
105 public String toString() {
106 StringBuilder sb = new StringBuilder();
107 _toString(sb);
108 return sb.toString();
109 }
110
111 protected void _toString(StringBuilder sb) {
112 Data.DataType type = (null == dataType) ? Data.DataType.DATA : dataType;
113 sb.append("type: " + type.toString());
114 sb.append(", canEdit: " + canEdit);
115 sb.append(", canView: " + canView);
116 sb.append(", defaultValue: ");
117 sb.append(null == defaultValue ? "null" : defaultValue.toString());
118 sb.append(", constraints: {");
119 if (null != constraints) {
120 for (ConstraintMetadata constraint : constraints) {
121 sb.append(constraint.toString());
122 }
123 }
124 sb.append("}");
125 sb.append(", Properties: {");
126 if (null != childProperties) {
127 for (Entry<String, Metadata> e : childProperties.entrySet()) {
128 sb.append("(");
129 sb.append(e.getKey());
130 sb.append(" = ");
131 Metadata m = e.getValue();
132 if (m == null) {
133 sb.append("null");
134 } else {
135 m._toString(sb);
136 }
137 sb.append(");");
138 }
139 }
140 sb.append("}");
141
142 }
143
144 public List<ConstraintMetadata> getConstraints() {
145 if (constraints == null) {
146 constraints = new ArrayList<ConstraintMetadata>();
147 }
148 return constraints;
149 }
150
151 public void setConstraints(List<ConstraintMetadata> constraints) {
152 this.constraints = constraints;
153 }
154
155
156
157
158
159
160 public void setNonServerConstraints(List<ConstraintMetadata> constraints) {
161 if (constraints != null){
162 List<ConstraintMetadata> metadataConstraints = new ArrayList<ConstraintMetadata>();
163 for (ConstraintMetadata constraint:constraints){
164 if (!"single".equals(constraint.getId()) &&
165 !"optional".equals(constraint.getId()) &&
166 !constraint.isServerSide()){
167 metadataConstraints.add(constraint);
168 }
169 }
170 this.constraints = metadataConstraints;
171 }
172 }
173
174 public Data.DataType getDataType() {
175 return dataType;
176 }
177
178 public void setDataType(Data.DataType dataType) {
179 this.dataType = dataType;
180 }
181
182 public Data.Value getDefaultValue() {
183 return defaultValue;
184 }
185
186 public void setDefaultValue(Data.Value defaultValue) {
187 this.defaultValue = defaultValue;
188 }
189
190 public String getDefaultValuePath() {
191 return defaultValuePath;
192 }
193
194 public void setDefaultValuePath(String defaultValuePath) {
195 this.defaultValuePath = defaultValuePath;
196 }
197
198 public LookupMetadata getInitialLookup() {
199 return initialLookup;
200 }
201
202 public void setInitialLookup(LookupMetadata initialLookup) {
203 this.initialLookup = initialLookup;
204 }
205
206 public String getLookupContextPath() {
207 return lookupContextPath;
208 }
209
210 public void setLookupContextPath(String lookupContextPath) {
211 this.lookupContextPath = lookupContextPath;
212 }
213
214 public List<LookupMetadata> getAdditionalLookups() {
215 if (additionalLookups == null) {
216 additionalLookups = new ArrayList<LookupMetadata>();
217 }
218 return additionalLookups;
219 }
220
221 public void setAdditionalLookups(List<LookupMetadata> additionalLookups) {
222 this.additionalLookups = additionalLookups;
223 }
224
225 public Map<String, Metadata> getProperties() {
226 if (childProperties == null) {
227 childProperties = new LinkedHashMap<String, Metadata>();
228 }
229 return childProperties;
230 }
231
232 public void setProperties(Map<String, Metadata> properties) {
233 this.childProperties = properties;
234 }
235
236 public WriteAccess getWriteAccess() {
237 return writeAccess;
238 }
239
240 public void setWriteAccess(WriteAccess writeAccess) {
241 this.writeAccess = writeAccess;
242 }
243
244
245 public boolean isOnChangeRefreshMetadata() {
246 return onChangeRefreshMetadata;
247 }
248
249 public void setOnChangeRefreshMetadata(boolean onChangeRefereshMetadata) {
250 this.onChangeRefreshMetadata = onChangeRefereshMetadata;
251 }
252
253 public boolean isCanUnmask() {
254 return canUnmask;
255 }
256
257 public void setCanUnmask(boolean canUnmask) {
258 this.canUnmask = canUnmask;
259 }
260
261 public boolean isCanView() {
262 return canView;
263 }
264
265 public void setCanView(boolean canView) {
266 this.canView = canView;
267 }
268
269 public boolean isCanEdit() {
270 return canEdit;
271 }
272
273 public void setCanEdit(boolean canEdit) {
274 this.canEdit = canEdit;
275 }
276
277 public String getName() {
278 return name;
279 }
280
281 public void setName(String name) {
282 this.name = name;
283 }
284
285 public boolean isDynamic() {
286 return dynamic;
287 }
288
289 public void setDynamic(boolean dynamic) {
290 this.dynamic = dynamic;
291 }
292
293 public String getLabelKey() {
294 return labelKey;
295 }
296
297 public void setLabelKey(String labelKey) {
298 this.labelKey = labelKey;
299 }
300
301 public String getPartialMaskFormatter() {
302 return partialMaskFormatter;
303 }
304
305 public void setPartialMaskFormatter(String partialMaskFormatter) {
306 this.partialMaskFormatter = partialMaskFormatter;
307 }
308
309 public String getMaskFormatter() {
310 return maskFormatter;
311 }
312
313 public void setMaskFormatter(String maskFormatter) {
314 this.maskFormatter = maskFormatter;
315 }
316 }