From fff836cc017968e80c06f4b6e6571017cac6a072 Mon Sep 17 00:00:00 2001 From: Philip Durbin Date: Thu, 30 Nov 2017 16:39:26 -0500 Subject: [PATCH] add null check for datasetAuthor.getAffiliation() #4330 --- src/main/java/edu/harvard/iq/dataverse/DatasetVersion.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main/java/edu/harvard/iq/dataverse/DatasetVersion.java b/src/main/java/edu/harvard/iq/dataverse/DatasetVersion.java index a01422ac2da..ca5791786a7 100644 --- a/src/main/java/edu/harvard/iq/dataverse/DatasetVersion.java +++ b/src/main/java/edu/harvard/iq/dataverse/DatasetVersion.java @@ -1236,13 +1236,18 @@ public String getJsonLd() { for (DatasetAuthor datasetAuthor : this.getDatasetAuthors()) { JsonObjectBuilder author = Json.createObjectBuilder(); String name = datasetAuthor.getName().getValue(); - String affiliation = datasetAuthor.getAffiliation().getValue(); + DatasetField authorAffiliation = datasetAuthor.getAffiliation(); + String affiliation = null; + if (authorAffiliation != null) { + affiliation = datasetAuthor.getAffiliation().getValue(); + } // We are aware of "givenName" and "familyName" but instead of a person it might be an organization such as "Gallup Organization". //author.add("@type", "Person"); author.add("name", name); // We are aware that the following error is thrown by https://search.google.com/structured-data/testing-tool // "The property affiliation is not recognized by Google for an object of type Thing." // Someone at Google has said this is ok. + // This logic could be moved into the `if (authorAffiliation != null)` block above. if (!StringUtil.isEmpty(affiliation)) { author.add("affiliation", affiliation); }