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
1 change: 1 addition & 0 deletions doc/release-notes/12008-dataset-api-locks.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The API returning information about datasets (`/api/datasets/{id}`) now includes a `locks` field containing a list of the types of all existing locks, e.g. `"locks": ["InReview"]`.
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,13 @@ public static JsonObjectBuilder json(Dataset ds, Boolean returnOwners) {
bld.add("isPartOf", getOwnersFromDvObject(ds));
}
bld.add("datasetType", ds.getDatasetType().getName());

JsonArrayBuilder locksArrayBuilder = Json.createArrayBuilder();
for (DatasetLock lock : ds.getLocks()) {
locksArrayBuilder.add(lock.getReason().toString());
}
bld.add("locks", locksArrayBuilder);

return bld;
}

Expand Down
16 changes: 15 additions & 1 deletion src/test/java/edu/harvard/iq/dataverse/api/DatasetsIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -3077,12 +3077,19 @@ public void testDatasetLocksApi() {
.statusCode(200);

// Check again:
// This should return an empty list, as the dataset should have no locks just yet:
// This should no longer return an empty list, as the dataset now has a lock:
checkDatasetLocks = UtilIT.checkDatasetLocks(datasetId.longValue(), "Ingest", apiToken);
checkDatasetLocks.prettyPrint();
checkDatasetLocks.then().assertThat()
.body("data[0].lockType", equalTo("Ingest"))
.statusCode(200);

// Confirm that when getting the dataset, the lock is also listed
Response getDatasetJson = UtilIT.nativeGet(datasetId, apiToken);
getDatasetJson.prettyPrint();
getDatasetJson.then().assertThat()
.body("data.locks[0]", equalTo("Ingest"))
.statusCode(200);

// Try to lock the dataset with the same type lock, AGAIN
// (this should fail, of course!)
Expand Down Expand Up @@ -3197,6 +3204,13 @@ public void testDatasetLocksApi() {
checkDatasetLocks.then().assertThat()
.body("data", equalTo(emptyArray))
.statusCode(200);

// Confirm that when getting the dataset, the lock is also no longer listed
getDatasetJson = UtilIT.nativeGet(datasetId, apiToken);
getDatasetJson.prettyPrint();
getDatasetJson.then().assertThat()
.body("data.locks", equalTo(emptyArray))
.statusCode(200);
}

/**
Expand Down
16 changes: 16 additions & 0 deletions src/test/java/edu/harvard/iq/dataverse/api/InReviewWorkflowIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import io.restassured.response.Response;
import edu.harvard.iq.dataverse.authorization.DataverseRole;
import jakarta.json.Json;
import jakarta.json.JsonArray;
import jakarta.json.JsonObjectBuilder;

import static edu.harvard.iq.dataverse.UserNotification.Type.*;
Expand Down Expand Up @@ -120,6 +121,13 @@ public void testCuratorSendsCommentsToAuthor() {
.body("message", equalTo("You cannot submit this dataset for review because it is already in review."))
.statusCode(FORBIDDEN.getStatusCode());

// Confirm that when getting the dataset, the "InReview" lock is listed
Response getDatasetJson = UtilIT.nativeGet(datasetId, authorApiToken);
getDatasetJson.prettyPrint();
getDatasetJson.then().assertThat()
.body("data.locks[0]", equalTo("InReview"))
.statusCode(200);

Response authorsChecksForCommentsPrematurely = UtilIT.getNotifications(authorApiToken);
authorsChecksForCommentsPrematurely.prettyPrint();
authorsChecksForCommentsPrematurely.then().assertThat()
Expand Down Expand Up @@ -429,6 +437,14 @@ public void testCuratorSendsCommentsToAuthor() {
// .body("data[3].reasonsForReturn", equalTo(null))
.statusCode(OK.getStatusCode());

// Confirm that when getting the dataset, the "InReview" lock is no longer listed
JsonArray emptyArray = Json.createArrayBuilder().build();
getDatasetJson = UtilIT.nativeGet(datasetId, authorApiToken);
getDatasetJson.prettyPrint();
getDatasetJson.then().assertThat()
.body("data.locks", equalTo(emptyArray))
.statusCode(200);

// These println's are here in case you want to log into the GUI to see what notifications look like.
System.out.println("Curator username/password: " + curatorUsername);
System.out.println("Author username/password: " + authorUsername);
Expand Down