Skip to content

Commit ef0158a

Browse files
committed
Refinements to customizer code, and many new SIV-related ETLs
1 parent 54f3bb2 commit ef0158a

File tree

1 file changed

+44
-4
lines changed

1 file changed

+44
-4
lines changed

LDK/src/org/labkey/ldk/query/DefaultTableCustomizer.java

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,21 @@ private void setDetailsUrl(AbstractTableInfo ti)
125125
assert queryName != null;
126126

127127
List<String> keyFields = ti.getPkColumnNames();
128-
assert keyFields.size() > 0 : "No key fields found for the table: " + ti.getPublicSchemaName() + "." + ti.getPublicName();
128+
assert !keyFields.isEmpty() : "No key fields found for the table: " + ti.getPublicSchemaName() + "." + ti.getPublicName();
129+
130+
if (_settings.getPrimaryKeyField() != null)
131+
{
132+
String alternatePK = _settings.getPrimaryKeyField();
133+
if (!keyFields.contains(alternatePK))
134+
{
135+
_log.error("Table: " + ti.getUserSchema().getSchemaName() + "." + ti.getPublicName() + " supplied an alternate primaryKeyField that doesnt match actual PKs: " + alternatePK);
136+
return;
137+
}
138+
139+
keyFields.clear();
140+
keyFields.add(alternatePK);
141+
}
142+
129143
if (keyFields.size() != 1)
130144
{
131145
_log.error("Table: " + ti.getUserSchema().getSchemaName() + "." + ti.getPublicName() + " has more than 1 PK: " + StringUtils.join(keyFields, ";") + ", cannot apply custom links - please update the TableCustomizer properties");
@@ -159,14 +173,28 @@ else if (_settings.isSetEditLinkOverrides())
159173
assert queryName != null;
160174

161175
List<String> keyFields = ti.getPkColumnNames();
162-
assert keyFields.size() > 0 : "No key fields found for the table: " + ti.getPublicSchemaName() + "." + ti.getPublicName();
176+
assert !keyFields.isEmpty() : "No key fields found for the table: " + ti.getPublicSchemaName() + "." + ti.getPublicName();
177+
178+
if (_settings.getPrimaryKeyField() != null)
179+
{
180+
String alternatePK = _settings.getPrimaryKeyField();
181+
if (!keyFields.contains(alternatePK))
182+
{
183+
_log.error("Table: " + ti.getUserSchema().getSchemaName() + "." + ti.getPublicName() + " supplied an alternate primaryKeyField that doesnt match actual PKs: " + alternatePK);
184+
return;
185+
}
186+
187+
keyFields.clear();
188+
keyFields.add(alternatePK);
189+
}
190+
163191
if (keyFields.size() != 1)
164192
{
165193
_log.error("Table: " + schemaName + "." + queryName + " has more than 1 PK: " + StringUtils.join(keyFields, ";") + ", cannot apply custom links - please update the TableCustomizer properties");
166194
return;
167195
}
168196

169-
if (schemaName != null && queryName != null && keyFields.size() > 0)
197+
if (schemaName != null && queryName != null && !keyFields.isEmpty())
170198
{
171199
String keyField = keyFields.get(0);
172200
if (!AbstractTableInfo.LINK_DISABLER_ACTION_URL.equals(ti.getImportDataURL(ti.getUserSchema().getContainer())))
@@ -445,7 +473,8 @@ public enum PROPERIES
445473
setEditLinkOverrides(Boolean.class, true),
446474
auditMode(String.class, AuditBehaviorType.DETAILED.name()),
447475
disableFacetingForNumericCols(Boolean.class, true),
448-
overrideDetailsUrl(Boolean.class, true);
476+
overrideDetailsUrl(Boolean.class, true),
477+
primaryKeyField(String.class, null);
449478

450479
private final Class _clazz;
451480
private final Object _defaultVal;
@@ -531,6 +560,17 @@ public AuditBehaviorType getAuditMode()
531560
return AuditBehaviorType.DETAILED;
532561
}
533562

563+
public String getPrimaryKeyField()
564+
{
565+
Object fieldName = getProperty(PROPERIES.primaryKeyField);
566+
if (fieldName != null)
567+
{
568+
return fieldName.toString();
569+
}
570+
571+
return null;
572+
}
573+
534574
public boolean isDisableFacetingForNumericCols()
535575
{
536576
return (boolean)getProperty(PROPERIES.disableFacetingForNumericCols);

0 commit comments

Comments
 (0)