Skip to content

Commit deb4dc1

Browse files
committed
- Replaced ShortUrl column in DatasetStatus table with ExperimentAnnotationsId. DatasetStatus is associated with a particular copy of the data. If a new copy is made, the data status resets. Status associated with the previous copy is no longer relevant.
1 parent f13c7ed commit deb4dc1

12 files changed

Lines changed: 68 additions & 59 deletions
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
-- ------------------------------------------------------------------------
2+
-- Replace the ShortUrl column with an ExperimentAnnotationsId column.
3+
-- ------------------------------------------------------------------------
4+
5+
-- Add ExperimentAnnotationsId column as nullable first
6+
ALTER TABLE panoramapublic.DatasetStatus ADD COLUMN ExperimentAnnotationsId INT;
7+
8+
-- Populate the column by matching ShortUrl values
9+
UPDATE panoramapublic.DatasetStatus
10+
SET ExperimentAnnotationsId = ea.Id
11+
FROM panoramapublic.ExperimentAnnotations ea
12+
WHERE ea.ShortUrl = panoramapublic.DatasetStatus.ShortUrl;
13+
14+
-- Delete rows that couldn't be matched (where ExperimentAnnotationsId is still null)
15+
DELETE FROM panoramapublic.DatasetStatus WHERE ExperimentAnnotationsId IS NULL;
16+
17+
-- Now make ExperimentAnnotationsId NOT NULL
18+
ALTER TABLE panoramapublic.DatasetStatus ALTER COLUMN ExperimentAnnotationsId SET NOT NULL;
19+
20+
-- Add constraints and index
21+
ALTER TABLE panoramapublic.DatasetStatus ADD CONSTRAINT FK_DatasetStatus_ExperimentAnnotations FOREIGN KEY (ExperimentAnnotationsId) REFERENCES panoramapublic.ExperimentAnnotations(Id);
22+
ALTER TABLE panoramapublic.DatasetStatus ADD CONSTRAINT UQ_DatasetStatus_ExperimentAnnotations UNIQUE (ExperimentAnnotationsId);
23+
CREATE INDEX IX_DatasetStatus_ExperimentAnnotations ON panoramapublic.DatasetStatus(ExperimentAnnotationsId);
24+
25+
-- Drop old constraints and index
26+
ALTER TABLE panoramapublic.DatasetStatus DROP CONSTRAINT FK_DatasetStatus_ShortUrl;
27+
ALTER TABLE panoramapublic.DatasetStatus DROP CONSTRAINT UQ_DatasetStatus_ShortUrl;
28+
DROP INDEX panoramapublic.IX_DatasetStatus_ShortUrl;
29+
30+
-- Finally drop the ShortUrl column
31+
ALTER TABLE panoramapublic.DatasetStatus DROP COLUMN ShortUrl;
32+

panoramapublic/resources/schemas/panoramapublic.xml

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -860,13 +860,7 @@
860860
<isHidden>true</isHidden>
861861
</column>
862862
<column columnName="Id"/>
863-
<column columnName="ShortUrl">
864-
<fk>
865-
<fkColumnName>EntityId</fkColumnName>
866-
<fkDbSchema>core</fkDbSchema>
867-
<fkTable>ShortUrl</fkTable>
868-
</fk>
869-
</column>
863+
<column columnName="ExperimentAnnotationsId" />
870864
<column columnName="LastReminderDate" />
871865
<column columnName="ExtensionRequestedDate" />
872866
<column columnName="DeletionRequestedDate"/>

panoramapublic/src/org/labkey/panoramapublic/PanoramaPublicController.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10396,7 +10396,7 @@ public void validateCommand(ShortUrlForm shortUrlForm, Errors errors)
1039610396

1039710397
ensureCorrectContainer(getContainer(), _exptAnnotations.getContainer(), getViewContext());
1039810398

10399-
_datasetStatus = DatasetStatusManager.getForShortUrl(_exptAnnotations.getShortUrl());
10399+
_datasetStatus = DatasetStatusManager.getForExperiment(_exptAnnotations);
1040010400

