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