Search in sources :

Example 1 with ReturnDatasetToAuthorCommand

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();
    }
}
Also used : ReturnDatasetToAuthorCommand(edu.harvard.iq.dataverse.engine.command.impl.ReturnDatasetToAuthorCommand) Dataset(edu.harvard.iq.dataverse.Dataset) StringReader(java.io.StringReader) JsonObject(javax.json.JsonObject) JsonObjectBuilder(javax.json.JsonObjectBuilder) AuthenticatedUser(edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST)

Aggregations

Dataset (edu.harvard.iq.dataverse.Dataset)1 AuthenticatedUser (edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser)1 ReturnDatasetToAuthorCommand (edu.harvard.iq.dataverse.engine.command.impl.ReturnDatasetToAuthorCommand)1 StringReader (java.io.StringReader)1 JsonObject (javax.json.JsonObject)1 JsonObjectBuilder (javax.json.JsonObjectBuilder)1 POST (javax.ws.rs.POST)1 Path (javax.ws.rs.Path)1