1040110401
// Action-specific validation
1040210402
doValidationForAction(errors);
@@ -10410,7 +10410,7 @@ public boolean handlePost(ShortUrlForm shortUrlForm, BindException errors) throw
1041010410
if (_datasetStatus == null)
1041110411
{
1041210412
_datasetStatus = new DatasetStatus();
10413-
_datasetStatus.setShortUrl(_exptAnnotations.getShortUrl());
10413+
_datasetStatus.setExperimentAnnotationsId(_exptAnnotations.getId());
1041410414
updateDatasetStatus(_datasetStatus);
1041510415
DatasetStatusManager.save(_datasetStatus, getUser());
1041610416
}
@@ -10458,13 +10458,13 @@ protected void doValidationForAction(Errors errors)
1045810458
PrivateDataReminderSettings settings = PrivateDataReminderSettings.get();
1045910459
if (settings.isExtensionValid(_datasetStatus))
1046010460
{
10461-
errors.reject(ERROR_MSG, "An extension has already been requested for the data with short URL " + _datasetStatus.getShortUrl().renderShortURL()
10461+
errors.reject(ERROR_MSG, "An extension has already been requested for the data with short URL " + _exptAnnotations.getShortUrl().renderShortURL()
1046210462
+ ". The extension is valid until " + settings.extensionValidUntilFormatted(_datasetStatus));
1046310463
}
1046410464
else if (_datasetStatus.deletionRequested())
1046510465
{
1046610466
errors.reject(ERROR_MSG, "A deletion request was submitted on " + _datasetStatus.getDeletionRequestedDate()
10467-
+ " for the data with short URL " + _datasetStatus.getShortUrl().renderShortURL());
10467+
+ " for the data with short URL " + _exptAnnotations.getShortUrl().renderShortURL());
1046810468
}
1046910469
}
1047010470
}
@@ -10522,7 +10522,7 @@ protected void doValidationForAction(Errors errors)
1052210522
if (_datasetStatus.deletionRequested())
1052310523
{
1052410524
errors.reject(ERROR_MSG, "A deletion request was already submitted on " + _datasetStatus.getDeletionRequestedDateFormatted()
10525-
+ " for the data with short URL " + _datasetStatus.getShortUrl().renderShortURL());
10525+
+ " for the data with short URL " + _exptAnnotations.getShortUrl().renderShortURL());
1052610526
}
1052710527
}
1052810528
}

panoramapublic/src/org/labkey/panoramapublic/PanoramaPublicModule.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public String getName()
9292
@Override
9393
public @Nullable Double getSchemaVersion()
9494
{
95-
return 25.002;
95+
return 25.003;
9696
}
9797

9898
@Override

panoramapublic/src/org/labkey/panoramapublic/model/DatasetStatus.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,19 @@
88

