Skip to content
Merged
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
43 changes: 43 additions & 0 deletions announcements/src/org/labkey/announcements/AnnouncementModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,19 @@
import org.labkey.api.announcements.CommSchema;
import org.labkey.api.announcements.api.AnnouncementService;
import org.labkey.api.attachments.AttachmentService;
import org.labkey.api.attachments.AttachmentType;
import org.labkey.api.audit.AuditLogService;
import org.labkey.api.audit.provider.MessageAuditProvider;
import org.labkey.api.data.Container;
import org.labkey.api.data.ContainerManager;
import org.labkey.api.data.DbSchema;
import org.labkey.api.data.SqlExecutor;
import org.labkey.api.data.TableInfo;
import org.labkey.api.message.digest.DailyMessageDigest;
import org.labkey.api.message.settings.MessageConfigService;
import org.labkey.api.migration.DatabaseMigrationConfiguration;
import org.labkey.api.migration.DatabaseMigrationService;
import org.labkey.api.migration.DefaultMigrationSchemaHandler;
import org.labkey.api.module.DefaultModule;
import org.labkey.api.module.ModuleContext;
import org.labkey.api.rss.RSSService;
Expand All @@ -53,6 +59,7 @@
import org.labkey.api.view.ViewContext;
import org.labkey.api.view.WebPartFactory;
import org.labkey.api.view.WebPartView;
import org.labkey.api.wiki.WikiService;

import java.util.ArrayList;
import java.util.Collection;
Expand Down Expand Up @@ -165,6 +172,42 @@ public void doStartup(ModuleContext moduleContext)
{
fsr.addFactories(new NotificationSettingsWriterFactory(), new NotificationSettingsImporterFactory());
}

// AnnouncementModule owns the schema, so it registers the schema handler... even though it's mostly about wiki
DatabaseMigrationService.get().registerSchemaHandler(new DefaultMigrationSchemaHandler(CommSchema.getInstance().getSchema())
{
@Override
public void beforeSchema()
{
new SqlExecutor(getSchema()).execute("ALTER TABLE comm.Pages DROP CONSTRAINT FK_Pages_PageVersions");
new SqlExecutor(getSchema()).execute("ALTER TABLE comm.Pages DROP CONSTRAINT FK_Pages_Parent");
}

@Override
public List<TableInfo> getTablesToCopy()
{
List<TableInfo> tablesToCopy = super.getTablesToCopy();
tablesToCopy.add(CommSchema.getInstance().getTableInfoPages());
tablesToCopy.add(CommSchema.getInstance().getTableInfoPageVersions());

return tablesToCopy;
}

@Override
public void afterSchema(DatabaseMigrationConfiguration configuration, DbSchema sourceSchema, DbSchema targetSchema)
{
new SqlExecutor(getSchema()).execute("ALTER TABLE comm.Pages ADD CONSTRAINT FK_Pages_PageVersions FOREIGN KEY (PageVersionId) REFERENCES comm.PageVersions (RowId)");
new SqlExecutor(getSchema()).execute("ALTER TABLE comm.Pages ADD CONSTRAINT FK_Pages_Parent FOREIGN KEY (Parent) REFERENCES comm.Pages (RowId)");
}

@Override
public @NotNull Collection<AttachmentType> getAttachmentTypes()
{
// It's theoretically possible to deploy Announcement without Wiki, so conditionalize
WikiService ws = WikiService.get();
return ws != null ? List.of(AnnouncementType.get(), ws.getAttachmentType()) : List.of(AnnouncementType.get());
}
});
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package org.labkey.announcements.model;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.labkey.api.announcements.CommSchema;
import org.labkey.api.attachments.AttachmentType;
import org.labkey.api.data.SQLFragment;
Expand All @@ -40,8 +41,8 @@ public static AttachmentType get()
}

