Skip to content
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

fix get major version when deaccessioned #10974

Merged
Show file tree
Hide file tree
Changes from 3 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
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.
stevenwinship marked this conversation as resolved.
Show resolved Hide resolved
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.
stevenwinship marked this conversation as resolved.
Show resolved Hide resolved

Example:
```shell
curl http://localhost:8080/api/admin/index/dataset?persistentId=doi:10.7910/DVN/6X4ZZL
```
stevenwinship marked this conversation as resolved.
Show resolved Hide resolved
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);
}
}
Loading