Skip to content

Commit d022e3e

Browse files
authored
Merge pull request #12008 from vera/feat/is-in-review-state
feat: add "isInReviewState" to API responses about dataset versions
2 parents 3e5b9bb + 3a7bb2c commit d022e3e

File tree

4 files changed

+39
-1
lines changed

4 files changed

+39
-1
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
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"]`.

src/main/java/edu/harvard/iq/dataverse/util/json/JsonPrinter.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,13 @@ public static JsonObjectBuilder json(Dataset ds, Boolean returnOwners) {
486486
bld.add("isPartOf", getOwnersFromDvObject(ds));
487487
}
488488
bld.add("datasetType", ds.getDatasetType().getName());
489+
490+
JsonArrayBuilder locksArrayBuilder = Json.createArrayBuilder();
491+
for (DatasetLock lock : ds.getLocks()) {
492+
locksArrayBuilder.add(lock.getReason().toString());
493+
}
494+
bld.add("locks", locksArrayBuilder);
495+
489496
return bld;
490497
}
491498

src/test/java/edu/harvard/iq/dataverse/api/DatasetsIT.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3077,12 +3077,19 @@ public void testDatasetLocksApi() {
30773077
.statusCode(200);
30783078

30793079
// Check again:
3080-
// This should return an empty list, as the dataset should have no locks just yet:
3080+
// This should no longer return an empty list, as the dataset now has a lock:
30813081
checkDatasetLocks = UtilIT.checkDatasetLocks(datasetId.longValue(), "Ingest", apiToken);
30823082
checkDatasetLocks.prettyPrint();
30833083
checkDatasetLocks.then().assertThat()
30843084
.body("data[0].lockType", equalTo("Ingest"))
30853085
.statusCode(200);
3086+
3087+
// Confirm that when getting the dataset, the lock is also listed
3088+
Response getDatasetJson = UtilIT.nativeGet(datasetId, apiToken);
3089+
getDatasetJson.prettyPrint();
3090+
getDatasetJson.then().assertThat()
3091+
.body("data.locks[0]", equalTo("Ingest"))
3092+
.statusCode(200);
30863093

30873094
// Try to lock the dataset with the same type lock, AGAIN
30883095
// (this should fail, of course!)
@@ -3197,6 +3204,13 @@ public void testDatasetLocksApi() {
31973204
checkDatasetLocks.then().assertThat()
31983205
.body("data", equalTo(emptyArray))
31993206
.statusCode(200);
3207+
3208+
// Confirm that when getting the dataset, the lock is also no longer listed
3209+
getDatasetJson = UtilIT.nativeGet(datasetId, apiToken);
3210+
getDatasetJson.prettyPrint();
3211+
getDatasetJson.then().assertThat()
3212+
.body("data.locks", equalTo(emptyArray))
3213+
.statusCode(200);
32003214
}
32013215

32023216
/**

src/test/java/edu/harvard/iq/dataverse/api/InReviewWorkflowIT.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import io.restassured.response.Response;
77
import edu.harvard.iq.dataverse.authorization.DataverseRole;
88
import jakarta.json.Json;
9+
import jakarta.json.JsonArray;
910
import jakarta.json.JsonObjectBuilder;
1011

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

124+
// Confirm that when getting the dataset, the "InReview" lock is listed
125+
Response getDatasetJson = UtilIT.nativeGet(datasetId, authorApiToken);
126+
getDatasetJson.prettyPrint();
127+
getDatasetJson.then().assertThat()
128+
.body("data.locks[0]", equalTo("InReview"))
129+
.statusCode(200);
130+
123131
Response authorsChecksForCommentsPrematurely = UtilIT.getNotifications(authorApiToken);
124132
authorsChecksForCommentsPrematurely.prettyPrint();
125133
authorsChecksForCommentsPrematurely.then().assertThat()
@@ -429,6 +437,14 @@ public void testCuratorSendsCommentsToAuthor() {
429437
// .body("data[3].reasonsForReturn", equalTo(null))
430438
.statusCode(OK.getStatusCode());
431439

440+
// Confirm that when getting the dataset, the "InReview" lock is no longer listed
441+
JsonArray emptyArray = Json.createArrayBuilder().build();
442+
getDatasetJson = UtilIT.nativeGet(datasetId, authorApiToken);
443+
getDatasetJson.prettyPrint();
444+
getDatasetJson.then().assertThat()
445+
.body("data.locks", equalTo(emptyArray))
446+
.statusCode(200);
447+
432448
// These println's are here in case you want to log into the GUI to see what notifications look like.
433449
System.out.println("Curator username/password: " + curatorUsername);
434450
System.out.println("Author username/password: " + authorUsername);

0 commit comments

Comments
 (0)