From c96d2a4ecde7a81d11d7285bbc240f81fc9e2d34 Mon Sep 17 00:00:00 2001 From: labkey-susanh Date: Fri, 13 Feb 2026 07:55:54 -0800 Subject: [PATCH] Better handling for an empty UnreferencedSampleFiles table and make test reset flags --- .../ExpUnreferencedSampleFilesTableImpl.java | 60 ++++++++++--------- 1 file changed, 32 insertions(+), 28 deletions(-) diff --git a/experiment/src/org/labkey/experiment/api/ExpUnreferencedSampleFilesTableImpl.java b/experiment/src/org/labkey/experiment/api/ExpUnreferencedSampleFilesTableImpl.java index fb4cbe5ab2f..cdb35f20821 100644 --- a/experiment/src/org/labkey/experiment/api/ExpUnreferencedSampleFilesTableImpl.java +++ b/experiment/src/org/labkey/experiment/api/ExpUnreferencedSampleFilesTableImpl.java @@ -48,38 +48,42 @@ public FileUnionTable(@NotNull ExpSchema schema) FileContentService svc = FileContentService.get(); _query = new SQLFragment(); - if (svc == null) - return; - - SQLFragment listQuery = svc.listSampleFilesQuery(schema.getUser()); - if (StringUtils.isEmpty(listQuery)) - return; - - TableInfo expDataTable = ExperimentService.get().getTinfoData(); - TableInfo materialTable = ExperimentService.get().getTinfoMaterial(); + SQLFragment listQuery = new SQLFragment(); + if (svc != null) + listQuery = svc.listSampleFilesQuery(schema.getUser()); _query.appendComment("", getSchema().getSqlDialect()); - SQLFragment sampleFileSql = new SQLFragment("SELECT m.Container, if.FilePathShort \n") - .append("FROM (") - .append(svc.listSampleFilesQuery(schema.getUser())) - .append(") AS if \n") - .append("JOIN ") - .append(materialTable, "m") - .append(" ON if.SourceKey = m.RowId"); - - SQLFragment unreferencedFileSql = new SQLFragment("SELECT ed.rowId, ed.name as filename, ed.container, ed.created, ed.createdBy, ed.DataFileUrl FROM ") - .append(expDataTable, "ed") - .append(" LEFT JOIN (") - .append(sampleFileSql) - .append(" ) sf\n") - .append(" ON ed.name = sf.FilePathShort AND ed.container = sf.container\n") - .append(" WHERE ed.datafileurl LIKE ") - .appendValue("%@files/sampletype/%") - .append(" AND sf.FilePathShort IS NULL"); - - _query.append(unreferencedFileSql); + TableInfo expDataTable = ExperimentService.get().getTinfoData(); + if (!StringUtils.isEmpty(listQuery)) + { + TableInfo materialTable = ExperimentService.get().getTinfoMaterial(); + + SQLFragment sampleFileSql = new SQLFragment("SELECT m.Container, if.FilePathShort \n") + .append("FROM (") + .append(listQuery) + .append(") AS if \n") + .append("JOIN ") + .append(materialTable, "m") + .append(" ON if.SourceKey = m.RowId"); + + SQLFragment unreferencedFileSql = new SQLFragment("SELECT ed.rowId, ed.name as filename, ed.container, ed.created, ed.createdBy, ed.DataFileUrl FROM ") + .append(expDataTable, "ed") + .append(" LEFT JOIN (") + .append(sampleFileSql) + .append(" ) sf\n") + .append(" ON ed.name = sf.FilePathShort AND ed.container = sf.container\n") + .append(" WHERE ed.datafileurl LIKE ") + .appendValue("%@files/sampletype/%") + .append(" AND sf.FilePathShort IS NULL"); + + _query.append(unreferencedFileSql); + } + else + { + _query.append("SELECT RowId, FileName, Container, Created, CreatedBy, DataFileUrl FROM ").append(expDataTable).append(" WHERE (1=0)"); + } _query.appendComment("", getSchema().getSqlDialect()); var rowIdCol = new BaseColumnInfo("RowId", this, JdbcType.INTEGER);