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