-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathFieldDefinition.java
More file actions
1208 lines (1030 loc) · 32.7 KB
/
FieldDefinition.java
File metadata and controls
1208 lines (1030 loc) · 32.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright (c) 2016-2019 LabKey Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.labkey.test.params;
import org.apache.commons.lang3.StringUtils;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.json.JSONArray;
import org.json.JSONObject;
import org.junit.Assert;
import org.labkey.api.exp.query.ExpSchema;
import org.labkey.remoteapi.domain.ConditionalFormat;
import org.labkey.remoteapi.domain.PropertyDescriptor;
import org.labkey.remoteapi.query.Filter;
import org.labkey.test.components.html.OptionSelect;
import org.labkey.test.util.EscapeUtil;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import static org.labkey.test.util.TestDataGenerator.DOMAIN_SPECIAL_STRING;
public class FieldDefinition extends PropertyDescriptor
{
public static final String SNOWMAN = "\u2603";
public static final String ANGSTROM = "\u00C5";
public static final String A_UMLAUT = "\u00E4";
// Non-alphanumeric characters supported for field names
public static final String TRICKY_CHARACTERS = "><&$,/%\\'}{][ \";:" + SNOWMAN + ANGSTROM + A_UMLAUT;
public static final String DOMAIN_TRICKY_CHARACTERS = DOMAIN_SPECIAL_STRING + SNOWMAN + ANGSTROM + A_UMLAUT;
// for UI helpers
private ColumnType _type;
private String _principalConceptSearchSourceOntology;
private String _principalConceptSearchExpression;
private ExpSchema.DerivationDataScopeType _aliquotOption;
// Stash validator collection to avoid having to convert back from JSON Maps
private List<FieldValidator<?>> _validators;
// Collection of JSON properties not explicitly known by 'PropertyDescriptor'
private final Map<String, Object> _extraFieldProperties = new HashMap<>();
private String _namePart;
/**
* Define a non-lookup field of the specified type
* @param name field name
* @param type field type
*/
public FieldDefinition(@NotNull String name, @NotNull ColumnType type)
{
setName(name);
setType(type);
// Clear out default advanced properties to avoid opening advanced field properties dialog
setMeasure(null);
setDimension(null);
setMvEnabled(null);
}
public FieldDefinition withNewName(String newName)
{
setName(newName);
return this;
}
/**
* Define a String field
* @param name field name
*/
public FieldDefinition(@NotNull String name)
{
this(name, ColumnType.String);
}
// See BaseColumnInfo.labelFromName
public static String labelFromName(String name)
{
if (name == null)
return null;
if (name.isEmpty())
return name;
StringBuilder buf = new StringBuilder(name.length() + 10);
char[] chars = new char[name.length()];
name.getChars(0, name.length(), chars, 0);
buf.append(Character.toUpperCase(chars[0]));
for (int i = 1; i < name.length(); i++)
{
char c = chars[i];
if (c == '_' && i < name.length() - 1)
{
buf.append(" ");
i++;
buf.append(Character.isLowerCase(chars[i]) ? Character.toUpperCase(chars[i]) : chars[i]);
}
else if (Character.isUpperCase(c) && Character.isLowerCase(chars[i - 1]))
{
buf.append(" ");
buf.append(c);
}
else
{
buf.append(c);
}
}
return buf.toString();
}
public String getEffectiveLabel()
{
return Objects.requireNonNullElseGet(getLabel(), () -> labelFromName(getName()));
}
@Override
public Map<String, Object> getAllProperties()
{
Map<String, Object> allProperties = new HashMap<>(_extraFieldProperties);
allProperties.putIfAbsent("defaultValueType", DefaultType.FIXED_EDITABLE);
return allProperties;
}
public ColumnType getType()
{
return _type;
}
private void setType(ColumnType type)
{
if (type == ColumnType.Lookup)
{
throw new IllegalArgumentException("Use IntLookup or StringLookup to create lookup fields");
}
_type = type;
if (type.getLookupInfo() != null)
{
super.setLookup(type.getLookupInfo().getSchema(),
type.getLookupInfo().getTable(),
type.getLookupInfo().getFolder());
}
super.setRangeURI(type.getRangeURI());
setFieldProperty("conceptURI", type.getConceptURI());
}
@Override
public PropertyDescriptor setRangeURI(String rangeURI)
{
throw new UnsupportedOperationException("Field type should be set at instantiation time.");
}
// Override return type of PropertyDescriptor setters
@Override
public FieldDefinition setLabel(String label)
{
super.setLabel(label);
return this;
}
@Override
public FieldDefinition setDescription(String description)
{
super.setDescription(description);
return this;
}
@Override
public FieldDefinition setFormat(String format)
{
super.setFormat(format);
return this;
}
@Override
public FieldDefinition setMvEnabled(Boolean mvEnabled)
{
super.setMvEnabled(mvEnabled);
return this;
}
@Override
public FieldDefinition setRequired(Boolean required)
{
super.setRequired(required);
return this;
}
@Override
public FieldDefinition setMeasure(Boolean measure)
{
super.setMeasure(measure);
return this;
}
@Override
public FieldDefinition setHidden(Boolean hidden)
{
super.setHidden(hidden);
return this;
}
@Override
public FieldDefinition setConditionalFormats(List<ConditionalFormat> conditionalFormats)
{
super.setConditionalFormats(conditionalFormats);
return this;
}
public LookupInfo getLookup()
{
return _type.getLookupInfo();
}
@Override
public FieldDefinition setLookup(String schema, String query, String container)
{
throw new UnsupportedOperationException("Lookup info should be set at instantiation time.");
}
// Additional field properties, not currently supported by 'PropertyDescriptor'
private Object getFieldProperty(String propertyName)
{
return _extraFieldProperties.get(propertyName);
}
private void setFieldProperty(String propertyName, Object value)
{
_extraFieldProperties.put(propertyName, value);
}
public List<FieldValidator<?>> getValidators()
{
return _validators;
}
public FieldDefinition setValidators(List<FieldValidator<?>> validators)
{
JSONArray propertyValidators = null;
if (validators != null)
{
propertyValidators = new JSONArray();
validators.stream().map(FieldValidator::toJSONObject).forEachOrdered(propertyValidators::put);
}
setFieldProperty("propertyValidators", propertyValidators);
_validators = validators;
return this;
}
public String getURL()
{
return (String) getFieldProperty("URL");
}
public FieldDefinition setURL(String url)
{
setFieldProperty("URL", url);
return this;
}
public boolean isURLOpenNewTab()
{
Object val = getFieldProperty("URLTarget");
return "_blank".equals(val);
}
public FieldDefinition setURLOpenNewTab(boolean openNewTab)
{
setFieldProperty("URLTarget", openNewTab ? "_blank" : null);
return this;
}
public String getImportAliases()
{
return (String) getFieldProperty("importAliases");
}
public FieldDefinition setImportAliases(String importAliases)
{
setFieldProperty("importAliases", importAliases);
return this;
}
public FieldDefinition setValueExpression(String valueExpression)
{
setFieldProperty("valueExpression", valueExpression);
return this;
}
public String getValueExpression()
{
return (String) getFieldProperty("valueExpression");
}
public Integer getScale()
{
return (Integer) getFieldProperty("scale");
}
public FieldDefinition setScale(Integer scale)
{
setFieldProperty("scale", scale);
return this;
}
public Boolean isPrimaryKey()
{
return (Boolean) getFieldProperty("isPrimaryKey");
}
public FieldDefinition setPrimaryKey(Boolean isPrimaryKey)
{
setFieldProperty("isPrimaryKey", isPrimaryKey);
return this;
}
public Boolean getLookupValidatorEnabled()
{
return (Boolean) getFieldProperty("lookupValidatorEnabled");
}
public FieldDefinition setLookupValidatorEnabled(Boolean lookupValidatorEnabled)
{
setFieldProperty("lookupValidatorEnabled", lookupValidatorEnabled);
return this;
}
public Boolean getShownInDetailsView()
{
return (Boolean) getFieldProperty("shownInDetailsView");
}
public FieldDefinition setShownInDetailsView(Boolean shownInDetailsView)
{
setFieldProperty("shownInDetailsView", shownInDetailsView);
return this;
}
public Boolean getShownInInsertView()
{
return (Boolean) getFieldProperty("shownInInsertView");
}
public FieldDefinition setShownInInsertView(Boolean shownInInsertView)
{
setFieldProperty("shownInInsertView", shownInInsertView);
return this;
}
public Boolean getShownInUpdateView()
{
return (Boolean) getFieldProperty("shownInUpdateView");
}
public FieldDefinition setShownInUpdateView(Boolean shownInUpdateView)
{
setFieldProperty("shownInUpdateView", shownInUpdateView);
return this;
}
public FieldDefinition setPHI(PhiSelectType phiType)
{
super.setPHI(phiType.name());
return this;
}
public PhiSelectType getPhiLevel()
{
if (StringUtils.isBlank(getPHI()))
{
return PhiSelectType.NotPHI;
}
else
{
return PhiSelectType.valueOf(getPHI());
}
}
public String getSourceOntology()
{
return (String) getFieldProperty("sourceOntology");
}
public FieldDefinition setSourceOntology(String sourceOntology)
{
setFieldProperty("sourceOntology", sourceOntology);
return this;
}
public String getConceptLabelColumn()
{
return (String) getFieldProperty("conceptLabelColumn");
}
public FieldDefinition setConceptLabelColumn(String conceptLabelColumn)
{
setFieldProperty("conceptLabelColumn", conceptLabelColumn);
return this;
}
public String getConceptImportColumn()
{
return (String) getFieldProperty("conceptImportColumn");
}
public FieldDefinition setConceptImportColumn(String conceptImportColumn)
{
setFieldProperty("conceptImportColumn", conceptImportColumn);
return this;
}
public String getConceptSubTree()
{
return (String) getFieldProperty("conceptSubtree");
}
public FieldDefinition setConceptSubtree(String subtree)
{
setFieldProperty("conceptSubtree", subtree);
return this;
}
public String getPrincipalConceptCode()
{
return (String) getFieldProperty("principalConceptCode");
}
public FieldDefinition setPrincipalConceptCode(String principalConceptCode)
{
setFieldProperty("principalConceptCode", principalConceptCode);
return this;
}
public String getPrincipalConceptSearchSourceOntology()
{
return _principalConceptSearchSourceOntology;
}
public String getPrincipalConceptSearchExpression()
{
return _principalConceptSearchExpression;
}
public FieldDefinition setPrincipalConceptSearchExpression(String ontologyName, String searchExpression)
{
_principalConceptSearchSourceOntology = ontologyName;
_principalConceptSearchExpression = searchExpression;
return this;
}
public FieldDefinition setTextChoiceValues(List<String> values)
{
Assert.assertEquals("Invalid field type for text choice values.", ColumnType.TextChoice, getType());
setValidators(List.of(new FieldDefinition.TextChoiceValidator(values)));
return this;
}
public ExpSchema.DerivationDataScopeType getAliquotOption()
{
return _aliquotOption;
}
public void setAliquotOption(ExpSchema.DerivationDataScopeType aliquotOption)
{
super.setDerivationDataScope(aliquotOption.name());
_aliquotOption = aliquotOption;
}
public void setNamePart(String namePart)
{
_namePart = namePart;
}
public boolean isNamePartMatch(String namePart)
{
return _namePart != null && _namePart.equals(namePart);
}
public enum RangeType
{
Equals("Equals", Filter.Operator.EQUAL),
NE("Does Not Equal", Filter.Operator.NEQ),
GT("Greater than", Filter.Operator.GT),
GTE("Greater than or Equals", Filter.Operator.GTE),
LT("Less than", Filter.Operator.LT),
LTE("Less than or Equals", Filter.Operator.LTE);
private final String _description;
private final Filter.Operator _operator;
RangeType(String description, Filter.Operator operator)
{
_description = description;
_operator = operator;
}
public String toString()
{
return _description;
}
public Filter.Operator getOperator()
{
return _operator;
}
}
public static class SampleColumnType implements ColumnType
{
private final LookupInfo _lookupInfo;
public SampleColumnType(String sampleTypeName)
{
_lookupInfo = new LookupInfo(null, "samples", sampleTypeName);
}
@Override
public String getLabel()
{
throw new IllegalStateException("UI helpers don't support this method of defining sample columns");
}
@Override
public boolean isLookup()
{
return false;
}
@Override
public String getRangeURI()
{
return ColumnType.Sample.getRangeURI();
}
@Override
public String getConceptURI()
{
return ColumnType.Sample.getConceptURI();
}
@Override
public LookupInfo getLookupInfo()
{
return _lookupInfo;
}
}
public interface ColumnType
{
ColumnType MultiLine = new ColumnTypeImpl("Multi-Line Text", "multiLine");
ColumnType Integer = new ColumnTypeImpl("Integer", "int")
{
@Override
public boolean isMeasureByDefault()
{
return true;
}
};
ColumnType String = new ColumnTypeImpl("Text", "string");
ColumnType Subject = new ColumnTypeImpl("Subject/Participant", "string", "http://cpas.labkey.com/Study#ParticipantId", null);
ColumnType DateAndTime = new ColumnTypeImpl("Date Time", "dateTime");
ColumnType Date = new ColumnTypeImpl("Date", "date");
ColumnType Time = new ColumnTypeImpl("Time", "time");
ColumnType Boolean = new ColumnTypeImpl("Boolean", "boolean");
ColumnType Double = new ColumnTypeImpl("Number (Double)", "float")
{
@Override
public boolean isMeasureByDefault()
{
return true;
}
};
ColumnType Decimal = new ColumnTypeImpl("Decimal (floating point)", "double")
{
@Override
public boolean isMeasureByDefault()
{
return true;
}
};
ColumnType File = new ColumnTypeImpl("File", "http://cpas.fhcrc.org/exp/xml#fileLink");
ColumnType Flag = new ColumnTypeImpl("Flag", "string", "http://www.labkey.org/exp/xml#flag", null);
ColumnType Attachment = new ColumnTypeImpl("Attachment", "http://www.labkey.org/exp/xml#attachment");
ColumnType User = new ColumnTypeImpl("User", "int", null, new IntLookup("core", "users"));
@Deprecated(since = "22.10") // 'Lookup' isn't a type outside of the UI
ColumnType Lookup = new ColumnTypeImpl("Lookup", null);
ColumnType OntologyLookup = new ColumnTypeImpl("Ontology Lookup", "string", "http://www.labkey.org/types#conceptCode", null);
ColumnType VisitId = new ColumnTypeImpl("Visit ID", "double", "http://cpas.labkey.com/Study#VisitId", null);
ColumnType VisitDate = new ColumnTypeImpl("Visit Date", "dateTime", "http://cpas.labkey.com/Study#VisitId", null);
ColumnType VisitLabel = new ColumnTypeImpl("Visit Label", "string", "http://cpas.labkey.com/Study#VisitId", null);
ColumnType Sample = new ColumnTypeImpl("Sample", "int", "http://www.labkey.org/exp/xml#sample", new IntLookup( "exp", "Materials"));
ColumnType Barcode = new ColumnTypeImpl("Unique ID", "string", "http://www.labkey.org/types#storageUniqueId", null);
ColumnType TextChoice = new ColumnTypeImpl("Text Choice", "string", "http://www.labkey.org/types#textChoice", null);
ColumnType SMILES = new ColumnTypeImpl("SMILES", "string", "http://www.labkey.org/exp/xml#smiles", null);
ColumnType Calculation = new ColumnTypeImpl("Calculation", null, "http://www.labkey.org/exp/xml#calculated", null);
/**
* UI: The Option text for the column type.
* API: Unused
*/
String getLabel();
/**
* UI: Is this a plain lookup field. (Formerly 'ColumnType.Lookup'). Some column type have lookup info but are
* defined as lookups in the domain designer.
* API: Unused
*/
boolean isLookup();
/**
* UI: Unused
* API: The value used by the server to determine the field's type
*/
String getRangeURI();
/**
* UI: Unused
* API: For definiting column types that add special functionality.
*/
default String getConceptURI()
{
return null;
}
/**
* UI: Lookup info for plain lookup fields ({@link #isLookup()} == true)
* API: Lookup info for plain and special (e.g. 'Sample') lookup fields
*/
default FieldDefinition.LookupInfo getLookupInfo()
{
return null;
}
default boolean isMeasureByDefault()
{
return false;
}
static List<ColumnType> values()
{
return Collections.unmodifiableList(ColumnTypeImpl.COLUMN_TYPES);
}
}
public enum ScaleType implements OptionSelect.SelectOption
{
LINEAR("Linear"),
LOG("Log");
private final String _text;
ScaleType(String text)
{
_text = text;
}
@Override
public String getValue()
{
return name();
}
@Override
public String getText()
{
return _text;
}
}
public enum DefaultType implements OptionSelect.SelectOption
{
FIXED_EDITABLE("Editable default"),
LAST_ENTERED("Last entered"),
FIXED_NON_EDITABLE("Fixed value");
private final String _text;
DefaultType(String text)
{
_text = text;
}
@Override
public String getValue()
{
return name();
}
@Override
public String getText()
{
return _text;
}
}
/**
* Represents possible PHI levels for a field
*
* @see org.labkey.api.data.PHI
*/
public enum PhiSelectType implements OptionSelect.SelectOption
{
// Ordered from least to most restrictive
NotPHI("Not PHI", null),
Limited("Limited PHI", "Limited PHI Reader"),
PHI("Full PHI", "Full PHI Reader"),
Restricted("Restricted PHI", "Restricted PHI Reader");
private final String _text;
private final String _roleName;
PhiSelectType(String text, String roleName)
{
_text = text;
_roleName = roleName;
}
@Override
public String getValue()
{
return name();
}
@Override
public String getText()
{
return _text;
}
public int getRank()
{
return ordinal();
}
public String getRoleName()
{
return _roleName;
}
}
public static class LookupInfo implements ColumnType
{
private final String _folder;
private final String _schema;
private final String _table;
private ColumnType _tableType;
/**
* @deprecated Use {@link IntLookup} or {@link StringLookup}
*/
@Deprecated (since = "22.10")
public LookupInfo(@Nullable String folder, String schema, String table)
{
if (folder == null || folder.isEmpty())
{
_folder = null;
}
else if (!folder.startsWith("/"))
{
//container must exactly match an item in the dropdown
_folder = "/" + folder;
}
else
{
_folder = folder;
}
_schema = StringUtils.trimToNull(schema);
_table = StringUtils.trimToNull(table);
_tableType = ColumnType.String;
}
public String getFolder()
{
return _folder;
}
public String getSchema()
{
return _schema;
}
public String getTable()
{
return _table;
}
public ColumnType getTableType()
{
return _tableType;
}
/**
* @deprecated Use {@link IntLookup} or {@link StringLookup}
*/
@Deprecated (since = "22.10")
public LookupInfo setTableType(ColumnType tableType)
{
_tableType = tableType;
return this;
}
@Override
public String toString()
{
StringBuilder sb = new StringBuilder();
if (_folder != null)
{
sb.append("(Current container)");
}
else
{
sb.append(_folder);
}
sb.append(" : ");
sb.append(getSchema());
sb.append(".");
sb.append(getTable());
return sb.toString();
}
@Override
public String getLabel()
{
return ColumnType.Lookup.getLabel();
}
@Override
public String getRangeURI()
{
return _tableType.getRangeURI();
}
@Override
public LookupInfo getLookupInfo()
{
return this;
}
@Override
public boolean isLookup()
{
return true;
}
}
private static abstract class Lookup extends LookupInfo
{
public Lookup(@Nullable String folder, String schema, String table, ColumnType lookupType)
{
super(folder, schema, table);
super.setTableType(lookupType);
}
@Deprecated (since = "22.10")
@Override
public LookupInfo setTableType(ColumnType tableType)
{
throw new UnsupportedOperationException();
}
}
public static class IntLookup extends Lookup
{
public IntLookup(@Nullable String folder, String schema, String table)
{
super(folder, schema, table, ColumnType.Integer);
}
public IntLookup(String schema, String table)
{
this(null, schema, table);
}
}
public static class StringLookup extends Lookup
{
public StringLookup(@Nullable String folder, String schema, String table)
{
super(folder, schema, table, ColumnType.String);
}
public StringLookup(String schema, String table)
{
this(null, schema, table);
}
}
public static abstract class FieldValidator<V extends FieldValidator<V>>
{
private final String _name;
private final String _description;
private final String _message;
private boolean _failOnMatch = false;
protected FieldValidator(String name, String description, String message)
{
_name = name;
_description = description;
_message = message;
}
public String getName()
{
return _name;
}
public String getDescription()
{
return _description;
}
public String getMessage()
{
return _message;
}
public V setFailOnMatch(boolean failOnMatch)
{
_failOnMatch = failOnMatch;
return getThis();
}
protected abstract V getThis();
protected abstract String getExpression();
protected abstract String getType();
protected JSONObject getProperties()
{
JSONObject json = new JSONObject();
json.put("failOnMatch", _failOnMatch);
return json;
}
// Even with the <pre> tag the & needs to be escaped for a javadoc compile.
// "expression": "~gt=34&~lt=99", & -> &
/**
* JSON for a field validator looks something like this:
* <pre>
* {
* "description": "description",
* "errorMessage": "error message",
* "expression": "~gt=34&~lt=99",
* "name": "V range 1",
* "new": true,
* "properties": {
* "failOnMatch": false
* },
* "type": "Range"
* }
* </pre>
* @return Serializable representation of field validator
*/
protected JSONObject toJSONObject()
{
JSONObject json = new JSONObject();
json.put("name", _name);
json.put("expression", getExpression());
if (_description != null)
{
json.put("description", _description);
}
if (_message != null)
{
json.put("errorMessage", _message);
}
json.put("new", true);
json.put("properties", getProperties());
json.put("type", getType());
return json;
}
}
public static class RegExValidator extends FieldValidator<RegExValidator>
{
private final String _expression;