From 4135db450baa8da68209f138628a4294c304e84b Mon Sep 17 00:00:00 2001 From: bbimber Date: Fri, 14 Mar 2025 13:57:34 -0700 Subject: [PATCH 1/7] Improve handling of generated queries when dealing with a container-scoped list --- .../query/LaboratoryTableCustomizer.java | 82 +++++++++++-------- 1 file changed, 46 insertions(+), 36 deletions(-) diff --git a/laboratory/src/org/labkey/laboratory/query/LaboratoryTableCustomizer.java b/laboratory/src/org/labkey/laboratory/query/LaboratoryTableCustomizer.java index af8a869d..65c3b69c 100644 --- a/laboratory/src/org/labkey/laboratory/query/LaboratoryTableCustomizer.java +++ b/laboratory/src/org/labkey/laboratory/query/LaboratoryTableCustomizer.java @@ -7,6 +7,7 @@ import org.apache.logging.log4j.Logger; import org.jetbrains.annotations.Nullable; import org.labkey.api.data.AbstractTableInfo; +import org.labkey.api.data.BaseColumnInfo; import org.labkey.api.data.ColumnInfo; import org.labkey.api.data.Container; import org.labkey.api.data.ContainerFilter; @@ -18,7 +19,7 @@ import org.labkey.api.data.SQLFragment; import org.labkey.api.data.TableCustomizer; import org.labkey.api.data.TableInfo; -import org.labkey.api.data.WrappedColumn; +import org.labkey.api.data.WrappedColumnInfo; import org.labkey.api.gwt.client.FacetingBehaviorType; import org.labkey.api.laboratory.LaboratoryService; import org.labkey.api.ldk.LDKService; @@ -183,8 +184,7 @@ public void customizeColumns(AbstractTableInfo ti) { container.setHidden(true); - WrappedColumn wrappedContainer = new WrappedColumn(container, "workbook"); - wrappedContainer.setLabel("Workbook"); + BaseColumnInfo wrappedContainer = WrappedColumnInfo.wrapAsCopy(ti, FieldKey.fromString("workbook"), container, "Workbook", null); wrappedContainer.setFk(QueryForeignKey .from(ti.getUserSchema(), ti.getContainerFilter()) .schema(us) @@ -290,8 +290,7 @@ private void appendDemographicsCols(final UserSchema us, AbstractTableInfo ti, C if (ti.getColumn(name) != null) continue; - WrappedColumn col = new WrappedColumn(subjectCol, name); - col.setLabel(qd.getLabel()); + BaseColumnInfo col = WrappedColumnInfo.wrapAsCopy(ti, FieldKey.fromString(name), subjectCol, qd.getLabel(), null); col.setReadOnly(true); col.setIsUnselectable(true); col.setUserEditable(false); @@ -366,8 +365,7 @@ private void appendMajorEventsCol(final UserSchema us, AbstractTableInfo ds, fin final String pkColSelectName = pk.getFieldKey().toSQLString(); final String pkColRawName = pk.getName(); - MutableColumnInfo col = new WrappedColumn(pk, name); - col.setLabel("Major Events"); + BaseColumnInfo col = WrappedColumnInfo.wrapAsCopy(ds, FieldKey.fromString(name), pk, "Major Events", null); 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."); col.setReadOnly(true); col.setIsUnselectable(true); @@ -384,11 +382,10 @@ private void appendMajorEventsCol(final UserSchema us, AbstractTableInfo ds, fin @Override public TableInfo getLookupTableInfo() { - Container target = us.getContainer().isWorkbookOrTab() ? us.getContainer().getParent() : us.getContainer(); - UserSchema effectiveUs = us.getContainer().isWorkbookOrTab() ? QueryService.get().getUserSchema(us.getUser(), target, us.getSchemaPath()) : us; - QueryDefinition qd = QueryService.get().createQueryDef(us.getUser(), target, effectiveUs, colName); + Container parentContainer = us.getContainer().isWorkbookOrTab() ? us.getContainer().getParent() : us.getContainer(); + QueryDefinition qd = createQueryDef(us, colName); - qd.setSql(getMajorEventsSql(target, schemaName, querySelectName, pkColSelectName, subjectSelectName, dateSelectName)); + qd.setSql(getMajorEventsSql(parentContainer, schemaName, querySelectName, pkColSelectName, subjectSelectName, dateSelectName)); qd.setIsTemporary(true); List errors = new ArrayList<>(); @@ -444,8 +441,7 @@ private void appendOverlapingProjectsCol(final UserSchema us, AbstractTableInfo final String subjectSelectName = ds.getSqlDialect().makeLegalIdentifier(subjectColName); final String dateSelectName = dateColName == null ? null : ds.getSqlDialect().makeLegalIdentifier(dateColName); - WrappedColumn col = new WrappedColumn(pk, name); - col.setLabel("Overlapping Groups"); + BaseColumnInfo col = WrappedColumnInfo.wrapAsCopy(ds, FieldKey.fromString(name), pk, "Overlapping Groups", null); col.setDescription("This column shows all groups to which this subject belonged at the time of this sample."); col.setReadOnly(true); col.setIsUnselectable(true); @@ -454,11 +450,10 @@ private void appendOverlapingProjectsCol(final UserSchema us, AbstractTableInfo @Override public TableInfo getLookupTableInfo() { - Container target = us.getContainer().isWorkbookOrTab() ? us.getContainer().getParent() : us.getContainer(); - UserSchema effectiveUs = us.getContainer().isWorkbookOrTab() ? QueryService.get().getUserSchema(us.getUser(), target, us.getSchemaPath()) : us; - QueryDefinition qd = QueryService.get().createQueryDef(us.getUser(), target, effectiveUs, colName); + Container parentContainer = us.getContainer().isWorkbookOrTab() ? us.getContainer().getParent() : us.getContainer(); + QueryDefinition qd = createQueryDef(us, colName); - qd.setSql(getOverlapSql(target, schemaName, querySelectName, pkColSelectName, subjectSelectName, dateSelectName)); + qd.setSql(getOverlapSql(parentContainer, schemaName, querySelectName, pkColSelectName, subjectSelectName, dateSelectName)); qd.setIsTemporary(true); List errors = new ArrayList<>(); @@ -490,8 +485,7 @@ public TableInfo getLookupTableInfo() //add pivot column String pivotColName = "overlappingProjectsPivot"; - WrappedColumn col2 = new WrappedColumn(pk, pivotColName); - col2.setLabel("Overlapping Group List"); + BaseColumnInfo col2 = WrappedColumnInfo.wrapAsCopy(ds, FieldKey.fromString(pivotColName), pk, "Overlapping Group List", null); col2.setDescription("Shows groups to which this subject belonged at the time of this sample."); col2.setHidden(true); col2.setReadOnly(true); @@ -503,7 +497,7 @@ public TableInfo getLookupTableInfo() public TableInfo getLookupTableInfo() { Container target = us.getContainer().isWorkbookOrTab() ? us.getContainer().getParent() : us.getContainer(); - QueryDefinition qd = QueryService.get().createQueryDef(us.getUser(), target, us, lookupColName); + QueryDefinition qd = createQueryDef(us, lookupColName); qd.setSql(getOverlapPivotSql(target, schemaName, querySelectName, pkColSelectName, subjectColName, dateColName)); qd.setIsTemporary(true); @@ -555,8 +549,7 @@ public void appendProjectsCol(final UserSchema us, AbstractTableInfo ds, final S final String publicTableName = ds.getPublicName(); final String colName = ds.getName() + "_allProjects"; - WrappedColumn col = new WrappedColumn(pk, name); - col.setLabel("Groups"); + BaseColumnInfo col = WrappedColumnInfo.wrapAsCopy(ds, FieldKey.fromString(name), pk, "Groups", null); 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"); col.setReadOnly(true); col.setIsUnselectable(true); @@ -565,11 +558,10 @@ public void appendProjectsCol(final UserSchema us, AbstractTableInfo ds, final S @Override public TableInfo getLookupTableInfo() { - Container target = us.getContainer().isWorkbookOrTab() ? us.getContainer().getParent() : us.getContainer(); - UserSchema effectiveUs = us.getContainer().isWorkbookOrTab() ? QueryService.get().getUserSchema(us.getUser(), target, us.getSchemaPath()) : us; - QueryDefinition qd = QueryService.get().createQueryDef(us.getUser(), target, effectiveUs, colName); + Container parentContainer = us.getContainer().isWorkbookOrTab() ? us.getContainer().getParent() : us.getContainer(); + QueryDefinition qd = createQueryDef(us, colName); - qd.setSql(getOverlapSql(target, schemaName, querySelectName, pkColSelectName, subjectSelectName, null)); + qd.setSql(getOverlapSql(parentContainer, schemaName, querySelectName, pkColSelectName, subjectSelectName, null)); qd.setIsTemporary(true); List errors = new ArrayList<>(); @@ -602,8 +594,7 @@ public TableInfo getLookupTableInfo() //add pivot column String pivotColName = "allProjectsPivot"; final String lookupName = ds.getName() + "_allProjectsPivot"; - WrappedColumn col2 = new WrappedColumn(pk, pivotColName); - col2.setLabel("Group Summary List"); + BaseColumnInfo col2 = WrappedColumnInfo.wrapAsCopy(ds, FieldKey.fromString(pivotColName), pk, "Group Summary List", null); col2.setDescription("Shows groups to which this subject belonged at any point in time."); col2.setHidden(true); col2.setReadOnly(true); @@ -614,8 +605,7 @@ public TableInfo getLookupTableInfo() public TableInfo getLookupTableInfo() { Container target = us.getContainer().isWorkbookOrTab() ? us.getContainer().getParent() : us.getContainer(); - UserSchema effectiveUs = us.getContainer().isWorkbookOrTab() ? QueryService.get().getUserSchema(us.getUser(), target, us.getSchemaPath()) : us; - QueryDefinition qd = QueryService.get().createQueryDef(us.getUser(), target, effectiveUs, lookupName); + QueryDefinition qd = createQueryDef(us, lookupName); qd.setSql(getOverlapPivotSql(target, schemaName, querySelectName, pkColSelectName, subjectSelectName, null)); qd.setIsTemporary(true); @@ -749,8 +739,7 @@ private void appendRelativeDatesCol(final UserSchema us, AbstractTableInfo ds, f final String pkColSelectName = pk.getFieldKey().toSQLString(); final String pkColRawName = pk.getName(); - WrappedColumn col = new WrappedColumn(pk, name); - col.setLabel("Relative Dates"); + BaseColumnInfo col = WrappedColumnInfo.wrapAsCopy(ds, FieldKey.fromString(name), pk, "Relative Dates", null); col.setReadOnly(true); col.setIsUnselectable(true); col.setUserEditable(false); @@ -765,9 +754,8 @@ private void appendRelativeDatesCol(final UserSchema us, AbstractTableInfo ds, f @Override public TableInfo getLookupTableInfo() { - Container target = us.getContainer().isWorkbookOrTab() ? us.getContainer().getParent() : us.getContainer(); - UserSchema effectiveUs = us.getContainer().isWorkbookOrTab() ? QueryService.get().getUserSchema(us.getUser(), target, us.getSchemaPath()) : us; - QueryDefinition qd = QueryService.get().createQueryDef(us.getUser(), target, effectiveUs, colName); + Container parentContainer = us.getContainer().isWorkbookOrTab() ? us.getContainer().getParent() : us.getContainer(); + QueryDefinition qd = createQueryDef(us, colName); qd.setSql("SELECT\n" + "t." + pkColSelectName + ",\n" + @@ -795,7 +783,7 @@ public TableInfo getLookupTableInfo() "ROUND(CONVERT(age_in_months(p.startdate, s." + dateSelectName + "), DOUBLE) / 12, 1) AS YearsPostStartDecimal,\n" + "\n" + "FROM " + schemaName + "." + publicTableName + " s\n" + - "JOIN \"" + target.getPath() + "\".laboratory.project_usage p\n" + + "JOIN \"" + parentContainer.getPath() + "\".laboratory.project_usage p\n" + "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" + "WHERE s." + dateSelectName + " IS NOT NULL and s." + subjectSelectName + " IS NOT NULL\n" + "\n" + @@ -830,6 +818,28 @@ public TableInfo getLookupTableInfo() ds.addColumn(col); } + private QueryDefinition createQueryDef(UserSchema us, String queryName) + { + if (!us.getContainer().isWorkbook()) + { + return QueryService.get().createQueryDef(us.getUser(), us.getContainer(), us, queryName); + } + + // The rationale is that if we are querying from a workbook, preferentially translate to the parent US + // However, there are situations like workbook-scoped lists, where that query might not exist on the parent + UserSchema parentUserSchema = QueryService.get().getUserSchema(us.getUser(), us.getContainer().getParent(), us.getSchemaPath()); + assert parentUserSchema != null; + + if (parentUserSchema.getTableNames().contains(queryName)) + { + return QueryService.get().createQueryDef(parentUserSchema.getUser(), parentUserSchema.getContainer(), parentUserSchema, queryName); + } + else + { + return QueryService.get().createQueryDef(us.getUser(), us.getContainer(), us, queryName); + } + } + public UserSchema getUserSchema(AbstractTableInfo ds, String name) { UserSchema us = ds.getUserSchema(); From 6646ed044d203215cfc7643c72aa8bfcb18c9083 Mon Sep 17 00:00:00 2001 From: bbimber Date: Sat, 15 Mar 2025 07:41:13 -0700 Subject: [PATCH 2/7] Explicitly set keyField to false --- .../labkey/laboratory/query/LaboratoryTableCustomizer.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/laboratory/src/org/labkey/laboratory/query/LaboratoryTableCustomizer.java b/laboratory/src/org/labkey/laboratory/query/LaboratoryTableCustomizer.java index 65c3b69c..83c01781 100644 --- a/laboratory/src/org/labkey/laboratory/query/LaboratoryTableCustomizer.java +++ b/laboratory/src/org/labkey/laboratory/query/LaboratoryTableCustomizer.java @@ -294,6 +294,7 @@ private void appendDemographicsCols(final UserSchema us, AbstractTableInfo ti, C col.setReadOnly(true); col.setIsUnselectable(true); col.setUserEditable(false); + col.setKeyField(false); UserSchema targetSchema = qd.getTableInfo(targetContainer, us.getUser()).getUserSchema(); col.setFk(new QueryForeignKey(us, ti.getContainerFilter(), targetSchema, null, qd.getQueryName(), qd.getTargetColumn(), qd.getTargetColumn()) @@ -370,6 +371,7 @@ private void appendMajorEventsCol(final UserSchema us, AbstractTableInfo ds, fin col.setReadOnly(true); col.setIsUnselectable(true); col.setUserEditable(false); + col.setKeyField(false); final String schemaName = ds.getUserSchema().getSchemaPath().toSQLString(); final String subjectSelectName = ds.getSqlDialect().makeLegalIdentifier(subjectColName); @@ -446,6 +448,7 @@ private void appendOverlapingProjectsCol(final UserSchema us, AbstractTableInfo col.setReadOnly(true); col.setIsUnselectable(true); col.setUserEditable(false); + col.setKeyField(false); col.setFk(new LookupForeignKey(){ @Override public TableInfo getLookupTableInfo() @@ -491,6 +494,7 @@ public TableInfo getLookupTableInfo() col2.setReadOnly(true); col2.setIsUnselectable(true); col2.setUserEditable(false); + col2.setKeyField(false); final String lookupColName = ds.getName() + "_overlappingProjectsPivot"; col2.setFk(new LookupForeignKey(){ @Override @@ -554,6 +558,7 @@ public void appendProjectsCol(final UserSchema us, AbstractTableInfo ds, final S col.setReadOnly(true); col.setIsUnselectable(true); col.setUserEditable(false); + col.setKeyField(false); col.setFk(new LookupForeignKey(){ @Override public TableInfo getLookupTableInfo() @@ -600,6 +605,7 @@ public TableInfo getLookupTableInfo() col2.setReadOnly(true); col2.setIsUnselectable(true); col2.setUserEditable(false); + col2.setKeyField(false); col2.setFk(new LookupForeignKey(){ @Override public TableInfo getLookupTableInfo() @@ -743,6 +749,7 @@ private void appendRelativeDatesCol(final UserSchema us, AbstractTableInfo ds, f col.setReadOnly(true); col.setIsUnselectable(true); col.setUserEditable(false); + col.setKeyField(false); final String colName = ds.getName() + "_relativeDates"; final String schemaName = ds.getUserSchema().getSchemaPath().toSQLString(); From 745b92511bebb20e5005c0feaa3a2cb89e451275 Mon Sep 17 00:00:00 2001 From: bbimber Date: Sat, 15 Mar 2025 09:00:16 -0700 Subject: [PATCH 3/7] Set col name --- .../org/labkey/api/ldk/table/ContainerScopedTable.java | 2 +- .../api/laboratory/query/ContainerIncrementingTable.java | 2 +- .../laboratory/query/LaboratoryTableCustomizer.java | 8 ++++++++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/LDK/api-src/org/labkey/api/ldk/table/ContainerScopedTable.java b/LDK/api-src/org/labkey/api/ldk/table/ContainerScopedTable.java index 975f117e..3575eeca 100644 --- a/LDK/api-src/org/labkey/api/ldk/table/ContainerScopedTable.java +++ b/LDK/api-src/org/labkey/api/ldk/table/ContainerScopedTable.java @@ -122,7 +122,7 @@ public DataIteratorBuilder persistRows(DataIteratorBuilder data, DataIteratorCon protected class UpdateService extends SimpleQueryUpdateService { - private KeyManager _keyManager = new KeyManager(); + private final KeyManager _keyManager = new KeyManager(); public UpdateService(SimpleUserSchema.SimpleTable ti) { diff --git a/laboratory/api-src/org/labkey/api/laboratory/query/ContainerIncrementingTable.java b/laboratory/api-src/org/labkey/api/laboratory/query/ContainerIncrementingTable.java index bc3e7843..0845cbc6 100644 --- a/laboratory/api-src/org/labkey/api/laboratory/query/ContainerIncrementingTable.java +++ b/laboratory/api-src/org/labkey/api/laboratory/query/ContainerIncrementingTable.java @@ -59,7 +59,7 @@ public ContainerIncrementingTable(UserSchema us, TableInfo st, ContainerFilter c } @Override - public SimpleUserSchema.SimpleTable init() + public SimpleUserSchema.SimpleTable init() { super.init(); diff --git a/laboratory/src/org/labkey/laboratory/query/LaboratoryTableCustomizer.java b/laboratory/src/org/labkey/laboratory/query/LaboratoryTableCustomizer.java index 83c01781..9184090c 100644 --- a/laboratory/src/org/labkey/laboratory/query/LaboratoryTableCustomizer.java +++ b/laboratory/src/org/labkey/laboratory/query/LaboratoryTableCustomizer.java @@ -185,6 +185,7 @@ public void customizeColumns(AbstractTableInfo ti) container.setHidden(true); BaseColumnInfo wrappedContainer = WrappedColumnInfo.wrapAsCopy(ti, FieldKey.fromString("workbook"), container, "Workbook", null); + wrappedContainer.setName("workbook"); wrappedContainer.setFk(QueryForeignKey .from(ti.getUserSchema(), ti.getContainerFilter()) .schema(us) @@ -291,6 +292,7 @@ private void appendDemographicsCols(final UserSchema us, AbstractTableInfo ti, C continue; BaseColumnInfo col = WrappedColumnInfo.wrapAsCopy(ti, FieldKey.fromString(name), subjectCol, qd.getLabel(), null); + col.setName(name); col.setReadOnly(true); col.setIsUnselectable(true); col.setUserEditable(false); @@ -368,6 +370,7 @@ private void appendMajorEventsCol(final UserSchema us, AbstractTableInfo ds, fin BaseColumnInfo col = WrappedColumnInfo.wrapAsCopy(ds, FieldKey.fromString(name), pk, "Major Events", null); 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."); + col.setName(name); col.setReadOnly(true); col.setIsUnselectable(true); col.setUserEditable(false); @@ -445,6 +448,7 @@ private void appendOverlapingProjectsCol(final UserSchema us, AbstractTableInfo BaseColumnInfo col = WrappedColumnInfo.wrapAsCopy(ds, FieldKey.fromString(name), pk, "Overlapping Groups", null); col.setDescription("This column shows all groups to which this subject belonged at the time of this sample."); + col.setName(name); col.setReadOnly(true); col.setIsUnselectable(true); col.setUserEditable(false); @@ -489,6 +493,7 @@ public TableInfo getLookupTableInfo() //add pivot column String pivotColName = "overlappingProjectsPivot"; BaseColumnInfo col2 = WrappedColumnInfo.wrapAsCopy(ds, FieldKey.fromString(pivotColName), pk, "Overlapping Group List", null); + col2.setName(pivotColName); col2.setDescription("Shows groups to which this subject belonged at the time of this sample."); col2.setHidden(true); col2.setReadOnly(true); @@ -554,6 +559,7 @@ public void appendProjectsCol(final UserSchema us, AbstractTableInfo ds, final S final String colName = ds.getName() + "_allProjects"; BaseColumnInfo col = WrappedColumnInfo.wrapAsCopy(ds, FieldKey.fromString(name), pk, "Groups", null); + col.setName(name); 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"); col.setReadOnly(true); col.setIsUnselectable(true); @@ -600,6 +606,7 @@ public TableInfo getLookupTableInfo() String pivotColName = "allProjectsPivot"; final String lookupName = ds.getName() + "_allProjectsPivot"; BaseColumnInfo col2 = WrappedColumnInfo.wrapAsCopy(ds, FieldKey.fromString(pivotColName), pk, "Group Summary List", null); + col2.setName(pivotColName); col2.setDescription("Shows groups to which this subject belonged at any point in time."); col2.setHidden(true); col2.setReadOnly(true); @@ -746,6 +753,7 @@ private void appendRelativeDatesCol(final UserSchema us, AbstractTableInfo ds, f final String pkColRawName = pk.getName(); BaseColumnInfo col = WrappedColumnInfo.wrapAsCopy(ds, FieldKey.fromString(name), pk, "Relative Dates", null); + col.setName(name); col.setReadOnly(true); col.setIsUnselectable(true); col.setUserEditable(false); From 69d734b8fe65d0962e0c9660f27e69c869f897ae Mon Sep 17 00:00:00 2001 From: bbimber Date: Sat, 15 Mar 2025 09:47:39 -0700 Subject: [PATCH 4/7] Set calculated=true --- .../laboratory/query/LaboratoryTableCustomizer.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/laboratory/src/org/labkey/laboratory/query/LaboratoryTableCustomizer.java b/laboratory/src/org/labkey/laboratory/query/LaboratoryTableCustomizer.java index 9184090c..07bc50f3 100644 --- a/laboratory/src/org/labkey/laboratory/query/LaboratoryTableCustomizer.java +++ b/laboratory/src/org/labkey/laboratory/query/LaboratoryTableCustomizer.java @@ -186,6 +186,7 @@ public void customizeColumns(AbstractTableInfo ti) BaseColumnInfo wrappedContainer = WrappedColumnInfo.wrapAsCopy(ti, FieldKey.fromString("workbook"), container, "Workbook", null); wrappedContainer.setName("workbook"); + wrappedContainer.setCalculated(true); wrappedContainer.setFk(QueryForeignKey .from(ti.getUserSchema(), ti.getContainerFilter()) .schema(us) @@ -293,6 +294,7 @@ private void appendDemographicsCols(final UserSchema us, AbstractTableInfo ti, C BaseColumnInfo col = WrappedColumnInfo.wrapAsCopy(ti, FieldKey.fromString(name), subjectCol, qd.getLabel(), null); col.setName(name); + col.setCalculated(true); col.setReadOnly(true); col.setIsUnselectable(true); col.setUserEditable(false); @@ -371,6 +373,7 @@ private void appendMajorEventsCol(final UserSchema us, AbstractTableInfo ds, fin BaseColumnInfo col = WrappedColumnInfo.wrapAsCopy(ds, FieldKey.fromString(name), pk, "Major Events", null); 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."); col.setName(name); + col.setCalculated(true); col.setReadOnly(true); col.setIsUnselectable(true); col.setUserEditable(false); @@ -449,6 +452,7 @@ private void appendOverlapingProjectsCol(final UserSchema us, AbstractTableInfo BaseColumnInfo col = WrappedColumnInfo.wrapAsCopy(ds, FieldKey.fromString(name), pk, "Overlapping Groups", null); col.setDescription("This column shows all groups to which this subject belonged at the time of this sample."); col.setName(name); + col.setCalculated(true); col.setReadOnly(true); col.setIsUnselectable(true); col.setUserEditable(false); @@ -494,6 +498,7 @@ public TableInfo getLookupTableInfo() String pivotColName = "overlappingProjectsPivot"; BaseColumnInfo col2 = WrappedColumnInfo.wrapAsCopy(ds, FieldKey.fromString(pivotColName), pk, "Overlapping Group List", null); col2.setName(pivotColName); + col2.setCalculated(true); col2.setDescription("Shows groups to which this subject belonged at the time of this sample."); col2.setHidden(true); col2.setReadOnly(true); @@ -560,6 +565,7 @@ public void appendProjectsCol(final UserSchema us, AbstractTableInfo ds, final S final String colName = ds.getName() + "_allProjects"; BaseColumnInfo col = WrappedColumnInfo.wrapAsCopy(ds, FieldKey.fromString(name), pk, "Groups", null); col.setName(name); + col.setCalculated(true); 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"); col.setReadOnly(true); col.setIsUnselectable(true); @@ -607,6 +613,7 @@ public TableInfo getLookupTableInfo() final String lookupName = ds.getName() + "_allProjectsPivot"; BaseColumnInfo col2 = WrappedColumnInfo.wrapAsCopy(ds, FieldKey.fromString(pivotColName), pk, "Group Summary List", null); col2.setName(pivotColName); + col2.setCalculated(true); col2.setDescription("Shows groups to which this subject belonged at any point in time."); col2.setHidden(true); col2.setReadOnly(true); @@ -754,6 +761,7 @@ private void appendRelativeDatesCol(final UserSchema us, AbstractTableInfo ds, f BaseColumnInfo col = WrappedColumnInfo.wrapAsCopy(ds, FieldKey.fromString(name), pk, "Relative Dates", null); col.setName(name); + col.setCalculated(true); col.setReadOnly(true); col.setIsUnselectable(true); col.setUserEditable(false); From fa845fa9c1333ad1a2d3ce93629417fff44833c1 Mon Sep 17 00:00:00 2001 From: bbimber Date: Sat, 15 Mar 2025 09:50:15 -0700 Subject: [PATCH 5/7] Set setShownInInsertView/setShownInUpdateView --- .../query/LaboratoryTableCustomizer.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/laboratory/src/org/labkey/laboratory/query/LaboratoryTableCustomizer.java b/laboratory/src/org/labkey/laboratory/query/LaboratoryTableCustomizer.java index 07bc50f3..57329cc1 100644 --- a/laboratory/src/org/labkey/laboratory/query/LaboratoryTableCustomizer.java +++ b/laboratory/src/org/labkey/laboratory/query/LaboratoryTableCustomizer.java @@ -187,6 +187,8 @@ public void customizeColumns(AbstractTableInfo ti) BaseColumnInfo wrappedContainer = WrappedColumnInfo.wrapAsCopy(ti, FieldKey.fromString("workbook"), container, "Workbook", null); wrappedContainer.setName("workbook"); wrappedContainer.setCalculated(true); + wrappedContainer.setShownInInsertView(false); + wrappedContainer.setShownInUpdateView(false); wrappedContainer.setFk(QueryForeignKey .from(ti.getUserSchema(), ti.getContainerFilter()) .schema(us) @@ -295,6 +297,8 @@ private void appendDemographicsCols(final UserSchema us, AbstractTableInfo ti, C BaseColumnInfo col = WrappedColumnInfo.wrapAsCopy(ti, FieldKey.fromString(name), subjectCol, qd.getLabel(), null); col.setName(name); col.setCalculated(true); + col.setShownInInsertView(false); + col.setShownInUpdateView(false); col.setReadOnly(true); col.setIsUnselectable(true); col.setUserEditable(false); @@ -374,6 +378,8 @@ private void appendMajorEventsCol(final UserSchema us, AbstractTableInfo ds, fin 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."); col.setName(name); col.setCalculated(true); + col.setShownInInsertView(false); + col.setShownInUpdateView(false); col.setReadOnly(true); col.setIsUnselectable(true); col.setUserEditable(false); @@ -453,6 +459,8 @@ private void appendOverlapingProjectsCol(final UserSchema us, AbstractTableInfo col.setDescription("This column shows all groups to which this subject belonged at the time of this sample."); col.setName(name); col.setCalculated(true); + col.setShownInInsertView(false); + col.setShownInUpdateView(false); col.setReadOnly(true); col.setIsUnselectable(true); col.setUserEditable(false); @@ -499,6 +507,8 @@ public TableInfo getLookupTableInfo() BaseColumnInfo col2 = WrappedColumnInfo.wrapAsCopy(ds, FieldKey.fromString(pivotColName), pk, "Overlapping Group List", null); col2.setName(pivotColName); col2.setCalculated(true); + col2.setShownInInsertView(false); + col2.setShownInUpdateView(false); col2.setDescription("Shows groups to which this subject belonged at the time of this sample."); col2.setHidden(true); col2.setReadOnly(true); @@ -566,6 +576,8 @@ public void appendProjectsCol(final UserSchema us, AbstractTableInfo ds, final S BaseColumnInfo col = WrappedColumnInfo.wrapAsCopy(ds, FieldKey.fromString(name), pk, "Groups", null); col.setName(name); col.setCalculated(true); + col.setShownInInsertView(false); + col.setShownInUpdateView(false); 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"); col.setReadOnly(true); col.setIsUnselectable(true); @@ -614,6 +626,8 @@ public TableInfo getLookupTableInfo() BaseColumnInfo col2 = WrappedColumnInfo.wrapAsCopy(ds, FieldKey.fromString(pivotColName), pk, "Group Summary List", null); col2.setName(pivotColName); col2.setCalculated(true); + col2.setShownInInsertView(false); + col2.setShownInUpdateView(false); col2.setDescription("Shows groups to which this subject belonged at any point in time."); col2.setHidden(true); col2.setReadOnly(true); @@ -762,6 +776,8 @@ private void appendRelativeDatesCol(final UserSchema us, AbstractTableInfo ds, f BaseColumnInfo col = WrappedColumnInfo.wrapAsCopy(ds, FieldKey.fromString(name), pk, "Relative Dates", null); col.setName(name); col.setCalculated(true); + col.setShownInInsertView(false); + col.setShownInUpdateView(false); col.setReadOnly(true); col.setIsUnselectable(true); col.setUserEditable(false); From 37b3a157261d072b36b582f43977b5f21450bb2b Mon Sep 17 00:00:00 2001 From: bbimber Date: Sat, 15 Mar 2025 10:34:26 -0700 Subject: [PATCH 6/7] Update URL --- .../org/labkey/laboratory/query/LaboratoryTableCustomizer.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/laboratory/src/org/labkey/laboratory/query/LaboratoryTableCustomizer.java b/laboratory/src/org/labkey/laboratory/query/LaboratoryTableCustomizer.java index 57329cc1..5f0ae687 100644 --- a/laboratory/src/org/labkey/laboratory/query/LaboratoryTableCustomizer.java +++ b/laboratory/src/org/labkey/laboratory/query/LaboratoryTableCustomizer.java @@ -193,7 +193,7 @@ public void customizeColumns(AbstractTableInfo ti) .from(ti.getUserSchema(), ti.getContainerFilter()) .schema(us) .to("workbooks", LaboratoryWorkbooksTable.WORKBOOK_COL, "workbookId")); - wrappedContainer.setURL(DetailsURL.fromString("/project/start.view")); + wrappedContainer.setURL(DetailsURL.fromString("/project/begin.view")); wrappedContainer.setShownInDetailsView(true); wrappedContainer.setFacetingBehaviorType(FacetingBehaviorType.ALWAYS_OFF); wrappedContainer.setDisplayColumnFactory(new DisplayColumnFactory() From 5cdcedcb53a9289ea0999805fd112ea9d003214c Mon Sep 17 00:00:00 2001 From: bbimber Date: Sat, 15 Mar 2025 11:47:04 -0700 Subject: [PATCH 7/7] Code cleanup --- LDK/src/org/labkey/ldk/LDKController.java | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/LDK/src/org/labkey/ldk/LDKController.java b/LDK/src/org/labkey/ldk/LDKController.java index 3f40d163..168ac090 100644 --- a/LDK/src/org/labkey/ldk/LDKController.java +++ b/LDK/src/org/labkey/ldk/LDKController.java @@ -847,14 +847,10 @@ public ModelAndView getView(QueryForm form, BindException errors) throws Excepti if (keyField != null) { + // Note: the ContainerContext will need to be set within QueryView DetailsURL importUrl = DetailsURL.fromString("/query/importData.view?schemaName=" + schemaName + "&query.queryName=" + queryName + "&keyField=" + keyField); - importUrl.setContainerContext(getContainer()); - DetailsURL updateUrl = DetailsURL.fromString("/ldk/manageRecord.view?schemaName=" + schemaName + "&query.queryName=" + queryName + "&keyField=" + keyField + "&key=${" + keyField + "}"); - updateUrl.setContainerContext(getContainer()); - DetailsURL deleteUrl = DetailsURL.fromString("/query/deleteQueryRows.view?schemaName=" + schemaName + "&query.queryName=" + queryName); - deleteUrl.setContainerContext(getContainer()); url.addParameter("importURL", importUrl.toString()); url.addParameter("updateURL", updateUrl.toString()); @@ -866,7 +862,7 @@ public ModelAndView getView(QueryForm form, BindException errors) throws Excepti url.addParameter("queryName", queryName); url.addParameter("allowChooseQuery", false); - WebPartFactory factory = Portal.getPortalPartCaseInsensitive("Query"); + WebPartFactory factory = Portal.getPortalPart("Query"); Portal.WebPart part = factory.createWebPart(); part.setProperties(url.getQueryString());