Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions doc/release-notes/8868-fix-json-import.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Under "bug fixes":

Small bugs have been fixed in the dataset export in the JSON and DDI formats; eliminating the export of "undefined" as a metadata language in the former, and a duplicate keyword tag in the latter.

Run ReExportall to update Exports

Following the directions in the [Admin Guide](http://guides.dataverse.org/en/5.12/admin/metadataexport.html#batch-exports-through-the-api)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@landreev, I added a quick release note. Please feel free to edit as you wish.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perfect.

Copy link
Contributor

@landreev landreev Aug 26, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Going to take you up on that "feel free" - adding a mention of the duplicate keyword in the DDI under bugfixes in the note, per Jim's suggestion. (I want to merge this PR tonight!)

3 changes: 3 additions & 0 deletions src/main/java/edu/harvard/iq/dataverse/DvObjectContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ public void setMetadataLanguage(String ml) {
}
}

public static boolean isMetadataLanguageSet(String mdLang) {
return mdLang!=null && !mdLang.equals(UNDEFINED_METADATA_LANGUAGE_CODE);
}


/* Dataverse collections can be configured to allow use of Curation labels and have this inheritable value to decide which set of labels to use.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
public class DublinCoreExporter implements Exporter {



@Override
public String getProviderName() {
return "oai_dc";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ private static void dtoddi(DatasetDTO datasetDto, OutputStream outputStream) thr
xmlw.writeAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
xmlw.writeAttribute("xsi:schemaLocation", DDIExporter.DEFAULT_XML_NAMESPACE + " " + DDIExporter.DEFAULT_XML_SCHEMALOCATION);
writeAttribute(xmlw, "version", DDIExporter.DEFAULT_XML_VERSION);
if(isMetadataLanguageSet(datasetDto.getMetadataLanguage())) {
if(DvObjectContainer.isMetadataLanguageSet(datasetDto.getMetadataLanguage())) {
writeAttribute(xmlw, "xml:lang", datasetDto.getMetadataLanguage());
}
createStdyDscr(xmlw, datasetDto);
Expand All @@ -151,7 +151,7 @@ public static void datasetJson2ddi(JsonObject datasetDtoAsJson, DatasetVersion v
xmlw.writeAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
xmlw.writeAttribute("xsi:schemaLocation", DDIExporter.DEFAULT_XML_NAMESPACE + " " + DDIExporter.DEFAULT_XML_SCHEMALOCATION);
writeAttribute(xmlw, "version", DDIExporter.DEFAULT_XML_VERSION);
if(isMetadataLanguageSet(datasetDto.getMetadataLanguage())) {
if(DvObjectContainer.isMetadataLanguageSet(datasetDto.getMetadataLanguage())) {
writeAttribute(xmlw, "xml:lang", datasetDto.getMetadataLanguage());
}
createStdyDscr(xmlw, datasetDto);
Expand All @@ -161,14 +161,6 @@ public static void datasetJson2ddi(JsonObject datasetDtoAsJson, DatasetVersion v
xmlw.writeEndElement(); // codeBook
xmlw.flush();
}


private static boolean isMetadataLanguageSet(String mdLang) {
if(mdLang!=null && !mdLang.equals(DvObjectContainer.UNDEFINED_METADATA_LANGUAGE_CODE)) {
return true;
}
return false;
}

/**
* @todo This is just a stub, copied from DDIExportServiceBean. It should
Expand Down Expand Up @@ -944,7 +936,7 @@ private static void writeDistributorsElement(XMLStreamWriter xmlw, DatasetVersio
}
if (!distributorName.isEmpty()) {
xmlw.writeStartElement("distrbtr");
if(isMetadataLanguageSet(lang)) {
if(DvObjectContainer.isMetadataLanguageSet(lang)) {
writeAttribute(xmlw, "xml:lang", lang);
}
if (!distributorAffiliation.isEmpty()) {
Expand Down Expand Up @@ -1064,7 +1056,7 @@ private static void writeAbstractElement(XMLStreamWriter xmlw, DatasetVersionDTO
if(!descriptionDate.isEmpty()){
writeAttribute(xmlw,"date",descriptionDate);
}
if(isMetadataLanguageSet(lang)) {
if(DvObjectContainer.isMetadataLanguageSet(lang)) {
writeAttribute(xmlw, "xml:lang", lang);
}
xmlw.writeCharacters(descriptionText);
Expand Down Expand Up @@ -1538,7 +1530,7 @@ private static void writeFullElement (XMLStreamWriter xmlw, String name, String
//For the simplest Elements we can
if (!StringUtilisEmpty(value)) {
xmlw.writeStartElement(name);
if(isMetadataLanguageSet(lang)) {
if(DvObjectContainer.isMetadataLanguageSet(lang)) {
writeAttribute(xmlw, "xml:lang", lang);
}
xmlw.writeCharacters(value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public JsonObjectBuilder getOREMapBuilder(boolean aggregationOnly) throws Except

aggBuilder.add(JsonLDTerm.schemaOrg("isPartOf").getLabel(), getDataverseDescription(dataset.getOwner()));
String mdl = dataset.getMetadataLanguage();
if(!mdl.equals(DvObjectContainer.UNDEFINED_METADATA_LANGUAGE_CODE)) {
if (DvObjectContainer.isMetadataLanguageSet(mdl)) {
aggBuilder.add(JsonLDTerm.schemaOrg("inLanguage").getLabel(), mdl);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -314,16 +314,19 @@ public static JsonObjectBuilder json(BuiltinUser user) {
}

public static JsonObjectBuilder json(Dataset ds) {
return jsonObjectBuilder()
JsonObjectBuilder bld = jsonObjectBuilder()
.add("id", ds.getId())
.add("identifier", ds.getIdentifier())
.add("persistentUrl", ds.getPersistentURL())
.add("protocol", ds.getProtocol())
.add("authority", ds.getAuthority())
.add("publisher", BrandingUtil.getInstallationBrandName())
.add("publicationDate", ds.getPublicationDateFormattedYYYYMMDD())
.add("storageIdentifier", ds.getStorageIdentifier())
.add("metadataLanguage", ds.getMetadataLanguage());
.add("storageIdentifier", ds.getStorageIdentifier());
if (DvObjectContainer.isMetadataLanguageSet(ds.getMetadataLanguage())) {
bld.add("metadataLanguage", ds.getMetadataLanguage());
}
return bld;
}

public static JsonObjectBuilder json(DatasetVersion dsv) {
Expand Down
8 changes: 7 additions & 1 deletion src/test/java/edu/harvard/iq/dataverse/api/DataversesIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ public void testDataFileAPIPermissions() {
}

@Test
public void testImportDDI() throws IOException {
public void testImportDDI() throws IOException, InterruptedException {

Response createUser = UtilIT.createRandomUser();
String username = UtilIT.getUsernameFromResponse(createUser);
Expand Down Expand Up @@ -534,6 +534,12 @@ public void testImportDDI() throws IOException {
Response destroyDatasetResponsePidRel = UtilIT.destroyDataset(datasetIdIntPidRel, apiToken);
assertEquals(200, destroyDatasetResponsePidRel.getStatusCode());

// This last dataset we have just imported, let's give it a sec. to finish indexing (?)
// or whatever it is that may still be happening. (Have been seeing intermittent 500 from the next
// destroyDataset() line lately)

Thread.sleep(1000L);

Integer datasetIdIntRelease = JsonPath.from(importDDIRelease.body().asString()).getInt("data.id");
Response destroyDatasetResponseRelease = UtilIT.destroyDataset(datasetIdIntRelease, apiToken);
assertEquals(200, destroyDatasetResponseRelease.getStatusCode());
Expand Down