Skip to content

Commit

Permalink
map dc:date to pub date or field for citation date #8129
Browse files Browse the repository at this point in the history
  • Loading branch information
pdurbin committed Aug 5, 2024
1 parent c59f743 commit a9f7d79
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 4 deletions.
2 changes: 1 addition & 1 deletion doc/release-notes/8129-harvesting.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
2 changes: 1 addition & 1 deletion doc/sphinx-guides/source/api/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions doc/sphinx-guides/source/api/native-api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));

Expand Down
19 changes: 18 additions & 1 deletion src/test/java/edu/harvard/iq/dataverse/api/DatasetsIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down
13 changes: 13 additions & 0 deletions src/test/java/edu/harvard/iq/dataverse/api/UtilIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit a9f7d79

Please sign in to comment.