Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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<AttachmentParentType> getAttachmentTypes()
{
return List.of(CatalogImageAttachmentType.get());
}

@Override
public Collection<AttachmentParentType> copyAttachments(DatabaseMigrationConfiguration configuration, DbSchema sourceSchema, DbSchema targetSchema, @Nullable Set<GUID> copyContainers)
{
Collection<AttachmentParentType> 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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -40,8 +41,14 @@ 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; 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(" INNER JOIN ")
.append(PanoramaPublicManager.getTableInfoExperimentAnnotations(), "ea")
.unsafeAppend(" ON ea.ShortUrl = su.EntityId");
}
}