diff --git a/src/main/java/edu/harvard/iq/dataverse/DatasetPage.java b/src/main/java/edu/harvard/iq/dataverse/DatasetPage.java index 030553916d3..fbdb53cbbcd 100644 --- a/src/main/java/edu/harvard/iq/dataverse/DatasetPage.java +++ b/src/main/java/edu/harvard/iq/dataverse/DatasetPage.java @@ -3984,5 +3984,8 @@ public List getDatasetSummaryFields() { return DatasetUtil.getDatasetSummaryFields(workingVersion, customFields); } - + + public String getJsonLd() { + return DatasetUtil.getJsonLd(workingVersion); + } } diff --git a/src/main/java/edu/harvard/iq/dataverse/dataset/DatasetUtil.java b/src/main/java/edu/harvard/iq/dataverse/dataset/DatasetUtil.java index 101c5fb7804..156774172a7 100644 --- a/src/main/java/edu/harvard/iq/dataverse/dataset/DatasetUtil.java +++ b/src/main/java/edu/harvard/iq/dataverse/dataset/DatasetUtil.java @@ -2,9 +2,13 @@ import edu.harvard.iq.dataverse.DataFile; import edu.harvard.iq.dataverse.Dataset; +import edu.harvard.iq.dataverse.DatasetAuthor; import edu.harvard.iq.dataverse.DatasetField; import edu.harvard.iq.dataverse.DatasetVersion; import edu.harvard.iq.dataverse.FileMetadata; +import edu.harvard.iq.dataverse.authorization.AuthenticatedUserDisplayInfo; +import edu.harvard.iq.dataverse.authorization.providers.shib.ShibUserNameFields; +import edu.harvard.iq.dataverse.authorization.providers.shib.ShibUtil; import edu.harvard.iq.dataverse.dataaccess.DataAccess; import static edu.harvard.iq.dataverse.dataaccess.DataAccess.getStorageIO; import edu.harvard.iq.dataverse.dataaccess.StorageIO; @@ -33,6 +37,9 @@ import java.util.HashSet; import java.util.Map; import javax.imageio.ImageIO; +import javax.json.Json; +import javax.json.JsonArrayBuilder; +import javax.json.JsonObjectBuilder; import org.apache.commons.io.IOUtils; public class DatasetUtil { @@ -416,4 +423,86 @@ public static List getDatasetSummaryFields(DatasetVersion datasetV return datasetFields; } +/* +{ + "@context": "http://schema.org", + "@type": "Dataset", + "@id": "https://doi.org/10.7910/dvn/icfngt", + "additionalType": "Dataset", + "name": "Replication Data for: Parties, Legislators, and the Origins of Proportional Representation", + "author": [ + { + "@type": "Person", + "name": "Gary W. Cox", + "givenName": "Gary W.", + "familyName": "Cox" + }, + { + "@type": "Person", + "name": "Jon H. Fiva", + "givenName": "Jon H.", + "familyName": "Fiva" + }, + { + "@type": "Person", + "name": "Daniel M. Smith", + "givenName": "Daniel M.", + "familyName": "Smith" + } + ], + "datePublished": "2017", + "schemaVersion": "http://datacite.org/schema/kernel-4", + "publisher": { + "@type": "Organization", + "name": "Harvard Dataverse" + }, + "provider": { + "@type": "Organization", + "name": "DataCite" + } +} +*/ + public static String getJsonLd(DatasetVersion workingVersion) { + JsonObjectBuilder job = Json.createObjectBuilder(); + job.add("@context", "http://schema.org"); + job.add("@type", "Dataset"); + // FIXME + job.add("@id", "https://doi.org/10.7910/dvn/icfngt"); + job.add("additionalType", "Dataset"); + job.add("name", workingVersion.getTitle()); + job.add("@context", "http://schema.org"); + JsonArrayBuilder authors = Json.createArrayBuilder(); + for (DatasetAuthor datasetAuthor : workingVersion.getDatasetAuthors()) { + JsonObjectBuilder author = Json.createObjectBuilder(); + author.add("@type", "Person"); + ShibUserNameFields shibUserNameFields = ShibUtil.findBestFirstAndLastName(null, null, datasetAuthor.getName().getValue().replaceAll(",", "")); + AuthenticatedUserDisplayInfo displayInfo = new AuthenticatedUserDisplayInfo( + shibUserNameFields.getFirstName(), + shibUserNameFields.getLastName(), + "", + "", + "" + ); + author.add("name", displayInfo.getFirstName() + " " + displayInfo.getLastName()); + author.add("givenName", displayInfo.getFirstName()); + author.add("familyName", displayInfo.getLastName()); + authors.add(author); + } + job.add("author", authors); + // FIXME + job.add("datePublished", "2017"); + job.add("schemaVersion", "http://datacite.org/schema/kernel-4"); + job.add("publisher", Json.createObjectBuilder() + .add("@type", "Organization") + // FIXME + .add("name", "Harvard Dataverse") + ); + job.add("provider", Json.createObjectBuilder() + .add("@type", "Organization") + // FIXME + .add("name", "DataCite") + ); + return job.build().toString(); + } + } diff --git a/src/main/webapp/dataset.xhtml b/src/main/webapp/dataset.xhtml index 4a71e3b274f..7d1192140b2 100755 --- a/src/main/webapp/dataset.xhtml +++ b/src/main/webapp/dataset.xhtml @@ -34,6 +34,11 @@ + + + diff --git a/src/main/webapp/dataverse_template.xhtml b/src/main/webapp/dataverse_template.xhtml index 1d581b1f19d..5726173e328 100644 --- a/src/main/webapp/dataverse_template.xhtml +++ b/src/main/webapp/dataverse_template.xhtml @@ -14,6 +14,7 @@ <h:outputText value="#{pageTitle}"/> +