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
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ api/src/org/labkey/api/attachments/AttachmentDirectory.java -text
api/src/org/labkey/api/attachments/AttachmentFile.java -text
api/src/org/labkey/api/attachments/AttachmentForm.java -text
api/src/org/labkey/api/attachments/AttachmentParent.java -text
api/src/org/labkey/api/attachments/AttachmentParentType.java -text
api/src/org/labkey/api/attachments/AttachmentParentFactory.java -text
api/src/org/labkey/api/attachments/AttachmentService.java -text
api/src/org/labkey/api/attachments/AttachmentType.java -text
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
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.attachments.AttachmentParentType;
import org.labkey.api.audit.AuditLogService;
import org.labkey.api.audit.provider.MessageAuditProvider;
import org.labkey.api.data.Container;
Expand Down Expand Up @@ -106,7 +106,7 @@ protected void init()
EmailTemplateService.get().registerTemplate(AnnouncementManager.NotificationEmailTemplate.class);
EmailTemplateService.get().registerTemplate(AnnouncementDigestProvider.DailyDigestEmailTemplate.class);

AttachmentService.get().registerAttachmentType(AnnouncementType.get());
AttachmentService.get().registerAttachmentParentType(AnnouncementType.get());
}

@Override
Expand Down Expand Up @@ -201,7 +201,7 @@ public void afterSchema(DatabaseMigrationConfiguration configuration, DbSchema s
}

