From 3fa8e0e8422ae2a5c3453011132d5232e0c1b7f3 Mon Sep 17 00:00:00 2001 From: Stian Soiland-Reyes Date: Thu, 23 May 2013 21:46:47 +0100 Subject: [PATCH] nullchecks --- .../common/writer/RDFMessageBodyWriter.java | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/orcid-api-common/src/main/java/org/orcid/api/common/writer/RDFMessageBodyWriter.java b/orcid-api-common/src/main/java/org/orcid/api/common/writer/RDFMessageBodyWriter.java index aa660752645..5772abaa4c9 100644 --- a/orcid-api-common/src/main/java/org/orcid/api/common/writer/RDFMessageBodyWriter.java +++ b/orcid-api-common/src/main/java/org/orcid/api/common/writer/RDFMessageBodyWriter.java @@ -34,6 +34,7 @@ import org.orcid.jaxb.model.message.OrcidMessage; import org.orcid.jaxb.model.message.OrcidProfile; +import org.orcid.jaxb.model.message.PersonalDetails; import com.hp.hpl.jena.ontology.DatatypeProperty; import com.hp.hpl.jena.ontology.Individual; @@ -153,13 +154,21 @@ public void writeTo(OrcidMessage xml, Class type, Type genericType, Annotatio // AnnotationProperty foafName = m.getAnnotationProperty(FOAF_0_1 + "name"); DatatypeProperty foafName = m.getDatatypeProperty(FOAF_0_1 + "name"); - person.addProperty(foafName, orcidProfile.getOrcidBio().getPersonalDetails().getCreditName().getContent()); - DatatypeProperty foafGivenName = m.getDatatypeProperty(FOAF_0_1 + "givenName"); - person.addProperty(foafGivenName, orcidProfile.getOrcidBio().getPersonalDetails().getGivenNames().getContent()); - DatatypeProperty familyName = m.getDatatypeProperty(FOAF_0_1 + "familyName"); - person.addProperty(familyName, orcidProfile.getOrcidBio().getPersonalDetails().getFamilyName().getContent()); + + PersonalDetails personalDetails = orcidProfile.getOrcidBio().getPersonalDetails(); + + if (personalDetails.getCreditName() != null) { + person.addProperty(foafName, personalDetails.getCreditName().getContent()); + } + + if (personalDetails.getGivenNames() != null) { + person.addProperty(foafGivenName, personalDetails.getGivenNames().getContent()); + } + if (personalDetails.getFamilyName() != null) { + person.addProperty(familyName, personalDetails.getFamilyName().getContent()); + } m.write(entityStream); }