-
Notifications
You must be signed in to change notification settings - Fork 7
Issue 695: Add feature to allow unreferenced files to be deleted from apps #7320
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
labkey-susanh
wants to merge
15
commits into
release25.11-SNAPSHOT
Choose a base branch
from
25.11_fb_staleSampleFiles
base: release25.11-SNAPSHOT
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
9034063
StaleSampleFiles table for listing files no longer referenced by sample
XingY a2ffc20
crlf
XingY f51bd73
Working toward adding reference count column in file tables
labkey-susanh 7350ecc
experimental flag
XingY 9031881
crlf
XingY dbc018d
include rowId
XingY e103580
fix sql
XingY 8d84c5c
Add RowId as key column to table and move display column to ExpData t…
labkey-susanh 82c8247
Rename "Stale" to "Unreferenced"
labkey-susanh 6bec4b5
Export experimental feature flag to moduleContext
labkey-susanh bdb8893
Hide column and exclude column when feature is not enabled
labkey-susanh 62ac8de
Add comment
labkey-susanh 2a78a9d
Refactor for better code
labkey-susanh 4b7da07
Fix CreatedBy foreign key
labkey-susanh 347f319
Minor updates from code review
labkey-susanh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
114 changes: 114 additions & 0 deletions
114
api/src/org/labkey/api/exp/query/ExpUnreferencedSampleFilesTable.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,114 @@ | ||
| package org.labkey.api.exp.query; | ||
|
|
||
| import org.apache.commons.lang3.StringUtils; | ||
| import org.jetbrains.annotations.NotNull; | ||
| import org.labkey.api.data.BaseColumnInfo; | ||
| import org.labkey.api.data.ContainerFilter; | ||
| import org.labkey.api.data.CoreSchema; | ||
| import org.labkey.api.data.JdbcType; | ||
| import org.labkey.api.data.SQLFragment; | ||
| import org.labkey.api.data.TableInfo; | ||
| import org.labkey.api.data.VirtualTable; | ||
| import org.labkey.api.exp.api.ExperimentService; | ||
| import org.labkey.api.files.FileContentService; | ||
| import org.labkey.api.query.FilteredTable; | ||
| import org.labkey.api.query.UserIdQueryForeignKey; | ||
| import org.labkey.api.query.UserSchema; | ||
| import org.labkey.api.query.column.BuiltInColumnTypes; | ||
|
|
||
| public class ExpUnreferencedSampleFilesTable extends FilteredTable<ExpSchema> | ||
| { | ||
| public ExpUnreferencedSampleFilesTable(@NotNull ExpSchema schema, ContainerFilter cf) | ||
| { | ||
| super(createVirtualTable(schema), schema, cf); | ||
| setDescription("Contains all sample files that are not referenced by any domain fields."); | ||
| wrapAllColumns(true); | ||
| } | ||
|
|
||
| private static TableInfo createVirtualTable(@NotNull ExpSchema schema) | ||
| { | ||
| return new ExpUnreferencedSampleFilesTable.FileUnionTable(schema); | ||
| } | ||
|
|
||
| private static class FileUnionTable extends VirtualTable<ExpSchema> | ||
| { | ||
| private final SQLFragment _query; | ||
|
|
||
| public FileUnionTable(@NotNull ExpSchema schema) | ||
| { | ||
| super(CoreSchema.getInstance().getSchema(), ExpSchema.SAMPLE_FILES_TABLE, schema); | ||
|
|
||
| FileContentService svc = FileContentService.get(); | ||
|
|
||
| _query = new SQLFragment(); | ||
| if (svc == null) | ||
| return; | ||
|
|
||
| SQLFragment listQuery = svc.listSampleFilesQuery(schema.getUser()); | ||
| if (StringUtils.isEmpty(listQuery)) | ||
| return; | ||
|
|
||
| TableInfo expDataTable = ExperimentService.get().getTinfoData(); | ||
| TableInfo materialTable = ExperimentService.get().getTinfoMaterial(); | ||
|
|
||
| _query.appendComment("<SampleFileListTableInfo>", getSchema().getSqlDialect()); | ||
|
|
||
| SQLFragment sampleFileSql = new SQLFragment("SELECT m.Container, if.FilePathShort \n") | ||
| .append("FROM (") | ||
| .append(svc.listSampleFilesQuery(schema.getUser())) | ||
| .append(") AS if \n") | ||
| .append("JOIN ") | ||
| .append(materialTable, "m") | ||
| .append(" ON if.SourceKey = m.RowId"); | ||
|
|
||
| SQLFragment unreferencedFileSql = new SQLFragment("SELECT ed.rowId, ed.name as filename, ed.container, ed.created, ed.createdBy, ed.DataFileUrl FROM ") | ||
| .append(expDataTable, "ed") | ||
| .append(" LEFT JOIN (") | ||
| .append(sampleFileSql) | ||
| .append(" ) sf\n") | ||
| .append(" ON ed.name = sf.FilePathShort AND ed.container = sf.container\n") | ||
| .append(" WHERE ed.datafileurl LIKE ") | ||
| .appendValue("%@files/sampletype/%") | ||
| .append(" AND sf.FilePathShort IS NULL"); | ||
|
|
||
| _query.append(unreferencedFileSql); | ||
|
|
||
| _query.appendComment("</SampleFileListTableInfo>", getSchema().getSqlDialect()); | ||
|
|
||
| var rowIdCol = new BaseColumnInfo("RowId", this, JdbcType.INTEGER); | ||
| rowIdCol.setHidden(true); | ||
| rowIdCol.setKeyField(true); | ||
| addColumn(rowIdCol); | ||
|
|
||
| var fileNameCol = new BaseColumnInfo("FileName", this, JdbcType.VARCHAR); | ||
| addColumn(fileNameCol); | ||
|
|
||
| if (schema.getUser().hasApplicationAdminPermission()) | ||
| { | ||
| var filePathCol = new BaseColumnInfo("DataFileUrl", this, JdbcType.VARCHAR); | ||
| filePathCol.setHidden(true); | ||
| addColumn(filePathCol); | ||
| } | ||
|
|
||
| var containerCol = new BaseColumnInfo("Container", this, JdbcType.VARCHAR); | ||
| containerCol.setConceptURI(BuiltInColumnTypes.CONTAINERID_CONCEPT_URI); | ||
| addColumn(containerCol); | ||
|
|
||
| var createdCol = new BaseColumnInfo("Created", this, JdbcType.DATE); | ||
| addColumn(createdCol); | ||
|
|
||
| var createdByCol = new BaseColumnInfo("CreatedBy", this, JdbcType.INTEGER); | ||
| createdByCol.setFk(new UserIdQueryForeignKey(getUserSchema(), true)); | ||
| addColumn(createdByCol); | ||
| } | ||
|
|
||
| @NotNull | ||
| @Override | ||
| public SQLFragment getFromSQL() | ||
| { | ||
| return _query; | ||
| } | ||
|
|
||
| } | ||
|
|
||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.