@Override
public @NotNull Collection<AttachmentType> getAttachmentTypes()
public @NotNull Collection<AttachmentParentType> getAttachmentTypes()
{
// It's theoretically possible to deploy Announcement without Wiki, so conditionalize
WikiService ws = WikiService.get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
package org.labkey.announcements.model;

import org.jetbrains.annotations.NotNull;
import org.labkey.api.attachments.AttachmentType;
import org.labkey.api.attachments.AttachmentParentType;
import org.labkey.api.data.EntityAttachmentParent;

public class AnnouncementAttachmentParent extends EntityAttachmentParent
Expand All @@ -28,7 +28,7 @@ public AnnouncementAttachmentParent(AnnouncementModel ann)

@NotNull
@Override
public AttachmentType getAttachmentType()
public AttachmentParentType getAttachmentParentType()
{
return AnnouncementType.get();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,26 @@
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.attachments.AttachmentParentType;
import org.labkey.api.data.SQLFragment;

public class AnnouncementType implements AttachmentType
public class AnnouncementType implements AttachmentParentType
{
private static final AttachmentType INSTANCE = new AnnouncementType();
private static final AttachmentParentType INSTANCE = new AnnouncementType();

private AnnouncementType()
{
}

public static AttachmentType get()
public static AttachmentParentType get()
{
return INSTANCE;
}

@Override
public @NotNull String getUniqueName()
{
return getClass().getName();
return "Announcement";
}

@Override
Expand Down
14 changes: 14 additions & 0 deletions api/resources/queries/core/DocumentsGroupedByParentType.query.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<query xmlns="http://labkey.org/data/xml/query" hidden="true">
<metadata>
<tables xmlns="http://labkey.org/data/xml">
<table tableName="DocumentsGroupedByParentType" tableDbType="NOT_IN_DB">
<columns>
<column columnName="Count">
<url replaceMissing="blankValue">query-executeQuery.view?schemaName=core&amp;queryName=Documents&amp;query.ParentType~eq=${ParentType}&amp;query.containerFilterName=${containerFilterName}</url>
<formatString>#,##0</formatString>
</column>
</columns>
</table>
</tables>
</metadata>
</query>
4 changes: 4 additions & 0 deletions api/resources/queries/core/DocumentsGroupedByParentType.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
SELECT ParentType, COUNT(*) AS "Count"
FROM Documents
GROUP BY ParentType
ORDER BY ParentType
8 changes: 4 additions & 4 deletions api/src/org/labkey/api/ApiModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -217,10 +217,10 @@ public class ApiModule extends CodeOnlyModule
protected void init()
{
ModuleLoader.getInstance().registerResourcePrefix("/org/labkey/vfs", this);
AttachmentService.get().registerAttachmentType(ReportType.get());
AttachmentService.get().registerAttachmentType(LookAndFeelResourceType.get());
AttachmentService.get().registerAttachmentType(AuthenticationLogoType.get());
AttachmentService.get().registerAttachmentType(AvatarType.get());
AttachmentService.get().registerAttachmentParentType(ReportType.get());
AttachmentService.get().registerAttachmentParentType(LookAndFeelResourceType.get());
AttachmentService.get().registerAttachmentParentType(AuthenticationLogoType.get());
AttachmentService.get().registerAttachmentParentType(AvatarType.get());

PropertyManager.registerEncryptionMigrationHandler();
AuthenticationManager.registerEncryptionMigrationHandler();
Expand Down
2 changes: 1 addition & 1 deletion api/src/org/labkey/api/attachments/AttachmentParent.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ public interface AttachmentParent
{
String getEntityId();
String getContainerId();
@NotNull AttachmentType getAttachmentType();
@NotNull AttachmentParentType getAttachmentParentType();
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,20 @@
import org.labkey.api.data.SQLFragment;

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

AttachmentType UNKNOWN = new AttachmentType()
AttachmentParentType UNKNOWN = new AttachmentParentType()
{
@NotNull
@Override
public String getUniqueName()
{
return "UnknownAttachmentType";
return "Unknown";
}

@Override
Expand All @@ -43,6 +43,7 @@ public void addWhereSql(SQLFragment sql, String parentColumn, String documentNam
}
};

// A short, human-friendly, unique name for this attachment parent type
@NotNull String getUniqueName();

/**
Expand Down
4 changes: 2 additions & 2 deletions api/src/org/labkey/api/attachments/AttachmentService.java
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,12 @@ static AttachmentService get()

void clearLastIndexed(List<String> parentIds);

void registerAttachmentType(AttachmentType type);
void registerAttachmentParentType(AttachmentParentType type);

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

HttpView<?> getAdminView(ActionURL currentUrl);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public LookAndFeelResourceAttachmentParent(Container c)
}

@Override
public @NotNull AttachmentType getAttachmentType()
public @NotNull AttachmentParentType getAttachmentParentType()
{
return LookAndFeelResourceType.get();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import org.labkey.api.data.CoreSchema;
import org.labkey.api.data.SQLFragment;

public class LookAndFeelResourceType implements AttachmentType
public class LookAndFeelResourceType implements AttachmentParentType
{
private static final LookAndFeelResourceType INSTANCE = new LookAndFeelResourceType();

Expand All @@ -35,7 +35,7 @@ private LookAndFeelResourceType()
@Override
public @NotNull String getUniqueName()
{
return getClass().getName();
return "LookAndFeelResource";
}

@Override
Expand Down
6 changes: 3 additions & 3 deletions api/src/org/labkey/api/data/AttachmentDisplayColumn.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import org.jetbrains.annotations.NotNull;
import org.labkey.api.attachments.AttachmentParent;
import org.labkey.api.attachments.AttachmentService;
import org.labkey.api.attachments.AttachmentType;
import org.labkey.api.attachments.AttachmentParentType;
import org.labkey.api.query.FieldKey;

import java.io.File;
Expand Down Expand Up @@ -105,9 +105,9 @@ public String getContainerId()
}

@Override
public @NotNull AttachmentType getAttachmentType()
public @NotNull AttachmentParentType getAttachmentParentType()
{
return AttachmentType.UNKNOWN;
return AttachmentParentType.UNKNOWN;
}
}
}
18 changes: 14 additions & 4 deletions api/src/org/labkey/api/data/SqlScriptExecutor.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@

import org.apache.commons.lang3.mutable.MutableBoolean;
import org.apache.commons.lang3.mutable.MutableInt;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.labkey.api.cache.CacheManager;
import org.labkey.api.module.DefaultModule.UpgradeMethod;
import org.labkey.api.module.ModuleContext;
import org.labkey.api.module.ModuleLoader;
import org.labkey.api.util.logging.LogHelper;

import java.lang.reflect.Method;
import java.sql.Connection;
Expand All @@ -41,7 +42,7 @@
*/
public class SqlScriptExecutor
{
private static final Logger _log = LogManager.getLogger(SqlScriptExecutor.class);
private static final Logger LOG = LogHelper.getLogger(SqlScriptExecutor.class, "Upgrade code invocations");

private final String _scriptName;
private final String _sql;
Expand Down Expand Up @@ -202,19 +203,23 @@ public void execute()

UpgradeMethod upgradeMethod = new UpgradeMethod(_moduleContext, _scriptName, _methodName);

// Make sure cached database metadata reflects all previously executed SQL. For example, core.UpgradeSteps
// needs to appear as "in the physical database" before any deferred upgrade methods can be stashed.
CacheManager.clearAllKnownCaches();

try
{
// Retrieve Method in all cases (even deferred upgrade) to proactively validate
Method method = upgradeMethod.getMethod();

if (method.isAnnotationPresent(DeferredUpgrade.class))
{
_log.info("Adding deferred upgrade to execute {}", upgradeMethod.getDisplayName());
LOG.info("Adding deferred upgrade to execute {}", upgradeMethod.getDisplayName());
_moduleContext.addDeferredUpgradeMethod(upgradeMethod);
}
else
{
_log.info("Executing {}", upgradeMethod.getDisplayName());
LOG.info("Executing {}", upgradeMethod.getDisplayName());
_moduleContext.invokeUpgradeMethod(upgradeMethod);
}
}
Expand All @@ -223,6 +228,11 @@ public void execute()
// Give the upgrade code a chance to recognize something that doesn't map to a Java method.
upgradeMethod.getUpgradeCode().fallthroughHandler(_methodName);
}
finally
{
// Just to be safe
CacheManager.clearAllKnownCaches();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

import org.jetbrains.annotations.NotNull;
import org.labkey.api.attachments.AttachmentParent;
import org.labkey.api.attachments.AttachmentType;
import org.labkey.api.attachments.AttachmentParentType;

public class ExpProtocolAttachmentParent implements AttachmentParent
{
Expand All @@ -41,7 +41,7 @@ public String getContainerId()
}

@Override
public @NotNull AttachmentType getAttachmentType()
public @NotNull AttachmentParentType getAttachmentParentType()
{
return ExpProtocolAttachmentType.get();
}
Expand Down
6 changes: 3 additions & 3 deletions api/src/org/labkey/api/exp/api/ExpProtocolAttachmentType.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@

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

public class ExpProtocolAttachmentType implements AttachmentType
public class ExpProtocolAttachmentType implements AttachmentParentType
{
private static final ExpProtocolAttachmentType INSTANCE = new ExpProtocolAttachmentType();

Expand All @@ -36,7 +36,7 @@ private ExpProtocolAttachmentType()
@Override
public @NotNull String getUniqueName()
{
return getClass().getName();
return "ExpProtocol";
}

@Override
Expand Down
4 changes: 2 additions & 2 deletions api/src/org/labkey/api/exp/api/ExpRunAttachmentParent.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

import org.jetbrains.annotations.NotNull;
import org.labkey.api.attachments.AttachmentParent;
import org.labkey.api.attachments.AttachmentType;
import org.labkey.api.attachments.AttachmentParentType;

public class ExpRunAttachmentParent implements AttachmentParent
{
Expand All @@ -41,7 +41,7 @@ public String getContainerId()
}

@Override
public @NotNull AttachmentType getAttachmentType()
public @NotNull AttachmentParentType getAttachmentParentType()
{
return ExpRunAttachmentType.get();
}
Expand Down
6 changes: 3 additions & 3 deletions api/src/org/labkey/api/exp/api/ExpRunAttachmentType.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@

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

public class ExpRunAttachmentType implements AttachmentType
public class ExpRunAttachmentType implements AttachmentParentType
{
private static final ExpRunAttachmentType INSTANCE = new ExpRunAttachmentType();

Expand All @@ -36,7 +36,7 @@ private ExpRunAttachmentType()
@Override
public @NotNull String getUniqueName()
{
return getClass().getName();
return "ExpRun";
}

@Override
Expand Down
6 changes: 3 additions & 3 deletions api/src/org/labkey/api/files/FileSystemAttachmentType.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.labkey.api.attachments.AttachmentType;
import org.labkey.api.attachments.AttachmentParentType;
import org.labkey.api.data.CoreSchema;
import org.labkey.api.data.SQLFragment;

public class FileSystemAttachmentType implements AttachmentType
public class FileSystemAttachmentType implements AttachmentParentType
{
private static final FileSystemAttachmentType INSTANCE = new FileSystemAttachmentType();

Expand All @@ -37,7 +37,7 @@ private FileSystemAttachmentType()
@Override
public @NotNull String getUniqueName()
{
return getClass().getName();
return "FileSystem";
}

@Override
Expand Down
Loading