From bd47b8e7f459e9f3abb141c5837297466c7ac1ec Mon Sep 17 00:00:00 2001 From: Philip Durbin Date: Wed, 21 Sep 2022 15:46:16 -0400 Subject: [PATCH] support database IDs too (as well as PIDs) #8720 --- .../source/admin/metadataexport.rst | 6 +++++- .../edu/harvard/iq/dataverse/api/Metadata.java | 18 +++++------------- .../harvard/iq/dataverse/api/DatasetsIT.java | 4 ++++ .../edu/harvard/iq/dataverse/api/UtilIT.java | 10 ++++++++-- 4 files changed, 22 insertions(+), 16 deletions(-) diff --git a/doc/sphinx-guides/source/admin/metadataexport.rst b/doc/sphinx-guides/source/admin/metadataexport.rst index 4deb82fe996..78b8c8ce223 100644 --- a/doc/sphinx-guides/source/admin/metadataexport.rst +++ b/doc/sphinx-guides/source/admin/metadataexport.rst @@ -24,7 +24,7 @@ In addition to the automated exports, a Dataverse installation admin can start a ``curl http://localhost:8080/api/admin/metadata/clearExportTimestamps`` -``curl http://localhost:8080/api/admin/metadata/reExportDataset?persistentId=doi:10.5072/FK2/AAA000`` +``curl http://localhost:8080/api/admin/metadata/:persistentId/reExportDataset?persistentId=doi:10.5072/FK2/AAA000`` The first will attempt to export all the published, local (non-harvested) datasets that haven't been exported yet. The second will *force* a re-export of every published, local dataset, regardless of whether it has already been exported or not. @@ -37,6 +37,10 @@ Calling clearExportTimestamps should return ``{"status":"OK","data":{"message":" The reExportDataset call gives you the opportunity to *force* a re-export of only a specific dataset and (with some script automation) could allow you the export specific batches of datasets. This might be usefull when handling exporting problems or when reExportAll takes too much time and is overkill. Note that :ref:`export-dataset-metadata-api` is a related API. +reExportDataset can be called with either ``persistentId`` (as shown above, with a DOI) or with the database id of a dataset (as shown below, with "42" as the database id). + +``curl http://localhost:8080/api/admin/metadata/42/reExportDataset`` + Note, that creating, modifying, or re-exporting an OAI set will also attempt to export all the unexported datasets found in the set. Export Failures diff --git a/src/main/java/edu/harvard/iq/dataverse/api/Metadata.java b/src/main/java/edu/harvard/iq/dataverse/api/Metadata.java index b66928d70a1..b0d82b69d1b 100644 --- a/src/main/java/edu/harvard/iq/dataverse/api/Metadata.java +++ b/src/main/java/edu/harvard/iq/dataverse/api/Metadata.java @@ -68,22 +68,14 @@ public Response reExportAll() { } @GET - @Path("reExportDataset") - public Response indexDatasetByPersistentId(@QueryParam("persistentId") String persistentId) { - if (persistentId == null) { - return error(Response.Status.BAD_REQUEST, "No persistent id given."); - } - Dataset dataset = null; + @Path("{id}/reExportDataset") + public Response indexDatasetByPersistentId(@PathParam("id") String id) { try { - dataset = datasetService.findByGlobalId(persistentId); - } catch (Exception ex) { - return error(Response.Status.BAD_REQUEST, "Problem looking up dataset with persistent id \"" + persistentId + "\". Error: " + ex.getMessage()); - } - if (dataset != null) { + Dataset dataset = findDatasetOrDie(id); datasetService.reExportDatasetAsync(dataset); return ok("export started"); - } else { - return error(Response.Status.BAD_REQUEST, "Could not find dataset with persistent id " + persistentId); + } catch (WrappedResponse wr) { + return wr.getResponse(); } } diff --git a/src/test/java/edu/harvard/iq/dataverse/api/DatasetsIT.java b/src/test/java/edu/harvard/iq/dataverse/api/DatasetsIT.java index 9647f301805..ac4b4147a38 100644 --- a/src/test/java/edu/harvard/iq/dataverse/api/DatasetsIT.java +++ b/src/test/java/edu/harvard/iq/dataverse/api/DatasetsIT.java @@ -649,6 +649,10 @@ public void testExport() { reexportAllFormats.prettyPrint(); reexportAllFormats.then().assertThat().statusCode(OK.getStatusCode()); + Response reexportAllFormatsUsingId = UtilIT.reexportDatasetAllFormats(datasetId.toString()); + reexportAllFormatsUsingId.prettyPrint(); + reexportAllFormatsUsingId.then().assertThat().statusCode(OK.getStatusCode()); + Response deleteDatasetResponse = UtilIT.destroyDataset(datasetId, apiToken); deleteDatasetResponse.prettyPrint(); assertEquals(200, deleteDatasetResponse.getStatusCode()); diff --git a/src/test/java/edu/harvard/iq/dataverse/api/UtilIT.java b/src/test/java/edu/harvard/iq/dataverse/api/UtilIT.java index ed4b68819a6..7107ee783d7 100644 --- a/src/test/java/edu/harvard/iq/dataverse/api/UtilIT.java +++ b/src/test/java/edu/harvard/iq/dataverse/api/UtilIT.java @@ -1831,9 +1831,15 @@ static Response exportDataset(String datasetPersistentId, String exporter, Strin .get("/api/datasets/export" + "?persistentId=" + datasetPersistentId + "&exporter=" + exporter); } - static Response reexportDatasetAllFormats(String datasetPersistentId) { + static Response reexportDatasetAllFormats(String idOrPersistentId) { + String idInPath = idOrPersistentId; // Assume it's a number. + String optionalQueryParam = ""; // If idOrPersistentId is a number we'll just put it in the path. + if (!NumberUtils.isDigits(idOrPersistentId)) { + idInPath = ":persistentId"; + optionalQueryParam = "?persistentId=" + idOrPersistentId; + } return given() - .get("/api/admin/metadata/reExportDataset?persistentId=" + datasetPersistentId); + .get("/api/admin/metadata/" + idInPath + "/reExportDataset" + optionalQueryParam); } static Response exportDataverse(String identifier, String apiToken) {