Skip to content

Commit

Permalink
addressing comments - fix error handling, add api doc
Browse files Browse the repository at this point in the history
  • Loading branch information
qqmyers committed Jun 4, 2020
1 parent 73e42e2 commit 9fd7f23
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
2 changes: 2 additions & 0 deletions doc/sphinx-guides/source/api/dataaccess.rst
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ Multiple File ("bundle") download

``/api/access/datafiles/$id1,$id2,...$idN``

Alternate Form: POST to ``/api/access/datafiles`` with a ``fileIds`` input field containing the same comma separated list of file ids. This is most useful when your list of files surpasses the allowed URL length (varies but can be ~2000 characters).

Returns the files listed, zipped.

.. note:: If the request can only be completed partially - if only *some* of the requested files can be served (because of the permissions and/or size restrictions), the file MANIFEST.TXT included in the zipped bundle will have entries specifying the reasons the missing files could not be downloaded. IN THE FUTURE the API will return a 207 status code to indicate that the result was a partial success. (As of writing this - v.4.11 - this hasn't been implemented yet)
Expand Down
21 changes: 13 additions & 8 deletions src/main/java/edu/harvard/iq/dataverse/api/Access.java
Original file line number Diff line number Diff line change
Expand Up @@ -538,11 +538,7 @@ public DownloadInstance tabularDatafileMetadataPreprocessed(@PathParam("fileId")
@Produces({ "application/zip" })
public Response postDownloadDatafiles(String fileIds, @QueryParam("gbrecs") boolean gbrecs, @QueryParam("key") String apiTokenParam, @Context UriInfo uriInfo, @Context HttpHeaders headers, @Context HttpServletResponse response) throws WebApplicationException {

fileIds = fileIds.substring(8); // String "fileIds=" from the front
/* Note - fileIds also has a ',' after the last file id number and before a
* final '\n' - the latter appears to stop the last item from being parsed in
* the fileIds.split(","); line below.
*/

return downloadDatafiles(fileIds, gbrecs, apiTokenParam, uriInfo, headers, response);
}
/*
Expand All @@ -558,7 +554,7 @@ public Response datafiles(@PathParam("fileIds") String fileIds, @QueryParam("gbr
return downloadDatafiles(fileIds, gbrecs, apiTokenParam, uriInfo, headers, response);
}

private Response downloadDatafiles(String fileIds, boolean gbrecs, String apiTokenParam, UriInfo uriInfo, HttpHeaders headers, HttpServletResponse response) throws WebApplicationException /* throws NotFoundException, ServiceUnavailableException, PermissionDeniedException, AuthorizationRequiredException*/ {
private Response downloadDatafiles(String rawFileIds, boolean gbrecs, String apiTokenParam, UriInfo uriInfo, HttpHeaders headers, HttpServletResponse response) throws WebApplicationException /* throws NotFoundException, ServiceUnavailableException, PermissionDeniedException, AuthorizationRequiredException*/ {
long setLimit = systemConfig.getZipDownloadLimit();
if (!(setLimit > 0L)) {
setLimit = DataFileZipper.DEFAULT_ZIPFILE_LIMIT;
Expand All @@ -568,10 +564,19 @@ private Response downloadDatafiles(String fileIds, boolean gbrecs, String apiTok

logger.fine("setting zip download size limit to " + zipDownloadSizeLimit + " bytes.");

if (fileIds == null || fileIds.equals("")) {
if (rawFileIds == null || rawFileIds.equals("")) {
throw new BadRequestException();
}

final String fileIds;
if(rawFileIds.startsWith("fileIds=")) {
fileIds = rawFileIds.substring(8); // String "fileIds=" from the front
} else {
fileIds=rawFileIds;
}
/* Note - fileIds coming from the POST ends in '\n' and a ',' has been added after the last file id number and before a
* final '\n' - this stops the last item from being parsed in the fileIds.split(","); line below.
*/

String apiToken = (apiTokenParam == null || apiTokenParam.equals(""))
? headers.getHeaderString(API_KEY_HEADER)
: apiTokenParam;
Expand Down

0 comments on commit 9fd7f23

Please sign in to comment.