Skip to content
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,10 @@
### Dataset version summaries API changedFileMetaData count fix

The endpoint ``{id}/versions/compareSummary`` was previously returning an incorrect count for
the ``changedFileMetaData`` field.
The logic for calculating this count has been fixed to accurately reflect the total number of file metadata changes
across all files in the dataset version.

### Related issues

- https://github.com/IQSS/dataverse/issues/11921
Original file line number Diff line number Diff line change
Expand Up @@ -1760,12 +1760,7 @@ private JsonObjectBuilder getFileSummaryAsJson(){
job.add("replaced", 0);
}

if (!changedFileMetadata.isEmpty()) {
job.add("changedFileMetaData", changedFileMetadata.size());

} else{
job.add("changedFileMetaData", 0);
}
job.add("changedFileMetaData", getTotalFileMetadataChangesCount());

if (!changedVariableMetadata.isEmpty()) {
job.add("changedVariableMetadata", changedVariableMetadata.size());
Expand Down Expand Up @@ -1907,4 +1902,26 @@ private JsonObjectBuilder filesDiffJson(FileMetadata fileMetadata) {
}
return job;
}

/**
* Calculates the total number of individual file metadata field changes
* across all files tracked in the {@code changedFileMetadataDiff} map.
*
* @return The total count of all file metadata field changes.
*/
private int getTotalFileMetadataChangesCount() {
int totalChanges = 0;

if (this.changedFileMetadataDiff == null) {
return 0;
}

for (Map<String, List<String>> fileSpecificDiffs : this.changedFileMetadataDiff.values()) {
if (fileSpecificDiffs != null) {
totalChanges += fileSpecificDiffs.size();
}
}

return totalChanges;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ public void testGetSummaryAsJson(){
JsonPath dataFile = JsonPath.from(JsonUtil.prettyPrint(obj));

assertTrue("true".equalsIgnoreCase(dataFile.getString("termsAccessChanged")));
assertEquals(2,(Long.parseLong(dataFile.getString("files.changedFileMetaData"))));
assertEquals(1,(Long.parseLong(dataFile.getString("files.changedFileMetaData"))));
assertEquals(0,(Long.parseLong(dataFile.getString("testMetadataBlock.deleted"))));
assertEquals(1, (int) (Long.parseLong(dataFile.getString("testMetadataBlock.added"))));
assertEquals(1,(Long.parseLong(dataFile.getString("files.added"))));
Expand Down
30 changes: 24 additions & 6 deletions src/test/java/edu/harvard/iq/dataverse/api/DatasetsIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -6612,12 +6612,21 @@ public void testSummaryDatasetVersionsDifferencesAPI() throws InterruptedExcepti
.add("Data")
);
JsonObject jsonObj = json.build();

String pathToFile = "src/main/webapp/resources/images/dataverse-icon-1200.png";
Response uploadResponse = UtilIT.uploadFileViaNative(String.valueOf(datasetId), pathToFile, jsonObj, apiToken);
uploadResponse.prettyPrint();
uploadResponse.then().assertThat()
.statusCode(OK.getStatusCode());
Integer modifyFileId = UtilIT.getDataFileIdFromResponse(uploadResponse);
Integer firstFileToModify = UtilIT.getDataFileIdFromResponse(uploadResponse);

pathToFile = "src/test/resources/images/coffeeshop.png";
uploadResponse = UtilIT.uploadFileViaNative(String.valueOf(datasetId), pathToFile, jsonObj, apiToken);
uploadResponse.prettyPrint();
uploadResponse.then().assertThat()
.statusCode(OK.getStatusCode());
Integer secondFileToModify = UtilIT.getDataFileIdFromResponse(uploadResponse);

pathToFile = "src/main/webapp/resources/images/dataverseproject_logo.jpg";
uploadResponse = UtilIT.uploadFileViaNative(String.valueOf(datasetId), pathToFile, jsonObj, apiToken);
uploadResponse.then().assertThat()
Expand Down Expand Up @@ -6670,9 +6679,18 @@ public void testSummaryDatasetVersionsDifferencesAPI() throws InterruptedExcepti
replaceResponse.then().assertThat()
.statusCode(OK.getStatusCode());

// Test modify by restricting the file
Response restrictResponse = UtilIT.restrictFile(modifyFileId.toString(), true, apiToken);
restrictResponse.prettyPrint();
// Test modify first file by adding a new category
Response setFileCategoriesResponse = UtilIT.setFileCategories(firstFileToModify.toString(), apiToken, List.of("Category"));
setFileCategoriesResponse.then().assertThat()
.statusCode(OK.getStatusCode());

// Test modify first file by restricting it
Response restrictResponse = UtilIT.restrictFile(firstFileToModify.toString(), true, apiToken);
restrictResponse.then().assertThat()
.statusCode(OK.getStatusCode());

// Test modify second file by restricting it
restrictResponse = UtilIT.restrictFile(secondFileToModify.toString(), true, apiToken);
restrictResponse.then().assertThat()
.statusCode(OK.getStatusCode());

Expand All @@ -6682,7 +6700,6 @@ public void testSummaryDatasetVersionsDifferencesAPI() throws InterruptedExcepti
updateTerms.then().assertThat()
.statusCode(OK.getStatusCode());


Response compareResponse = UtilIT.summaryDatasetVersionDifferences(datasetPersistentId, apiToken);
compareResponse.prettyPrint();

Expand All @@ -6701,7 +6718,8 @@ public void testSummaryDatasetVersionsDifferencesAPI() throws InterruptedExcepti
.body("data[0].summary.'Life Sciences Metadata'.added", equalTo(2))
.body("data[0].summary.'Life Sciences Metadata'.deleted", equalTo(0))
.body("data[0].summary.files.added", equalTo(1))
.body("data[0].summary.files.changedFileMetaData", equalTo(2))
// Expected total file metadata field changes: 3 (File 1 has 2 modifications + File 2 has 1 modification)
.body("data[0].summary.files.changedFileMetaData", equalTo(3))
.statusCode(OK.getStatusCode());

//user with no privileges will only see the published version
Expand Down