1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
package org.kuali.student.common.assembly.dictionary; |
16 | |
|
17 | |
import java.util.ArrayList; |
18 | |
import java.util.Collections; |
19 | |
import java.util.List; |
20 | |
import java.util.Set; |
21 | |
|
22 | |
import org.kuali.student.common.assembly.data.ConstraintMetadata; |
23 | |
import org.kuali.student.common.assembly.data.Data; |
24 | |
import org.kuali.student.common.assembly.data.LookupMetadata; |
25 | |
import org.kuali.student.common.assembly.data.LookupParamMetadata; |
26 | |
import org.kuali.student.common.assembly.data.Metadata; |
27 | |
import org.kuali.student.common.assembly.data.MetadataInterrogator; |
28 | |
|
29 | |
public class MetadataFormatter { |
30 | |
|
31 | 4 | private StringBuilder builder = new StringBuilder(5000); |
32 | |
private Metadata structureMetadata; |
33 | |
private String type; |
34 | 4 | private String rowSeperator = "\n"; |
35 | 4 | private String colSeperator = "|"; |
36 | |
private String structureName; |
37 | |
private int level; |
38 | |
|
39 | |
private Set<Metadata> structuresAlreadyProcessed; |
40 | |
private MetadataFormatter parent; |
41 | |
|
42 | |
public MetadataFormatter(String structureName, Metadata structureMetadata, |
43 | |
String type, MetadataFormatter parent, |
44 | 4 | Set<Metadata> structuresAlreadyProcessed, int level) { |
45 | 4 | this.structureName = structureName; |
46 | 4 | this.structureMetadata = structureMetadata; |
47 | 4 | this.type = type; |
48 | 4 | this.parent = parent; |
49 | 4 | this.structuresAlreadyProcessed = structuresAlreadyProcessed; |
50 | 4 | this.level = level; |
51 | 4 | } |
52 | |
|
53 | |
public String getStructureName() { |
54 | 0 | return structureName; |
55 | |
} |
56 | |
|
57 | |
public MetadataFormatter getParent() { |
58 | 0 | return parent; |
59 | |
} |
60 | |
|
61 | |
public String getRowSeperator() { |
62 | 0 | return rowSeperator; |
63 | |
} |
64 | |
|
65 | |
public void setRowSeperator(String rowSeperator) { |
66 | 0 | this.rowSeperator = rowSeperator; |
67 | 0 | } |
68 | |
|
69 | |
public String getColSeparator() { |
70 | 0 | return colSeperator; |
71 | |
} |
72 | |
|
73 | |
public void setColSeparator(String separator) { |
74 | 0 | this.colSeperator = separator; |
75 | 0 | } |
76 | |
|
77 | |
private String pad(String str, int size) { |
78 | 132 | StringBuilder padStr = new StringBuilder(size); |
79 | 132 | padStr.append(str); |
80 | 1758 | while (padStr.length() < size) { |
81 | 1626 | padStr.append(' '); |
82 | |
} |
83 | 132 | return padStr.toString(); |
84 | |
} |
85 | |
|
86 | |
public String formatForWiki() { |
87 | 4 | if (!this.structuresAlreadyProcessed.add(structureMetadata)) { |
88 | 0 | return ""; |
89 | |
} |
90 | 4 | if (level == 1) { |
91 | 4 | builder.append(rowSeperator); |
92 | |
|
93 | |
|
94 | 4 | builder.append(rowSeperator); |
95 | 4 | String header = "h1. " + this.calcSimpleName(structureName); |
96 | 4 | if (type != null) { |
97 | 2 | header = "h2. " + type; |
98 | |
} |
99 | 4 | builder.append(header); |
100 | 4 | builder.append("{anchor:" + structureName + "}"); |
101 | 4 | builder.append(rowSeperator); |
102 | 4 | builder.append("The object key is " + structureName); |
103 | 4 | builder.append(rowSeperator); |
104 | 4 | builder.append("The type is " + type); |
105 | 4 | builder.append(rowSeperator); |
106 | 4 | builder.append(colSeperator); |
107 | 4 | builder.append(colSeperator); |
108 | 4 | builder.append("Field"); |
109 | 4 | builder.append(colSeperator); |
110 | 4 | builder.append(colSeperator); |
111 | 4 | builder.append("Required?"); |
112 | 4 | builder.append(colSeperator); |
113 | 4 | builder.append(colSeperator); |
114 | 4 | builder.append("DataType"); |
115 | 4 | builder.append(colSeperator); |
116 | 4 | builder.append(colSeperator); |
117 | 4 | builder.append("Length"); |
118 | 4 | builder.append(colSeperator); |
119 | 4 | builder.append(colSeperator); |
120 | 4 | builder.append("Dynamic"); |
121 | 4 | builder.append(colSeperator); |
122 | 4 | builder.append(colSeperator); |
123 | 4 | builder.append("Default"); |
124 | 4 | builder.append(colSeperator); |
125 | 4 | builder.append(colSeperator); |
126 | 4 | builder.append("Repeats?"); |
127 | 4 | builder.append(colSeperator); |
128 | 4 | builder.append(colSeperator); |
129 | 4 | builder.append("Valid Characters"); |
130 | 4 | builder.append(colSeperator); |
131 | 4 | builder.append(colSeperator); |
132 | 4 | builder.append("Lookup Widget"); |
133 | 4 | builder.append(colSeperator); |
134 | 4 | builder.append(colSeperator); |
135 | 4 | builder.append("Lookup"); |
136 | 4 | builder.append(colSeperator); |
137 | 4 | builder.append(colSeperator); |
138 | 4 | builder.append(rowSeperator); |
139 | |
} |
140 | |
|
141 | 4 | List<String> keys = new ArrayList<String>(); |
142 | 4 | keys.addAll(structureMetadata.getProperties().keySet()); |
143 | 4 | Collections.sort(keys); |
144 | 4 | for (String key : keys) { |
145 | 22 | if (key.equalsIgnoreCase ("_runtimeData")) |
146 | |
{ |
147 | 0 | continue; |
148 | |
} |
149 | 22 | Metadata fieldMeta = structureMetadata.getProperties().get(key); |
150 | 22 | builder.append(colSeperator); |
151 | 22 | builder.append(calcFieldInfo (key, fieldMeta)); |
152 | 22 | builder.append(colSeperator); |
153 | 22 | builder.append(pad(calcRequired(fieldMeta), 10)); |
154 | 22 | builder.append(colSeperator); |
155 | 22 | builder.append(pad(calcDataType(fieldMeta), 25)); |
156 | 22 | builder.append(colSeperator); |
157 | 22 | builder.append(pad(calcLength(fieldMeta), 15)); |
158 | 22 | builder.append(colSeperator); |
159 | 22 | builder.append(pad(calcDynamic(fieldMeta), 7)); |
160 | 22 | builder.append(colSeperator); |
161 | 22 | builder.append(pad(calcDefaultValue(fieldMeta), 15)); |
162 | 22 | builder.append(colSeperator); |
163 | 22 | builder.append(calcRepeating(fieldMeta)); |
164 | 22 | builder.append(colSeperator); |
165 | 22 | builder.append(calcValidChars(fieldMeta)); |
166 | 22 | builder.append(colSeperator); |
167 | 22 | builder.append(calcWidget(fieldMeta)); |
168 | 22 | builder.append(colSeperator); |
169 | 22 | builder.append(calcLookup(fieldMeta)); |
170 | 22 | builder.append(colSeperator); |
171 | 22 | builder.append(rowSeperator); |
172 | 22 | if (fieldMeta.getDataType().equals(Data.DataType.DATA) |
173 | |
|| fieldMeta.getDataType().equals(Data.DataType.LIST)) { |
174 | 0 | if (fieldMeta.getProperties() == null) { |
175 | 0 | throw new IllegalArgumentException( |
176 | |
fieldMeta.getName() |
177 | |
+ " is DATA but does not have a sub-structure defined"); |
178 | |
} |
179 | 0 | MetadataFormatter formatter = new MetadataFormatter(key, |
180 | |
fieldMeta, null, this, structuresAlreadyProcessed, |
181 | |
level + 1); |
182 | 0 | builder.append(formatter.formatForWiki()); |
183 | |
} |
184 | 22 | } |
185 | |
|
186 | 4 | return builder.toString(); |
187 | |
} |
188 | |
|
189 | |
private String calcDataType(Metadata fieldMeta) { |
190 | 22 | if (fieldMeta.getDataType().equals(Data.DataType.LIST)) { |
191 | 0 | StringBuilder type = new StringBuilder(); |
192 | 0 | type.append("LIST of "); |
193 | 0 | String comma = ""; |
194 | 0 | for (String key : fieldMeta.getProperties().keySet()) { |
195 | 0 | type.append(comma); |
196 | 0 | type.append(fieldMeta.getProperties().get(key).getDataType() |
197 | |
.toString()); |
198 | 0 | comma = ", "; |
199 | |
} |
200 | 0 | return type.toString(); |
201 | |
} |
202 | 22 | return fieldMeta.getDataType().toString(); |
203 | |
} |
204 | |
|
205 | |
private String calcDefaultValue(Metadata fieldMeta) { |
206 | 22 | if (fieldMeta.getDefaultValue() != null) { |
207 | 0 | return fieldMeta.getDefaultValue().toString(); |
208 | |
} |
209 | 22 | return " "; |
210 | |
} |
211 | |
|
212 | |
private String calcDynamic(Metadata meta) { |
213 | 22 | if (meta.isDynamic()) { |
214 | 0 | return "dynamic"; |
215 | |
} |
216 | 22 | return " "; |
217 | |
} |
218 | |
|
219 | |
private String calcFieldInfo (String key, Metadata fieldMeta) |
220 | |
{ |
221 | 22 | StringBuilder bldr = new StringBuilder (40); |
222 | 22 | bldr.append (pad(calcFullyQualifiedFieldName(key), 30)); |
223 | 22 | if (fieldMeta.getLabelKey () != null) |
224 | |
{ |
225 | 0 | bldr.append ("\\\\\n"); |
226 | 0 | bldr.append ("Label: "); |
227 | 0 | bldr.append (fieldMeta.getLabelKey ()); |
228 | |
} |
229 | 22 | return bldr.toString (); |
230 | |
} |
231 | |
|
232 | |
public String calcFullyQualifiedFieldName(String fieldName) { |
233 | 22 | if (parent == null) { |
234 | 22 | return escapeWiki(fieldName); |
235 | |
} |
236 | 0 | return parent.calcFullyQualifiedFieldName(structureName) + "." |
237 | |
+ escapeWiki(fieldName); |
238 | |
} |
239 | |
|
240 | |
private String calcSimpleName(String name) { |
241 | 4 | if (name.lastIndexOf(".") != -1) { |
242 | 0 | name = name.substring(name.lastIndexOf(".") + 1); |
243 | |
} |
244 | 4 | return name; |
245 | |
} |
246 | |
|
247 | |
private String calcNotSoSimpleName(String name) { |
248 | 0 | if (name.lastIndexOf(".") == -1) { |
249 | 0 | return name; |
250 | |
} |
251 | 0 | String simpleName = calcSimpleName(name); |
252 | 0 | String fieldName = calcSimpleName(name.substring(0, name.length() |
253 | |
- simpleName.length() - 1)); |
254 | 0 | return fieldName + "." + simpleName; |
255 | |
} |
256 | |
|
257 | |
private String calcRequired(Metadata fieldMeta) { |
258 | 22 | for (ConstraintMetadata cons : fieldMeta.getConstraints()) { |
259 | 22 | if (cons.getMaxOccurs() != null) { |
260 | 9 | if (cons.getMaxOccurs() == 0) { |
261 | 0 | return "NOT USED"; |
262 | |
} |
263 | |
} |
264 | |
|
265 | 22 | if (cons.getMinOccurs() != null) { |
266 | 20 | if (cons.getMinOccurs() >= 1) { |
267 | 14 | return "required"; |
268 | |
} |
269 | |
} |
270 | |
} |
271 | 8 | return " "; |
272 | |
|
273 | |
} |
274 | |
|
275 | |
private static final String LINK_TO_DEFINITIONS = "KULSTG:Formatted View of Base Dictionary#Valid Character Definitions"; |
276 | |
|
277 | |
private String calcValidChars(Metadata fieldMeta) { |
278 | 22 | for (ConstraintMetadata cons : fieldMeta.getConstraints()) { |
279 | 22 | if (cons.getValidChars() == null) { |
280 | 15 | continue; |
281 | |
} |
282 | 7 | String validChars = escapeWiki(cons.getValidChars()); |
283 | 7 | String descr = "[" + "See" + "|" + LINK_TO_DEFINITIONS + "]" |
284 | |
+ "\\\\\n" + validChars; |
285 | 7 | return descr; |
286 | |
} |
287 | 15 | return " "; |
288 | |
} |
289 | |
|
290 | |
private String escapeWiki(String str) { |
291 | 29 | StringBuilder bldr = new StringBuilder(str.length()); |
292 | 29 | boolean precededByBackSlash = false; |
293 | 242 | for (int i = 0; i < str.length(); i++) { |
294 | 213 | char c = str.charAt(i); |
295 | 213 | switch (c) { |
296 | |
case '\\': |
297 | |
case '[': |
298 | |
case '*': |
299 | |
case ']': |
300 | |
case '|': |
301 | 21 | if (!precededByBackSlash) { |
302 | 21 | bldr.append('\\'); |
303 | |
} |
304 | |
break; |
305 | |
default: |
306 | |
break; |
307 | |
} |
308 | 213 | bldr.append(c); |
309 | 213 | if (c == '\\') { |
310 | 0 | precededByBackSlash = true; |
311 | |
} else { |
312 | 213 | precededByBackSlash = false; |
313 | |
} |
314 | |
} |
315 | 29 | return bldr.toString(); |
316 | |
} |
317 | |
|
318 | |
private String calcWidget(Metadata fieldMeta) { |
319 | 22 | StringBuilder bldr = new StringBuilder(); |
320 | 22 | String comma = ""; |
321 | 22 | if (!fieldMeta.isCanEdit()) { |
322 | 2 | bldr.append(comma); |
323 | 2 | bldr.append("not editable"); |
324 | 2 | comma = ", "; |
325 | |
} |
326 | 22 | if (!fieldMeta.isCanView()) { |
327 | 0 | bldr.append(comma); |
328 | 0 | bldr.append("not viewable"); |
329 | 0 | comma = ", "; |
330 | |
} |
331 | 22 | if (!fieldMeta.isCanUnmask()) { |
332 | 1 | bldr.append(comma); |
333 | 1 | bldr.append("Not unmaskable"); |
334 | 1 | comma = ", "; |
335 | |
} |
336 | 22 | if (fieldMeta.getInitialLookup() != null) { |
337 | 2 | bldr.append(comma); |
338 | 2 | bldr.append(fieldMeta.getInitialLookup().getWidget()); |
339 | 2 | comma = ", "; |
340 | |
} |
341 | 22 | if (bldr.length() == 0) { |
342 | 18 | bldr.append(" "); |
343 | |
} |
344 | 22 | return bldr.toString(); |
345 | |
} |
346 | |
|
347 | |
private String calcLookup(Metadata fieldMeta) { |
348 | 22 | StringBuilder bldr = new StringBuilder (); |
349 | 22 | if (fieldMeta.getInitialLookup() != null) { |
350 | 2 | bldr.append (calcLookup (fieldMeta.getInitialLookup ())); |
351 | |
} |
352 | |
|
353 | 22 | if (fieldMeta.getAdditionalLookups () != null) { |
354 | 22 | if (fieldMeta.getAdditionalLookups ().size () > 0) { |
355 | 0 | if (fieldMeta.getInitialLookup() == null) { |
356 | 0 | bldr.append ("No initial lookup but..."); |
357 | |
} |
358 | 0 | bldr.append("\\\\"); |
359 | 0 | bldr.append("\n"); |
360 | 0 | bldr.append("\\\\"); |
361 | 0 | bldr.append("\n"); |
362 | 0 | bldr.append ("Additional Lookups:"); |
363 | 0 | bldr.append("\\\\"); |
364 | 0 | bldr.append("\n"); |
365 | |
} |
366 | 22 | for (LookupMetadata lm : fieldMeta.getAdditionalLookups ()) { |
367 | 0 | bldr.append("\\\\"); |
368 | 0 | bldr.append("\n"); |
369 | 0 | bldr.append (calcLookup (lm)); |
370 | 0 | bldr.append("\\\\"); |
371 | 0 | bldr.append("\n"); |
372 | |
} |
373 | |
} |
374 | 22 | if (bldr.length () == 0) |
375 | |
{ |
376 | 20 | bldr.append (" "); |
377 | |
} |
378 | 22 | return bldr.toString (); |
379 | |
} |
380 | |
|
381 | |
private String calcLookup(LookupMetadata lm) { |
382 | 2 | StringBuilder bldr = new StringBuilder(); |
383 | 2 | bldr.append(lm.getId()); |
384 | |
|
385 | |
|
386 | |
|
387 | |
|
388 | 2 | bldr.append (" - "); |
389 | 2 | bldr.append (lm.getName()); |
390 | 2 | bldr.append (" " + lm.getWidget ()); |
391 | 2 | String and = " with option "; |
392 | 2 | if (lm.getWidgetOptions () != null) { |
393 | 0 | for (LookupMetadata.WidgetOption wo: lm.getWidgetOptions ().keySet ()) |
394 | |
{ |
395 | 0 | bldr.append (" and "); |
396 | 0 | bldr.append (wo); |
397 | 0 | bldr.append ("="); |
398 | 0 | bldr.append (lm.getWidgetOptions ().get (wo)); |
399 | |
} |
400 | |
} |
401 | 2 | and = ""; |
402 | 2 | bldr.append("\\\\\n"); |
403 | 2 | bldr.append("Implemented using search: "); |
404 | 2 | String searchPage = calcWikiSearchPage(lm.getSearchTypeId()); |
405 | 2 | bldr.append("[" + lm.getSearchTypeId() + "|" + searchPage + "#" |
406 | |
+ lm.getSearchTypeId() + "]"); |
407 | 2 | List<LookupParamMetadata> configuredParameters = filterConfiguredParams(lm |
408 | |
.getParams()); |
409 | 2 | if (configuredParameters.size() > 0) { |
410 | 2 | bldr.append("\\\\"); |
411 | 2 | bldr.append("\n"); |
412 | 2 | bldr.append(" where "); |
413 | 2 | and = ""; |
414 | 2 | for (LookupParamMetadata param : configuredParameters) { |
415 | 2 | bldr.append(and); |
416 | 2 | and = " and "; |
417 | 2 | bldr.append(param.getName()); |
418 | 2 | bldr.append (" (" + param.getDataType () + ") "); |
419 | 2 | bldr.append("="); |
420 | 2 | if (param.getDefaultValueString() != null) { |
421 | 2 | bldr.append(param.getDefaultValueString()); |
422 | |
} |
423 | 2 | if (param.getDefaultValueList() != null) { |
424 | 0 | String comma = ""; |
425 | 0 | for (String defValue : param.getDefaultValueList()) { |
426 | 0 | bldr.append(comma); |
427 | 0 | comma = ", "; |
428 | 0 | bldr.append(defValue); |
429 | |
} |
430 | 2 | } |
431 | |
} |
432 | |
} |
433 | 2 | List<LookupParamMetadata> userEnterableParameters = this.filterUserEnterableParams (lm |
434 | |
.getParams()); |
435 | 2 | if (userEnterableParameters.size() > 0) { |
436 | 0 | bldr.append("\\\\"); |
437 | 0 | bldr.append("\n"); |
438 | 0 | bldr.append(" and the user can enter: "); |
439 | 0 | for (LookupParamMetadata param : userEnterableParameters) { |
440 | 0 | bldr.append ("\\\\\n"); |
441 | 0 | bldr.append(param.getName()); |
442 | 0 | bldr.append (" (" + param.getDataType () + ")"); |
443 | 0 | if (param.getWidget () != null) { |
444 | 0 | bldr.append(" using widget "); |
445 | 0 | bldr.append (param.getWidget ()); |
446 | |
} |
447 | 0 | if (param.getDefaultValueString() != null) { |
448 | 0 | bldr.append("defaulted to " + param.getDefaultValueString()); |
449 | |
} |
450 | 0 | if (param.getDefaultValueList() != null) { |
451 | 0 | String comma = "defaulted to "; |
452 | 0 | for (String defValue : param.getDefaultValueList()) { |
453 | 0 | bldr.append(comma); |
454 | 0 | comma = ", "; |
455 | 0 | bldr.append(defValue); |
456 | |
} |
457 | |
} |
458 | 0 | if (param.getChildLookup () != null) |
459 | |
{ |
460 | 0 | bldr.append("\\\\"); |
461 | 0 | bldr.append("\n"); |
462 | 0 | bldr.append ("using a child lookup: "); |
463 | 0 | bldr.append("\\\\"); |
464 | 0 | bldr.append("\n"); |
465 | 0 | bldr.append (calcLookup (param.getChildLookup ())); |
466 | |
} |
467 | |
} |
468 | |
} |
469 | 2 | return bldr.toString(); |
470 | |
} |
471 | |
|
472 | |
private static final String PAGE_PREFIX = "Formatted View of "; |
473 | |
private static final String PAGE_SUFFIX = " Searches"; |
474 | |
|
475 | |
private String calcWikiSearchPage(String searchType) { |
476 | 2 | return PAGE_PREFIX + calcWikigPageAbbrev(searchType) + PAGE_SUFFIX; |
477 | |
} |
478 | |
|
479 | |
private String calcWikigPageAbbrev(String searchType) { |
480 | 2 | if (searchType == null) { |
481 | 0 | return null; |
482 | |
} |
483 | 2 | if (searchType.equals("enumeration.management.search")) { |
484 | 2 | return "EM"; |
485 | |
} |
486 | 0 | if (searchType.startsWith("lu.")) { |
487 | 0 | return "LU"; |
488 | |
} |
489 | 0 | if (searchType.startsWith("cluset.")) { |
490 | 0 | return "LU"; |
491 | |
} |
492 | 0 | if (searchType.startsWith("lo.")) { |
493 | 0 | return "LO"; |
494 | |
} |
495 | 0 | if (searchType.startsWith("lrc.")) { |
496 | 0 | return "LRC"; |
497 | |
} |
498 | 0 | if (searchType.startsWith("comment.")) { |
499 | 0 | return "Comment"; |
500 | |
} |
501 | 0 | if (searchType.startsWith("org.")) { |
502 | 0 | return "Organization"; |
503 | |
} |
504 | 0 | if (searchType.startsWith("atp.")) { |
505 | 0 | return "ATP"; |
506 | |
} |
507 | 0 | if (searchType.startsWith("person.")) { |
508 | 0 | return "Person"; |
509 | |
} |
510 | 0 | if (searchType.startsWith("proposal.")) { |
511 | 0 | return "Proposal"; |
512 | |
} |
513 | 0 | throw new IllegalArgumentException("Unknown type of search: " |
514 | |
+ searchType); |
515 | |
} |
516 | |
|
517 | |
private List<LookupParamMetadata> filterConfiguredParams( |
518 | |
List<LookupParamMetadata> params) { |
519 | 2 | List<LookupParamMetadata> list = new ArrayList<LookupParamMetadata>(); |
520 | 2 | if (params == null) { |
521 | 0 | return list; |
522 | |
} |
523 | 2 | if (params.size() == 0) { |
524 | 0 | return list; |
525 | |
} |
526 | 2 | for (LookupParamMetadata param : params) { |
527 | 10 | if (param.getDefaultValueString() != null) { |
528 | 2 | list.add(param); |
529 | 2 | continue; |
530 | |
} |
531 | 8 | if (param.getDefaultValueList() != null) { |
532 | 0 | list.add(param); |
533 | 0 | continue; |
534 | |
} |
535 | |
} |
536 | 2 | return list; |
537 | |
} |
538 | |
|
539 | |
private List<LookupParamMetadata> filterUserEnterableParams ( |
540 | |
List<LookupParamMetadata> params) { |
541 | 2 | List<LookupParamMetadata> list = new ArrayList<LookupParamMetadata>(); |
542 | 2 | if (params == null) { |
543 | 0 | return list; |
544 | |
} |
545 | 2 | if (params.size() == 0) { |
546 | 0 | return list; |
547 | |
} |
548 | 2 | for (LookupParamMetadata param : params) { |
549 | 10 | if (param.getWriteAccess () != null) { |
550 | 8 | if ( ! param.getWriteAccess ().equals (Metadata.WriteAccess.NEVER)) { |
551 | 0 | list.add(param); |
552 | 0 | continue; |
553 | |
} |
554 | |
} |
555 | |
} |
556 | 2 | return list; |
557 | |
} |
558 | |
|
559 | |
private String calcRepeating(Metadata fieldMeta) { |
560 | 22 | if (!fieldMeta.getDataType().equals(Data.DataType.LIST)) { |
561 | 22 | return " "; |
562 | |
} |
563 | |
|
564 | 0 | MetadataInterrogator mi = new MetadataInterrogator(fieldMeta); |
565 | 0 | if (mi.getSmallestMaxOccurs() == null) { |
566 | 0 | if (mi.getLargestMinOccurs() != null |
567 | |
&& mi.getLargestMinOccurs() > 1) { |
568 | 0 | return "repeating: minimum " + mi.getLargestMinOccurs() |
569 | |
+ " times"; |
570 | |
} |
571 | 0 | return "repeating: unlimited"; |
572 | |
} |
573 | 0 | if (mi.getSmallestMaxOccurs() == 0) { |
574 | 0 | return "NOT USED"; |
575 | |
} |
576 | 0 | if (mi.getSmallestMaxOccurs() == 1) { |
577 | 0 | return " "; |
578 | |
|
579 | |
} |
580 | |
|
581 | 0 | if (mi.getLargestMinOccurs() != null) { |
582 | 0 | if (mi.getLargestMinOccurs() > 1) { |
583 | 0 | return "repeating: " + mi.getLargestMinOccurs() + " to " |
584 | |
+ mi.getSmallestMaxOccurs() + " times"; |
585 | |
} |
586 | |
} |
587 | 0 | return "repeating: maximum " + mi.getSmallestMaxOccurs() + " times"; |
588 | |
} |
589 | |
|
590 | |
private String calcLength(Metadata fieldMeta) { |
591 | 22 | MetadataInterrogator mi = new MetadataInterrogator(fieldMeta); |
592 | 22 | if (mi.getSmallestMaxLength() != null) { |
593 | 19 | if (mi.getLargestMinLength() != null |
594 | |
&& mi.getLargestMinLength() != 0) { |
595 | 19 | if (mi.getSmallestMaxLength() == mi.getLargestMinLength()) { |
596 | 9 | return ("(must be " + mi.getSmallestMaxLength() + ")"); |
597 | |
} |
598 | 10 | return "(" + mi.getLargestMinLength() + " to " |
599 | |
+ mi.getSmallestMaxLength() + ")"; |
600 | |
} |
601 | 0 | return "(up to " + mi.getSmallestMaxLength() + ")"; |
602 | |
} |
603 | 3 | if (mi.getLargestMinLength() != null) { |
604 | 0 | return "(over " + mi.getLargestMinLength() + ")"; |
605 | |
} |
606 | 3 | return " "; |
607 | |
} |
608 | |
} |