Skip to content

Commit 7ada757

Browse files
authored
Merge pull request #42 from bimberlabinternal/25.3_fb_merge
Merge discvr-24.11 to discvr-25.3
2 parents 941049d + 6d51be2 commit 7ada757

File tree

4 files changed

+90
-45
lines changed

4 files changed

+90
-45
lines changed

LDK/api-src/org/labkey/api/ldk/table/ContainerScopedTable.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ public DataIteratorBuilder persistRows(DataIteratorBuilder data, DataIteratorCon
122122

123123
protected class UpdateService extends SimpleQueryUpdateService
124124
{
125-
private KeyManager _keyManager = new KeyManager();
125+
private final KeyManager _keyManager = new KeyManager();
126126

127127
public UpdateService(SimpleUserSchema.SimpleTable<?> ti)
128128
{

LDK/src/org/labkey/ldk/LDKController.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -847,14 +847,10 @@ public ModelAndView getView(QueryForm form, BindException errors) throws Excepti
847847

848848
if (keyField != null)
849849
{
850+
// Note: the ContainerContext will need to be set within QueryView
850851
DetailsURL importUrl = DetailsURL.fromString("/query/importData.view?schemaName=" + schemaName + "&query.queryName=" + queryName + "&keyField=" + keyField);
851-
importUrl.setContainerContext(getContainer());
852-
853852
DetailsURL updateUrl = DetailsURL.fromString("/ldk/manageRecord.view?schemaName=" + schemaName + "&query.queryName=" + queryName + "&keyField=" + keyField + "&key=${" + keyField + "}");
854-
updateUrl.setContainerContext(getContainer());
855-
856853
DetailsURL deleteUrl = DetailsURL.fromString("/query/deleteQueryRows.view?schemaName=" + schemaName + "&query.queryName=" + queryName);
857-
deleteUrl.setContainerContext(getContainer());
858854

859855
url.addParameter("importURL", importUrl.toString());
860856
url.addParameter("updateURL", updateUrl.toString());
@@ -866,7 +862,7 @@ public ModelAndView getView(QueryForm form, BindException errors) throws Excepti
866862
url.addParameter("queryName", queryName);
867863
url.addParameter("allowChooseQuery", false);
868864

869-
WebPartFactory factory = Portal.getPortalPartCaseInsensitive("Query");
865+
WebPartFactory factory = Portal.getPortalPart("Query");
870866
Portal.WebPart part = factory.createWebPart();
871867
part.setProperties(url.getQueryString());
872868

laboratory/api-src/org/labkey/api/laboratory/query/ContainerIncrementingTable.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public ContainerIncrementingTable(UserSchema us, TableInfo st, ContainerFilter c
5959
}
6060

6161
@Override
62-
public SimpleUserSchema.SimpleTable init()
62+
public SimpleUserSchema.SimpleTable<?> init()
6363
{
6464
super.init();
6565

laboratory/src/org/labkey/laboratory/query/LaboratoryTableCustomizer.java

Lines changed: 86 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import org.apache.logging.log4j.Logger;
88
import org.jetbrains.annotations.Nullable;
99
import org.labkey.api.data.AbstractTableInfo;
10+
import org.labkey.api.data.BaseColumnInfo;
1011
import org.labkey.api.data.ColumnInfo;
1112
import org.labkey.api.data.Container;
1213
import org.labkey.api.data.ContainerFilter;
@@ -18,7 +19,7 @@
1819
import org.labkey.api.data.SQLFragment;
1920
import org.labkey.api.data.TableCustomizer;
2021
import org.labkey.api.data.TableInfo;
21-
import org.labkey.api.data.WrappedColumn;
22+
import org.labkey.api.data.WrappedColumnInfo;
2223
import org.labkey.api.gwt.client.FacetingBehaviorType;
2324
import org.labkey.api.laboratory.LaboratoryService;
2425
import org.labkey.api.ldk.LDKService;
@@ -183,13 +184,16 @@ public void customizeColumns(AbstractTableInfo ti)
183184
{
184185
container.setHidden(true);
185186

186-
WrappedColumn wrappedContainer = new WrappedColumn(container, "workbook");
187-
wrappedContainer.setLabel("Workbook");
187+
BaseColumnInfo wrappedContainer = WrappedColumnInfo.wrapAsCopy(ti, FieldKey.fromString("workbook"), container, "Workbook", null);
188+
wrappedContainer.setName("workbook");
189+
wrappedContainer.setCalculated(true);
190+
wrappedContainer.setShownInInsertView(false);
191+
wrappedContainer.setShownInUpdateView(false);
188192
wrappedContainer.setFk(QueryForeignKey
189193
.from(ti.getUserSchema(), ti.getContainerFilter())
190194
.schema(us)
191195
.to("workbooks", LaboratoryWorkbooksTable.WORKBOOK_COL, "workbookId"));
192-
wrappedContainer.setURL(DetailsURL.fromString("/project/start.view"));
196+
wrappedContainer.setURL(DetailsURL.fromString("/project/begin.view"));
193197
wrappedContainer.setShownInDetailsView(true);
194198
wrappedContainer.setFacetingBehaviorType(FacetingBehaviorType.ALWAYS_OFF);
195199
wrappedContainer.setDisplayColumnFactory(new DisplayColumnFactory()
@@ -290,11 +294,15 @@ private void appendDemographicsCols(final UserSchema us, AbstractTableInfo ti, C
290294
if (ti.getColumn(name) != null)
291295
continue;
292296

293-
WrappedColumn col = new WrappedColumn(subjectCol, name);
294-
col.setLabel(qd.getLabel());
297+
BaseColumnInfo col = WrappedColumnInfo.wrapAsCopy(ti, FieldKey.fromString(name), subjectCol, qd.getLabel(), null);
298+
col.setName(name);
299+
col.setCalculated(true);
300+
col.setShownInInsertView(false);
301+
col.setShownInUpdateView(false);
295302
col.setReadOnly(true);
296303
col.setIsUnselectable(true);
297304
col.setUserEditable(false);
305+
col.setKeyField(false);
298306

299307
UserSchema targetSchema = qd.getTableInfo(targetContainer, us.getUser()).getUserSchema();
300308
col.setFk(new QueryForeignKey(us, ti.getContainerFilter(), targetSchema, null, qd.getQueryName(), qd.getTargetColumn(), qd.getTargetColumn())
@@ -366,12 +374,16 @@ private void appendMajorEventsCol(final UserSchema us, AbstractTableInfo ds, fin
366374
final String pkColSelectName = pk.getFieldKey().toSQLString();
367375
final String pkColRawName = pk.getName();
368376

369-
MutableColumnInfo col = new WrappedColumn(pk, name);
370-
col.setLabel("Major Events");
377+
BaseColumnInfo col = WrappedColumnInfo.wrapAsCopy(ds, FieldKey.fromString(name), pk, "Major Events", null);
371378
col.setDescription("This column shows all major events recorded in this subject's history and will calculate the time elapsed between the current sample and these dates.");
379+
col.setName(name);
380+
col.setCalculated(true);
381+
col.setShownInInsertView(false);
382+
col.setShownInUpdateView(false);
372383
col.setReadOnly(true);
373384
col.setIsUnselectable(true);
374385
col.setUserEditable(false);
386+
col.setKeyField(false);
375387

376388
final String schemaName = ds.getUserSchema().getSchemaPath().toSQLString();
377389
final String subjectSelectName = ds.getSqlDialect().makeLegalIdentifier(subjectColName);
@@ -384,11 +396,10 @@ private void appendMajorEventsCol(final UserSchema us, AbstractTableInfo ds, fin
384396
@Override
385397
public TableInfo getLookupTableInfo()
386398
{
387-
Container target = us.getContainer().isWorkbookOrTab() ? us.getContainer().getParent() : us.getContainer();
388-
UserSchema effectiveUs = us.getContainer().isWorkbookOrTab() ? QueryService.get().getUserSchema(us.getUser(), target, us.getSchemaPath()) : us;
389-
QueryDefinition qd = QueryService.get().createQueryDef(us.getUser(), target, effectiveUs, colName);
399+
Container parentContainer = us.getContainer().isWorkbookOrTab() ? us.getContainer().getParent() : us.getContainer();
400+
QueryDefinition qd = createQueryDef(us, colName);
390401

391-
qd.setSql(getMajorEventsSql(target, schemaName, querySelectName, pkColSelectName, subjectSelectName, dateSelectName));
402+
qd.setSql(getMajorEventsSql(parentContainer, schemaName, querySelectName, pkColSelectName, subjectSelectName, dateSelectName));
392403
qd.setIsTemporary(true);
393404

394405
List<QueryException> errors = new ArrayList<>();
@@ -444,21 +455,24 @@ private void appendOverlapingProjectsCol(final UserSchema us, AbstractTableInfo
444455
final String subjectSelectName = ds.getSqlDialect().makeLegalIdentifier(subjectColName);
445456
final String dateSelectName = dateColName == null ? null : ds.getSqlDialect().makeLegalIdentifier(dateColName);
446457

447-
WrappedColumn col = new WrappedColumn(pk, name);
448-
col.setLabel("Overlapping Groups");
458+
BaseColumnInfo col = WrappedColumnInfo.wrapAsCopy(ds, FieldKey.fromString(name), pk, "Overlapping Groups", null);
449459
col.setDescription("This column shows all groups to which this subject belonged at the time of this sample.");
460+
col.setName(name);
461+
col.setCalculated(true);
462+
col.setShownInInsertView(false);
463+
col.setShownInUpdateView(false);
450464
col.setReadOnly(true);
451465
col.setIsUnselectable(true);
452466
col.setUserEditable(false);
467+
col.setKeyField(false);
453468
col.setFk(new LookupForeignKey(){
454469
@Override
455470
public TableInfo getLookupTableInfo()
456471
{
457-
Container target = us.getContainer().isWorkbookOrTab() ? us.getContainer().getParent() : us.getContainer();
458-
UserSchema effectiveUs = us.getContainer().isWorkbookOrTab() ? QueryService.get().getUserSchema(us.getUser(), target, us.getSchemaPath()) : us;
459-
QueryDefinition qd = QueryService.get().createQueryDef(us.getUser(), target, effectiveUs, colName);
472+
Container parentContainer = us.getContainer().isWorkbookOrTab() ? us.getContainer().getParent() : us.getContainer();
473+
QueryDefinition qd = createQueryDef(us, colName);
460474

461-
qd.setSql(getOverlapSql(target, schemaName, querySelectName, pkColSelectName, subjectSelectName, dateSelectName));
475+
qd.setSql(getOverlapSql(parentContainer, schemaName, querySelectName, pkColSelectName, subjectSelectName, dateSelectName));
462476
qd.setIsTemporary(true);
463477

464478
List<QueryException> errors = new ArrayList<>();
@@ -490,20 +504,24 @@ public TableInfo getLookupTableInfo()
490504

491505
//add pivot column
492506
String pivotColName = "overlappingProjectsPivot";
493-
WrappedColumn col2 = new WrappedColumn(pk, pivotColName);
494-
col2.setLabel("Overlapping Group List");
507+
BaseColumnInfo col2 = WrappedColumnInfo.wrapAsCopy(ds, FieldKey.fromString(pivotColName), pk, "Overlapping Group List", null);
508+
col2.setName(pivotColName);
509+
col2.setCalculated(true);
510+
col2.setShownInInsertView(false);
511+
col2.setShownInUpdateView(false);
495512
col2.setDescription("Shows groups to which this subject belonged at the time of this sample.");
496513
col2.setHidden(true);
497514
col2.setReadOnly(true);
498515
col2.setIsUnselectable(true);
499516
col2.setUserEditable(false);
517+
col2.setKeyField(false);
500518
final String lookupColName = ds.getName() + "_overlappingProjectsPivot";
501519
col2.setFk(new LookupForeignKey(){
502520
@Override
503521
public TableInfo getLookupTableInfo()
504522
{
505523
Container target = us.getContainer().isWorkbookOrTab() ? us.getContainer().getParent() : us.getContainer();
506-
QueryDefinition qd = QueryService.get().createQueryDef(us.getUser(), target, us, lookupColName);
524+
QueryDefinition qd = createQueryDef(us, lookupColName);
507525

508526
qd.setSql(getOverlapPivotSql(target, schemaName, querySelectName, pkColSelectName, subjectColName, dateColName));
509527
qd.setIsTemporary(true);
@@ -555,21 +573,24 @@ public void appendProjectsCol(final UserSchema us, AbstractTableInfo ds, final S
555573
final String publicTableName = ds.getPublicName();
556574

557575
final String colName = ds.getName() + "_allProjects";
558-
WrappedColumn col = new WrappedColumn(pk, name);
559-
col.setLabel("Groups");
576+
BaseColumnInfo col = WrappedColumnInfo.wrapAsCopy(ds, FieldKey.fromString(name), pk, "Groups", null);
577+
col.setName(name);
578+
col.setCalculated(true);
579+
col.setShownInInsertView(false);
580+
col.setShownInUpdateView(false);
560581
col.setDescription("This column shows all groups to which this subject has ever been a member, regardless of whether that assignment overlaps with the current data point");
561582
col.setReadOnly(true);
562583
col.setIsUnselectable(true);
563584
col.setUserEditable(false);
585+
col.setKeyField(false);
564586
col.setFk(new LookupForeignKey(){
565587
@Override
566588
public TableInfo getLookupTableInfo()
567589
{
568-
Container target = us.getContainer().isWorkbookOrTab() ? us.getContainer().getParent() : us.getContainer();
569-
UserSchema effectiveUs = us.getContainer().isWorkbookOrTab() ? QueryService.get().getUserSchema(us.getUser(), target, us.getSchemaPath()) : us;
570-
QueryDefinition qd = QueryService.get().createQueryDef(us.getUser(), target, effectiveUs, colName);
590+
Container parentContainer = us.getContainer().isWorkbookOrTab() ? us.getContainer().getParent() : us.getContainer();
591+
QueryDefinition qd = createQueryDef(us, colName);
571592

572-
qd.setSql(getOverlapSql(target, schemaName, querySelectName, pkColSelectName, subjectSelectName, null));
593+
qd.setSql(getOverlapSql(parentContainer, schemaName, querySelectName, pkColSelectName, subjectSelectName, null));
573594
qd.setIsTemporary(true);
574595

575596
List<QueryException> errors = new ArrayList<>();
@@ -602,20 +623,23 @@ public TableInfo getLookupTableInfo()
602623
//add pivot column
603624
String pivotColName = "allProjectsPivot";
604625
final String lookupName = ds.getName() + "_allProjectsPivot";
605-
WrappedColumn col2 = new WrappedColumn(pk, pivotColName);
606-
col2.setLabel("Group Summary List");
626+
BaseColumnInfo col2 = WrappedColumnInfo.wrapAsCopy(ds, FieldKey.fromString(pivotColName), pk, "Group Summary List", null);
627+
col2.setName(pivotColName);
628+
col2.setCalculated(true);
629+
col2.setShownInInsertView(false);
630+
col2.setShownInUpdateView(false);
607631
col2.setDescription("Shows groups to which this subject belonged at any point in time.");
608632
col2.setHidden(true);
609633
col2.setReadOnly(true);
610634
col2.setIsUnselectable(true);
611635
col2.setUserEditable(false);
636+
col2.setKeyField(false);
612637
col2.setFk(new LookupForeignKey(){
613638
@Override
614639
public TableInfo getLookupTableInfo()
615640
{
616641
Container target = us.getContainer().isWorkbookOrTab() ? us.getContainer().getParent() : us.getContainer();
617-
UserSchema effectiveUs = us.getContainer().isWorkbookOrTab() ? QueryService.get().getUserSchema(us.getUser(), target, us.getSchemaPath()) : us;
618-
QueryDefinition qd = QueryService.get().createQueryDef(us.getUser(), target, effectiveUs, lookupName);
642+
QueryDefinition qd = createQueryDef(us, lookupName);
619643

620644
qd.setSql(getOverlapPivotSql(target, schemaName, querySelectName, pkColSelectName, subjectSelectName, null));
621645
qd.setIsTemporary(true);
@@ -749,11 +773,15 @@ private void appendRelativeDatesCol(final UserSchema us, AbstractTableInfo ds, f
749773
final String pkColSelectName = pk.getFieldKey().toSQLString();
750774
final String pkColRawName = pk.getName();
751775

752-
WrappedColumn col = new WrappedColumn(pk, name);
753-
col.setLabel("Relative Dates");
776+
BaseColumnInfo col = WrappedColumnInfo.wrapAsCopy(ds, FieldKey.fromString(name), pk, "Relative Dates", null);
777+
col.setName(name);
778+
col.setCalculated(true);
779+
col.setShownInInsertView(false);
780+
col.setShownInUpdateView(false);
754781
col.setReadOnly(true);
755782
col.setIsUnselectable(true);
756783
col.setUserEditable(false);
784+
col.setKeyField(false);
757785

758786
final String colName = ds.getName() + "_relativeDates";
759787
final String schemaName = ds.getUserSchema().getSchemaPath().toSQLString();
@@ -765,9 +793,8 @@ private void appendRelativeDatesCol(final UserSchema us, AbstractTableInfo ds, f
765793
@Override
766794
public TableInfo getLookupTableInfo()
767795
{
768-
Container target = us.getContainer().isWorkbookOrTab() ? us.getContainer().getParent() : us.getContainer();
769-
UserSchema effectiveUs = us.getContainer().isWorkbookOrTab() ? QueryService.get().getUserSchema(us.getUser(), target, us.getSchemaPath()) : us;
770-
QueryDefinition qd = QueryService.get().createQueryDef(us.getUser(), target, effectiveUs, colName);
796+
Container parentContainer = us.getContainer().isWorkbookOrTab() ? us.getContainer().getParent() : us.getContainer();
797+
QueryDefinition qd = createQueryDef(us, colName);
771798

772799
qd.setSql("SELECT\n" +
773800
"t." + pkColSelectName + ",\n" +
@@ -795,7 +822,7 @@ public TableInfo getLookupTableInfo()
795822
"ROUND(CONVERT(age_in_months(p.startdate, s." + dateSelectName + "), DOUBLE) / 12, 1) AS YearsPostStartDecimal,\n" +
796823
"\n" +
797824
"FROM " + schemaName + "." + publicTableName + " s\n" +
798-
"JOIN \"" + target.getPath() + "\".laboratory.project_usage p\n" +
825+
"JOIN \"" + parentContainer.getPath() + "\".laboratory.project_usage p\n" +
799826
"ON (s." + subjectSelectName + " = p.subjectId AND CONVERT(p.startdate, DATE) <= CONVERT(s." + dateSelectName + ", DATE) AND CONVERT(s." + dateSelectName + ", DATE) <= CONVERT(COALESCE(p.enddate, {fn curdate()}), DATE))\n" +
800827
"WHERE s." + dateSelectName + " IS NOT NULL and s." + subjectSelectName + " IS NOT NULL\n" +
801828
"\n" +
@@ -830,6 +857,28 @@ public TableInfo getLookupTableInfo()
830857
ds.addColumn(col);
831858
}
832859

860+
private QueryDefinition createQueryDef(UserSchema us, String queryName)
861+
{
862+
if (!us.getContainer().isWorkbook())
863+
{
864+
return QueryService.get().createQueryDef(us.getUser(), us.getContainer(), us, queryName);
865+
}
866+
867+
// The rationale is that if we are querying from a workbook, preferentially translate to the parent US
868+
// However, there are situations like workbook-scoped lists, where that query might not exist on the parent
869+
UserSchema parentUserSchema = QueryService.get().getUserSchema(us.getUser(), us.getContainer().getParent(), us.getSchemaPath());
870+
assert parentUserSchema != null;
871+
872+
if (parentUserSchema.getTableNames().contains(queryName))
873+
{
874+
return QueryService.get().createQueryDef(parentUserSchema.getUser(), parentUserSchema.getContainer(), parentUserSchema, queryName);
875+
}
876+
else
877+
{
878+
return QueryService.get().createQueryDef(us.getUser(), us.getContainer(), us, queryName);
879+
}
880+
}
881+
833882
public UserSchema getUserSchema(AbstractTableInfo ds, String name)
834883
{
835884
UserSchema us = ds.getUserSchema();

0 commit comments

Comments
 (0)