Skip to content

Commit

Permalink
Merge pull request #10974 from IQSS/10947-unpublished-files-appearing…
Browse files Browse the repository at this point in the history
…-in-search-results-for-anon-user

fix get major version when deaccessioned
  • Loading branch information
ofahimIQSS authored Oct 31, 2024
2 parents f0cc9c8 + 2dfdaa2 commit d18f01f
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
## Unpublished file bug fix

A bug fix was made that gets the major version of a Dataset when all major versions were deaccessioned. This fixes the incorrect showing of the files as "Unpublished" in the search list even when they are published.
This fix affects the indexing, meaning these datasets must be re-indexed once Dataverse is updated. This can be manually done by calling the index API for each affected Dataset.

Example:
```shell
curl http://localhost:8080/api/admin/index/dataset?persistentId=doi:10.7910/DVN/6X4ZZL
```

See also #10947 and #10974.
11 changes: 10 additions & 1 deletion src/main/java/edu/harvard/iq/dataverse/Dataset.java
Original file line number Diff line number Diff line change
Expand Up @@ -483,8 +483,17 @@ public Date getMostRecentMajorVersionReleaseDate() {
if (this.isHarvested()) {
return getVersions().get(0).getReleaseTime();
} else {
Long majorVersion = null;
for (DatasetVersion version : this.getVersions()) {
if (version.isReleased() && version.getMinorVersionNumber().equals((long) 0)) {
if (version.isReleased()) {
if (version.getMinorVersionNumber().equals((long) 0)) {
return version.getReleaseTime();
} else if (majorVersion == null) {
majorVersion = version.getVersionNumber();
}
} else if (version.isDeaccessioned() && majorVersion != null
&& majorVersion.longValue() == version.getVersionNumber().longValue()
&& version.getMinorVersionNumber().equals((long) 0)) {
return version.getReleaseTime();
}
}
Expand Down
39 changes: 38 additions & 1 deletion src/test/java/edu/harvard/iq/dataverse/DatasetTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import static org.junit.jupiter.api.Assertions.*;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
Expand Down Expand Up @@ -240,5 +241,41 @@ public void datasetShouldBeDeaccessionedWithDeaccessionedAndDeaccessionedVersion

assertTrue(dataset.isDeaccessioned());
}


@Test
public void testGetMostRecentMajorVersionReleaseDateWithDeaccessionedVersions() {
List<DatasetVersion> versionList = new ArrayList<DatasetVersion>();

long ver = 5;
// 5.2
DatasetVersion relVersion = new DatasetVersion();
relVersion.setVersionState(VersionState.RELEASED);
relVersion.setMinorVersionNumber(2L);
relVersion.setVersionNumber(ver);
versionList.add(relVersion);

// 5.1
relVersion = new DatasetVersion();
relVersion.setVersionState(VersionState.DEACCESSIONED);
relVersion.setMinorVersionNumber(1L);
relVersion.setVersionNumber(ver);
versionList.add(relVersion);

// 5.0, 4.0, 3.0, 2.0, 1.0
while (ver > 0) {
DatasetVersion deaccessionedVersion = new DatasetVersion();
deaccessionedVersion.setVersionState(VersionState.DEACCESSIONED);
// only add an actual date to v5.0 so the assertNotNull will only pass if this version's date is returned
deaccessionedVersion.setReleaseTime((ver == 5) ? new Date() : null);
deaccessionedVersion.setMinorVersionNumber(0L);
deaccessionedVersion.setVersionNumber(ver--);
versionList.add(deaccessionedVersion);
}

Dataset dataset = new Dataset();
dataset.setVersions(versionList);

Date releaseDate = dataset.getMostRecentMajorVersionReleaseDate();
assertNotNull(releaseDate);
}
}

0 comments on commit d18f01f

Please sign in to comment.