Skip to content

Commit

Permalink
Merge branch 'develop' into 10229-fix-featured-dv-selection
Browse files Browse the repository at this point in the history
  • Loading branch information
sekmiller committed Feb 6, 2024
2 parents 4309ab0 + 08cf9a8 commit 82f797b
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 5 deletions.
1 change: 1 addition & 0 deletions doc/release-notes/10297-metadata-api-fix.md
@@ -0,0 +1 @@
The API endpoint `api/datasets/{id}/metadata` has been changed to default to the latest version of the dataset that the user has access.
2 changes: 1 addition & 1 deletion src/main/java/edu/harvard/iq/dataverse/api/Datasets.java
Expand Up @@ -778,7 +778,7 @@ public Response getVersionJsonLDMetadata(@Context ContainerRequestContext crc, @
@Path("{id}/metadata")
@Produces("application/ld+json, application/json-ld")
public Response getVersionJsonLDMetadata(@Context ContainerRequestContext crc, @PathParam("id") String id, @Context UriInfo uriInfo, @Context HttpHeaders headers) {
return getVersionJsonLDMetadata(crc, id, DS_VERSION_DRAFT, uriInfo, headers);
return getVersionJsonLDMetadata(crc, id, DS_VERSION_LATEST, uriInfo, headers);
}

@PUT
Expand Down
60 changes: 56 additions & 4 deletions src/test/java/edu/harvard/iq/dataverse/api/DatasetsIT.java
Expand Up @@ -3013,6 +3013,46 @@ public void testSemanticMetadataAPIs() {
response = UtilIT.updateDatasetJsonLDMetadata(datasetId, apiToken, badTerms, false);
response.then().assertThat().statusCode(BAD_REQUEST.getStatusCode());


//We publish the dataset and dataverse
UtilIT.publishDataverseViaNativeApi(dataverseAlias, apiToken).then().assertThat().statusCode(OK.getStatusCode());
UtilIT.publishDatasetViaNativeApi(datasetId, "major", apiToken).then().assertThat().statusCode(OK.getStatusCode());

//We check the version is published
response = UtilIT.getDatasetJsonLDMetadata(datasetId, apiToken);
response.prettyPrint();
jsonLDString = getData(response.getBody().asString());
jsonLDObject = JSONLDUtil.decontextualizeJsonLD(jsonLDString);
String publishedVersion = jsonLDObject.getString("http://schema.org/version");
assertNotEquals("DRAFT", publishedVersion);

// Upload a file so a draft version is created
String pathToFile = "src/main/webapp/resources/images/cc0.png";
Response uploadResponse = UtilIT.uploadFileViaNative(datasetId.toString(), pathToFile, apiToken);
uploadResponse.prettyPrint();
uploadResponse.then().assertThat().statusCode(OK.getStatusCode());
int fileID = uploadResponse.jsonPath().getInt("data.files[0].dataFile.id");

//We check the authenticated user gets DRAFT
response = UtilIT.getDatasetJsonLDMetadata(datasetId, apiToken);
response.prettyPrint();
jsonLDString = getData(response.getBody().asString());
jsonLDObject = JSONLDUtil.decontextualizeJsonLD(jsonLDString);
assertEquals("DRAFT", jsonLDObject.getString("http://schema.org/version"));

// Create user with no permission and check they get published version
String apiTokenNoPerms = UtilIT.createRandomUserGetToken();
response = UtilIT.getDatasetJsonLDMetadata(datasetId, apiTokenNoPerms);
response.prettyPrint();
jsonLDString = getData(response.getBody().asString());
jsonLDObject = JSONLDUtil.decontextualizeJsonLD(jsonLDString);
assertNotEquals("DRAFT", jsonLDObject.getString("http://schema.org/version"));

// Delete the file
Response deleteFileResponse = UtilIT.deleteFileInDataset(fileID, apiToken);
deleteFileResponse.prettyPrint();
deleteFileResponse.then().assertThat().statusCode(OK.getStatusCode());

// Delete the terms of use
response = UtilIT.deleteDatasetJsonLDMetadata(datasetId, apiToken,
"{\"https://dataverse.org/schema/core#termsOfUse\": \"New terms\"}");
Expand All @@ -3026,15 +3066,27 @@ public void testSemanticMetadataAPIs() {
jsonLDObject = JSONLDUtil.decontextualizeJsonLD(jsonLDString);
assertTrue(!jsonLDObject.containsKey("https://dataverse.org/schema/core#termsOfUse"));

// Cleanup - delete dataset, dataverse, user...
Response deleteDatasetResponse = UtilIT.deleteDatasetViaNativeApi(datasetId, apiToken);
deleteDatasetResponse.prettyPrint();
assertEquals(200, deleteDatasetResponse.getStatusCode());
//Delete the DRAFT dataset
Response deleteDraftResponse = UtilIT.deleteDatasetVersionViaNativeApi(datasetId, DS_VERSION_DRAFT, apiToken);
deleteDraftResponse.prettyPrint();
deleteDraftResponse.then().assertThat().statusCode(OK.getStatusCode());

//We set the user as superuser so we can delete the published dataset
Response superUserResponse = UtilIT.makeSuperUser(username);
superUserResponse.prettyPrint();
deleteDraftResponse.then().assertThat().statusCode(OK.getStatusCode());

//Delete the published dataset
Response deletePublishedResponse = UtilIT.deleteDatasetViaNativeApi(datasetId, apiToken);
deletePublishedResponse.prettyPrint();
deleteDraftResponse.then().assertThat().statusCode(OK.getStatusCode());

//Delete the dataverse
Response deleteDataverseResponse = UtilIT.deleteDataverse(dataverseAlias, apiToken);
deleteDataverseResponse.prettyPrint();
assertEquals(200, deleteDataverseResponse.getStatusCode());

//Delete the user
Response deleteUserResponse = UtilIT.deleteUser(username);
deleteUserResponse.prettyPrint();
assertEquals(200, deleteUserResponse.getStatusCode());
Expand Down

0 comments on commit 82f797b

Please sign in to comment.