Skip to content

Commit 388e87c

Browse files
committed
Add and populate core.Documents.ParentType column
1 parent 8963dc5 commit 388e87c

70 files changed

Lines changed: 369 additions & 238 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

announcements/src/org/labkey/announcements/AnnouncementModule.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
import org.labkey.api.announcements.CommSchema;
3232
import org.labkey.api.announcements.api.AnnouncementService;
3333
import org.labkey.api.attachments.AttachmentService;
34-
import org.labkey.api.attachments.AttachmentType;
34+
import org.labkey.api.attachments.AttachmentParentType;
3535
import org.labkey.api.audit.AuditLogService;
3636
import org.labkey.api.audit.provider.MessageAuditProvider;
3737
import org.labkey.api.data.Container;
@@ -106,7 +106,7 @@ protected void init()
106106
EmailTemplateService.get().registerTemplate(AnnouncementManager.NotificationEmailTemplate.class);
107107
EmailTemplateService.get().registerTemplate(AnnouncementDigestProvider.DailyDigestEmailTemplate.class);
108108

109-
AttachmentService.get().registerAttachmentType(AnnouncementType.get());
109+
AttachmentService.get().registerAttachmentParentType(AnnouncementType.get());
110110
}
111111

112112
@Override
@@ -201,7 +201,7 @@ public void afterSchema(DatabaseMigrationConfiguration configuration, DbSchema s
201201
}
202202

