From e213346f05148a390af648611f9643304051822f Mon Sep 17 00:00:00 2001 From: Adam Rauch Date: Tue, 24 Nov 2026 14:53:47 -0800 Subject: [PATCH 1/2] Kanban 2228: Report attachments whose container doesn't match their parent's --- .../bluesky/PanoramaPublicLogoResourceType.java | 2 +- .../catalog/CatalogImageAttachmentType.java | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/panoramapublic/src/org/labkey/panoramapublic/bluesky/PanoramaPublicLogoResourceType.java b/panoramapublic/src/org/labkey/panoramapublic/bluesky/PanoramaPublicLogoResourceType.java index cb1d3554..6229ff7d 100644 --- a/panoramapublic/src/org/labkey/panoramapublic/bluesky/PanoramaPublicLogoResourceType.java +++ b/panoramapublic/src/org/labkey/panoramapublic/bluesky/PanoramaPublicLogoResourceType.java @@ -51,7 +51,7 @@ public void addWhereSql(SQLFragment sql, String parentColumn, String documentNam } @Override - public @NotNull SQLFragment getSelectEntityIdAndDescriptionSql() + public @NotNull SQLFragment getSelectEntityIdContainerAndDescriptionSql() { return PARENT_CONTAINER_SQL; } diff --git a/panoramapublic/src/org/labkey/panoramapublic/catalog/CatalogImageAttachmentType.java b/panoramapublic/src/org/labkey/panoramapublic/catalog/CatalogImageAttachmentType.java index e9a66595..1320a72f 100644 --- a/panoramapublic/src/org/labkey/panoramapublic/catalog/CatalogImageAttachmentType.java +++ b/panoramapublic/src/org/labkey/panoramapublic/catalog/CatalogImageAttachmentType.java @@ -19,6 +19,7 @@ import org.labkey.api.attachments.AttachmentParentType; import org.labkey.api.data.CoreSchema; import org.labkey.api.data.SQLFragment; +import org.labkey.panoramapublic.PanoramaPublicManager; public class CatalogImageAttachmentType implements AttachmentParentType { @@ -40,8 +41,13 @@ private CatalogImageAttachmentType() } @Override - public @NotNull SQLFragment getSelectEntityIdAndDescriptionSql() + public @NotNull SQLFragment getSelectEntityIdContainerAndDescriptionSql() { - return new SQLFragment("SELECT EntityId, ShortUrl AS Description FROM ").append(CoreSchema.getInstance().getTableInfoShortURL()); + // The image's attachment parent uses the container of the experiment that owns the short URL + return SQLFragment.unsafe("SELECT su.EntityId, ea.Container, su.ShortUrl AS Description FROM ") + .append(CoreSchema.getInstance().getTableInfoShortURL(), "su") + .unsafeAppend(" LEFT JOIN ") + .append(PanoramaPublicManager.getTableInfoExperimentAnnotations(), "ea") + .unsafeAppend(" ON ea.ShortUrl = su.EntityId"); } } From 8642ea4fd1bb3a452a9aeaf3923a08416d7c8dc1 Mon Sep 17 00:00:00 2001 From: Adam Rauch Date: Tue, 24 Nov 2026 19:08:39 -0800 Subject: [PATCH 2/2] Kanban 2292: Migrate Panorama Public attachments and report unowned catalog images as orphans --- .../PanoramaPublicMigrationHandler.java | 67 +++++++++++++++++++ .../panoramapublic/PanoramaPublicModule.java | 7 ++ .../catalog/CatalogImageAttachmentType.java | 5 +- 3 files changed, 77 insertions(+), 2 deletions(-) create mode 100644 panoramapublic/src/org/labkey/panoramapublic/PanoramaPublicMigrationHandler.java diff --git a/panoramapublic/src/org/labkey/panoramapublic/PanoramaPublicMigrationHandler.java b/panoramapublic/src/org/labkey/panoramapublic/PanoramaPublicMigrationHandler.java new file mode 100644 index 00000000..453e6cde --- /dev/null +++ b/panoramapublic/src/org/labkey/panoramapublic/PanoramaPublicMigrationHandler.java @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2026 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.panoramapublic; + +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import org.labkey.api.attachments.AttachmentParentType; +import org.labkey.api.data.DbSchema; +import org.labkey.api.data.SQLFragment; +import org.labkey.api.data.SimpleFilter.SQLClause; +import org.labkey.api.migration.DatabaseMigrationConfiguration; +import org.labkey.api.migration.DefaultMigrationSchemaHandler; +import org.labkey.api.util.GUID; +import org.labkey.panoramapublic.bluesky.PanoramaPublicLogoManager; +import org.labkey.panoramapublic.bluesky.PanoramaPublicLogoResourceType; +import org.labkey.panoramapublic.catalog.CatalogImageAttachmentType; + +import java.util.Collection; +import java.util.LinkedList; +import java.util.List; +import java.util.Set; + +class PanoramaPublicMigrationHandler extends DefaultMigrationSchemaHandler +{ + PanoramaPublicMigrationHandler() + { + super(PanoramaPublicSchema.getSchema()); + } + + @Override + public @NotNull Collection getAttachmentTypes() + { + return List.of(CatalogImageAttachmentType.get()); + } + + @Override + public Collection copyAttachments(DatabaseMigrationConfiguration configuration, DbSchema sourceSchema, DbSchema targetSchema, @Nullable Set copyContainers) + { + Collection ret = new LinkedList<>(super.copyAttachments(configuration, sourceSchema, targetSchema, copyContainers)); + + // Logos are attached to their container, so select them by name instead + SQLFragment sql = SQLFragment.unsafe("Parent"); + + if (copyContainers != null) + sql.appendInClause(copyContainers, sourceSchema.getSqlDialect()); + else + sql.unsafeAppend(" IN (SELECT EntityId FROM core.Containers)"); + + sql.unsafeAppend(" AND Name LIKE ?", PanoramaPublicLogoManager.LOGO_FILE_PREFIX + "%"); + ret.addAll(copyAttachments(configuration, new SQLClause(sql), PanoramaPublicLogoResourceType.get())); + + return ret; + } +} diff --git a/panoramapublic/src/org/labkey/panoramapublic/PanoramaPublicModule.java b/panoramapublic/src/org/labkey/panoramapublic/PanoramaPublicModule.java index d175c5d4..0ae16232 100644 --- a/panoramapublic/src/org/labkey/panoramapublic/PanoramaPublicModule.java +++ b/panoramapublic/src/org/labkey/panoramapublic/PanoramaPublicModule.java @@ -26,6 +26,7 @@ import org.labkey.api.data.SimpleFilter; import org.labkey.api.exp.api.ExperimentService; import org.labkey.api.files.FileContentService; +import org.labkey.api.migration.DatabaseMigrationService; import org.labkey.api.module.ModuleContext; import org.labkey.api.module.SpringModule; import org.labkey.api.pipeline.PipelineService; @@ -120,6 +121,12 @@ protected void init() AttachmentService.get().registerAttachmentParentType(PanoramaPublicLogoResourceType.get()); } + @Override + public void registerMigrationHandlers(@NotNull DatabaseMigrationService service) + { + service.registerSchemaHandler(new PanoramaPublicMigrationHandler()); + } + @Override protected void startupAfterSpringConfig(ModuleContext moduleContext) { diff --git a/panoramapublic/src/org/labkey/panoramapublic/catalog/CatalogImageAttachmentType.java b/panoramapublic/src/org/labkey/panoramapublic/catalog/CatalogImageAttachmentType.java index 1320a72f..2d3a549a 100644 --- a/panoramapublic/src/org/labkey/panoramapublic/catalog/CatalogImageAttachmentType.java +++ b/panoramapublic/src/org/labkey/panoramapublic/catalog/CatalogImageAttachmentType.java @@ -43,10 +43,11 @@ private CatalogImageAttachmentType() @Override public @NotNull SQLFragment getSelectEntityIdContainerAndDescriptionSql() { - // The image's attachment parent uses the container of the experiment that owns the short URL + // The image's attachment parent uses the container of the experiment that owns the short URL; images whose short + // URL no experiment owns are orphans return SQLFragment.unsafe("SELECT su.EntityId, ea.Container, su.ShortUrl AS Description FROM ") .append(CoreSchema.getInstance().getTableInfoShortURL(), "su") - .unsafeAppend(" LEFT JOIN ") + .unsafeAppend(" INNER JOIN ") .append(PanoramaPublicManager.getTableInfoExperimentAnnotations(), "ea") .unsafeAppend(" ON ea.ShortUrl = su.EntityId"); }