Skip to content

Commit

Permalink
Merge pull request #6 from pdurbin/8720-support-ids-too
Browse files Browse the repository at this point in the history
support database IDs too (as well as PIDs) IQSS#8720
  • Loading branch information
PaulBoon authored Sep 27, 2022
2 parents d6e84cb + bd47b8e commit c909ba5
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 16 deletions.
6 changes: 5 additions & 1 deletion doc/sphinx-guides/source/admin/metadataexport.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand Down
18 changes: 5 additions & 13 deletions src/main/java/edu/harvard/iq/dataverse/api/Metadata.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}

Expand Down
4 changes: 4 additions & 0 deletions src/test/java/edu/harvard/iq/dataverse/api/DatasetsIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
10 changes: 8 additions & 2 deletions src/test/java/edu/harvard/iq/dataverse/api/UtilIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit c909ba5

Please sign in to comment.