| 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 | 0 | private StringBuilder builder = new StringBuilder(5000); |
| 32 | |
private Metadata structureMetadata; |
| 33 | |
private String type; |
| 34 | 0 | private String rowSeperator = "\n"; |
| 35 | 0 | 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 | 0 | Set<Metadata> structuresAlreadyProcessed, int level) { |
| 45 | 0 | this.structureName = structureName; |
| 46 | 0 | this.structureMetadata = structureMetadata; |
| 47 | 0 | this.type = type; |
| 48 | 0 | this.parent = parent; |
| 49 | 0 | this.structuresAlreadyProcessed = structuresAlreadyProcessed; |
| 50 | 0 | this.level = level; |
| 51 | 0 | } |
| 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 | 0 | StringBuilder padStr = new StringBuilder(size); |
| 79 | 0 | padStr.append(str); |
| 80 | 0 | while (padStr.length() < size) { |
| 81 | 0 | padStr.append(' '); |
| 82 | |
} |
| 83 | 0 | return padStr.toString(); |
| 84 | |
} |
| 85 | |
|
| 86 | |
public String formatForWiki() { |
| 87 | 0 | if (!this.structuresAlreadyProcessed.add(structureMetadata)) { |
| 88 | 0 | return ""; |
| 89 | |
} |
| 90 | 0 | if (level == 1) { |
| 91 | 0 | builder.append(rowSeperator); |
| 92 | |
|
| 93 | |
|
| 94 | 0 | builder.append(rowSeperator); |
| 95 | 0 | String header = "h1. " + this.calcSimpleName(structureName); |
| 96 | 0 | if (type != null) { |
| 97 | 0 | header = "h2. " + type; |
| 98 | |
} |
| 99 | 0 | builder.append(header); |
| 100 | 0 | builder.append("{anchor:" + structureName + "}"); |
| 101 | 0 | builder.append(rowSeperator); |
| 102 | 0 | builder.append("The object key is " + structureName); |
| 103 | 0 | builder.append(rowSeperator); |
| 104 | 0 | builder.append("The type is " + type); |
| 105 | 0 | builder.append(rowSeperator); |
| 106 | 0 | builder.append(colSeperator); |
| 107 | 0 | builder.append(colSeperator); |
| 108 | 0 | builder.append("Field"); |
| 109 | 0 | builder.append(colSeperator); |
| 110 | 0 | builder.append(colSeperator); |
| 111 | 0 | builder.append("Required?"); |
| 112 | 0 | builder.append(colSeperator); |
| 113 | 0 | builder.append(colSeperator); |
| 114 | 0 | builder.append("DataType"); |
| 115 | 0 | builder.append(colSeperator); |
| 116 | 0 | builder.append(colSeperator); |
| 117 | 0 | builder.append("Length"); |
| 118 | 0 | builder.append(colSeperator); |
| 119 | 0 | builder.append(colSeperator); |
| 120 | 0 | builder.append("Dynamic"); |
| 121 | 0 | builder.append(colSeperator); |
| 122 | 0 | builder.append(colSeperator); |
| 123 | 0 | builder.append("Default"); |
| 124 | 0 | builder.append(colSeperator); |
| 125 | 0 | builder.append(colSeperator); |
| 126 | 0 | builder.append("Repeats?"); |
| 127 | 0 | builder.append(colSeperator); |
| 128 | 0 | builder.append(colSeperator); |
| 129 | 0 | builder.append("Valid Characters"); |
| 130 | 0 | builder.append(colSeperator); |
| 131 | 0 | builder.append(colSeperator); |
| 132 | 0 | builder.append("Lookup Widget"); |
| 133 | 0 | builder.append(colSeperator); |
| 134 | 0 | builder.append(colSeperator); |
| 135 | 0 | builder.append("Lookup"); |
| 136 | 0 | builder.append(colSeperator); |
| 137 | 0 | builder.append(colSeperator); |
| 138 | 0 | builder.append(rowSeperator); |
| 139 | |
} |
| 140 | |
|
| 141 | 0 | List<String> keys = new ArrayList<String>(); |
| 142 | 0 | keys.addAll(structureMetadata.getProperties().keySet()); |
| 143 | 0 | Collections.sort(keys); |
| 144 | 0 | for (String key : keys) { |
| 145 | 0 | if (key.equalsIgnoreCase ("_runtimeData")) |
| 146 | |
{ |
| 147 | 0 | continue; |
| 148 | |
} |
| 149 | 0 | Metadata fieldMeta = structureMetadata.getProperties().get(key); |
| 150 | 0 | builder.append(colSeperator); |
| 151 | 0 | builder.append(calcFieldInfo (key, fieldMeta)); |
| 152 | 0 | builder.append(colSeperator); |
| 153 | 0 | builder.append(pad(calcRequired(fieldMeta), 10)); |
| 154 | 0 | builder.append(colSeperator); |
| 155 | 0 | builder.append(pad(calcDataType(fieldMeta), 25)); |
| 156 | 0 | builder.append(colSeperator); |
| 157 | 0 | builder.append(pad(calcLength(fieldMeta), 15)); |
| 158 | 0 | builder.append(colSeperator); |
| 159 | 0 | builder.append(pad(calcDynamic(fieldMeta), 7)); |
| 160 | 0 | builder.append(colSeperator); |
| 161 | 0 | builder.append(pad(calcDefaultValue(fieldMeta), 15)); |
| 162 | 0 | builder.append(colSeperator); |
| 163 | 0 | builder.append(calcRepeating(fieldMeta)); |
| 164 | 0 | builder.append(colSeperator); |
| 165 | 0 | builder.append(calcValidChars(fieldMeta)); |
| 166 | 0 | builder.append(colSeperator); |
| 167 | 0 | builder.append(calcWidget(fieldMeta)); |
| 168 | 0 | builder.append(colSeperator); |
| 169 | 0 | builder.append(calcLookup(fieldMeta)); |
| 170 | 0 | builder.append(colSeperator); |
| 171 | 0 | builder.append(rowSeperator); |
| 172 | 0 | 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 | 0 | } |
| 185 | |
|
| 186 | 0 | return builder.toString(); |
| 187 | |
} |
| 188 | |
|
| 189 | |
private String calcDataType(Metadata fieldMeta) { |
| 190 | 0 | 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 | 0 | return fieldMeta.getDataType().toString(); |
| 203 | |
} |
| 204 | |
|
| 205 | |
private String calcDefaultValue(Metadata fieldMeta) { |
| 206 | 0 | if (fieldMeta.getDefaultValue() != null) { |
| 207 | 0 | return fieldMeta.getDefaultValue().toString(); |
| 208 | |
} |
| 209 | 0 | return " "; |
| 210 | |
} |
| 211 | |
|
| 212 | |
private String calcDynamic(Metadata meta) { |
| 213 | 0 | if (meta.isDynamic()) { |
| 214 | 0 | return "dynamic"; |
| 215 | |
} |
| 216 | 0 | return " "; |
| 217 | |
} |
| 218 | |
|
| 219 | |
private String calcFieldInfo (String key, Metadata fieldMeta) |
| 220 | |
{ |
| 221 | 0 | StringBuilder bldr = new StringBuilder (40); |
| 222 | 0 | bldr.append (pad(calcFullyQualifiedFieldName(key), 30)); |
| 223 | 0 | if (fieldMeta.getLabelKey () != null) |
| 224 | |
{ |
| 225 | 0 | bldr.append ("\\\\\n"); |
| 226 | 0 | bldr.append ("Label: "); |
| 227 | 0 | bldr.append (fieldMeta.getLabelKey ()); |
| 228 | |
} |
| 229 | 0 | return bldr.toString (); |
| 230 | |
} |
| 231 | |
|
| 232 | |
public String calcFullyQualifiedFieldName(String fieldName) { |
| 233 | 0 | if (parent == null) { |
| 234 | 0 | return escapeWiki(fieldName); |
| 235 | |
} |
| 236 | 0 | return parent.calcFullyQualifiedFieldName(structureName) + "." |
| 237 | |
+ escapeWiki(fieldName); |
| 238 | |
} |
| 239 | |
|
| 240 | |
private String calcSimpleName(String name) { |
| 241 | 0 | if (name.lastIndexOf(".") != -1) { |
| 242 | 0 | name = name.substring(name.lastIndexOf(".") + 1); |
| 243 | |
} |
| 244 | 0 | 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 | 0 | for (ConstraintMetadata cons : fieldMeta.getConstraints()) { |
| 259 | 0 | if (cons.getMaxOccurs() != null) { |
| 260 | 0 | if (cons.getMaxOccurs() == 0) { |
| 261 | 0 | return "NOT USED"; |
| 262 | |
} |
| 263 | |
} |
| 264 | |
|
| 265 | 0 | if (cons.getMinOccurs() != null) { |
| 266 | 0 | if (cons.getMinOccurs() >= 1) { |
| 267 | 0 | return "required"; |
| 268 | |
} |
| 269 | |
} |
| 270 | |
} |
| 271 | 0 | 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 | 0 | for (ConstraintMetadata cons : fieldMeta.getConstraints()) { |
| 279 | 0 | if (cons.getValidChars() == null) { |
| 280 | 0 | continue; |
| 281 | |
} |
| 282 | 0 | String validChars = escapeWiki(cons.getValidChars()); |
| 283 | 0 | String descr = "[" + "See" + "|" + LINK_TO_DEFINITIONS + "]" |
| 284 | |
+ "\\\\\n" + validChars; |
| 285 | 0 | return descr; |
| 286 | |
} |
| 287 | 0 | return " "; |
| 288 | |
} |
| 289 | |
|
| 290 | |
private String escapeWiki(String str) { |
| 291 | 0 | StringBuilder bldr = new StringBuilder(str.length()); |
| 292 | 0 | boolean precededByBackSlash = false; |
| 293 | 0 | for (int i = 0; i < str.length(); i++) { |
| 294 | 0 | char c = str.charAt(i); |
| 295 | 0 | switch (c) { |
| 296 | |
case '\\': |
| 297 | |
case '[': |
| 298 | |
case '*': |
| 299 | |
case ']': |
| 300 | |
case '|': |
| 301 | 0 | if (!precededByBackSlash) { |
| 302 | 0 | bldr.append('\\'); |
| 303 | |
} |
| 304 | |
break; |
| 305 | |
default: |
| 306 | |
break; |
| 307 | |
} |
| 308 | 0 | bldr.append(c); |
| 309 | 0 | if (c == '\\') { |
| 310 | 0 | precededByBackSlash = true; |
| 311 | |
} else { |
| 312 | 0 | precededByBackSlash = false; |
| 313 | |
} |
| 314 | |
} |
| 315 | 0 | return bldr.toString(); |
| 316 | |
} |
| 317 | |
|
| 318 | |
private String calcWidget(Metadata fieldMeta) { |
| 319 | 0 | StringBuilder bldr = new StringBuilder(); |
| 320 | 0 | String comma = ""; |
| 321 | 0 | if (!fieldMeta.isCanEdit()) { |
| 322 | 0 | bldr.append(comma); |
| 323 | 0 | bldr.append("not editable"); |
| 324 | 0 | comma = ", "; |
| 325 | |
} |
| 326 | 0 | if (!fieldMeta.isCanView()) { |
| 327 | 0 | bldr.append(comma); |
| 328 | 0 | bldr.append("not viewable"); |
| 329 | 0 | comma = ", "; |
| 330 | |
} |
| 331 | 0 | if (!fieldMeta.isCanUnmask()) { |
| 332 | 0 | bldr.append(comma); |
| 333 | 0 | bldr.append("Not unmaskable"); |
| 334 | 0 | comma = ", "; |
| 335 | |
} |
| 336 | 0 | if (fieldMeta.getInitialLookup() != null) { |
| 337 | 0 | bldr.append(comma); |
| 338 | 0 | bldr.append(fieldMeta.getInitialLookup().getWidget()); |
| 339 | 0 | comma = ", "; |
| 340 | |
} |
| 341 | 0 | if (bldr.length() == 0) { |
| 342 | 0 | bldr.append(" "); |
| 343 | |
} |
| 344 | 0 | return bldr.toString(); |
| 345 | |
} |
| 346 | |
|
| 347 | |
private String calcLookup(Metadata fieldMeta) { |
| 348 | 0 | StringBuilder bldr = new StringBuilder (); |
| 349 | 0 | if (fieldMeta.getInitialLookup() != null) { |
| 350 | 0 | bldr.append (calcLookup (fieldMeta.getInitialLookup ())); |
| 351 | |
} |
| 352 | |
|
| 353 | 0 | if (fieldMeta.getAdditionalLookups () != null) { |
| 354 | 0 | 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 | 0 | 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 | 0 | if (bldr.length () == 0) |
| 375 | |
{ |
| 376 | 0 | bldr.append (" "); |
| 377 | |
} |
| 378 | 0 | return bldr.toString (); |
| 379 | |
} |
| 380 | |
|
| 381 | |
private String calcLookup(LookupMetadata lm) { |
| 382 | 0 | StringBuilder bldr = new StringBuilder(); |
| 383 | 0 | bldr.append(lm.getId()); |
| 384 | |
|
| 385 | |
|
| 386 | |
|
| 387 | |
|
| 388 | 0 | bldr.append (" - "); |
| 389 | 0 | bldr.append (lm.getName()); |
| 390 | 0 | bldr.append (" " + lm.getWidget ()); |
| 391 | 0 | String and = " with option "; |
| 392 | 0 | 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 | 0 | and = ""; |
| 402 | 0 | bldr.append("\\\\\n"); |
| 403 | 0 | bldr.append("Implemented using search: "); |
| 404 | 0 | String searchPage = calcWikiSearchPage(lm.getSearchTypeId()); |
| 405 | 0 | bldr.append("[" + lm.getSearchTypeId() + "|" + searchPage + "#" |
| 406 | |
+ lm.getSearchTypeId() + "]"); |
| 407 | 0 | List<LookupParamMetadata> configuredParameters = filterConfiguredParams(lm |
| 408 | |
.getParams()); |
| 409 | 0 | if (configuredParameters.size() > 0) { |
| 410 | 0 | bldr.append("\\\\"); |
| 411 | 0 | bldr.append("\n"); |
| 412 | 0 | bldr.append(" where "); |
| 413 | 0 | and = ""; |
| 414 | 0 | for (LookupParamMetadata param : configuredParameters) { |
| 415 | 0 | bldr.append(and); |
| 416 | 0 | and = " and "; |
| 417 | 0 | bldr.append(param.getName()); |
| 418 | 0 | bldr.append (" (" + param.getDataType () + ") "); |
| 419 | 0 | bldr.append("="); |
| 420 | 0 | if (param.getDefaultValueString() != null) { |
| 421 | 0 | bldr.append(param.getDefaultValueString()); |
| 422 | |
} |
| 423 | 0 | 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 | 0 | } |
| 431 | |
} |
| 432 | |
} |
| 433 | 0 | List<LookupParamMetadata> userEnterableParameters = this.filterUserEnterableParams (lm |
| 434 | |
.getParams()); |
| 435 | 0 | 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 | 0 | 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 | 0 | return PAGE_PREFIX + calcWikigPageAbbrev(searchType) + PAGE_SUFFIX; |
| 477 | |
} |
| 478 | |
|
| 479 | |
private String calcWikigPageAbbrev(String searchType) { |
| 480 | 0 | if (searchType == null) { |
| 481 | 0 | return null; |
| 482 | |
} |
| 483 | 0 | if (searchType.equals("enumeration.management.search")) { |
| 484 | 0 | 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 | 0 | List<LookupParamMetadata> list = new ArrayList<LookupParamMetadata>(); |
| 520 | 0 | if (params == null) { |
| 521 | 0 | return list; |
| 522 | |
} |
| 523 | 0 | if (params.size() == 0) { |
| 524 | 0 | return list; |
| 525 | |
} |
| 526 | 0 | for (LookupParamMetadata param : params) { |
| 527 | 0 | if (param.getDefaultValueString() != null) { |
| 528 | 0 | list.add(param); |
| 529 | 0 | continue; |
| 530 | |
} |
| 531 | 0 | if (param.getDefaultValueList() != null) { |
| 532 | 0 | list.add(param); |
| 533 | 0 | continue; |
| 534 | |
} |
| 535 | |
} |
| 536 | 0 | return list; |
| 537 | |
} |
| 538 | |
|
| 539 | |
private List<LookupParamMetadata> filterUserEnterableParams ( |
| 540 | |
List<LookupParamMetadata> params) { |
| 541 | 0 | List<LookupParamMetadata> list = new ArrayList<LookupParamMetadata>(); |
| 542 | 0 | if (params == null) { |
| 543 | 0 | return list; |
| 544 | |
} |
| 545 | 0 | if (params.size() == 0) { |
| 546 | 0 | return list; |
| 547 | |
} |
| 548 | 0 | for (LookupParamMetadata param : params) { |
| 549 | 0 | if (param.getWriteAccess () != null) { |
| 550 | 0 | if ( ! param.getWriteAccess ().equals (Metadata.WriteAccess.NEVER)) { |
| 551 | 0 | list.add(param); |
| 552 | 0 | continue; |
| 553 | |
} |
| 554 | |
} |
| 555 | |
} |
| 556 | 0 | return list; |
| 557 | |
} |
| 558 | |
|
| 559 | |
private String calcRepeating(Metadata fieldMeta) { |
| 560 | 0 | if (!fieldMeta.getDataType().equals(Data.DataType.LIST)) { |
| 561 | 0 | 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 | 0 | MetadataInterrogator mi = new MetadataInterrogator(fieldMeta); |
| 592 | 0 | if (mi.getSmallestMaxLength() != null) { |
| 593 | 0 | if (mi.getLargestMinLength() != null |
| 594 | |
&& mi.getLargestMinLength() != 0) { |
| 595 | 0 | if (mi.getSmallestMaxLength() == mi.getLargestMinLength()) { |
| 596 | 0 | return ("(must be " + mi.getSmallestMaxLength() + ")"); |
| 597 | |
} |
| 598 | 0 | return "(" + mi.getLargestMinLength() + " to " |
| 599 | |
+ mi.getSmallestMaxLength() + ")"; |
| 600 | |
} |
| 601 | 0 | return "(up to " + mi.getSmallestMaxLength() + ")"; |
| 602 | |
} |
| 603 | 0 | if (mi.getLargestMinLength() != null) { |
| 604 | 0 | return "(over " + mi.getLargestMinLength() + ")"; |
| 605 | |
} |
| 606 | 0 | return " "; |
| 607 | |
} |
| 608 | |
} |