Skip to content

Commit a9f7d79

Browse files
committed
map dc:date to pub date or field for citation date #8129
1 parent c59f743 commit a9f7d79

File tree

6 files changed

+46
-4
lines changed

6 files changed

+46
-4
lines changed

doc/release-notes/8129-harvesting.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
The `oai_dc` export and harvesting format has had the following fields remapped:
44

55
- dc:type was mapped to the field "Kind of Data". Now it is hard-coded to the word "Dataset".
6-
- 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".
6+
- 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)).
77
- dc:rights was not mapped to anything. Now it is mapped (when available) to terms of use, restrictions, and license.
88

99
As these are backward incompatible changes, they have been noted in the [API changelog](https://guides.dataverse.org/en/latest/api/changelog.html).

doc/sphinx-guides/source/api/changelog.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ v6.4
1313
- For the ``oai_dc`` metadata export and harvesting (OAI-PMH) format:
1414

1515
- dc:type was mapped to the field "Kind of Data". Now it is hard-coded to the word "Dataset".
16-
- 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".
16+
- 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`).
1717
- dc:rights was not mapped to anything. Now it is mapped (when available) to terms of use, restrictions, and license.
1818

1919
v6.3

doc/sphinx-guides/source/api/native-api.rst

+2
Original file line numberDiff line numberDiff line change
@@ -1756,6 +1756,8 @@ The fully expanded example above (without environment variables) looks like this
17561756
17571757
.. 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.
17581758

1759+
.. _set-citation-date-field:
1760+
17591761
Set Citation Date Field Type for a Dataset
17601762
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
17611763

src/main/java/edu/harvard/iq/dataverse/export/dublincore/DublinCoreExportUtil.java

+11-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
import com.google.gson.Gson;
99
import edu.harvard.iq.dataverse.DatasetFieldConstant;
10+
import edu.harvard.iq.dataverse.DatasetFieldType;
11+
import edu.harvard.iq.dataverse.DatasetServiceBean;
1012
import edu.harvard.iq.dataverse.GlobalId;
1113
import edu.harvard.iq.dataverse.api.dto.DatasetDTO;
1214
import edu.harvard.iq.dataverse.api.dto.DatasetVersionDTO;
@@ -184,8 +186,16 @@ private static void createOAIDC(XMLStreamWriter xmlw, DatasetDTO datasetDto, Str
184186
* The Tromsø Recommendations for Citation of Research Data in
185187
* Linguistics; https://doi.org/10.15497/rda00040 ." --
186188
* https://github.com/IQSS/dataverse/issues/8129
189+
*
190+
* However, if the citation date field has been set, use that.
187191
*/
188-
writeFullElement(xmlw, dcFlavor+":"+"date", datasetDto.getPublicationDate());
192+
String date = datasetDto.getPublicationDate();
193+
DatasetFieldType citationDataType = jakarta.enterprise.inject.spi.CDI.current().select(DatasetServiceBean.class).get().findByGlobalId(globalId.asString()).getCitationDateDatasetFieldType();
194+
if (citationDataType != null) {
195+
date = dto2Primitive(version, citationDataType.getName());
196+
}
197+
198+
writeFullElement(xmlw, dcFlavor+":"+"date", date);
189199

190200
writeFullElement(xmlw, dcFlavor+":"+"contributor", dto2Primitive(version, DatasetFieldConstant.depositor));
191201

src/test/java/edu/harvard/iq/dataverse/api/DatasetsIT.java

+18-1
Original file line numberDiff line numberDiff line change
@@ -4011,8 +4011,25 @@ public void testCitationDate() throws IOException {
40114011

40124012
Response exportDatasetAsDublinCore = UtilIT.exportDataset(datasetPid, "oai_dc", apiToken);
40134013
exportDatasetAsDublinCore.prettyPrint();
4014-
String todayDate = LocalDate.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
40154014
exportDatasetAsDublinCore.then().assertThat()
4015+
.body("oai_dc.type", equalTo("Dataset"))
4016+
.body("oai_dc.date", equalTo("1999-12-31"))
4017+
.body("oai_dc.rights", equalTo("CC0 1.0"))
4018+
.statusCode(OK.getStatusCode());
4019+
4020+
Response clearDateField = UtilIT.clearDatasetCitationDateField(datasetPid, apiToken);
4021+
clearDateField.prettyPrint();
4022+
clearDateField.then().assertThat().statusCode(OK.getStatusCode());
4023+
4024+
// Clearing not enough. You have to reexport because the previous date is cached.
4025+
Response rexport = UtilIT.reexportDatasetAllFormats(datasetPid);
4026+
rexport.prettyPrint();
4027+
rexport.then().assertThat().statusCode(OK.getStatusCode());
4028+
4029+
String todayDate = LocalDate.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
4030+
Response exportPostClear = UtilIT.exportDataset(datasetPid, "oai_dc", apiToken);
4031+
exportPostClear.prettyPrint();
4032+
exportPostClear.then().assertThat()
40164033
.body("oai_dc.type", equalTo("Dataset"))
40174034
.body("oai_dc.date", equalTo(todayDate))
40184035
.body("oai_dc.rights", equalTo("CC0 1.0"))

src/test/java/edu/harvard/iq/dataverse/api/UtilIT.java

+13
Original file line numberDiff line numberDiff line change
@@ -3686,6 +3686,19 @@ static Response setDatasetCitationDateField(String datasetIdOrPersistentId, Stri
36863686
return response;
36873687
}
36883688

3689+
static Response clearDatasetCitationDateField(String datasetIdOrPersistentId, String apiToken) {
3690+
String idInPath = datasetIdOrPersistentId; // Assume it's a number.
3691+
String optionalQueryParam = ""; // If idOrPersistentId is a number we'll just put it in the path.
3692+
if (!NumberUtils.isCreatable(datasetIdOrPersistentId)) {
3693+
idInPath = ":persistentId";
3694+
optionalQueryParam = "?persistentId=" + datasetIdOrPersistentId;
3695+
}
3696+
Response response = given()
3697+
.header(API_TOKEN_HTTP_HEADER, apiToken)
3698+
.delete("/api/datasets/" + idInPath + "/citationdate" + optionalQueryParam);
3699+
return response;
3700+
}
3701+
36893702
static Response getFileCitation(Integer fileId, String datasetVersion, String apiToken) {
36903703
Boolean includeDeaccessioned = null;
36913704
return getFileCitation(fileId, datasetVersion, includeDeaccessioned, apiToken);

0 commit comments

Comments
 (0)