99
public class DatasetStatus extends DbEntity
1010
{
11-
private ShortURLRecord _shortUrl;
11+
private int _experimentAnnotationsId;
1212
private Date _lastReminderDate;
1313
private Date _extensionRequestedDate;
1414
private Date _deletionRequestedDate;
1515

16-
public ShortURLRecord getShortUrl()
16+
public int getExperimentAnnotationsId()
1717
{
18-
return _shortUrl;
18+
return _experimentAnnotationsId;
1919
}
2020

21-
public void setShortUrl(ShortURLRecord shortUrl)
21+
public void setExperimentAnnotationsId(int experimentAnnotationsId)
2222
{
23-
_shortUrl = shortUrl;
23+
_experimentAnnotationsId = experimentAnnotationsId;
2424
}
2525

2626
public Date getLastReminderDate()

panoramapublic/src/org/labkey/panoramapublic/pipeline/CopyExperimentFinalTask.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -151,12 +151,6 @@ private void finishUp(PipelineJob job, CopyExperimentJobSupport jobSupport) thro
151151

152152
// Update the row in panoramapublic.ExperimentAnnotations - set the shortURL and version
153153
ExperimentAnnotations targetExperiment = updateExperimentAnnotations(container, sourceExperiment, js, user, log);
154-
if (previousCopy != null)
155-
{
156-
// If this is a re-copy, a row may exist in DatasetStatus for the short URL associated with the experiment. Remove it now.
157-
// This is a fresh copy, so data status should be reset.
158-
DatasetStatusManager.deleteStatusForExperiment(targetExperiment);
159-
}
160154

161155
// If there is a Panorama Public data catalog entry associated with the previous copy of the experiment, move it to the
162156
// new container.

panoramapublic/src/org/labkey/panoramapublic/pipeline/PrivateDataReminderJob.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ private static ReminderDecision getReminderDecision(@NotNull ExperimentAnnotatio
100100
return ReminderDecision.skip("Not the current version of the experiment");
101101
}
102102

103-
DatasetStatus datasetStatus = DatasetStatusManager.getForShortUrl(exptAnnotations.getShortUrl());
103+
DatasetStatus datasetStatus = DatasetStatusManager.getForExperiment(exptAnnotations);
104104
if (datasetStatus != null)
105105
{
106106
if (datasetStatus.deletionRequested())
@@ -293,11 +293,11 @@ private void postReminderMessage(ExperimentAnnotations expAnnotations, JournalSu
293293

294294
private void updateDatasetStatus(ExperimentAnnotations expAnnotations)
295295
{
296-
DatasetStatus datasetStatus = DatasetStatusManager.getForShortUrl(expAnnotations.getShortUrl());
296+
DatasetStatus datasetStatus = DatasetStatusManager.getForExperiment(expAnnotations);
297297
if (datasetStatus == null)
298298
{
299299
datasetStatus = new DatasetStatus();
300-
datasetStatus.setShortUrl(expAnnotations.getShortUrl());
300+
datasetStatus.setExperimentAnnotationsId(expAnnotations.getId());
301301
datasetStatus.setLastReminderDate(new Date());
302302
DatasetStatusManager.save(datasetStatus, getUser());
303303
}

panoramapublic/src/org/labkey/panoramapublic/query/DatasetStatusManager.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import org.labkey.api.data.TableSelector;
88
import org.labkey.api.query.FieldKey;
99
import org.labkey.api.security.User;
10-
import org.labkey.api.view.ShortURLRecord;
1110
import org.labkey.panoramapublic.PanoramaPublicManager;
1211
import org.labkey.panoramapublic.model.DatasetStatus;
1312
import org.labkey.panoramapublic.model.ExperimentAnnotations;
@@ -19,12 +18,12 @@ public static DatasetStatus get(int datasetStatusId)
1918
return new TableSelector(PanoramaPublicManager.getTableInfoDatasetStatus(),null, null).getObject(datasetStatusId, DatasetStatus.class);
2019
}
2120

22-
public static @Nullable DatasetStatus getForShortUrl(ShortURLRecord shortUrl)
21+
public static @Nullable DatasetStatus getForExperiment(ExperimentAnnotations experimentAnnotations)
2322
{
24-
if (shortUrl != null)
23+
if (experimentAnnotations != null)
2524
{
2625
SimpleFilter filter = new SimpleFilter();
27-
filter.addCondition(FieldKey.fromParts("ShortUrl"), shortUrl.getEntityId());
26+
filter.addCondition(FieldKey.fromParts("ExperimentAnnotationsId"), experimentAnnotations.getId());
2827
return new TableSelector(PanoramaPublicManager.getTableInfoDatasetStatus(), filter, null).getObject(DatasetStatus.class);
2928
}
3029
return null;
@@ -42,12 +41,11 @@ public static void update(DatasetStatus datasetStatus, User user)
4241

4342
public static void deleteStatusForExperiment(ExperimentAnnotations expAnnotations)
4443
{
45-
DatasetStatus status = getForShortUrl(expAnnotations.getShortUrl());
46-
if (status == null) return;
44+
if (expAnnotations == null) return;
4745

4846
try(DbScope.Transaction transaction = PanoramaPublicManager.getSchema().getScope().ensureTransaction())
4947
{
50-
Table.delete(PanoramaPublicManager.getTableInfoDatasetStatus(), new SimpleFilter(FieldKey.fromParts("id"), status.getId()));
48+
Table.delete(PanoramaPublicManager.getTableInfoDatasetStatus(), new SimpleFilter(FieldKey.fromParts("ExperimentAnnotationsId"), expAnnotations.getId()));
5149
transaction.commit();
5250
}
5351
}

panoramapublic/src/org/labkey/panoramapublic/query/DatasetStatusTableInfo.java

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,13 @@ public class DatasetStatusTableInfo extends PanoramaPublicTable
1919
public DatasetStatusTableInfo(@NotNull PanoramaPublicSchema userSchema, ContainerFilter cf)
2020
{
2121
super(PanoramaPublicManager.getTableInfoDatasetStatus(), userSchema, cf,
22-
new ContainerJoin("ShortUrl", PanoramaPublicManager.getTableInfoExperimentAnnotations(), "ShortUrl"));
22+
new ContainerJoin("ExperimentAnnotationsId", PanoramaPublicManager.getTableInfoExperimentAnnotations(), "Id"));
2323

24+
var shortUrlCol = wrapColumn("ShortURL", getRealTable().getColumn("ExperimentAnnotationsId"));
25+
shortUrlCol.setDisplayColumnFactory(new ShortUrlDisplayColumnFactory(FieldKey.fromParts("ShortUrl")));
26+
addColumn(shortUrlCol);
2427

25-
var accessUrlCol = getMutableColumn(FieldKey.fromParts("ShortUrl"));
26-
if (accessUrlCol != null)
27-
{
28-
accessUrlCol.setDisplayColumnFactory(new ShortUrlDisplayColumnFactory());
29-
}
30-
31-
SQLFragment expColSql = new SQLFragment(" (SELECT Id FROM ")
32-
.append(PanoramaPublicManager.getTableInfoExperimentAnnotations(), "exp")
33-
.append(" WHERE exp.shortUrl = ").append(ExprColumn.STR_TABLE_ALIAS).append(".shortUrl")
34-
.append(") ");
35-
var experimentTitleCol = new ExprColumn(this, "Title", expColSql, JdbcType.VARCHAR);
28+
var experimentTitleCol = wrapColumn("Title", getRealTable().getColumn(FieldKey.fromParts("ExperimentAnnotationsId")));
3629
experimentTitleCol.setFk(QueryForeignKey.from(getUserSchema(), cf).schema(getUserSchema()).to(PanoramaPublicSchema.TABLE_EXPERIMENT_ANNOTATIONS, "Id", null));
3730
addColumn(experimentTitleCol);
3831

panoramapublic/src/org/labkey/panoramapublic/query/ExperimentAnnotationsManager.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -283,10 +283,6 @@ private static void deleteExperiment(ExperimentAnnotations expAnnotations, User
283283
}
284284
else
285285
{
286-
// Delete the row in DatasetStatus for this experiment. Do this before setting the experiment's shortURL to null
287-
// in SubmissionManager.beforeCopiedExperimentDeleted().
288-
DatasetStatusManager.deleteStatusForExperiment(expAnnotations);
289-
290286
// This experiment is a journal copy (i.e. in the Panorama Public project on PanoramaWeb)
291287
SubmissionManager.beforeCopiedExperimentDeleted(expAnnotations, user);
292288
}
@@ -305,6 +301,9 @@ private static void deleteExperiment(ExperimentAnnotations expAnnotations, User
305301
// Delete the Panorama Public data catalog entry for this experiment, if one exists
306302
CatalogEntryManager.deleteEntryForExperiment(expAnnotations, user);
307303

304+
// Delete the row in DatasetStatus for this experiment, if one exists.
305+
DatasetStatusManager.deleteStatusForExperiment(expAnnotations);
306+
308307
Table.delete(PanoramaPublicManager.getTableInfoExperimentAnnotations(), expAnnotations.getId());
309308

310309
if(expAnnotations.isJournalCopy() && expAnnotations.getShortUrl() != null)

0 commit comments

Comments
 (0)