@Override
public void addWhereSql(SQLFragment sql, String parentColumn, String documentNameColumn)
public @Nullable SQLFragment getSelectParentEntityIdsSql()
{
sql.append(parentColumn).append(" IN (SELECT EntityId FROM ").append(CommSchema.getInstance().getTableInfoAnnouncements(), "ann").append(")");
return new SQLFragment("SELECT EntityId FROM ").append(CommSchema.getInstance().getTableInfoAnnouncements(), "ann");
}
}
2 changes: 0 additions & 2 deletions api/src/org/labkey/api/ApiModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import org.labkey.api.attachments.AttachmentService;
import org.labkey.api.attachments.ImageServlet;
import org.labkey.api.attachments.LookAndFeelResourceType;
import org.labkey.api.attachments.SecureDocumentType;
import org.labkey.api.audit.query.AbstractAuditDomainKind;
import org.labkey.api.cache.BlockingCache;
import org.labkey.api.collections.ArrayListMap;
Expand Down Expand Up @@ -222,7 +221,6 @@ protected void init()
AttachmentService.get().registerAttachmentType(LookAndFeelResourceType.get());
AttachmentService.get().registerAttachmentType(AuthenticationLogoType.get());
AttachmentService.get().registerAttachmentType(AvatarType.get());
AttachmentService.get().registerAttachmentType(SecureDocumentType.get());

PropertyManager.registerEncryptionMigrationHandler();
AuthenticationManager.registerEncryptionMigrationHandler();
Expand Down
5 changes: 5 additions & 0 deletions api/src/org/labkey/api/attachments/AttachmentService.java
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,11 @@ static AttachmentService get()

void registerAttachmentType(AttachmentType type);

/**
* Returns a collection of all registered AttachmentTypes
**/
Collection<AttachmentType> getAttachmentTypes();

HttpView<?> getAdminView(ActionURL currentUrl);

HttpView<?> getFindAttachmentParentsView();
Expand Down
28 changes: 25 additions & 3 deletions api/src/org/labkey/api/attachments/AttachmentType.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,17 @@
package org.labkey.api.attachments;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.labkey.api.data.SQLFragment;

/**
* Tags {@link Attachment} objects based on their intended use and what they're attached to. Does not
* necessarily indicate that they are a file of a particular type/format.
* indicate that they are a file of a particular type/format.
*/
public interface AttachmentType
{
SQLFragment NO_ENTITY_IDS = new SQLFragment("SELECT NULL AS EntityId WHERE 1 = 0");

AttachmentType UNKNOWN = new AttachmentType()
{
@NotNull
Expand All @@ -43,10 +46,29 @@ public void addWhereSql(SQLFragment sql, String parentColumn, String documentNam
@NotNull String getUniqueName();

/**
* Append to the where clause of a query that wants to select attachments of the implementing type
* Append to the where clause of a query that wants to select attachments of the implementing type from the
* core.Documents table
* @param sql Implementers MUST append a valid where clause to this SQLFragment
* @param parentColumn Column identifier for use in where clause. Usually represents 'core.Documents.Parent'
* @param documentNameColumn Column identifier for use in where clause. Usually represents 'core.Documents.DocumentName'
*/
void addWhereSql(SQLFragment sql, String parentColumn, String documentNameColumn);
default void addWhereSql(SQLFragment sql, String parentColumn, String documentNameColumn)
{
SQLFragment selectSql = getSelectParentEntityIdsSql();
if (selectSql == null)
throw new IllegalStateException("Must override either addWhereSql() or getSelectParentEntityIdsSql()");
sql.append(parentColumn).append(" IN (").append(selectSql).append(")");
}

/**
* Return a SQLFragment that selects all the EntityIds that might be attachment parents from the table(s) that
* provide attachments of this type, without involving the core.Documents table. For example,
* {@code SELECT EntityId FROM comm.Announcements}. Return null if this is not-yet-implemented or inappropriate.
* For example, some attachments' parents are container IDs. If the method determines that no parents exist, then
* return a valid query that selects no rows, for example, {@code NO_ENTITY_IDS}.
*/
default @Nullable SQLFragment getSelectParentEntityIdsSql()
{
return null;
}
}
45 changes: 0 additions & 45 deletions api/src/org/labkey/api/attachments/SecureDocumentType.java

This file was deleted.

22 changes: 22 additions & 0 deletions api/src/org/labkey/api/collections/ArrayListValuedTreeMap.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package org.labkey.api.collections;

import org.apache.commons.collections4.multimap.AbstractListValuedMap;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.TreeMap;

public class ArrayListValuedTreeMap<K, V> extends AbstractListValuedMap<K, V>
{
public ArrayListValuedTreeMap(Comparator<? super K> comparator)
{
super(new TreeMap<>(comparator));
}

@Override
protected List<V> createCollection()
{
return new ArrayList<>();
}
}
59 changes: 0 additions & 59 deletions api/src/org/labkey/api/data/DatabaseMigrationConfiguration.java

This file was deleted.

Loading