Skip to content

Commit

Permalink
the ld json fragment should now be structured as specified in the issue
Browse files Browse the repository at this point in the history
  • Loading branch information
landreev committed Nov 16, 2017
1 parent 8b8391f commit 67882ff
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 24 deletions.
66 changes: 44 additions & 22 deletions src/main/java/edu/harvard/iq/dataverse/DatasetVersion.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
import edu.harvard.iq.dataverse.util.MarkupChecker;
import edu.harvard.iq.dataverse.DatasetFieldType.FieldType;
import edu.harvard.iq.dataverse.util.StringUtil;
import edu.harvard.iq.dataverse.util.SystemConfig;
import edu.harvard.iq.dataverse.workflows.WorkflowComment;
import java.io.Serializable;
import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
Expand Down Expand Up @@ -778,7 +780,7 @@ public List<String> getDatasetSubjects() {
* @return List of Strings containing the version's Topic Classifications
*/
public List<String> getTopicClassifications() {
List<String> topicClassifications = new ArrayList<>();
List<String> topics = new ArrayList<>();
for (DatasetField dsf : this.getDatasetFields()) {
if (dsf.getDatasetFieldType().getName().equals(DatasetFieldConstant.topicClassification)) {
for (DatasetFieldCompoundValue topicClassValue : dsf.getDatasetFieldCompoundValues()) {
Expand All @@ -789,14 +791,14 @@ public List<String> getTopicClassifications() {
// - in the ideal world. But as we are realizing, they CAN
// be null in real life databases. So, a check, just in case:
if (!StringUtil.isEmpty(topic)) {
topicClassifications.add(subField.getValue());
topics.add(subField.getValue());
}
}
}
}
}
}
return topicClassifications;
return topics;
}

/**
Expand Down Expand Up @@ -1226,13 +1228,13 @@ public String getJsonLd() {
return "";
}

/*if (jsonLd != null) {
if (jsonLd != null) {
return jsonLd;
}*/
}
JsonObjectBuilder job = Json.createObjectBuilder();
job.add("@context", "http://schema.org");
job.add("@type", "Dataset");
job.add("@id", this.getDataset().getPersistentURL());
job.add("@identifier", this.getDataset().getPersistentURL());
job.add("name", this.getTitle());
JsonArrayBuilder authors = Json.createArrayBuilder();
for (DatasetAuthor datasetAuthor : this.getDatasetAuthors()) {
Expand Down Expand Up @@ -1263,24 +1265,25 @@ public String getJsonLd() {
*/
job.add("dateModified", this.getPublicationDateAsString());
job.add("version", this.getVersionNumber().toString());
job.add("description", this.getDescriptionPlainText());
/**
* "keywords" - contains subject(s), datasetkeyword(s) and topicclassification(s)
* metadata fields for the version. -- L.A.
* (see #2243 for details/discussion/feedback from Google)
*/
JsonArrayBuilder keywords = Json.createArrayBuilder();

this.getDatasetSubjects().forEach((subjects) -> {
keywords.add(subjects);
});
for (String subject : this.getDatasetSubjects()) {
keywords.add(subject);
}

this.getTopicClassifications().forEach((topics) -> {
keywords.add(topics);
});
for (String topic : this.getTopicClassifications()) {
keywords.add(topic);
}

this.getKeywords().forEach((keywordValues) -> {
keywords.add(keywordValues);
});
for (String keyword : this.getKeywords()) {
keywords.add(keyword);
}

job.add("keywords", keywords);

Expand Down Expand Up @@ -1308,21 +1311,40 @@ public String getJsonLd() {
}

/**
* spatialCoverage:
* (if available)
* spatialCoverage (if available)
* TODO
* (punted, for now - see #2243)
*
*/

/**
* "funder":
* funder (if available)
* TODO
* (see 2243 for info on how to format -- L.A.)
*/
* (punted, for now - see #2243)
*/

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

TermsOfUseAndAccess terms = this.getTermsOfUseAndAccess();
if (terms != null) {
if (TermsOfUseAndAccess.License.CC0.equals(terms.getLicense())) {
job.add("license", Json.createObjectBuilder()
.add("@type", "Dataset")
.add("text", "CC0")
.add("url", "https://creativecommons.org/publicdomain/zero/1.0/")
);

} else {
job.add("license", Json.createObjectBuilder()
.add("text", terms.getTermsOfUse())
);
}
}

job.add("includedInDataCatalog", Json.createObjectBuilder()
.add("@type", "DataCatalog")
.add("name", this.getRootDataverseNameforCitation())
.add("url", SystemConfig.getDataverseSiteUrlStatic())
);

job.add("provider", Json.createObjectBuilder()
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/edu/harvard/iq/dataverse/util/SystemConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,10 @@ public static int getMinutesUntilPasswordResetTokenExpires() {
* by the Settings Service configuration.
*/
public String getDataverseSiteUrl() {
return getDataverseSiteUrlStatic();
}

public static String getDataverseSiteUrlStatic() {
String hostUrl = System.getProperty(SITE_URL);
if (hostUrl != null && !"".equals(hostUrl)) {
return hostUrl;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public void testGetJsonLd() throws ParseException {
JsonObject obj = jsonReader.readObject();
assertEquals("http://schema.org", obj.getString("@context"));
assertEquals("Dataset", obj.getString("@type"));
assertEquals("http://dx.doi.org/10.5072/FK2/LK0D1H", obj.getString("@id"));
assertEquals("http://dx.doi.org/10.5072/FK2/LK0D1H", obj.getString("@identifier"));
assertEquals("https://schema.org/version/3.3", obj.getString("schemaVersion"));
assertEquals("1955-11-05", obj.getString("dateModified"));
assertEquals("1955-11-05", obj.getString("datePublished"));
Expand All @@ -134,7 +134,7 @@ public void testGetJsonLd() throws ParseException {
// TODO: If it ever becomes easier to mock subjects, test them.
assertEquals(emptyArray, obj.getJsonArray("keywords"));
assertEquals("Dataverse", obj.getJsonObject("provider").getString("name"));
assertEquals("LibraScholar", obj.getJsonObject("publisher").getString("name"));
assertEquals("LibraScholar", obj.getJsonObject("includedInDataCatalog").getString("name"));
assertEquals(datasetVersion.getCitation(), obj.getJsonObject("citation").getString("text"));
}

Expand Down

0 comments on commit 67882ff

Please sign in to comment.