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