Skip to content

Commit 3b6f294

Browse files
committed
Merge branch 'develop' into 11382-featured-items-unicode-filename #11382
2 parents 8f31656 + 416b02e commit 3b6f294

File tree

15 files changed

+211
-33
lines changed

15 files changed

+211
-33
lines changed

doc/release-notes/11415-app-tou.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
### Application Terms of Use Available via API
2+
3+
It's now possible to retrieve the Application Terms of Use (called General Terms of Use in the UI) via API. These are the terms users agree to when creating an account. See [the guides](https://dataverse-guide--11422.org.readthedocs.build/en/11422/api/native-api.html#get-application-terms-of-use-general-terms-of-use), #11415 and #11422.
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/admin/metadatacustomization.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ FieldType definitions
312312
| | permitted, only a subset of HTML |
313313
| | tags will be rendered in the UI. |
314314
| | See the |
315-
| | :ref:`supported-html-fields` |
315+
| | :ref:`supported-html-tags` |
316316
| | section of the Dataset + File |
317317
| | Management page in the User Guide. |
318318
+---------------+------------------------------------+

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 of the dataset and the latest version number, 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

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5544,6 +5544,28 @@ The fully expanded example above (without environment variables) looks like this
55445544
55455545
curl "https://demo.dataverse.org/api/info/settings/:DatasetPublishPopupCustomText"
55465546
5547+
.. _api-get-app-tou:
5548+
5549+
Get Application Terms of Use (General Terms of Use)
5550+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5551+
5552+
In the UI, Application Terms of Use is called "General Terms of Use" and can be seen when you sign up for an account. The terms come from the database setting :ref:`:ApplicationTermsOfUse`. If you have enabled :ref:`i18n` you can pass a two-character language code (e.g. "en") as the ``lang`` parameter.
5553+
5554+
.. note:: See :ref:`curl-examples-and-environment-variables` if you are unfamiliar with the use of export below.
5555+
5556+
.. code-block:: bash
5557+
5558+
export SERVER_URL=https://demo.dataverse.org
5559+
export LANG=en
5560+
5561+
curl "$SERVER_URL/api/info/applicationTermsOfUse?lang=$LANG"
5562+
5563+
The fully expanded example above (without environment variables) looks like this:
5564+
5565+
.. code-block:: bash
5566+
5567+
curl "https://demo.dataverse.org/api/info/applicationTermsOfUse?lang=en"
5568+
55475569
Get API Terms of Use URL
55485570
~~~~~~~~~~~~~~~~~~~~~~~~
55495571

doc/sphinx-guides/source/installation/config.rst

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3921,22 +3921,31 @@ If you don't want the datafiles to be validated on publish, set:
39213921

39223922
``curl -X PUT -d 'false' http://localhost:8080/api/admin/settings/:FileValidationOnPublishEnabled``
39233923

3924+
.. _:ApplicationTermsOfUse:
39243925

39253926
:ApplicationTermsOfUse
39263927
++++++++++++++++++++++
39273928

3928-
Upload an default language HTML file containing the Terms of Use to be displayed at sign up. Supported HTML tags are listed under the :doc:`/user/dataset-management` section of the User Guide.
3929+
Application Terms of Use (called "General Terms of Use" in the UI) are shown to the user when they sign up for an account. Some HTML tags are supported. For a list, see :ref:`supported-html-tags` in the User Guide.
39293930

3930-
``curl -X PUT -d@/tmp/apptou.html http://localhost:8080/api/admin/settings/:ApplicationTermsOfUse``
3931+
You can set terms like this:
39313932

3932-
To upload a language specific Terms of Use file,
3933+
``curl -X PUT http://localhost:8080/api/admin/settings/:ApplicationTermsOfUse --upload-file /tmp/apptou.html``
39333934

3934-
``curl -X PUT -d@/tmp/apptou_fr.html http://localhost:8080/api/admin/settings/:ApplicationTermsOfUse/lang/fr``
3935+
To delete terms:
39353936

3936-
To delete language specific option,
3937+
``curl -X DELETE http://localhost:8080/api/admin/settings/:ApplicationTermsOfUse``
3938+
3939+
If :ref:`i18n` is enabled, you can set the terms per language. To set terms for a specific language ("fr", for example):
3940+
3941+
``curl -X PUT http://localhost:8080/api/admin/settings/:ApplicationTermsOfUse/lang/fr --upload-file /tmp/apptou_fr.html``
3942+
3943+
To delete terms for a specific language ("fr", for example):
39373944

39383945
``curl -X DELETE http://localhost:8080/api/admin/settings/:ApplicationTermsOfUse/lang/fr``
39393946

3947+
To retrieve the values, see :ref:`api-get-app-tou` in the API Guide.
3948+
39403949
:ApplicationPrivacyPolicyUrl
39413950
++++++++++++++++++++++++++++
39423951

doc/sphinx-guides/source/user/dataset-management.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,10 @@ Adding a New Dataset
6464

