From a9f7d79f96414cb4f0e35ad15a94a870195e537d Mon Sep 17 00:00:00 2001 From: Philip Durbin Date: Mon, 5 Aug 2024 11:51:30 -0400 Subject: [PATCH] map dc:date to pub date or field for citation date #8129 --- doc/release-notes/8129-harvesting.md | 2 +- doc/sphinx-guides/source/api/changelog.rst | 2 +- doc/sphinx-guides/source/api/native-api.rst | 2 ++ .../dublincore/DublinCoreExportUtil.java | 12 +++++++++++- .../harvard/iq/dataverse/api/DatasetsIT.java | 19 ++++++++++++++++++- .../edu/harvard/iq/dataverse/api/UtilIT.java | 13 +++++++++++++ 6 files changed, 46 insertions(+), 4 deletions(-) diff --git a/doc/release-notes/8129-harvesting.md b/doc/release-notes/8129-harvesting.md index 05e2e7f455c..92d705709fc 100644 --- a/doc/release-notes/8129-harvesting.md +++ b/doc/release-notes/8129-harvesting.md @@ -3,7 +3,7 @@ The `oai_dc` export and harvesting format has had the following fields remapped: - dc:type was mapped to the field "Kind of Data". Now it is hard-coded to the word "Dataset". -- dc:date was mapped to the field "Production Date" when available and otherwise to "Publication Date". Now it is mapped only to the field "Publication Date". +- dc:date was mapped to the field "Production Date" when available and otherwise to "Publication Date". Now it is mapped the field “Publication Date” or the field used for the citation date, if set (see [Set Citation Date Field Type for a Dataset](https://guides.dataverse.org/en/6.3/api/native-api.html#set-citation-date-field-type-for-a-dataset)). - dc:rights was not mapped to anything. Now it is mapped (when available) to terms of use, restrictions, and license. As these are backward incompatible changes, they have been noted in the [API changelog](https://guides.dataverse.org/en/latest/api/changelog.html). diff --git a/doc/sphinx-guides/source/api/changelog.rst b/doc/sphinx-guides/source/api/changelog.rst index 680057a7807..071b14f3ca3 100644 --- a/doc/sphinx-guides/source/api/changelog.rst +++ b/doc/sphinx-guides/source/api/changelog.rst @@ -13,7 +13,7 @@ v6.4 - For the ``oai_dc`` metadata export and harvesting (OAI-PMH) format: - dc:type was mapped to the field "Kind of Data". Now it is hard-coded to the word "Dataset". - - dc:date was mapped to the field "Production Date" when available and otherwise to "Publication Date". Now it is mapped only to the field "Publication Date". + - dc:date was mapped to the field "Production Date" when available and otherwise to "Publication Date". Now it is mapped the field "Publication Date" or the field used for the citation date, if set (see :ref:`set-citation-date-field`). - dc:rights was not mapped to anything. Now it is mapped (when available) to terms of use, restrictions, and license. v6.3 diff --git a/doc/sphinx-guides/source/api/native-api.rst b/doc/sphinx-guides/source/api/native-api.rst index a5f7d03899a..92310187885 100644 --- a/doc/sphinx-guides/source/api/native-api.rst +++ b/doc/sphinx-guides/source/api/native-api.rst @@ -1756,6 +1756,8 @@ The fully expanded example above (without environment variables) looks like this .. note:: You cannot deaccession a dataset more than once. If you call this endpoint twice for the same dataset version, you will get a not found error on the second call, since the dataset you are looking for will no longer be published since it is already deaccessioned. +.. _set-citation-date-field: + Set Citation Date Field Type for a Dataset ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/src/main/java/edu/harvard/iq/dataverse/export/dublincore/DublinCoreExportUtil.java b/src/main/java/edu/harvard/iq/dataverse/export/dublincore/DublinCoreExportUtil.java index 0766466c699..b9992d08c91 100644 --- a/src/main/java/edu/harvard/iq/dataverse/export/dublincore/DublinCoreExportUtil.java +++ b/src/main/java/edu/harvard/iq/dataverse/export/dublincore/DublinCoreExportUtil.java @@ -7,6 +7,8 @@ import com.google.gson.Gson; import edu.harvard.iq.dataverse.DatasetFieldConstant; +import edu.harvard.iq.dataverse.DatasetFieldType; +import edu.harvard.iq.dataverse.DatasetServiceBean; import edu.harvard.iq.dataverse.GlobalId; import edu.harvard.iq.dataverse.api.dto.DatasetDTO; import edu.harvard.iq.dataverse.api.dto.DatasetVersionDTO; @@ -184,8 +186,16 @@ private static void createOAIDC(XMLStreamWriter xmlw, DatasetDTO datasetDto, Str * The Tromsø Recommendations for Citation of Research Data in * Linguistics; https://doi.org/10.15497/rda00040 ." -- * https://github.com/IQSS/dataverse/issues/8129 + * + * However, if the citation date field has been set, use that. */ - writeFullElement(xmlw, dcFlavor+":"+"date", datasetDto.getPublicationDate()); + String date = datasetDto.getPublicationDate(); + DatasetFieldType citationDataType = jakarta.enterprise.inject.spi.CDI.current().select(DatasetServiceBean.class).get().findByGlobalId(globalId.asString()).getCitationDateDatasetFieldType(); + if (citationDataType != null) { + date = dto2Primitive(version, citationDataType.getName()); + } + + writeFullElement(xmlw, dcFlavor+":"+"date", date); writeFullElement(xmlw, dcFlavor+":"+"contributor", dto2Primitive(version, DatasetFieldConstant.depositor)); 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 be6ff01b28c..180410ede97 100644 --- a/src/test/java/edu/harvard/iq/dataverse/api/DatasetsIT.java +++ b/src/test/java/edu/harvard/iq/dataverse/api/DatasetsIT.java @@ -4011,8 +4011,25 @@ public void testCitationDate() throws IOException { Response exportDatasetAsDublinCore = UtilIT.exportDataset(datasetPid, "oai_dc", apiToken); exportDatasetAsDublinCore.prettyPrint(); - String todayDate = LocalDate.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd")); exportDatasetAsDublinCore.then().assertThat() + .body("oai_dc.type", equalTo("Dataset")) + .body("oai_dc.date", equalTo("1999-12-31")) + .body("oai_dc.rights", equalTo("CC0 1.0")) + .statusCode(OK.getStatusCode()); + + Response clearDateField = UtilIT.clearDatasetCitationDateField(datasetPid, apiToken); + clearDateField.prettyPrint(); + clearDateField.then().assertThat().statusCode(OK.getStatusCode()); + + // Clearing not enough. You have to reexport because the previous date is cached. + Response rexport = UtilIT.reexportDatasetAllFormats(datasetPid); + rexport.prettyPrint(); + rexport.then().assertThat().statusCode(OK.getStatusCode()); + + String todayDate = LocalDate.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd")); + Response exportPostClear = UtilIT.exportDataset(datasetPid, "oai_dc", apiToken); + exportPostClear.prettyPrint(); + exportPostClear.then().assertThat() .body("oai_dc.type", equalTo("Dataset")) .body("oai_dc.date", equalTo(todayDate)) .body("oai_dc.rights", equalTo("CC0 1.0")) 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 960b520ded5..655b5cbae60 100644 --- a/src/test/java/edu/harvard/iq/dataverse/api/UtilIT.java +++ b/src/test/java/edu/harvard/iq/dataverse/api/UtilIT.java @@ -3686,6 +3686,19 @@ static Response setDatasetCitationDateField(String datasetIdOrPersistentId, Stri return response; } + static Response clearDatasetCitationDateField(String datasetIdOrPersistentId, String apiToken) { + String idInPath = datasetIdOrPersistentId; // Assume it's a number. + String optionalQueryParam = ""; // If idOrPersistentId is a number we'll just put it in the path. + if (!NumberUtils.isCreatable(datasetIdOrPersistentId)) { + idInPath = ":persistentId"; + optionalQueryParam = "?persistentId=" + datasetIdOrPersistentId; + } + Response response = given() + .header(API_TOKEN_HTTP_HEADER, apiToken) + .delete("/api/datasets/" + idInPath + "/citationdate" + optionalQueryParam); + return response; + } + static Response getFileCitation(Integer fileId, String datasetVersion, String apiToken) { Boolean includeDeaccessioned = null; return getFileCitation(fileId, datasetVersion, includeDeaccessioned, apiToken);