diff --git a/doc/release-notes/11892-bulk-export.md b/doc/release-notes/11892-bulk-export.md new file mode 100644 index 00000000000..728f2199f3a --- /dev/null +++ b/doc/release-notes/11892-bulk-export.md @@ -0,0 +1,34 @@ +### Bulk Metadata Export via API + +Metadata can now be retrieved for multiple dataset versions in a single request and delivered as **one combined export**. + +A new API endpoint, `POST /api/datasets/export`, accepts a JSON body with the name of the metadata export format and a list of datasets, each identified by its persistent identifier and a version specification. +Each version may be given explicitly (for example `1.0`) or by one of the symbolic selectors `:latest`, `:latest-published`, or `:draft`; when omitted, the latest published version is used. + +Please note: this is not a replacement for the OAI-PMH based harvesting protocol, which is still the recommended way to harvest metadata in larger quantities. +It reduces the number of round trips substantially for use cases around the Modern UI, where metadata for multiple user-selected datasets is requested. + +**Note:** Bulk export relies on export formats that support it. +Only formats whose exporter plugin declares the new bulk export capability can be used to export multiple datasets at once. +The built-in Dataverse JSON format supports bulk export and combines the requested versions into a single JSON array. +Other formats (or bulk export for formats provided by external plugins) becomes available as plugins adopt the new capability. +Requests naming only a single dataset are handled exactly like the previous per-dataset export, so no bulk-capable format is required in that case. + +#### Clear error reporting + +- Request bodies that are missing or malformed are now rejected with precise, human-readable validation messages pointing at the offending field (for example an invalid version selector or a blank persistent identifier). +- If some of the requested datasets are unknown or cannot be seen by the requester, the response still lists **all** such problems in one place (an HTTP 400 response with a list of violations) instead of stopping at the first one - and deliberately without revealing which datasets exist on the instance. + +#### Updates for System Administrators + +- **New setting:** the maximum number of dataset versions per bulk export request is controlled by a new JVM setting `dataverse.api.export.bulk.max-request-size` (default: `32`). +- **Log tracing:** every bulk export is assigned a unique correlation identifier, returned to the client in the `X-Dataverse-Export-ID` response header and included in all log records of that batch. + Use the identifier from a failing request to find the related log entries. +- Downloads served through bulk export are counted and reported by the MakeDataCount service like regular metadata exports (for each released version in the batch). + +#### Updates for Export Plugin Developers + +The Exporter Plugin API (dataverse-spi) gains a bulk export capability: plugins implementing `io.gdcc.spi.export.caps.bulk.BulkDatasetExporter` receive a `BulkDatasetContext` over a batch of dataset versions and decide how the individual exports are framed and joined. +- Exports are lazy: each one materializes on demand (read from cache, generated on the fly for drafts), in a short transaction of its own, so memory and database connections stay independent of the batch size. +- Streams handed out by the context are tracked and closed automatically when the batch finishes, even if the plugin leaves them open. +- Dataverse implements this capability for its built-in JSON exporter, and ships extensive new unit tests covering the API request validation, the pipeline, and the transaction behavior. diff --git a/doc/sphinx-guides/source/api/native-api.rst b/doc/sphinx-guides/source/api/native-api.rst index e08777c9cf2..ded6154bc54 100644 --- a/doc/sphinx-guides/source/api/native-api.rst +++ b/doc/sphinx-guides/source/api/native-api.rst @@ -2416,6 +2416,50 @@ The standard has further evolved into a format called Croissant. For details, se The ``schema.org`` format changed after Dataverse 6.4 as well. Previously its content type was "application/json" but now it is "application/ld+json". +.. _bulk-metadata-export-api: + +Export Metadata of Multiple Datasets in One Request +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +|CORS| Export the metadata of several dataset versions in a single request, combined into a single output by the chosen format. +This is a ``POST`` to the same path as the single-endpoint export described above, with a JSON body naming the format and the list of dataset versions to export: + +.. code-block:: bash + + export SERVER_URL=https://demo.dataverse.org + export API_TOKEN=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx + export METADATA_FORMAT=dataverse_json + export BODY="{\"exporter\":\"$METADATA_FORMAT\",\"datasets\":[{\"persistentId\":\"doi:10.5072/FK2/J8SJZB\",\"version\":\"1.0\"},{\"persistentId\":\"doi:10.5072/FK2/XY79KQ\"},{\"persistentId\":\"doi:10.5072/FK2/ABCDEF\",\"version\":\":draft\"}]}" + + curl -X POST -H "Content-Type: application/json" -H "X-Dataverse-key: $API_TOKEN" -d "$BODY" "$SERVER_URL/api/datasets/export" + +The fully expanded example above (without environment variables) looks like this: + +.. code-block:: bash + + curl -X POST -H "Content-Type: application/json" -H "X-Dataverse-key: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" -d "{\"exporter\":\"dataverse_json\",\"datasets\":[{\"persistentId\":\"doi:10.5072/FK2/J8SJZB\",\"version\":\"1.0\"},{\"persistentId\":\"doi:10.5072/FK2/XY79KQ\"},{\"persistentId\":\"doi:10.5072/FK2/ABCDEF\",\"version\":\":draft\"}]}" "https://demo.dataverse.org/api/datasets/export" + +Each entry in ``datasets`` couples a ``persistentId`` with an optional ``version``. +The version syntax is the same as for the :ref:`export-dataset-metadata-api` above (see :ref:`dataset-version-specifiers`): +``:latest``, ``:latest-published``, ``:draft``, or an explicit number such as ``1.0``. +When omitted, it defaults to ``:latest-published``, and an API token is not needed unless a version requires access. + +Requests listing exactly one dataset is handled like :ref:`the single-endpoint export `: +it returns the usual single-dataset output of the requested format. + +A request listing two or more datasets combines all of the requested versions into a single output. +The format must support this, and using a format that does not results in an HTTP 400 (Bad Request) error. +What the combined output contains for a given format is decided by that format. + +All requested datasets are resolved and their access checked before any export is produced. +If any requested dataset or version is not found or cannot be read by the requester, the *entire* request is rejected with an HTTP 400 response. +Each problematic entry is listed, so you get feedback on all entries in one round trip. +Similarly, a body that is missing or does not follow the schema above is rejected with a message naming the invalid field. + +The maximum number of dataset versions per request is limited by the :ref:`dataverse.api.export.bulk.max-request-size` setting. +The successful response contains an ``X-Dataverse-Export-ID`` header carrying the identifier of the batch. +In case an error occurs during data streaming, use its value to correlate with the server's log of events. + List Files in a Dataset ~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/doc/sphinx-guides/source/developers/coding-style.md b/doc/sphinx-guides/source/developers/coding-style.md index 1d8ae9b6577..d00c7aee936 100644 --- a/doc/sphinx-guides/source/developers/coding-style.md +++ b/doc/sphinx-guides/source/developers/coding-style.md @@ -133,6 +133,21 @@ If you know of a way to easily share Netbeans configuration across a team, pleas To avoid exposing potentially sensitive information in temporary files stored on the file system, use the `edu.harvard.iq.dataverse.util.SecureTempFiles` utility instead of Java mechanics as `Files.createTempFile` directly. +### Tracking Streams Handed Out Beyond the Core's Control + +When handing out streams to dataverse-spi based plugins, do not rely on them closing the streams. +The same is true for any library we use and hand streams to, as we cannot guarantee their diligence. +Use the `edu.harvard.iq.dataverse.util.StreamRegistry` utility to avoid leaking stream. +Hand out `registry.track(inputStream)` and close the registry in `try-with-resources` (or `finally`) when your operation is done. + +With a registry in place, the caller may close the stream, close it more than once, or not close it at all, without leaking file descriptors or storage connections. +The registry closes whatever is left over when it closes, and logs a warning if more streams than the configured threshold are held open at once. +The registry's bookkeeping is thread-safe, but the individual tracked streams are *not* made thread-safe by tracking, so they must not be shared between threads. + +The bulk metadata export pipeline (see `BulkExportPipeline`) is an example of this convention in action: +it lends each dataset version's export stream to exporter plugins through a `StreamRegistry`, +so plugins are free to process items in whatever order they like across threads. + ## Bash Generally, Google's Shell Style Guide at seems to have good advice. diff --git a/doc/sphinx-guides/source/installation/config.rst b/doc/sphinx-guides/source/installation/config.rst index 360a96e8eb5..a09c109142b 100644 --- a/doc/sphinx-guides/source/installation/config.rst +++ b/doc/sphinx-guides/source/installation/config.rst @@ -3452,6 +3452,21 @@ Can also be set via any `supported MicroProfile Config API source`_, e.g. the en This setting will be ignored unless the :ref:`dataverse.api.blocked.policy` is set to ``unblock-key``. Otherwise the deprecated :ref:`:BlockedApiKey` will be used +.. _dataverse.api.export.bulk.max-request-size: + +dataverse.api.export.bulk.max-request-size ++++++++++++++++++++++++++++++++++++++++++++ + +Limits the maximum number of dataset versions that may be requested in a single bulk metadata export request (see :ref:`bulk-metadata-export-api` in the API Guide). +Requests naming more dataset versions than this limit are rejected with an HTTP 400 response. + +Default: ``32`` + +``./asadmin create-jvm-options '-Ddataverse.api.export.bulk.max-request-size=16'`` + +Can also be set via any `supported MicroProfile Config API source`_, e.g. the environment variable ``DATAVERSE_API_EXPORT_BULK_MAX_REQUEST_SIZE``. + + .. _dataverse.legacy.api-response-message-style: dataverse.legacy.api-response-message-style diff --git a/modules/dataverse-parent/pom.xml b/modules/dataverse-parent/pom.xml index d71cbcd7fd3..e44cc2ffabc 100644 --- a/modules/dataverse-parent/pom.xml +++ b/modules/dataverse-parent/pom.xml @@ -450,7 +450,6 @@ -