6565
Note: You can add additional metadata once you have completed the initial dataset creation by going to clicking the Edit button and selecting Metadata from the dropdown menu.
6666

67-
.. _supported-html-fields:
67+
.. _supported-html-tags:
6868

69-
Supported HTML Fields
70-
---------------------
69+
Supported HTML Tags
70+
-------------------
7171

7272
We currently only support the following HTML tags for any of our textbox metadata fields (i.e., Description) : <a>, <b>, <blockquote>,
7373
<br>, <code>, <del>, <dd>, <dl>, <dt>, <em>, <hr>, <h1>-<h3>, <i>, <img>, <kbd>, <li>, <ol>, <p>, <pre>, <s>, <sup>, <sub>,

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

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ public class Access extends AbstractApiBean {
169169
@Inject
170170
DataverseFeaturedItemServiceBean dataverseFeaturedItemServiceBean;
171171

172+
private static final String DEFAULT_BUNDLE_NAME = "dataverse_files.zip";
172173
//@EJB
173174

174175
// TODO:
@@ -643,7 +644,7 @@ public DownloadInstance downloadAuxiliaryFile(@Context ContainerRequestContext c
643644
public Response postDownloadDatafiles(@Context ContainerRequestContext crc, String fileIds, @QueryParam("gbrecs") boolean gbrecs, @Context UriInfo uriInfo, @Context HttpHeaders headers, @Context HttpServletResponse response) throws WebApplicationException {
644645

645646

646-
return downloadDatafiles(getRequestUser(crc), fileIds, gbrecs, uriInfo, headers, response);
647+
return downloadDatafiles(getRequestUser(crc), fileIds, gbrecs, uriInfo, headers, response, null);
647648
}
648649

649650
@GET
@@ -664,7 +665,7 @@ public Response downloadAllFromLatest(@Context ContainerRequestContext crc, @Pat
664665
// We don't want downloads from Draft versions to be counted,
665666
// so we are setting the gbrecs (aka "do not write guestbook response")
666667
// variable accordingly:
667-
return downloadDatafiles(getRequestUser(crc), fileIds, true, uriInfo, headers, response);
668+
return downloadDatafiles(getRequestUser(crc), fileIds, true, uriInfo, headers, response, "draft");
668669
}
669670
}
670671

@@ -685,7 +686,7 @@ public Response downloadAllFromLatest(@Context ContainerRequestContext crc, @Pat
685686
}
686687

687688
String fileIds = getFileIdsAsCommaSeparated(latest.getFileMetadatas());
688-
return downloadDatafiles(getRequestUser(crc), fileIds, gbrecs, uriInfo, headers, response);
689+
return downloadDatafiles(getRequestUser(crc), fileIds, gbrecs, uriInfo, headers, response, latest.getFriendlyVersionNumber());
689690
} catch (WrappedResponse wr) {
690691
return wr.getResponse();
691692
}
@@ -735,7 +736,7 @@ public Command<DatasetVersion> handleLatestPublished() {
735736
if (dsv.isDraft()) {
736737
gbrecs = true;
737738
}
738-
return downloadDatafiles(getRequestUser(crc), fileIds, gbrecs, uriInfo, headers, response);
739+
return downloadDatafiles(getRequestUser(crc), fileIds, gbrecs, uriInfo, headers, response, dsv.getFriendlyVersionNumber().toLowerCase());
739740
} catch (WrappedResponse wr) {
740741
return wr.getResponse();
741742
}
@@ -749,6 +750,24 @@ private static String getFileIdsAsCommaSeparated(List<FileMetadata> fileMetadata
749750
}
750751
return String.join(",", ids);
751752
}
753+
754+
private String generateMultiFileBundleName(Dataset dataset, String versionTag) {
755+
String bundleName = DEFAULT_BUNDLE_NAME;
756+
757+
if (dataset != null && dataset.getGlobalId() != null) {
758+
String protocol = dataset.getProtocol();
759+
String authority = dataset.getAuthority().toLowerCase();
760+
String identifier = dataset.getIdentifier().replace('/', '-').toLowerCase();
761+
762+
if (versionTag != null) {
763+
bundleName = protocol + "-" + authority + "-" + identifier + "_" + versionTag + ".zip";
764+
} else {
765+
bundleName = protocol + "-" + authority + "-" + identifier + ".zip";
766+
}
767+
}
768+
769+
return bundleName;
770+
}
752771

