Skip to content

Commit

Permalink
Merge pull request #11051 from IQSS/10735-search-dataset-name-and-dat…
Browse files Browse the repository at this point in the history
…aset-citation-different

fix search files to return latest published citation
  • Loading branch information
ofahimIQSS authored Dec 20, 2024
2 parents 2ae639d + 1066b1e commit f7aabc8
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 10 deletions.
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 @@ -1325,7 +1325,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) ?
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 @@ -179,6 +179,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 @@ -189,20 +190,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

0 comments on commit f7aabc8

Please sign in to comment.