-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathColumnRenderPropertiesImpl.java
More file actions
778 lines (674 loc) · 18.9 KB
/
ColumnRenderPropertiesImpl.java
File metadata and controls
778 lines (674 loc) · 18.9 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
/*
* Copyright (c) 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.api.data;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.labkey.api.collections.CaseInsensitiveHashSet;
import org.labkey.api.data.Sort.SortDirection;
import org.labkey.api.exp.PropertyType;
import org.labkey.api.gwt.client.DefaultScaleType;
import org.labkey.api.gwt.client.DefaultValueType;
import org.labkey.api.gwt.client.FacetingBehaviorType;
import org.labkey.api.query.FieldKey;
import org.labkey.api.util.StringExpression;
import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* User: matthewb
* Date: Jul 21, 2008
* Time: 12:00:28 PM
*
* These are fields used by ColumnInfo and PropertyDescriptor that primarily affect
* how the field is rendered in the HTML grids, forms, and pickers
*/
public abstract class ColumnRenderPropertiesImpl implements ColumnRenderProperties
{
protected static final Set<String> NON_EDITABLE_COL_NAMES = Collections.unmodifiableSet(new CaseInsensitiveHashSet(
"created", "createdBy", "modified", "modifiedBy",
"_ts", "entityId", "container", "lsid", "lastIndexed"));
protected SortDirection _sortDirection = SortDirection.ASC;
protected String _inputType;
protected int _inputLength = -1;
protected int _inputRows = -1;
protected String _displayWidth;
protected String _format;
protected String _excelFormatString;
protected String _tsvFormatString;
protected StringExpression _textExpression;
protected int _scale = 0;
protected String _propertyURI;
protected String _conceptURI;
protected String _rangeURI;
protected PropertyType _propertyType;
// property descriptors default to nullable, while columninfos do not; PropertyDescriptor overrides this initializer
// in its constructor:
protected boolean _nullable = false;
protected boolean _required = false;
protected String _label;
/** The column's label, without any prefixes from parent lookups */
protected String _shortLabel;
protected String _description;
protected boolean _hidden;
protected Boolean _measure;
protected Boolean _dimension;
protected Boolean _recommendedVariable = false;
protected DefaultScaleType _defaultScale = DefaultScaleType.LINEAR;
protected boolean _shownInInsertView = true;
protected boolean _shownInUpdateView = true;
protected Boolean _shownInDetailsView;
protected StringExpression _url;
protected String _urlTargetWindow;
protected String _urlCls;
protected String _onClick;
protected Set<String> _importAliases = new LinkedHashSet<>();
protected DefaultValueType _defaultValueType = null;
protected FacetingBehaviorType _facetingBehaviorType = FacetingBehaviorType.AUTOMATIC;
protected PHI _phi = PHI.NotPHI;
protected String _redactedText = null;
protected Boolean _isExcludeFromShifting = false;
protected FieldKey _crosstabColumnDimension;
protected CrosstabMember _crosstabColumnMember;
abstract public void checkLocked();
private void _checkLocked()
{
checkLocked();
}
@Override
public void copyTo(ColumnRenderPropertiesImpl to)
{
to._checkLocked();
to._sortDirection = _sortDirection;
to.setInputType(getInputType());
to.setInputLength(getInputLength());
to.setInputRows(getInputRows());
to._nullable = _nullable;
to._required = _required;
to._displayWidth = _displayWidth;
to._format = _format;
to._excelFormatString = _excelFormatString;
to._tsvFormatString = _tsvFormatString;
to._textExpression = _textExpression;
to._label = _label;
to._shortLabel = _shortLabel;
to._description = _description;
to._hidden = _hidden;
to._shownInInsertView = _shownInInsertView;
to._shownInUpdateView = _shownInUpdateView;
to._shownInDetailsView = _shownInDetailsView;
to._measure = _measure;
to._dimension = _dimension;
to._recommendedVariable = _recommendedVariable;
to._defaultScale = _defaultScale;
to._url = _url;
to._importAliases = new LinkedHashSet<>(_importAliases);
to._facetingBehaviorType = _facetingBehaviorType;
to._crosstabColumnMember = _crosstabColumnMember;
to._phi = _phi;
to._redactedText = _redactedText;
to._isExcludeFromShifting = _isExcludeFromShifting;
to._scale = _scale;
to._propertyURI = _propertyURI;
to._conceptURI = _conceptURI;
to._rangeURI = _rangeURI;
to._propertyType = _propertyType;
to._defaultValueType = _defaultValueType;
}
@Override
public String getNonBlankCaption()
{
if (_label == null || "".equals(_label.trim()))
{
return getName();
}
return _label;
}
@Override
public SortDirection getSortDirection()
{
return _sortDirection;
}
public void setSortDirection(SortDirection sortDirection)
{
_checkLocked();
_sortDirection = sortDirection;
}
@Override
public String getInputType()
{
return _inputType;
}
public void setInputType(String inputType)
{
_checkLocked();
_inputType = inputType;
}
@Override
public int getInputLength()
{
return _inputLength;
}
public void setInputLength(int inputLength)
{
_checkLocked();
_inputLength = inputLength;
}
@Override
public int getInputRows()
{
return _inputRows;
}
public void setInputRows(int inputRows)
{
_checkLocked();
_inputRows = inputRows;
}
@Override
public String getDisplayWidth()
{
return _displayWidth;
}
public void setDisplayWidth(String displayWidth)
{
_checkLocked();
_displayWidth = displayWidth;
}
@Override
public String getFormat()
{
return _format;
}
public void setFormat(String format)
{
_checkLocked();
_format = format;
}
@Override
public String getExcelFormatString()
{
return _excelFormatString;
}
public void setExcelFormatString(String excelFormatString)
{
_checkLocked();
_excelFormatString = excelFormatString;
}
@Override
public String getTsvFormatString()
{
return _tsvFormatString;
}
public void setTsvFormatString(String tsvFormatString)
{
_checkLocked();
_tsvFormatString = tsvFormatString;
}
@Override
public StringExpression getTextExpression()
{
return _textExpression;
}
public void setTextExpression(StringExpression expr)
{
_checkLocked();
_textExpression = expr;
}
@Override
public String getLabel()
{
return _label;
}
public void setLabel(String label)
{
_label = label;
}
@Override
public String getShortLabel()
{
return _shortLabel == null ? getLabel() : _shortLabel;
}
public void setShortLabel(String shortLabel)
{
_checkLocked();
_shortLabel = shortLabel;
}
@Override
public String getDescription()
{
return _description;
}
public void setDescription(String description)
{
_checkLocked();
_description = description;
}
@Override
public boolean isHidden()
{
return _hidden;
}
public void setHidden(boolean hidden)
{
_checkLocked();
_hidden = hidden;
}
@Override
public boolean isShownInDetailsView()
{
if (_shownInDetailsView != null)
return _shownInDetailsView;
return inferShownInDetailsView();
}
// CONSIDER: Refactor BaseColumnInfo.inferMetadata() to use infer metadata methods?
protected boolean inferShownInDetailsView()
{
if (isAutoIncrement())
return false;
if (NON_EDITABLE_COL_NAMES.contains(getName()))
return false;
return true;
}
public void setShownInDetailsView(boolean shownInDetailsView)
{
_checkLocked();
_shownInDetailsView = shownInDetailsView;
}
@Override
public boolean isShownInInsertView()
{
return _shownInInsertView;
}
public void setShownInInsertView(boolean shownInInsertView)
{
_checkLocked();
_shownInInsertView = shownInInsertView;
}
@Override
public boolean isShownInUpdateView()
{
return _shownInUpdateView;
}
public void setShownInUpdateView(boolean shownInUpdateView)
{
_checkLocked();
_shownInUpdateView = shownInUpdateView;
}
@Override
public StringExpression getURL()
{
return _url;
}
public void setURL(StringExpression url)
{
_checkLocked();
_url = url;
}
@Override
public String getURLTargetWindow()
{
return _urlTargetWindow;
}
public void setURLTargetWindow(String urlTargetWindow)
{
_checkLocked();
_urlTargetWindow = urlTargetWindow;
}
@Override
public String getURLCls()
{
return _urlCls;
}
public void setURLCls(String urlCls)
{
_checkLocked();
_urlCls = urlCls;
}
@Override
public String getOnClick()
{
return _onClick;
}
public void setOnClick(String onClick)
{
_checkLocked();
_onClick = onClick;
}
@Override
public boolean isRecommendedVariable()
{
return _recommendedVariable;
}
public void setRecommendedVariable(boolean recommendedVariable)
{
_checkLocked();
_recommendedVariable = recommendedVariable;
}
@Override
public DefaultScaleType getDefaultScale()
{
return _defaultScale;
}
public void setDefaultScale(DefaultScaleType defaultScale)
{
_checkLocked();
_defaultScale = defaultScale;
}
public void setMeasure(boolean measure)
{
_checkLocked();
_measure = measure;
}
public void setDimension(boolean dimension)
{
_checkLocked();
_dimension = dimension;
}
public static boolean inferIsDimension(ColumnRenderProperties col)
{
return inferIsDimension(col.getName(), col.isLookup(), col.isHidden());
}
public static boolean inferIsDimension(String name, boolean isLookup, boolean isHidden)
{
return isLookup &&
!isHidden &&
!"CreatedBy".equalsIgnoreCase(name) &&
!"ModifiedBy".equalsIgnoreCase(name);
}
@Override
public boolean isDimension()
{
// If dimension is unspecified/null, make a best guess based on the type of the field:
if (_dimension == null)
return inferIsDimension(getName(), isLookup(), isHidden());
else
return _dimension;
}
public static boolean inferIsMeasure(ColumnRenderProperties col)
{
return inferIsMeasure(col.getName(),
col.getLabel(),
col.isNumericType(),
col.isAutoIncrement(),
col.isLookup(),
col.isHidden());
}
public static boolean inferIsMeasure(String name, String label, boolean isNumeric, boolean isAutoIncrement, boolean isLookup, boolean isHidden)
{
if (label != null)
{
String[] parts = label.toLowerCase().split("[ _]");
for (String part : parts)
{
if (part.equals("code") || part.equals("id") || part.equals("identifier") || part.equals("datafax"))
return false;
}
}
return isNumeric &&
!isAutoIncrement &&
!isLookup &&
!isHidden
&& !"ParticipantID".equalsIgnoreCase(name)
&& !"VisitID".equalsIgnoreCase(name)
&& !"SequenceNum".equalsIgnoreCase(name)
&& !"RowId".equalsIgnoreCase(name)
&& !"ObjectId".equalsIgnoreCase(name);
}
@Override
public boolean isMeasure()
{
// If measure is unspecified/null, make a best guess based on the type of the field:
if (_measure == null)
return inferIsMeasure(getName(), getLabel(), isNumericType(), isAutoIncrement(), isLookup(), isHidden());
else
return _measure;
}
/** value must not be null/empty */
@Override
public boolean isNullable()
{
return _nullable;
}
public void setNullable(boolean nullable)
{
_checkLocked();
_nullable = nullable;
}
/** value must not be null/empty OR a missing value indicator must be provided */
@Override
public boolean isRequired()
{
// !nullable is stricter and implies required
return !_nullable || _required;
}
/** Returns the 'raw' value of required which is useful for copying attributes. see isRequired() */
@Override
public boolean isRequiredSet()
{
return _required;
}
public void setRequired(boolean required)
{
_checkLocked();
_required = required;
}
@Override
@NotNull
public Set<String> getImportAliasSet()
{
return _importAliases;
}
public void setImportAliasesSet(Set<String> importAliases)
{
_checkLocked();
assert importAliases != null;
_importAliases = importAliases;
}
public static String convertToString(Set<String> set)
{
if (set.isEmpty())
{
return null;
}
StringBuilder sb = new StringBuilder();
String separator = "";
for (String alias : set)
{
sb.append(separator);
separator = ", ";
alias = alias.trim();
if (alias.contains(" "))
{
// Quote any values with spaces
sb.append("\"");
sb.append(alias);
sb.append("\"");
}
else
{
sb.append(alias);
}
}
return sb.toString();
}
@Override
@Nullable
public PropertyType getPropertyType()
{
if (_propertyType == null && getRangeURI() != null)
_propertyType = PropertyType.getFromURI(getConceptURI(), getRangeURI(), null);
return _propertyType;
}
public void setPropertyType(PropertyType propertyType)
{
_checkLocked();
_propertyType = propertyType;
}
@Override
public String getPropertyURI()
{
return _propertyURI;
}
@Override
public String getConceptURI()
{
return _conceptURI;
}
@Override
public String getRangeURI()
{
return _rangeURI;
}
private static Pattern STRING_PATTERN = Pattern.compile("[^,; \\t\\n\\f\"]+|\"[^\"]*\"");
public static Set<String> convertToSet(String s)
{
Set<String> result = new LinkedHashSet<>();
if (s != null)
{
Matcher m = STRING_PATTERN.matcher(s);
while (m.find())
{
String alias = m.group();
if (alias.startsWith("\"") && alias.endsWith("\""))
{
// Strip off the leading and trailing quotes
alias = alias.substring(1, alias.length() - 1);
}
result.add(alias);
}
}
return result;
}
@Override
public boolean isDateTimeType()
{
JdbcType type = getJdbcType();
return type==JdbcType.DATE || type==JdbcType.TIME || type==JdbcType.TIMESTAMP;
}
@Override
public boolean isStringType()
{
JdbcType type = getJdbcType();
return type.cls == String.class;
}
@Override
public boolean isLongTextType()
{
JdbcType type = getJdbcType();
return type == JdbcType.LONGVARCHAR;
}
@Override
public boolean isBooleanType()
{
return getJdbcType() == JdbcType.BOOLEAN;
}
@Override
public boolean isNumericType()
{
return getJdbcType().isNumeric();
}
/** Don't return TYPEs just real java objects */
@Override
public final Class getJavaObjectClass()
{
return getJavaClass(true);
}
/** Return Class or TYPE, based on isNullable */
@Override
public final Class getJavaClass()
{
return getJavaClass(isNullable());
}
@Override
public Class getJavaClass(boolean isNullable)
{
PropertyType pt = getPropertyType();
if (pt != null)
return pt.getJavaType();
return getJdbcType().getJavaClass(isNullable);
}
public void setFacetingBehaviorType(FacetingBehaviorType type)
{
_checkLocked();
_facetingBehaviorType = type;
}
@Override
public FacetingBehaviorType getFacetingBehaviorType()
{
return _facetingBehaviorType;
}
@Override
public FieldKey getCrosstabColumnDimension()
{
return _crosstabColumnDimension;
}
public void setCrosstabColumnDimension(FieldKey crosstabColumnDimension)
{
_checkLocked();
_crosstabColumnDimension = crosstabColumnDimension;
}
@Override
public CrosstabMember getCrosstabColumnMember()
{
return _crosstabColumnMember;
}
public void setCrosstabColumnMember(CrosstabMember member)
{
_checkLocked();
_crosstabColumnMember = member;
}
public void setPHI(PHI phi)
{
_checkLocked();
_phi = phi;
}
@Override
public PHI getPHI()
{
return _phi;
}
@Override
public String getRedactedText()
{
return _redactedText;
}
public void setRedactedText(String redactedText)
{
_checkLocked();
_redactedText = redactedText;
}
@Override
public boolean isExcludeFromShifting()
{
return _isExcludeFromShifting;
}
public void setExcludeFromShifting(boolean isExcludeFromShifting)
{
_checkLocked();
_isExcludeFromShifting = isExcludeFromShifting;
}
@Override
public int getScale()
{
return _scale;
}
public void setScale(int scale)
{
_checkLocked();
_scale = scale;
}
}