753772
/*
754773
* API method for downloading zipped bundles of multiple files:
@@ -758,10 +777,10 @@ private static String getFileIdsAsCommaSeparated(List<FileMetadata> fileMetadata
758777
@Path("datafiles/{fileIds}")
759778
@Produces({"application/zip"})
760779
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 {
761-
return downloadDatafiles(getRequestUser(crc), fileIds, gbrecs, uriInfo, headers, response);
780+
return downloadDatafiles(getRequestUser(crc), fileIds, gbrecs, uriInfo, headers, response, null);
762781
}
763782

764-
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*/ {
765784
final long zipDownloadSizeLimit = systemConfig.getZipDownloadLimit();
766785

767786
logger.fine("setting zip download size limit to " + zipDownloadSizeLimit + " bytes.");
@@ -852,8 +871,9 @@ public void write(OutputStream os) throws IOException,
852871
// to produce some output.
853872
zipper = new DataFileZipper(os);
854873
zipper.setFileManifest(fileManifest);
855-
response.setHeader("Content-disposition", "attachment; filename=\"dataverse_files.zip\"");
856-
response.setHeader("Content-Type", "application/zip; name=\"dataverse_files.zip\"");
874+
String bundleName = generateMultiFileBundleName(file.getOwner(), versionTag);
875+
response.setHeader("Content-disposition", "attachment; filename=\"" + bundleName + "\"");
876+
response.setHeader("Content-Type", "application/zip; name=\"" + bundleName + "\"");
857877
}
858878

859879
long size = 0L;
@@ -960,8 +980,8 @@ public InputStream tempPreview(@PathParam("fileSystemId") String fileSystemId, @
960980
961981
}*/
962982

963-
964-
983+
984+
965985
// TODO: Rather than only supporting looking up files by their database IDs, consider supporting persistent identifiers.
966986
@Path("fileCardImage/{fileId}")
967987
@GET

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

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,13 @@
2626
import jakarta.json.JsonValue;
2727
import jakarta.ws.rs.GET;
2828
import jakarta.ws.rs.Path;
29-
import jakarta.ws.rs.PathParam;
29+
import jakarta.ws.rs.QueryParam;
3030
import jakarta.ws.rs.core.MediaType;
3131
import jakarta.ws.rs.core.Response;
3232
import org.eclipse.microprofile.openapi.annotations.Operation;
33+
import org.eclipse.microprofile.openapi.annotations.enums.SchemaType;
34+
import org.eclipse.microprofile.openapi.annotations.media.Schema;
35+
import org.eclipse.microprofile.openapi.annotations.parameters.Parameter;
3336
import org.eclipse.microprofile.openapi.annotations.responses.APIResponse;
3437
import org.eclipse.microprofile.openapi.annotations.tags.Tag;
3538

@@ -78,6 +81,19 @@ public Response getServer() {
7881
return ok(JvmSettings.FQDN.lookup());
7982
}
8083

84+
@GET
85+
@Path("applicationTermsOfUse")
86+
@APIResponse(responseCode = "200",
87+
description = "Application Terms of Use (General Terms of Use) that must be agreed to at signup.")
88+
public Response getApplicationTermsOfUse(
89+
@Parameter(description = "Two-character language code.",
90+
required = false,
91+
example = "en",
92+
schema = @Schema(type = SchemaType.STRING))
93+
@QueryParam("lang") String lang) {
94+
return ok(systemConfig.getApplicationTermsOfUse(lang));
95+
}
96+
8197
@GET
8298
@Path("apiTermsOfUse")
8399
public Response getTermsOfUse() {

src/main/java/edu/harvard/iq/dataverse/util/SystemConfig.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -428,15 +428,24 @@ public boolean isThumbnailGenerationDisabledForPDF() {
428428
}
429429

430430
public String getApplicationTermsOfUse() {
431-
String language = BundleUtil.getCurrentLocale().getLanguage();
431+
return getApplicationTermsOfUse(null);
432+
}
433+
434+
public String getApplicationTermsOfUse(String languageIn) {
435+
String language = null;
436+
if (languageIn != null) {
437+
language = languageIn;
438+
} else {
439+
language = BundleUtil.getCurrentLocale().getLanguage();
440+
}
432441
String saneDefaultForAppTermsOfUse = BundleUtil.getStringFromBundle("system.app.terms");
433-
// Get the value for the defaultLocale. IT will either be used as the return
442+
// Get the value for the defaultLocale. It will either be used as the return
434443
// value, or as a better default than the saneDefaultForAppTermsOfUse if there
435444
// is no language-specific value
436445
String appTermsOfUse = settingsService.getValueForKey(SettingsServiceBean.Key.ApplicationTermsOfUse, saneDefaultForAppTermsOfUse);
437-
//Now get the language-specific value if it exists
446+
// Now get the language-specific value if it exists
438447
if (language != null && !language.equalsIgnoreCase(BundleUtil.getDefaultLocale().getLanguage())) {
439-
appTermsOfUse = settingsService.getValueForKey(SettingsServiceBean.Key.ApplicationTermsOfUse, language, appTermsOfUse);
448+
appTermsOfUse = settingsService.getValueForKey(SettingsServiceBean.Key.ApplicationTermsOfUse, language, appTermsOfUse);
440449
}
441450
return appTermsOfUse;
442451
}

0 commit comments

Comments
 (0)