Skip to content

Commit 656ae80

Browse files
committed
final checkin, with the guide edits and a short release note #9620
1 parent cbb925b commit 656ae80

File tree

3 files changed

+21
-13
lines changed

3 files changed

+21
-13
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
The Data Access APIs that generate multi-file zipped bundles will offer file name suggestions based on the persistent identifiers (for example, `doi-10.70122-fk2-xxyyzz.zip`), instead of the fixed `dataverse_files.zip` as in prior versions.
2+
See the Data Access API guide for more info.

doc/sphinx-guides/source/api/dataaccess.rst

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ There are a number of reasons why not all of the files can be downloaded:
2121
- Some of the files are restricted and your API token doesn't have access (you will still get the unrestricted files).
2222
- The Dataverse installation has limited how large the zip bundle can be.
2323

24-
In the curl example below, the flags ``-O`` and ``J`` are used. When there are no errors, this has the effect of saving the file as "dataverse_files.zip" (just like the web interface). The flags force errors to be downloaded as a file.
24+
In the curl example below, the flags ``-O`` and ``-J`` are used. When there are no errors, this has the effect of saving the file under the name suggested by Dataverse (which as of v6.7 will be based on the persistent identifier and the latest version number of the dataset, for example ``doi-10.70122-fk2-n2xgbj_1.1.zip``; in prior versions the file name was ``dataverse_files.zip`` in all cases). This mirrors the way the files are saved when downloaded in a browser. The flags also force error messages to be downloaded as a file.
2525

2626
Please note that in addition to the files from dataset, an additional file call "MANIFEST.TXT" will be included in the zipped bundle. It has additional information about the files.
2727

@@ -70,6 +70,8 @@ A curl example using a DOI (with version):
7070
7171
curl -O -J -H "X-Dataverse-key:$API_TOKEN" $SERVER_URL/api/access/dataset/:persistentId/versions/$VERSION?persistentId=$PERSISTENT_ID
7272
73+
Similarly to the API above, this will save the downloaded bundle under the name based on the persistent identifier and the version number, for example, ``doi-10.70122-fk2-n2xgbj_1.1.zip`` or ``doi-10.70122-fk2-n2xgbj_draft.zip``.
74+
7375
The fully expanded example above (without environment variables) looks like this:
7476

7577
.. code-block:: bash
@@ -173,7 +175,7 @@ Multiple File ("bundle") download
173175

174176
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).
175177

176-
Returns the files listed, zipped.
178+
Returns the files listed, zipped. As of v6.7 the name of the zipped bundle will be based on the persistent identifier of the parent dataset, for example, ``doi-10.70122-fk2-xxyyzz.zip``; in prior versions the file name was ``dataverse_files.zip`` in all cases).
177179

178180
.. 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)
179181

src/main/java/edu/harvard/iq/dataverse/api/Access.java

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -644,7 +644,7 @@ public DownloadInstance downloadAuxiliaryFile(@Context ContainerRequestContext c
644644
public Response postDownloadDatafiles(@Context ContainerRequestContext crc, String fileIds, @QueryParam("gbrecs") boolean gbrecs, @Context UriInfo uriInfo, @Context HttpHeaders headers, @Context HttpServletResponse response) throws WebApplicationException {
645645

646646

647-
return downloadDatafiles(getRequestUser(crc), fileIds, gbrecs, uriInfo, headers, response);
647+
return downloadDatafiles(getRequestUser(crc), fileIds, gbrecs, uriInfo, headers, response, null);
648648
}
649649

650650
@GET
@@ -665,7 +665,7 @@ public Response downloadAllFromLatest(@Context ContainerRequestContext crc, @Pat
665665
// We don't want downloads from Draft versions to be counted,
666666
// so we are setting the gbrecs (aka "do not write guestbook response")
667667
// variable accordingly:
668-
return downloadDatafiles(getRequestUser(crc), fileIds, true, uriInfo, headers, response);
668+
return downloadDatafiles(getRequestUser(crc), fileIds, true, uriInfo, headers, response, "draft");
669669
}
670670
}
671671

@@ -686,7 +686,7 @@ public Response downloadAllFromLatest(@Context ContainerRequestContext crc, @Pat
686686
}
687687

