Skip to content

Commit

Permalink
stub out dataset in json-ld format IQSS#3793
Browse files Browse the repository at this point in the history
  • Loading branch information
pdurbin committed Oct 31, 2017
1 parent 5efe63b commit 1b62596
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/main/java/edu/harvard/iq/dataverse/DatasetPage.java
Original file line number Diff line number Diff line change
Expand Up @@ -3984,5 +3984,8 @@ public List<DatasetField> getDatasetSummaryFields() {

return DatasetUtil.getDatasetSummaryFields(workingVersion, customFields);
}


public String getJsonLd() {
return DatasetUtil.getJsonLd(workingVersion);
}
}
89 changes: 89 additions & 0 deletions src/main/java/edu/harvard/iq/dataverse/dataset/DatasetUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -416,4 +423,86 @@ public static List<DatasetField> 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();
}

}
5 changes: 5 additions & 0 deletions src/main/webapp/dataset.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@
<meta name="DC.subject" content="#{subject}"/>
</ui:repeat>
</ui:define>
<ui:define name="jsonld_header">
<script type="application/ld+json">
<h:outputText value="#{DatasetPage.jsonLd}"/>
</script>
</ui:define>
<ui:define name="body">
<o:importFunctions type="edu.harvard.iq.dataverse.util.MarkupChecker" />
<f:metadata>
Expand Down
1 change: 1 addition & 0 deletions src/main/webapp/dataverse_template.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<title><h:outputText value="#{pageTitle}"/></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<ui:insert name="dc_meta_header"></ui:insert>
<ui:insert name="jsonld_header"></ui:insert>
<meta http-equiv="Content-Language" content="en"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
Expand Down

0 comments on commit 1b62596

Please sign in to comment.