203203
@Override
204-
public @NotNull Collection<AttachmentType> getAttachmentTypes()
204+
public @NotNull Collection<AttachmentParentType> getAttachmentTypes()
205205
{
206206
// It's theoretically possible to deploy Announcement without Wiki, so conditionalize
207207
WikiService ws = WikiService.get();

announcements/src/org/labkey/announcements/model/AnnouncementAttachmentParent.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
package org.labkey.announcements.model;
1717

1818
import org.jetbrains.annotations.NotNull;
19-
import org.labkey.api.attachments.AttachmentType;
19+
import org.labkey.api.attachments.AttachmentParentType;
2020
import org.labkey.api.data.EntityAttachmentParent;
2121

2222
public class AnnouncementAttachmentParent extends EntityAttachmentParent
@@ -28,7 +28,7 @@ public AnnouncementAttachmentParent(AnnouncementModel ann)
2828

2929
@NotNull
3030
@Override
31-
public AttachmentType getAttachmentType()
31+
public AttachmentParentType getAttachmentParentType()
3232
{
3333
return AnnouncementType.get();
3434
}

announcements/src/org/labkey/announcements/model/AnnouncementType.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,26 +18,26 @@
1818
import org.jetbrains.annotations.NotNull;
1919
import org.jetbrains.annotations.Nullable;
2020
import org.labkey.api.announcements.CommSchema;
21-
import org.labkey.api.attachments.AttachmentType;
21+
import org.labkey.api.attachments.AttachmentParentType;
2222
import org.labkey.api.data.SQLFragment;
2323

24-
public class AnnouncementType implements AttachmentType
24+
public class AnnouncementType implements AttachmentParentType
2525
{
26-
private static final AttachmentType INSTANCE = new AnnouncementType();
26+
private static final AttachmentParentType INSTANCE = new AnnouncementType();
2727

2828
private AnnouncementType()
2929
{
3030
}
3131

32-
public static AttachmentType get()
32+
public static AttachmentParentType get()
3333
{
3434
return INSTANCE;
3535
}
3636

3737
@Override
3838
public @NotNull String getUniqueName()
3939
{
40-
return getClass().getName();
40+
return "Announcement";
4141
}
4242

4343
@Override
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<tables xmlns="http://labkey.org/data/xml">
2+
<table tableName="DocumentsGroupedByType" tableDbType="NOT_IN_DB">
3+
<columns>
4+
<column columnName="Count">
5+
<url replaceMissing="blankValue">query-executeQuery.view?schemaName=core&amp;query.queryName=Documents&amp;query.ParentType~eq=${ParentType}&amp;query.containerFilterName=${containerFilterName}</url>
6+
</column>
7+
</columns>
8+
</table>
9+
</tables>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
SELECT ParentType, COUNT(*) AS "Count"
2+
FROM Documents
3+
GROUP BY ParentType
4+
ORDER BY ParentType

api/src/org/labkey/api/ApiModule.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -217,10 +217,10 @@ public class ApiModule extends CodeOnlyModule
217217
protected void init()
218218
{
219219
ModuleLoader.getInstance().registerResourcePrefix("/org/labkey/vfs", this);
220-
AttachmentService.get().registerAttachmentType(ReportType.get());
221-
AttachmentService.get().registerAttachmentType(LookAndFeelResourceType.get());
222-
AttachmentService.get().registerAttachmentType(AuthenticationLogoType.get());
223-
AttachmentService.get().registerAttachmentType(AvatarType.get());
220+
AttachmentService.get().registerAttachmentParentType(ReportType.get());
221+
AttachmentService.get().registerAttachmentParentType(LookAndFeelResourceType.get());
222+
AttachmentService.get().registerAttachmentParentType(AuthenticationLogoType.get());
223+
AttachmentService.get().registerAttachmentParentType(AvatarType.get());
224224

225225
PropertyManager.registerEncryptionMigrationHandler();
226226
AuthenticationManager.registerEncryptionMigrationHandler();

api/src/org/labkey/api/attachments/AttachmentParent.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,5 @@ public interface AttachmentParent
2222
{
2323
String getEntityId();
2424
String getContainerId();
25-
@NotNull AttachmentType getAttachmentType();
25+
@NotNull AttachmentParentType getAttachmentParentType();
2626
}

api/src/org/labkey/api/attachments/AttachmentType.java renamed to api/src/org/labkey/api/attachments/AttachmentParentType.java

Lines changed: 75 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,75 @@
1-
/*
2-
* Copyright (c) 2017-2018 LabKey Corporation
3-
*
4-
* Licensed under the Apache License, Version 2.0 (the "License");
5-
* you may not use this file except in compliance with the License.
6-
* You may obtain a copy of the License at
7-
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
10-
* Unless required by applicable law or agreed to in writing, software
11-
* distributed under the License is distributed on an "AS IS" BASIS,
12-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
* See the License for the specific language governing permissions and
14-
* limitations under the License.
15-
*/
16-
package org.labkey.api.attachments;
17-
18-
import org.jetbrains.annotations.NotNull;
19-
import org.jetbrains.annotations.Nullable;
20-
import org.labkey.api.data.SQLFragment;
21-
22-
/**
23-
* Tags {@link Attachment} objects based on their intended use and what they're attached to. Does not
24-
* indicate that they are a file of a particular type/format.
25-
*/
26-
public interface AttachmentType
27-
{
28-
SQLFragment NO_ENTITY_IDS = new SQLFragment("SELECT NULL AS EntityId WHERE 1 = 0");
29-
30-
AttachmentType UNKNOWN = new AttachmentType()
31-
{
32-
@NotNull
33-
@Override
34-
public String getUniqueName()
35-
{
36-
return "UnknownAttachmentType";
37-
}
38-
39-
@Override
40-
public void addWhereSql(SQLFragment sql, String parentColumn, String documentNameColumn)
41-
{
42-
sql.append("0 = 1");
43-
}
44-
};
45-
46-
@NotNull String getUniqueName();
47-
48-
/**
49-
* Append to the where clause of a query that wants to select attachments of the implementing type from the
50-
* core.Documents table
51-
* @param sql Implementers MUST append a valid where clause to this SQLFragment
52-
* @param parentColumn Column identifier for use in where clause. Usually represents 'core.Documents.Parent'
53-
* @param documentNameColumn Column identifier for use in where clause. Usually represents 'core.Documents.DocumentName'
54-
*/
55-
default void addWhereSql(SQLFragment sql, String parentColumn, String documentNameColumn)
56-
{
57-
SQLFragment selectSql = getSelectParentEntityIdsSql();
58-
if (selectSql == null)
59-
throw new IllegalStateException("Must override either addWhereSql() or getSelectParentEntityIdsSql()");
60-
sql.append(parentColumn).append(" IN (").append(selectSql).append(")");
61-
}
62-
63-
/**
64-
* Return a SQLFragment that selects all the EntityIds that might be attachment parents from the table(s) that
65-
* provide attachments of this type, without involving the core.Documents table. For example,
66-
* {@code SELECT EntityId FROM comm.Announcements}. Return null if this is not-yet-implemented or inappropriate.
67-
* For example, some attachments' parents are container IDs. If the method determines that no parents exist, then
68-
* return a valid query that selects no rows, for example, {@code NO_ENTITY_IDS}.
69-
*/
70-
default @Nullable SQLFragment getSelectParentEntityIdsSql()
71-
{
72-
return null;
73-
}
74-
}
1+
/*
2+
* Copyright (c) 2017-2018 LabKey Corporation
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.labkey.api.attachments;
17+
18+
import org.jetbrains.annotations.NotNull;
19+
import org.jetbrains.annotations.Nullable;
20+
import org.labkey.api.data.SQLFragment;
21+
22+
/**
23+
* Tags {@link Attachment} objects based on what they're attached to. Does not indicate that they are a file of a
24+
* particular type/format.
25+
*/
26+
public interface AttachmentParentType
27+
{
28+
SQLFragment NO_ENTITY_IDS = new SQLFragment("SELECT NULL AS EntityId WHERE 1 = 0");
29+
30+
AttachmentParentType UNKNOWN = new AttachmentParentType()
31+
{
32+
@NotNull
33+
@Override
34+
public String getUniqueName()
35+
{
36+
return "Unknown";
37+
}
38+
39+
@Override
40+
public void addWhereSql(SQLFragment sql, String parentColumn, String documentNameColumn)
41+
{
42+
sql.append("0 = 1");
43+
}
44+
};
45+
46+
// A short, human-friendly, unique name for this attachment parent type
47+
@NotNull String getUniqueName();
48+
49+
/**
50+
* Append to the where clause of a query that wants to select attachments of the implementing type from the
51+
* core.Documents table
52+
* @param sql Implementers MUST append a valid where clause to this SQLFragment
53+
* @param parentColumn Column identifier for use in where clause. Usually represents 'core.Documents.Parent'
54+
* @param documentNameColumn Column identifier for use in where clause. Usually represents 'core.Documents.DocumentName'
55+
*/
56+
default void addWhereSql(SQLFragment sql, String parentColumn, String documentNameColumn)
57+
{
58+
SQLFragment selectSql = getSelectParentEntityIdsSql();
59+
if (selectSql == null)
60+
throw new IllegalStateException("Must override either addWhereSql() or getSelectParentEntityIdsSql()");
61+
sql.append(parentColumn).append(" IN (").append(selectSql).append(")");
62+
}
63+
64+
/**
65+
* Return a SQLFragment that selects all the EntityIds that might be attachment parents from the table(s) that
66+
* provide attachments of this type, without involving the core.Documents table. For example,
67+
* {@code SELECT EntityId FROM comm.Announcements}. Return null if this is not-yet-implemented or inappropriate.
68+
* For example, some attachments' parents are container IDs. If the method determines that no parents exist, then
69+
* return a valid query that selects no rows, for example, {@code NO_ENTITY_IDS}.
70+
*/
71+
default @Nullable SQLFragment getSelectParentEntityIdsSql()
72+
{
73+
return null;
74+
}
75+
}

api/src/org/labkey/api/attachments/AttachmentService.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,12 +131,12 @@ static AttachmentService get()
131131

132132
void clearLastIndexed(List<String> parentIds);
133133

134-
void registerAttachmentType(AttachmentType type);
134+
void registerAttachmentParentType(AttachmentParentType type);
135135

136136
/**
137137
* Returns a collection of all registered AttachmentTypes
138138
**/
139-
Collection<AttachmentType> getAttachmentTypes();
139+
Collection<AttachmentParentType> getAttachmentParentTypes();
140140

141141
HttpView<?> getAdminView(ActionURL currentUrl);
142142

api/src/org/labkey/api/attachments/LookAndFeelResourceAttachmentParent.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public LookAndFeelResourceAttachmentParent(Container c)
2727
}
2828

2929
@Override
30-
public @NotNull AttachmentType getAttachmentType()
30+
public @NotNull AttachmentParentType getAttachmentParentType()
3131
{
3232
return LookAndFeelResourceType.get();
3333
}

0 commit comments

Comments
 (0)