688688
String fileIds = getFileIdsAsCommaSeparated(latest.getFileMetadatas());
689-
return downloadDatafiles(getRequestUser(crc), fileIds, gbrecs, uriInfo, headers, response);
689+
return downloadDatafiles(getRequestUser(crc), fileIds, gbrecs, uriInfo, headers, response, latest.getFriendlyVersionNumber());
690690
} catch (WrappedResponse wr) {
691691
return wr.getResponse();
692692
}
@@ -736,7 +736,7 @@ public Command<DatasetVersion> handleLatestPublished() {
736736
if (dsv.isDraft()) {
737737
gbrecs = true;
738738
}
739-
return downloadDatafiles(getRequestUser(crc), fileIds, gbrecs, uriInfo, headers, response);
739+
return downloadDatafiles(getRequestUser(crc), fileIds, gbrecs, uriInfo, headers, response, dsv.getFriendlyVersionNumber().toLowerCase());
740740
} catch (WrappedResponse wr) {
741741
return wr.getResponse();
742742
}
@@ -751,15 +751,19 @@ private static String getFileIdsAsCommaSeparated(List<FileMetadata> fileMetadata
751751
return String.join(",", ids);
752752
}
753753

754-
private String generateMultiFileBundleName(Dataset dataset) {
754+
private String generateMultiFileBundleName(Dataset dataset, String versionTag) {
755755
String bundleName = DEFAULT_BUNDLE_NAME;
756756

757-
if (dataset != null) {
757+
if (dataset != null && dataset.getGlobalId() != null) {
758758
String protocol = dataset.getProtocol();
759759
String authority = dataset.getAuthority().toLowerCase();
760760
String identifier = dataset.getIdentifier().replace('/', '-').toLowerCase();
761-
762-
bundleName = protocol + "-" + authority + "-" + identifier + ".zip";
761+
762+
if (versionTag != null) {
763+
bundleName = protocol + "-" + authority + "-" + identifier + "_" + versionTag + ".zip";
764+
} else {
765+
bundleName = protocol + "-" + authority + "-" + identifier + ".zip";
766+
}
763767
}
764768

765769
return bundleName;
@@ -773,10 +777,10 @@ private String generateMultiFileBundleName(Dataset dataset) {
773777
@Path("datafiles/{fileIds}")
774778
@Produces({"application/zip"})
775779
public Response datafiles(@Context ContainerRequestContext crc, @PathParam("fileIds") String fileIds, @QueryParam("gbrecs") boolean gbrecs, @Context UriInfo uriInfo, @Context HttpHeaders headers, @Context HttpServletResponse response) throws WebApplicationException {
776-
return downloadDatafiles(getRequestUser(crc), fileIds, gbrecs, uriInfo, headers, response);
780+
return downloadDatafiles(getRequestUser(crc), fileIds, gbrecs, uriInfo, headers, response, null);
777781
}
778782

779-
private Response downloadDatafiles(User user, String rawFileIds, boolean donotwriteGBResponse, UriInfo uriInfo, HttpHeaders headers, HttpServletResponse response) throws WebApplicationException /* throws NotFoundException, ServiceUnavailableException, PermissionDeniedException, AuthorizationRequiredException*/ {
783+
private Response downloadDatafiles(User user, String rawFileIds, boolean donotwriteGBResponse, UriInfo uriInfo, HttpHeaders headers, HttpServletResponse response, String versionTag) throws WebApplicationException /* throws NotFoundException, ServiceUnavailableException, PermissionDeniedException, AuthorizationRequiredException*/ {
780784
final long zipDownloadSizeLimit = systemConfig.getZipDownloadLimit();
781785

782786
logger.fine("setting zip download size limit to " + zipDownloadSizeLimit + " bytes.");
@@ -867,7 +871,7 @@ public void write(OutputStream os) throws IOException,
867871
// to produce some output.
868872
zipper = new DataFileZipper(os);
869873
zipper.setFileManifest(fileManifest);
870-
String bundleName = generateMultiFileBundleName(file.getOwner());
874+
String bundleName = generateMultiFileBundleName(file.getOwner(), versionTag);
871875
response.setHeader("Content-disposition", "attachment; filename=\"" + bundleName + "\"");
872876
response.setHeader("Content-Type", "application/zip; name=\"" + bundleName + "\"");
873877
}

0 commit comments

Comments
 (0)