Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8073 guestbook response api #8084

Merged
merged 11 commits into from
Sep 16, 2021
3 changes: 3 additions & 0 deletions doc/release-notes/8073-gb-response_api_update.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
### Update Retrieve Guestbook Response API to remove default output file

With this release the Retrieve Guestbook Responses for a Dataverse Collection will no longer produce a file by default. You may specify an output file by adding a -o $YOURFILENAME to the curl command.
7 changes: 4 additions & 3 deletions doc/sphinx-guides/source/api/native-api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,7 @@ You should expect a 200 ("OK") response and JSON output.
Retrieve Guestbook Responses for a Dataverse Collection
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

In order to retrieve a file containing a list of Guestbook Responses in csv format for Dataverse collection, you must know either its "alias" (which the GUI calls an "identifier") or its database ID. If the Dataverse collection has more than one guestbook you may provide the id of a single guestbook as an optional parameter. If no guestbook id is provided the results returned will be the same as pressing the "Download All Responses" button on the Manage Dataset Guestbook page. If the guestbook id is provided then only those responses from that guestbook will be included in the file.
In order to retrieve a file containing a list of Guestbook Responses in csv format for Dataverse collection, you must know either its "alias" (which the GUI calls an "identifier") or its database ID. If the Dataverse collection has more than one guestbook you may provide the id of a single guestbook as an optional parameter. If no guestbook id is provided the results returned will be the same as pressing the "Download All Responses" button on the Manage Dataset Guestbook page. If the guestbook id is provided then only those responses from that guestbook will be included. The FILENAME parameter is optional without it the responses will be displayed in the console.

.. note:: See :ref:`curl-examples-and-environment-variables` if you are unfamiliar with the use of ``export`` below.

Expand All @@ -597,14 +597,15 @@ In order to retrieve a file containing a list of Guestbook Responses in csv form
export SERVER_URL=https://demo.dataverse.org
export ID=root
export GUESTBOOK_ID=1
export FILENAME=myResponses.csv

curl -O -J -f -H X-Dataverse-key:$API_TOKEN $SERVER_URL/api/dataverses/$ID/guestbookResponses?guestbookId=$GUESTBOOK_ID
curl -H X-Dataverse-key:$API_TOKEN $SERVER_URL/api/dataverses/$ID/guestbookResponses?guestbookId=$GUESTBOOK_ID -o $FILENAME

The fully expanded example above (without environment variables) looks like this:

.. code-block:: bash

curl -O -J -f -H X-Dataverse-key:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx https://demo.dataverse.org/api/dataverses/root/guestbookResponses?guestbookId=1
curl -H X-Dataverse-key:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx https://demo.dataverse.org/api/dataverses/root/guestbookResponses?guestbookId=1 -o myResponses.csv

Datasets
--------
Expand Down
14 changes: 4 additions & 10 deletions src/main/java/edu/harvard/iq/dataverse/api/Dataverses.java
Original file line number Diff line number Diff line change
Expand Up @@ -946,10 +946,9 @@ public Response getGroupByOwnerAndAliasInOwner(@PathParam("identifier") String d

@GET
@Path("{identifier}/guestbookResponses/")
@Produces({"application/download"})
public Response getGuestbookResponsesByDataverse(@PathParam("identifier") String dvIdtf,
@QueryParam("guestbookId") Long gbId, @Context HttpServletResponse response) {

try {
Dataverse dv = findDataverseOrDie(dvIdtf);
User u = findUserOrDie();
Expand All @@ -960,13 +959,8 @@ public Response getGuestbookResponsesByDataverse(@PathParam("identifier") String
} else {
return error(Status.FORBIDDEN, "Not authorized");
}

String fileTimestamp = dateFormatter.format(new Date());
String filename = dv.getAlias() + "_GBResponses_" + fileTimestamp + ".csv";

response.setHeader("Content-Disposition", "attachment; filename="
+ filename);
ServletOutputStream outputStream = response.getOutputStream();

ServletOutputStream outputStream = response.getOutputStream();

Map<Integer, Object> customQandAs = guestbookResponseService.mapCustomQuestionAnswersAsStrings(dv.getId(), gbId);

Expand All @@ -979,7 +973,7 @@ public Response getGuestbookResponsesByDataverse(@PathParam("identifier") String
}
return Response.ok().build();
} catch (IOException io) {
return error(Status.BAD_REQUEST, "Failed to produce response file. Exception: " + io.getMessage());
return error(Status.BAD_REQUEST, "Failed to produce response. Exception: " + io.getMessage());
} catch (WrappedResponse wr) {
return wr.getResponse();
}
Expand Down