use of edu.harvard.iq.dataverse.engine.command.impl.ReturnDatasetToAuthorCommand in project dataverse by IQSS.
the class Datasets method returnToAuthor.
@POST
@Path("{id}/returnToAuthor")
public Response returnToAuthor(@PathParam("id") String idSupplied, String jsonBody) {
if (jsonBody == null || jsonBody.isEmpty()) {
return error(Response.Status.BAD_REQUEST, "You must supply JSON to this API endpoint and it must contain a reason for returning the dataset.");
}
StringReader rdr = new StringReader(jsonBody);
JsonObject json = Json.createReader(rdr).readObject();
try {
Dataset dataset = findDatasetOrDie(idSupplied);
String reasonForReturn = null;
reasonForReturn = json.getString("reasonForReturn");
// TODO: Once we add a box for the curator to type into, pass the reason for return to the ReturnDatasetToAuthorCommand and delete this check and call to setReturnReason on the API side.
if (reasonForReturn == null || reasonForReturn.isEmpty()) {
return error(Response.Status.BAD_REQUEST, "You must enter a reason for returning a dataset to the author(s).");
}
AuthenticatedUser authenticatedUser = findAuthenticatedUserOrDie();
Dataset updatedDataset = execCommand(new ReturnDatasetToAuthorCommand(createDataverseRequest(authenticatedUser), dataset, reasonForReturn));
boolean inReview = updatedDataset.isLockedFor(DatasetLock.Reason.InReview);
JsonObjectBuilder result = Json.createObjectBuilder();
result.add("inReview", inReview);
result.add("message", "Dataset id " + updatedDataset.getId() + " has been sent back to the author(s).");
return ok(result);
} catch (WrappedResponse wr) {
return wr.getResponse();
}
}
Aggregations