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

Add API endpoint for comparing Dataset Versions #10945

Merged
merged 9 commits into from
Nov 22, 2024
Prev Previous commit
Next Next commit
fixes for json output
  • Loading branch information
stevenwinship committed Oct 24, 2024
commit d957f60d5969c42697856adda927be160f0991c8
Original file line number Diff line number Diff line change
Expand Up @@ -1843,7 +1843,7 @@ public JsonObjectBuilder compareVersionsAsJson() {
job.add("oldVersion", jobVersion);
jobVersion = new NullSafeJsonBuilder();
jobVersion.add("versionNumber", newVersion.getFriendlyVersionNumber());
jobVersion.add("createdDate", new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'").format(newVersion.getCreateTime()));
jobVersion.add("lastUpdatedDate", new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'").format(newVersion.getLastUpdateTime()));
job.add("newVersion", jobVersion);

if (!this.detailDataByBlock.isEmpty()) {
Expand Down Expand Up @@ -1942,13 +1942,18 @@ public JsonObjectBuilder compareVersionsAsJson() {
private JsonObjectBuilder filesDiffJson(FileMetadata fileMetadata) {
NullSafeJsonBuilder job = new NullSafeJsonBuilder();
DataFile df = fileMetadata.getDataFile();
List<DataFileTag> tags = df.getTags();
job.add("fileName", df.getDisplayName())
.add("filePath", fileMetadata.getDirectoryLabel())
.add(df.getChecksumType().name(), df.getChecksumValue())
.add("type",df.getContentType())
.add("fileId", df.getId())
.add("description", df.getDescription())
.add("description", fileMetadata.getDescription())
.add("isRestricted", df.isRestricted());
if (fileMetadata.getCategories() != null && !fileMetadata.getCategories().isEmpty()) {
JsonArrayBuilder jabCategories = Json.createArrayBuilder();
fileMetadata.getCategories().forEach(c -> jabCategories.add(c.getName()));
job.add("categories", jabCategories);
}
if (df.getTags() != null && !df.getTags().isEmpty()) {
JsonArrayBuilder jabTags = Json.createArrayBuilder();
df.getTags().forEach(t -> jabTags.add(t.getTypeLabel()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -965,7 +965,6 @@ public void parseControlledVocabularyValue(DatasetField dsf, DatasetFieldType cv
if (cvv == null) {
if (allowHarvestingMissingCVV) {
// we need to process this as a primitive value
logger.warning(">>>> Value '" + strValue + "' does not exist in type '" + cvvType.getName() + "'. Processing as primitive per setting override.");
parsePrimitiveValue(dsf, cvvType , json);
return;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ private FileMetadata initFile(DatasetVersion dsv, Long prevId) {
fm.setId(id);
fm.setDataFile(df);
fm.setLabel("Label"+id);
fm.setDirectoryLabel("/myFilePath/");
fm.setDescription("Desc"+id);
dsv.getFileMetadatas().add(fm);
return fm;
}
Expand Down
22 changes: 16 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 @@ -5190,20 +5190,28 @@ public void testCompareDatasetVersionsAPI() throws InterruptedException {
String authority = JsonPath.from(getDatasetJsonBeforePublishing.getBody().asString()).getString("data.authority");
String identifier = JsonPath.from(getDatasetJsonBeforePublishing.getBody().asString()).getString("data.identifier");
String datasetPersistentId = protocol + ":" + authority + "/" + identifier;

// used for all added files
JsonObjectBuilder json = Json.createObjectBuilder()
.add("description", "my description")
.add("directoryLabel", "/data/subdir1/")
.add("categories", Json.createArrayBuilder()
.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, apiToken);
Response uploadResponse = UtilIT.uploadFileViaNative(String.valueOf(datasetId), pathToFile, jsonObj, apiToken);
uploadResponse.prettyPrint();
uploadResponse.then().assertThat()
.statusCode(OK.getStatusCode());
Integer modifyFileId = UtilIT.getDataFileIdFromResponse(uploadResponse);
pathToFile = "src/main/webapp/resources/images/dataverseproject_logo.jpg";
uploadResponse = UtilIT.uploadFileViaNative(String.valueOf(datasetId), pathToFile, apiToken);
uploadResponse = UtilIT.uploadFileViaNative(String.valueOf(datasetId), pathToFile, jsonObj, apiToken);
uploadResponse.then().assertThat()
.statusCode(OK.getStatusCode());
Integer deleteFileId = UtilIT.getDataFileIdFromResponse(uploadResponse);

pathToFile = "src/main/webapp/resources/images/fav/favicon-16x16.png";
uploadResponse = UtilIT.uploadFileViaNative(String.valueOf(datasetId), pathToFile, apiToken);
uploadResponse = UtilIT.uploadFileViaNative(String.valueOf(datasetId), pathToFile, jsonObj, apiToken);
uploadResponse.then().assertThat()
.statusCode(OK.getStatusCode());
Integer replaceFileId = UtilIT.getDataFileIdFromResponse(uploadResponse);
Expand All @@ -5221,7 +5229,7 @@ public void testCompareDatasetVersionsAPI() throws InterruptedException {

// Test adding a file
pathToFile = "src/test/resources/tab/test.tab";
Response uploadTabularFileResponse = UtilIT.uploadFileViaNative(Integer.toString(datasetId), pathToFile, Json.createObjectBuilder().build(), apiToken);
Response uploadTabularFileResponse = UtilIT.uploadFileViaNative(Integer.toString(datasetId), pathToFile, jsonObj, apiToken);
uploadTabularFileResponse.prettyPrint();
uploadTabularFileResponse.then().assertThat()
.statusCode(OK.getStatusCode());
Expand All @@ -5243,7 +5251,7 @@ public void testCompareDatasetVersionsAPI() throws InterruptedException {
.statusCode(NO_CONTENT.getStatusCode());

// Test Replacing a file
Response replaceResponse = UtilIT.replaceFile(String.valueOf(replaceFileId), "src/main/webapp/resources/images/fav/favicon-32x32.png", apiToken);
Response replaceResponse = UtilIT.replaceFile(String.valueOf(replaceFileId), "src/main/webapp/resources/images/fav/favicon-32x32.png", jsonObj, apiToken);
replaceResponse.prettyPrint();
replaceResponse.then().assertThat()
.statusCode(OK.getStatusCode());
Expand Down Expand Up @@ -5273,6 +5281,8 @@ public void testCompareDatasetVersionsAPI() throws InterruptedException {
.body("data.metadataChanges[1].changed[0].oldValue", CoreMatchers.containsString(""))
.body("data.metadataChanges[1].changed[0].newValue", CoreMatchers.containsString("Parallel Group Design; Nested Case Control Design"))
.body("data.filesAdded[0].fileName", CoreMatchers.equalTo("test.tab"))
.body("data.filesAdded[0].filePath", CoreMatchers.equalTo("data/subdir1"))
.body("data.filesAdded[0].description", CoreMatchers.equalTo("my description"))
.body("data.filesAdded[0].tags[0]", CoreMatchers.equalTo("Survey"))
.body("data.filesRemoved[0].fileName", CoreMatchers.equalTo("dataverseproject_logo.jpg"))
.body("data.fileChanges[0].fileName", CoreMatchers.equalTo("dataverse-icon-1200.png"))
Expand Down
Loading