Skip to content

Commit

Permalink
move getJsonLd method to DatasetVersion entity IQSS#2243
Browse files Browse the repository at this point in the history
  • Loading branch information
pdurbin committed Nov 2, 2017
1 parent 485a5ca commit 171c8f3
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/main/java/edu/harvard/iq/dataverse/DatasetPage.java
Original file line number Diff line number Diff line change
Expand Up @@ -3969,6 +3969,6 @@ public List<DatasetField> getDatasetSummaryFields() {
}

public String getJsonLd() {
return DatasetUtil.getJsonLd(workingVersion);
return workingVersion.getJsonLd();
}
}
39 changes: 39 additions & 0 deletions src/main/java/edu/harvard/iq/dataverse/DatasetVersion.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.json.Json;
import javax.json.JsonArrayBuilder;
import javax.json.JsonObjectBuilder;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
Expand Down Expand Up @@ -1120,4 +1123,40 @@ public String getPublicationDate() {
return r;
}

// TODO: Make this more performant by writing the output to the database or a file?
public String getJsonLd() {
// We show published datasets only for "datePublished" field below.
if (!this.isPublished()) {
return "";
}
JsonObjectBuilder job = Json.createObjectBuilder();
job.add("@context", "http://schema.org");
job.add("@type", "Dataset");
job.add("@id", this.getDataset().getPersistentURL());
job.add("additionalType", "Dataset");
job.add("name", this.getTitle());
job.add("@context", "http://schema.org");
JsonArrayBuilder authors = Json.createArrayBuilder();
for (DatasetAuthor datasetAuthor : this.getDatasetAuthors()) {
JsonObjectBuilder author = Json.createObjectBuilder();
String personOrOrganization = datasetAuthor.getName().getValue();
String name = personOrOrganization;
// We are aware of "givenName" and "familyName" but instead of a person it might be an organization such as "Gallup Organization".
author.add("name", name);
authors.add(author);
}
job.add("author", authors);
job.add("datePublished", this.getPublicationDate());
job.add("schemaVersion", "http://datacite.org/schema/kernel-4");
job.add("publisher", Json.createObjectBuilder()
.add("@type", "Organization")
.add("name", this.getRootDataverseNameforCitation())
);
job.add("provider", Json.createObjectBuilder()
.add("@type", "Organization")
.add("name", "Dataverse")
);
return job.build().toString();
}

}

0 comments on commit 171c8f3

Please sign in to comment.