Skip to content

Commit

Permalink
A few quick fixes for getJsonLd() (and the corresponding test in Data…
Browse files Browse the repository at this point in the history
…setVersionTest());

(ref IQSS#2243)
  • Loading branch information
landreev committed Nov 7, 2017
1 parent c941781 commit 8c74e37
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 4 deletions.
42 changes: 39 additions & 3 deletions src/main/java/edu/harvard/iq/dataverse/DatasetVersion.java
Original file line number Diff line number Diff line change
Expand Up @@ -1133,9 +1133,7 @@ public String getJsonLd() {
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();
Expand All @@ -1150,17 +1148,55 @@ public String getJsonLd() {
* We are aware that there is a "datePublished" field but it means "Date
* of first broadcast/publication." This only makes sense for a 1.0
* version.
*
* (Per @jggautier's comment 03/11/2017 in #2243, we are putting datePublished
* back -- L.A.)
*/
job.add("datePublished", this.getDataset().getPublicationDateFormattedYYYYMMDD());

/**
* "dateModified" is more appropriate for a version: "The date on which
* the CreativeWork was most recently modified or when the item's entry
* was modified within a DataFeed."
*/
job.add("dateModified", this.getPublicationDateAsString());
job.add("version", this.getVersionNumber().toString());
/**
* "keywords" - contains subject(s), datasetkeyword(s) and topicclassification(s)
* metadata fields for the version. -- L.A.
* TODO (see #2243 for details on how to format)
*/

/**
* citation:
*/
JsonObjectBuilder citation = Json.createObjectBuilder();
citation.add("@type", "Dataset");
citation.add("text", this.getCitation());
job.add("citation", citation);
/* TODO: should we use the HTML-style citation, i.e. this.getCitation(true) instead -- L.A.?) */

/**
* temporalCoverage:
* TODO (if available)
*/

/**
* spatialCoverage:
* TODO (if available)
*/

/**
* "funder":
* TODO
* (see 2243 for info on how to format -- L.A.)
*/

job.add("schemaVersion", "https://schema.org/version/3.3");
job.add("publisher", Json.createObjectBuilder()
.add("@type", "Organization")
.add("name", this.getRootDataverseNameforCitation())
);

job.add("provider", Json.createObjectBuilder()
.add("@type", "Organization")
.add("name", "Dataverse")
Expand Down
10 changes: 9 additions & 1 deletion src/test/java/edu/harvard/iq/dataverse/DatasetVersionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

import edu.harvard.iq.dataverse.mocks.MocksFactory;
import java.io.StringReader;
import java.sql.Timestamp;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import javax.json.Json;
import javax.json.JsonArray;
Expand Down Expand Up @@ -105,8 +107,11 @@ public void testGetJsonLd() throws ParseException {
// Only published datasets return any JSON.
assertEquals("", datasetVersion.getJsonLd());
datasetVersion.setVersionState(DatasetVersion.VersionState.RELEASED);
datasetVersion.setVersionNumber(1L);
SimpleDateFormat dateFmt = new SimpleDateFormat("yyyyMMdd");
datasetVersion.setReleaseTime(dateFmt.parse("19551105"));
Date publicationDate = dateFmt.parse("19551105");
datasetVersion.setReleaseTime(publicationDate);
dataset.setPublicationDate(new Timestamp(publicationDate.getTime()));
Dataverse dataverse = new Dataverse();
dataverse.setName("LibraScholar");
dataset.setOwner(dataverse);
Expand All @@ -119,13 +124,16 @@ public void testGetJsonLd() throws ParseException {
assertEquals("http://dx.doi.org/10.5072/FK2/LK0D1H", obj.getString("@id"));
assertEquals("https://schema.org/version/3.3", obj.getString("schemaVersion"));
assertEquals("1955-11-05", obj.getString("dateModified"));
assertEquals("1955-11-05", obj.getString("datePublished"));
assertEquals("1", obj.getString("version"));
// TODO: if it ever becomes easier to mock a dataset title, test it.
assertEquals("", obj.getString("name"));
// TODO: If it ever becomes easier to mock authors, test them.
JsonArray emptyArray = Json.createArrayBuilder().build();
assertEquals(emptyArray, obj.getJsonArray("author"));
assertEquals("Dataverse", obj.getJsonObject("provider").getString("name"));
assertEquals("LibraScholar", obj.getJsonObject("publisher").getString("name"));
assertEquals(datasetVersion.getCitation(), obj.getJsonObject("citation").getString("text"));
}

}

0 comments on commit 8c74e37

Please sign in to comment.