Skip to content

Commit

Permalink
more metadata-related changes
Browse files Browse the repository at this point in the history
  • Loading branch information
qqmyers committed Sep 11, 2018
1 parent 61bfb31 commit 319c8d9
Show file tree
Hide file tree
Showing 17 changed files with 262 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public String deactivateIdentifier(String identifier, HashMap<String, String> me
return retString;
}

private String getMetadataFromDvObject(String identifier, Map<String, String> metadata, DvObject dvObject) {
public String getMetadataFromDvObject(String identifier, Map<String, String> metadata, DvObject dvObject) {

Dataset dataset = null;

Expand Down
3 changes: 2 additions & 1 deletion src/main/java/edu/harvard/iq/dataverse/DatasetField.java
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,8 @@ public boolean isEmptyForDisplay() {

private boolean isEmpty(boolean forDisplay) {
if (datasetFieldType.isPrimitive()) { // primitive
for (String value : getValues()) {
List<String> values = forDisplay ? getValues() : getValues_nondisplay();
for (String value : values) {
if (!StringUtils.isBlank(value) && !(forDisplay && DatasetField.NA_VALUE.equals(value))) {
return false;
}
Expand Down
14 changes: 14 additions & 0 deletions src/main/java/edu/harvard/iq/dataverse/DatasetFieldType.java
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,20 @@ public void setMetadataBlock(MetadataBlock metadataBlock) {
this.metadataBlock = metadataBlock;
}

/**
* A formal URI for the field used in json-ld exports
*/
@Column(name = "uri", columnDefinition = "TEXT")
private String uri;

public String getUri() {
return uri;
}

public void setUri(String uri) {
this.uri=uri;
}

/**
* The list of controlled vocabulary terms that may be used as values for
* fields of this field type.
Expand Down
12 changes: 11 additions & 1 deletion src/main/java/edu/harvard/iq/dataverse/MetadataBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ public class MetadataBlock implements Serializable {
@Column( nullable = false )
private String displayName;

@Column( name = "namespaceuri", columnDefinition = "TEXT")
private String namespaceUri;

public Long getId() {
return id;
}
Expand All @@ -56,7 +59,14 @@ public String getName() {
public void setName(String name) {
this.name = name;
}


public String getNamespaceUri() {
return namespaceUri;
}
public void setNamespaceUri(String namespaceUri) {
this.namespaceUri = namespaceUri;
}

@OneToMany(mappedBy = "metadataBlock", cascade = {CascadeType.REMOVE, CascadeType.MERGE, CascadeType.PERSIST})
@OrderBy("displayOrder")
private List<DatasetFieldType> datasetFieldTypes;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,10 @@ private String parseMetadataBlock(String[] values) {
}
mdb.setDisplayName(values[3]);

if (!StringUtils.isEmpty(values[4])) {
mdb.setNamespaceUri(values[4]);
}

metadataBlockService.save(mdb);
return mdb.getName();
}
Expand Down Expand Up @@ -339,6 +343,9 @@ private String parseDatasetField(String[] values) {
dsf.setParentDatasetFieldType(datasetFieldService.findByName(values[14]));
}
dsf.setMetadataBlock(dataverseService.findMDBByName(values[15]));
if (!StringUtils.isEmpty(values[16])) {
dsf.setUri(values[16]);
}
datasetFieldService.save(dsf);
return dsf.getName();
}
Expand Down
11 changes: 4 additions & 7 deletions src/main/java/edu/harvard/iq/dataverse/api/Datasets.java
Original file line number Diff line number Diff line change
Expand Up @@ -206,15 +206,12 @@ public Response exportDataset(@QueryParam("persistentId") String persistentId, @

ExportService instance = ExportService.getInstance(settingsSvc);

InputStream xml = instance.getExport(dataset, exporter);
InputStream is = instance.getExport(dataset, exporter);

String mediaType = MediaType.TEXT_PLAIN;//PM - output formats appear to be either JSON or XML, unclear why text/plain is being used as default content-type.

if (instance.isXMLFormat(exporter)){
mediaType = MediaType.APPLICATION_XML;
}
String mediaType = instance.getMediaType(exporter);

return allowCors(Response.ok()
.entity(xml)
.entity(is)
.type(mediaType).
build());
} catch (Exception wr) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import edu.harvard.iq.dataverse.util.BundleUtil;
import java.io.OutputStream;
import javax.json.JsonObject;
import javax.ws.rs.core.MediaType;
import javax.xml.stream.XMLStreamException;

/**
Expand Down
13 changes: 7 additions & 6 deletions src/main/java/edu/harvard/iq/dataverse/export/DDIExporter.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.io.OutputStream;
import javax.ejb.EJB;
import javax.json.JsonObject;
import javax.ws.rs.core.MediaType;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamWriter;
import javax.xml.stream.XMLOutputFactory;
Expand Down Expand Up @@ -44,9 +45,9 @@ public String getDisplayName() {
@Override
public void exportDataset(DatasetVersion version, JsonObject json, OutputStream outputStream) throws ExportException {
try {
XMLStreamWriter xmlw = XMLOutputFactory.newInstance().createXMLStreamWriter(outputStream);
xmlw.writeStartDocument();
xmlw.flush();
XMLStreamWriter xmlw = XMLOutputFactory.newInstance().createXMLStreamWriter(outputStream);
xmlw.writeStartDocument();
xmlw.flush();
DdiExportUtil.datasetJson2ddi(json, version, outputStream);
} catch (XMLStreamException xse) {
throw new ExportException ("Caught XMLStreamException performing DDI export");
Expand Down Expand Up @@ -74,17 +75,17 @@ public Boolean isAvailableToUsers() {

@Override
public String getXMLNameSpace() throws ExportException {
return this.DEFAULT_XML_NAMESPACE;
return DDIExporter.DEFAULT_XML_NAMESPACE;
}

@Override
public String getXMLSchemaLocation() throws ExportException {
return this.DEFAULT_XML_SCHEMALOCATION;
return DDIExporter.DEFAULT_XML_SCHEMALOCATION;
}

@Override
public String getXMLSchemaVersion() throws ExportException {
return this.DEFAULT_XML_VERSION;
return DDIExporter.DEFAULT_XML_VERSION;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import java.util.ResourceBundle;

import javax.json.JsonObject;
import javax.ws.rs.core.MediaType;

/**
*
Expand Down Expand Up @@ -45,8 +46,8 @@ public String getDisplayName() {
public void exportDataset(DatasetVersion version, JsonObject json, OutputStream outputStream)
throws ExportException {
try {
DataCitation dc = new DataCitation(version);
DataCitation dc = new DataCitation(version);
Map<String, String> metadata = dc.getDataCiteMetadata();
String xml = DOIDataCiteRegisterService.getMetadataFromDvObject(
version.getDataset().getGlobalId().asString(), metadata, version.getDataset());
Expand Down Expand Up @@ -90,4 +91,5 @@ public String getXMLSchemaVersion() throws ExportException {
public void setParam(String name, Object value) {
// this exporter does not uses or supports any parameters as of now.
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import edu.harvard.iq.dataverse.util.BundleUtil;
import java.io.OutputStream;
import javax.json.JsonObject;
import javax.ws.rs.core.MediaType;
import javax.xml.stream.XMLStreamException;

/**
Expand Down
17 changes: 17 additions & 0 deletions src/main/java/edu/harvard/iq/dataverse/export/ExportService.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
import java.util.logging.Logger;
import javax.json.JsonObject;
import javax.json.JsonObjectBuilder;
import javax.ws.rs.core.MediaType;

import org.apache.commons.io.IOUtils;

/**
Expand Down Expand Up @@ -359,4 +361,19 @@ public Boolean isXMLFormat(String provider) {
return null;
}

public String getMediaType(String provider) {
try {
Iterator<Exporter> exporters = loader.iterator();
while (exporters.hasNext()) {
Exporter e = exporters.next();
if (e.getProviderName().equals(provider)) {
return e.getMediaType();
}
}
} catch (ServiceConfigurationError serviceError) {
serviceError.printStackTrace();
}
return MediaType.TEXT_PLAIN;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import java.io.OutputStreamWriter;
import java.io.Writer;
import javax.json.JsonObject;
import javax.ws.rs.core.MediaType;


/**
Expand Down Expand Up @@ -73,4 +74,9 @@ public void setParam(String name, Object value) {
// this exporter doesn't need/doesn't currently take any parameters
}

@Override
public String getMediaType() {
return MediaType.APPLICATION_JSON;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import java.util.logging.Logger;

import javax.json.JsonObject;
import javax.ws.rs.core.MediaType;

@AutoService(Exporter.class)
public class OAI_OREExporter implements Exporter {
Expand Down Expand Up @@ -80,6 +81,10 @@ public String getXMLSchemaVersion() throws ExportException {
public void setParam(String name, Object value) {
// this exporter doesn't need/doesn't currently take any parameters
}


@Override
public String getMediaType() {
return MediaType.APPLICATION_JSON;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import javax.json.Json;
import javax.json.JsonObject;
import javax.json.JsonReader;
import javax.ws.rs.core.MediaType;

@AutoService(Exporter.class)
public class SchemaDotOrgExporter implements Exporter {
Expand Down Expand Up @@ -82,5 +83,11 @@ public String getXMLSchemaVersion() throws ExportException {
public void setParam(String name, Object value) {
// this exporter doesn't need/doesn't currently take any parameters
}


@Override
public String getMediaType() {
return MediaType.APPLICATION_JSON;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import edu.harvard.iq.dataverse.export.ExportException;
import java.io.OutputStream;
import javax.json.JsonObject;
import javax.ws.rs.core.MediaType;

/**
*
Expand Down Expand Up @@ -43,5 +44,9 @@ but NOT close() it!
public String getXMLSchemaVersion() throws ExportException;

public void setParam(String name, Object value);

public default String getMediaType() {
return MediaType.APPLICATION_XML;
};

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package edu.harvard.iq.dataverse.util.json;

import edu.harvard.iq.dataverse.util.SystemConfig;

public class JsonLDNamespace {

String prefix;


String url;

//FixMe - use a universal Dataverse URL rather than an instance one for Core terms
public static JsonLDNamespace dvcore = new JsonLDNamespace("dvcore", SystemConfig.getDataverseSiteUrlStatic() + "/schema/core#");
public static JsonLDNamespace dcterms = new JsonLDNamespace("dcterms","http://purl.org/dc/terms/");
public static JsonLDNamespace ore = new JsonLDNamespace("ore","http://www.openarchives.org/ore/terms/");
public static JsonLDNamespace schema = new JsonLDNamespace("schema","http://schema.org/");

public JsonLDNamespace(String prefix, String url) {
this.prefix = prefix;
this.url = url;
}

public String getPrefix() {
return prefix;
}

public String getUrl() {
return url;
}

}

0 comments on commit 319c8d9

Please sign in to comment.