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 search files to return latest published citation #11051

Merged
Merged
Show file tree
Hide file tree
Changes from all 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,4 @@

### Search files Bug fix

dataset-citation was displaying DRAFT version instead of latest released version
Original file line number Diff line number Diff line change
Expand Up @@ -1328,7 +1328,8 @@ public SolrInputDocuments toSolrDocs(IndexableDataset indexableDataset, Set<Long
}
LocalDate embargoEndDate=null;
LocalDate retentionEndDate=null;
final String datasetCitation = dataset.getCitation();
final String datasetCitation = (dataset.isReleased() && dataset.getReleasedVersion() != null) ?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You wouldn't ever expect that a released dataset wouldn't have a released version unless maybe there's a deaccessioned version, maybe?

dataset.getCitation(dataset.getReleasedVersion()) : dataset.getCitation();
final Long datasetId = dataset.getId();
final String datasetGlobalId = dataset.getGlobalId().toString();
for (FileMetadata fileMetadata : fileMetadatas) {
Expand Down
48 changes: 39 additions & 9 deletions src/test/java/edu/harvard/iq/dataverse/api/SearchIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ public void testSearchCitation() {
Response createDatasetResponse = UtilIT.createRandomDatasetViaNativeApi(dataverseAlias, apiToken);
createDatasetResponse.prettyPrint();
Integer datasetId = UtilIT.getDatasetIdFromResponse(createDatasetResponse);
String datasetPersistentId = UtilIT.getDatasetPersistentIdFromResponse(createDatasetResponse);

Response searchResponse = UtilIT.search("id:dataset_" + datasetId + "_draft", apiToken);
searchResponse.prettyPrint();
Expand All @@ -185,20 +186,49 @@ public void testSearchCitation() {
.body("data.items[0].citationHtml", Matchers.containsString("href"))
.statusCode(200);

Response deleteDatasetResponse = UtilIT.deleteDatasetViaNativeApi(datasetId, apiToken);
deleteDatasetResponse.prettyPrint();
deleteDatasetResponse.then().assertThat()
String pathToFile = "src/main/webapp/resources/images/dataverseproject.png";
Response uploadImage = UtilIT.uploadFileViaNative(datasetId.toString(), pathToFile, apiToken);
uploadImage.prettyPrint();
uploadImage.then().assertThat()
.statusCode(200);

Response publishResponse = UtilIT.publishDataverseViaNativeApi(dataverseAlias, apiToken);
publishResponse.prettyPrint();
publishResponse.then().assertThat()
.statusCode(OK.getStatusCode());
publishResponse = UtilIT.publishDatasetViaNativeApi(datasetId, "major", apiToken);
publishResponse.prettyPrint();
publishResponse.then().assertThat()
.statusCode(OK.getStatusCode());

Response deleteDataverseResponse = UtilIT.deleteDataverse(dataverseAlias, apiToken);
deleteDataverseResponse.prettyPrint();
deleteDataverseResponse.then().assertThat()
Response updateTitleResponseAuthor = UtilIT.updateDatasetTitleViaSword(datasetPersistentId, "New Title", apiToken);
updateTitleResponseAuthor.prettyPrint();
updateTitleResponseAuthor.then().assertThat()
.statusCode(OK.getStatusCode());

Response deleteUserResponse = UtilIT.deleteUser(username);
deleteUserResponse.prettyPrint();
assertEquals(200, deleteUserResponse.getStatusCode());
// search descending will get the latest 100.
// This could fail if more than 100 get created between our update and the search. Highly unlikely
searchResponse = UtilIT.search("*&type=file&sort=date&order=desc&per_page=100&start=0&subtree=root" , apiToken);
searchResponse.prettyPrint();

int i=0;
String parentCitation = "";
String datasetName = "";
// most likely ours is in index 0, but it's not a guaranty.
while (i < 100) {
String dataset_persistent_id = searchResponse.body().jsonPath().getString("data.items[" + i + "].dataset_persistent_id");
if (datasetPersistentId.equalsIgnoreCase(dataset_persistent_id)) {
parentCitation = searchResponse.body().jsonPath().getString("data.items[" + i + "].dataset_citation");
datasetName = searchResponse.body().jsonPath().getString("data.items[" + i + "].dataset_name");
break;
}
i++;
}
// see https://github.com/IQSS/dataverse/issues/10735
// was showing the citation of the draft version and not the released parent
assertFalse(parentCitation.contains("New Title"));
assertTrue(parentCitation.contains(datasetName));
assertFalse(parentCitation.contains("DRAFT"));
}

@Test
Expand Down
Loading