diff --git a/src/main/java/edu/harvard/iq/dataverse/api/imports/ImportDDIServiceBean.java b/src/main/java/edu/harvard/iq/dataverse/api/imports/ImportDDIServiceBean.java
index 35d35316f73..31941d3c8c0 100644
--- a/src/main/java/edu/harvard/iq/dataverse/api/imports/ImportDDIServiceBean.java
+++ b/src/main/java/edu/harvard/iq/dataverse/api/imports/ImportDDIServiceBean.java
@@ -5,13 +5,21 @@
import edu.harvard.iq.dataverse.DatasetFieldType;
import edu.harvard.iq.dataverse.DatasetVersion;
import edu.harvard.iq.dataverse.DatasetVersion.VersionState;
-import edu.harvard.iq.dataverse.api.dto.*;
+import edu.harvard.iq.dataverse.api.dto.LicenseDTO;
import edu.harvard.iq.dataverse.api.dto.FieldDTO;
import edu.harvard.iq.dataverse.api.dto.MetadataBlockDTO;
+import edu.harvard.iq.dataverse.api.dto.DatasetDTO;
+import edu.harvard.iq.dataverse.api.dto.DatasetVersionDTO;
+import edu.harvard.iq.dataverse.api.dto.FileMetadataDTO;
+import edu.harvard.iq.dataverse.api.dto.DataFileDTO;
+import edu.harvard.iq.dataverse.api.dto.DataTableDTO;
+
import edu.harvard.iq.dataverse.api.imports.ImportUtil.ImportType;
import static edu.harvard.iq.dataverse.export.ddi.DdiExportUtil.NOTE_TYPE_CONTENTTYPE;
import static edu.harvard.iq.dataverse.export.ddi.DdiExportUtil.NOTE_TYPE_TERMS_OF_ACCESS;
+import edu.harvard.iq.dataverse.license.License;
+import edu.harvard.iq.dataverse.license.LicenseServiceBean;
import edu.harvard.iq.dataverse.util.StringUtil;
import java.io.File;
import java.io.FileInputStream;
@@ -32,6 +40,9 @@
import org.apache.commons.lang3.StringUtils;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
/**
*
* @author ellenk
@@ -103,6 +114,8 @@ public class ImportDDIServiceBean {
@EJB DatasetFieldServiceBean datasetFieldService;
@EJB ImportGenericServiceBean importGenericService;
+
+ @EJB LicenseServiceBean licenseService;
// TODO: stop passing the xml source as a string; (it could be huge!) -- L.A. 4.5
@@ -1180,7 +1193,24 @@ private void processDataAccs(XMLStreamReader xmlr, DatasetVersionDTO dvDTO) thro
String noteType = xmlr.getAttributeValue(null, "type");
if (NOTE_TYPE_TERMS_OF_USE.equalsIgnoreCase(noteType) ) {
if ( LEVEL_DV.equalsIgnoreCase(xmlr.getAttributeValue(null, "level"))) {
- dvDTO.setTermsOfUse(parseText(xmlr, "notes"));
+ String termsOfUseStr = parseText(xmlr, "notes").trim();
+ Pattern pattern = Pattern.compile("(.*)", Pattern.CASE_INSENSITIVE);
+ Matcher matcher = pattern.matcher(termsOfUseStr);
+ boolean matchFound = matcher.find();
+ if (matchFound) {
+ String uri = matcher.group(1);
+ String license = matcher.group(2);
+ License lic = licenseService.getByNameOrUri(license);
+ if (lic != null) {
+ LicenseDTO licenseDTO = new LicenseDTO();
+ licenseDTO.setName(license);
+ licenseDTO.setUri(uri);
+ dvDTO.setLicense(licenseDTO);
+ }
+
+ } else {
+ dvDTO.setTermsOfUse(termsOfUseStr);
+ }
}
} else if (NOTE_TYPE_TERMS_OF_ACCESS.equalsIgnoreCase(noteType) ) {
if (LEVEL_DV.equalsIgnoreCase(xmlr.getAttributeValue(null, "level"))) {
diff --git a/src/main/java/edu/harvard/iq/dataverse/export/ddi/DdiExportUtil.java b/src/main/java/edu/harvard/iq/dataverse/export/ddi/DdiExportUtil.java
index 05ddbe83e78..8fab6a6704d 100644
--- a/src/main/java/edu/harvard/iq/dataverse/export/ddi/DdiExportUtil.java
+++ b/src/main/java/edu/harvard/iq/dataverse/export/ddi/DdiExportUtil.java
@@ -5,11 +5,13 @@
import edu.harvard.iq.dataverse.ControlledVocabularyValue;
import edu.harvard.iq.dataverse.DatasetFieldConstant;
import edu.harvard.iq.dataverse.DvObjectContainer;
+import edu.harvard.iq.dataverse.api.dto.MetadataBlockDTO;
import edu.harvard.iq.dataverse.api.dto.DatasetDTO;
import edu.harvard.iq.dataverse.api.dto.DatasetVersionDTO;
-import edu.harvard.iq.dataverse.api.dto.FieldDTO;
import edu.harvard.iq.dataverse.api.dto.FileDTO;
-import edu.harvard.iq.dataverse.api.dto.MetadataBlockDTO;
+import edu.harvard.iq.dataverse.api.dto.FieldDTO;
+import edu.harvard.iq.dataverse.api.dto.LicenseDTO;
+
import static edu.harvard.iq.dataverse.export.DDIExportServiceBean.LEVEL_FILE;
import static edu.harvard.iq.dataverse.export.DDIExportServiceBean.NOTE_SUBJECT_TAG;
@@ -313,8 +315,16 @@ private static void writeDataAccess(XMLStreamWriter xmlw , DatasetVersionDTO ver
XmlWriterUtil.writeFullElement(xmlw, "conditions", version.getConditions());
XmlWriterUtil.writeFullElement(xmlw, "disclaimer", version.getDisclaimer());
xmlw.writeEndElement(); //useStmt
-
+
/* any s: */
+ if (version.getTermsOfUse() != null && !version.getTermsOfUse().trim().equals("")) {
+ xmlw.writeStartElement("notes");
+ xmlw.writeAttribute("type", NOTE_TYPE_TERMS_OF_USE);
+ xmlw.writeAttribute("level", LEVEL_DV);
+ xmlw.writeCharacters(version.getTermsOfUse());
+ xmlw.writeEndElement(); //notes
+ }
+
if (version.getTermsOfAccess() != null && !version.getTermsOfAccess().trim().equals("")) {
xmlw.writeStartElement("notes");
xmlw.writeAttribute("type", NOTE_TYPE_TERMS_OF_ACCESS);
@@ -322,6 +332,19 @@ private static void writeDataAccess(XMLStreamWriter xmlw , DatasetVersionDTO ver
xmlw.writeCharacters(version.getTermsOfAccess());
xmlw.writeEndElement(); //notes
}
+
+ LicenseDTO license = version.getLicense();
+ if (license != null) {
+ String name = license.getName();
+ String uri = license.getUri();
+ if ((name != null && !name.trim().equals("")) && (uri != null && !uri.trim().equals(""))) {
+ xmlw.writeStartElement("notes");
+ xmlw.writeAttribute("type", NOTE_TYPE_TERMS_OF_USE);
+ xmlw.writeAttribute("level", LEVEL_DV);
+ xmlw.writeCharacters("" + name + "");
+ xmlw.writeEndElement(); //notes
+ }
+ }
xmlw.writeEndElement(); //dataAccs
}
diff --git a/src/test/java/edu/harvard/iq/dataverse/export/ddi/DdiExportUtilTest.java b/src/test/java/edu/harvard/iq/dataverse/export/ddi/DdiExportUtilTest.java
index 41e6be61bb8..f594de4757d 100644
--- a/src/test/java/edu/harvard/iq/dataverse/export/ddi/DdiExportUtilTest.java
+++ b/src/test/java/edu/harvard/iq/dataverse/export/ddi/DdiExportUtilTest.java
@@ -64,6 +64,23 @@ public void testJson2DdiNoFiles() throws Exception {
XmlAssert.assertThat(result).and(datasetAsDdi).ignoreWhitespace().areSimilar();
}
+ @Test
+ public void testJson2DdiNoFilesTermsOfUse() throws Exception {
+ // given
+ Path datasetVersionJson = Path.of("src/test/java/edu/harvard/iq/dataverse/export/ddi/dataset-finch-terms-of-use.json");
+ String datasetVersionAsJson = Files.readString(datasetVersionJson, StandardCharsets.UTF_8);
+ Path ddiFile = Path.of("src/test/java/edu/harvard/iq/dataverse/export/ddi/dataset-finch-terms-of-use.xml");
+ String datasetAsDdi = XmlPrinter.prettyPrintXml(Files.readString(ddiFile, StandardCharsets.UTF_8));
+ logger.fine(datasetAsDdi);
+
+ // when
+ String result = DdiExportUtil.datasetDtoAsJson2ddi(datasetVersionAsJson);
+ logger.fine(result);
+
+ // then
+ XmlAssert.assertThat(result).and(datasetAsDdi).ignoreWhitespace().areSimilar();
+ }
+
@Test
public void testExportDDI() throws Exception {
// given
diff --git a/src/test/java/edu/harvard/iq/dataverse/export/ddi/dataset-finch-terms-of-use.json b/src/test/java/edu/harvard/iq/dataverse/export/ddi/dataset-finch-terms-of-use.json
new file mode 100644
index 00000000000..b3d6caff2e9
--- /dev/null
+++ b/src/test/java/edu/harvard/iq/dataverse/export/ddi/dataset-finch-terms-of-use.json
@@ -0,0 +1,404 @@
+{
+ "id": 11,
+ "identifier": "PCA2E3",
+ "persistentUrl": "https://doi.org/10.5072/FK2/PCA2E3",
+ "protocol": "doi",
+ "authority": "10.5072/FK2",
+ "metadataLanguage": "en",
+ "datasetVersion": {
+ "id": 2,
+ "versionNumber": 1,
+ "versionMinorNumber": 0,
+ "versionState": "RELEASED",
+ "productionDate": "Production Date",
+ "lastUpdateTime": "2015-09-24T17:07:57Z",
+ "releaseTime": "2015-09-24T17:07:57Z",
+ "createTime": "2015-09-24T16:47:51Z",
+ "termsOfUse":"This dataset is made available without information on how it can be used. You should communicate with the Contact(s) specified before use.",
+ "metadataBlocks": {
+ "citation": {
+ "displayName": "Citation Metadata",
+ "name":"citation",
+ "fields": [
+ {
+ "typeName": "title",
+ "multiple": false,
+ "typeClass": "primitive",
+ "value": "Darwin's Finches"
+ },
+ {
+ "typeName": "alternativeTitle",
+ "multiple": true,
+ "typeClass": "primitive",
+ "value": ["Darwin's Finches Alternative Title1", "Darwin's Finches Alternative Title2"]
+ },
+ {
+ "typeName": "author",
+ "multiple": true,
+ "typeClass": "compound",
+ "value": [
+ {
+ "authorName": {
+ "typeName": "authorName",
+ "multiple": false,
+ "typeClass": "primitive",
+ "value": "Finch, Fiona"
+ },
+ "authorAffiliation": {
+ "typeName": "authorAffiliation",
+ "multiple": false,
+ "typeClass": "primitive",
+ "value": "Birds Inc."
+ }
+ }
+ ]
+ },
+ {
+ "typeName": "timePeriodCovered",
+ "multiple": true,
+ "typeClass": "compound",
+ "value": [
+ {
+ "timePeriodStart": {
+ "typeName": "timePeriodCoveredStart",
+ "multiple": false,
+ "typeClass": "primitive",
+ "value": "20020816"
+ },
+ "timePeriodEnd": {
+ "typeName": "timePeriodCoveredEnd",
+ "multiple": false,
+ "typeClass": "primitive",
+ "value": "20160630"
+ }
+ }
+ ]
+ },
+ {
+ "typeName": "dateOfCollection",
+ "multiple": true,
+ "typeClass": "compound",
+ "value": [
+ {
+ "timePeriodStart": {
+ "typeName": "dateOfCollectionStart",
+ "multiple": false,
+ "typeClass": "primitive",
+ "value": "20070831"
+ },
+ "timePeriodEnd": {
+ "typeName": "dateOfCollectionEnd",
+ "multiple": false,
+ "typeClass": "primitive",
+ "value": "20130630"
+ }
+ }
+ ]
+ },
+ {
+ "typeName": "datasetContact",
+ "multiple": true,
+ "typeClass": "compound",
+ "value": [
+ {
+ "datasetContactEmail": {
+ "typeName": "datasetContactEmail",
+ "multiple": false,
+ "typeClass": "primitive",
+ "value": "finch@mailinator.com"
+ },
+ "datasetContactName": {
+ "typeName": "datasetContactName",
+ "multiple": false,
+ "typeClass": "primitive",
+ "value": "Jimmy Finch"
+ },
+ "datasetContactAffiliation": {
+ "typeName": "datasetContactAffiliation",
+ "multiple": false,
+ "typeClass": "primitive",
+ "value": "Finch Academy"
+ }
+ }
+ ]
+ },
+ {
+ "typeName": "producer",
+ "multiple": true,
+ "typeClass": "compound",
+ "value": [
+ {
+ "producerAbbreviation": {
+ "typeName": "producerAbbreviation",
+ "multiple": false,
+ "typeClass": "primitive",
+ "value": "ProdAbb"
+ },
+ "producerName": {
+ "typeName": "producerName",
+ "multiple": false,
+ "typeClass": "primitive",
+ "value": "Johnny Hawk"
+ },
+ "producerAffiliation": {
+ "typeName": "producerAffiliation",
+ "multiple": false,
+ "typeClass": "primitive",
+ "value": "Hawk Institute"
+ },
+ "producerURL": {
+ "typeName": "producerURL",
+ "multiple": false,
+ "typeClass": "primitive",
+ "value": "http://www.hawk.edu/url"
+ },
+ "producerLogoURL": {
+ "typeName": "producerLogoURL",
+ "multiple": false,
+ "typeClass": "primitive",
+ "value": "http://www.hawk.edu/logo"
+ }
+ }
+ ]
+ },
+ {
+ "typeName": "distributor",
+ "multiple": true,
+ "typeClass": "compound",
+ "value": [
+ {
+ "distributorAbbreviation": {
+ "typeName": "distributorAbbreviation",
+ "multiple": false,
+ "typeClass": "primitive",
+ "value": "Dist-Abb"
+ },
+ "producerName": {
+ "typeName": "distributorName",
+ "multiple": false,
+ "typeClass": "primitive",
+ "value": "Odin Raven"
+ },
+ "distributorAffiliation": {
+ "typeName": "distributorAffiliation",
+ "multiple": false,
+ "typeClass": "primitive",
+ "value": "Valhalla Polytechnic"
+ },
+ "distributorURL": {
+ "typeName": "distributorURL",
+ "multiple": false,
+ "typeClass": "primitive",
+ "value": "http://www.valhalla.edu/url"
+ },
+ "distributorLogoURL": {
+ "typeName": "distributorLogoURL",
+ "multiple": false,
+ "typeClass": "primitive",
+ "value": "http://www.valhalla.edu/logo"
+ }
+ }
+ ]
+ },
+ {
+ "typeName": "dsDescription",
+ "multiple": true,
+ "typeClass": "compound",
+ "value": [
+ {
+ "dsDescriptionValue": {
+ "typeName": "dsDescriptionValue",
+ "multiple": false,
+ "typeClass": "primitive",
+ "value": "Darwin's finches (also known as the Galápagos finches) are a group of about fifteen species of passerine birds."
+ }
+ }
+ ]
+ },
+ {
+ "typeName": "subject",
+ "multiple": true,
+ "typeClass": "controlledVocabulary",
+ "value": [
+ "Medicine, Health and Life Sciences"
+ ]
+ },
+ {
+ "typeName": "keyword",
+ "multiple": true,
+ "typeClass": "compound",
+ "value": [
+ {
+ "keywordValue": {
+ "typeName": "keywordValue",
+ "multiple": false,
+ "typeClass": "primitive",
+ "value": "Keyword Value 1"
+ },
+ "keywordTermURI": {
+ "typeName": "keywordTermURI",
+ "multiple": false,
+ "typeClass": "primitive",
+ "value": "http://keywordTermURI1.org"
+ },
+ "keywordVocabulary": {
+ "typeName": "keywordVocabulary",
+ "multiple": false,
+ "typeClass": "primitive",
+ "value": "Keyword Vocabulary"
+ },
+ "keywordVocabularyURI": {
+ "typeName": "keywordVocabularyURI",
+ "multiple": false,
+ "typeClass": "primitive",
+ "value": "http://www.keyword.com/one"
+ }
+ },
+ {
+ "keywordValue": {
+ "typeName": "keywordValue",
+ "multiple": false,
+ "typeClass": "primitive",
+ "value": "Keyword Value Two"
+ },
+ "keywordTermURI": {
+ "typeName": "keywordTermURI",
+ "multiple": false,
+ "typeClass": "primitive",
+ "value": "http://keywordTermURI1.org"
+ },
+ "keywordVocabulary": {
+ "typeName": "keywordVocabulary",
+ "multiple": false,
+ "typeClass": "primitive",
+ "value": "Keyword Vocabulary"
+ },
+ "keywordVocabularyURI": {
+ "typeName": "keywordVocabularyURI",
+ "multiple": false,
+ "typeClass": "primitive",
+ "value": "http://www.keyword.com/one"
+ }
+ }
+ ]
+ },
+ {
+ "typeName": "topicClassification",
+ "multiple": true,
+ "typeClass": "compound",
+ "value": [
+ {
+ "topicClassValue": {
+ "typeName": "topicClassValue",
+ "multiple": false,
+ "typeClass": "primitive",
+ "value": "TC Value 1"
+ },
+ "topicClassVocab": {
+ "typeName": "topicClassVocab",
+ "multiple": false,
+ "typeClass": "primitive",
+ "value": "TC Vocabulary"
+ },
+ "topicClassVocabURI": {
+ "typeName": "topicClassVocabURI",
+ "multiple": false,
+ "typeClass": "primitive",
+ "value": "http://www.topicClass.com/one"
+ }
+ }
+ ]
+ },
+ {
+ "typeName": "kindOfData",
+ "multiple": true,
+ "typeClass": "primitive",
+ "value": [
+ "Kind of Data"
+ ]
+ },
+ {
+ "typeName": "depositor",
+ "multiple": false,
+ "typeClass": "primitive",
+ "value": "Added, Depositor"
+ }
+ ]
+ },
+ "geospatial": {
+ "displayName": "Geospatial",
+ "name":"geospatial",
+ "fields": [
+ {
+ "typeName": "geographicCoverage",
+ "multiple": true,
+ "typeClass": "compound",
+ "value": [
+ {
+ "country": {
+ "typeName": "country",
+ "multiple": false,
+ "typeClass": "primitive",
+ "value": "USA"
+ },
+ "state": {
+ "typeName": "state",
+ "multiple": false,
+ "typeClass": "primitive",
+ "value": "MA"
+ },
+ "city": {
+ "typeName": "city",
+ "multiple": false,
+ "typeClass": "primitive",
+ "value": "Cambridge"
+ },
+ "otherGeographicCoverage": {
+ "typeName": "otherGeographicCoverage",
+ "multiple": false,
+ "typeClass": "primitive",
+ "value": "Other Geographic Coverage"
+ }
+ }
+ ]
+ },
+ {
+ "typeName": "geographicBoundingBox",
+ "multiple": true,
+ "typeClass": "compound",
+ "value": [
+ {
+ "westLongitude": {
+ "typeName": "westLongitude",
+ "multiple": false,
+ "typeClass": "primitive",
+ "value": "60.3"
+ },
+ "eastLongitude": {
+ "typeName": "eastLongitude",
+ "multiple": false,
+ "typeClass": "primitive",
+ "value": "59.8"
+ },
+ "southLatitude": {
+ "typeName": "southLatitude",
+ "multiple": false,
+ "typeClass": "primitive",
+ "value": "41.6"
+ },
+ "northLatitude": {
+ "typeName": "northLatitude",
+ "multiple": false,
+ "typeClass": "primitive",
+ "value": "43.8"
+ }
+ }
+ ]
+ }
+ ]
+ }
+ },
+ "files": [],
+ "citation": "Finch, Fiona, 2015, \"Darwin's Finches\", https://doi.org/10.5072/FK2/PCA2E3, Root Dataverse, V1"
+ }
+}
\ No newline at end of file
diff --git a/src/test/java/edu/harvard/iq/dataverse/export/ddi/dataset-finch-terms-of-use.xml b/src/test/java/edu/harvard/iq/dataverse/export/ddi/dataset-finch-terms-of-use.xml
new file mode 100644
index 00000000000..d813d155a90
--- /dev/null
+++ b/src/test/java/edu/harvard/iq/dataverse/export/ddi/dataset-finch-terms-of-use.xml
@@ -0,0 +1,78 @@
+
+
+
+
+
+ Darwin's Finches
+ doi:10.5072/FK2/PCA2E3
+
+
+
+ 1
+
+ Finch, Fiona, 2015, "Darwin's Finches", https://doi.org/10.5072/FK2/PCA2E3, Root Dataverse, V1
+
+
+
+
+
+ Darwin's Finches
+ Darwin's Finches Alternative Title1
+ Darwin's Finches Alternative Title2
+ doi:10.5072/FK2/PCA2E3
+
+
+ Finch, Fiona
+
+
+ Johnny Hawk
+
+
+ Odin Raven
+ Jimmy Finch
+ Added, Depositor
+
+
+
+
+
+ Medicine, Health and Life Sciences
+ Keyword Value 1
+ Keyword Value Two
+ TC Value 1
+
+ Darwin's finches (also known as the Galápagos finches) are a group of about fifteen species of passerine birds.
+
+ 20020816
+ 20160630
+ 20070831
+ 20130630
+ USA
+ Cambridge
+ MA
+ Other Geographic Coverage
+
+ 60.3
+ 59.8
+ 41.6
+ 43.8
+
+ Kind of Data
+
+
+
+
+
+
+
+
+
+
+
+
+ This dataset is made available without information on how it can be used. You should communicate with the Contact(s) specified before use.
+
+
+
+
+
diff --git a/src/test/java/edu/harvard/iq/dataverse/export/ddi/dataset-finch1.xml b/src/test/java/edu/harvard/iq/dataverse/export/ddi/dataset-finch1.xml
index 6730c44603a..010a5db4f2b 100644
--- a/src/test/java/edu/harvard/iq/dataverse/export/ddi/dataset-finch1.xml
+++ b/src/test/java/edu/harvard/iq/dataverse/export/ddi/dataset-finch1.xml
@@ -69,6 +69,7 @@
+ <a href="http://creativecommons.org/publicdomain/zero/1.0">CC0 1.0</a>
diff --git a/src/test/java/edu/harvard/iq/dataverse/export/ddi/exportfull.xml b/src/test/java/edu/harvard/iq/dataverse/export/ddi/exportfull.xml
index 507d752192d..e865dc0ffe4 100644
--- a/src/test/java/edu/harvard/iq/dataverse/export/ddi/exportfull.xml
+++ b/src/test/java/edu/harvard/iq/dataverse/export/ddi/exportfull.xml
@@ -161,6 +161,7 @@
Disclaimer
Terms of Access
+ <a href="http://creativecommons.org/publicdomain/zero/1.0">CC0 1.0</a>
RelatedMaterial1