diff --git a/orcid-core/src/main/java/org/orcid/pojo/summary/RecordSummary.java b/orcid-core/src/main/java/org/orcid/pojo/summary/RecordSummary.java index 1b8e3d9ad57..820d9219d9a 100644 --- a/orcid-core/src/main/java/org/orcid/pojo/summary/RecordSummary.java +++ b/orcid-core/src/main/java/org/orcid/pojo/summary/RecordSummary.java @@ -1,8 +1,11 @@ package org.orcid.pojo.summary; +import com.fasterxml.jackson.annotation.JsonFilter; + import java.util.List; +@JsonFilter("nameFilter") public class RecordSummary { private String name; private String orcid; diff --git a/orcid-web/src/main/java/org/orcid/frontend/web/controllers/PublicRecordController.java b/orcid-web/src/main/java/org/orcid/frontend/web/controllers/PublicRecordController.java index 9dec99bb5a1..c11b0442fb7 100644 --- a/orcid-web/src/main/java/org/orcid/frontend/web/controllers/PublicRecordController.java +++ b/orcid-web/src/main/java/org/orcid/frontend/web/controllers/PublicRecordController.java @@ -1,5 +1,8 @@ package org.orcid.frontend.web.controllers; +import com.fasterxml.jackson.databind.ser.FilterProvider; +import com.fasterxml.jackson.databind.ser.impl.SimpleBeanPropertyFilter; +import com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider; import org.orcid.core.exception.DeactivatedException; import org.orcid.core.exception.LockedException; import org.orcid.core.exception.OrcidDeprecatedException; @@ -70,6 +73,7 @@ import org.orcid.pojo.summary.ExternalIdentifiersSummary; import org.orcid.pojo.summary.RecordSummary; import org.orcid.utils.DateUtils; +import org.springframework.http.converter.json.MappingJacksonValue; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; @@ -316,8 +320,7 @@ PublicRecord getRecord(String orcid) { } @RequestMapping(value = "/{orcid:(?:\\d{4}-){3,}\\d{3}[\\dX]}/summary.json", method = RequestMethod.GET) - public @ResponseBody - RecordSummary getSummaryRecord(@PathVariable("orcid") String orcid) { + public @ResponseBody MappingJacksonValue getSummaryRecord(@PathVariable("orcid") String orcid) { RecordSummary recordSummary = new RecordSummary(); Boolean isDeprecated = false; @@ -332,14 +335,14 @@ RecordSummary getSummaryRecord(@PathVariable("orcid") String orcid) { } recordSummary.setName(localeManager.resolveMessage("public_profile.deactivated.given_names") + " " + localeManager.resolveMessage("public_profile.deactivated.family_name")); - return recordSummary; + return new MappingJacksonValue(recordSummary); } catch (OrcidNotClaimedException e) { recordSummary.setName(localeManager.resolveMessage("orcid.reserved_for_claim")); - return recordSummary; + return new MappingJacksonValue(recordSummary); } catch (OrcidDeprecatedException e) { isDeprecated = true; } catch (OrcidNoResultException e) { - return recordSummary; + return new MappingJacksonValue(recordSummary); } if (isDeprecated) { @@ -347,12 +350,20 @@ RecordSummary getSummaryRecord(@PathVariable("orcid") String orcid) { recordSummary.setEmploymentAffiliations(null); recordSummary.setProfessionalActivities(null); recordSummary.setExternalIdentifiers(null); + + return new MappingJacksonValue(recordSummary); } else { recordSummary = getSummary(orcid); recordSummary.setStatus("active"); - } - return recordSummary; + SimpleBeanPropertyFilter simpleBeanPropertyFilter = SimpleBeanPropertyFilter.serializeAllExcept("name"); + FilterProvider filterProvider = new SimpleFilterProvider().addFilter("nameFilter", simpleBeanPropertyFilter); + MappingJacksonValue mappingJacksonValue = new MappingJacksonValue(recordSummary); + if (recordSummary.getName() == null) { + mappingJacksonValue.setFilters(filterProvider); + } + return mappingJacksonValue; + } } public @ResponseBody @@ -362,7 +373,7 @@ RecordSummary getSummary(String orcid) { Record record = recordManagerReadOnly.getPublicRecord(orcid, false); Person person = record.getPerson(); if (person != null) { - String displayName = "undefined"; + String displayName = null; Name name = person.getName(); if (name != null) { if (name.getVisibility().equals(org.orcid.jaxb.model.v3.release.common.Visibility.PUBLIC)) { diff --git a/orcid-web/src/test/java/org/orcid/frontend/web/controllers/PublicRecordControllerTest.java b/orcid-web/src/test/java/org/orcid/frontend/web/controllers/PublicRecordControllerTest.java index d07f6fa16ff..2ebbd8a552a 100644 --- a/orcid-web/src/test/java/org/orcid/frontend/web/controllers/PublicRecordControllerTest.java +++ b/orcid-web/src/test/java/org/orcid/frontend/web/controllers/PublicRecordControllerTest.java @@ -140,7 +140,7 @@ public void testGetPublicRecord() { @Test public void testGetRecordSummary() { - RecordSummary record = publicRecordController.getSummaryRecord(userOrcid); + RecordSummary record = (RecordSummary) publicRecordController.getSummaryRecord(userOrcid).getValue(); assertEquals("active", record.getStatus()); assertNotNull(record.getName()); @@ -150,7 +150,7 @@ public void testGetRecordSummary() { assertEquals(1, record.getEmploymentAffiliations().size()); assertEquals(1, record.getEmploymentAffiliationsCount()); - assertEquals("An institution", record.getEmploymentAffiliations().get(0).getOrganizationName()); + assertEquals("An institution", record.getEmploymentAffiliations().get(0).getOrganizationName()); // Check external identifiers assertNotNull(record.getExternalIdentifiers()); @@ -179,12 +179,12 @@ public void testGetRecordSummary() { assertEquals(0, record.getSelfAssertedFunds()); assertNotNull(record.getProfessionalActivities()); - assertEquals(4, record.getProfessionalActivitiesCount()); + assertEquals(4, record.getProfessionalActivitiesCount()); } @Test public void testGetRecordSummaryDeactivated() { - RecordSummary record = publicRecordController.getSummaryRecord(deactivatedUserOrcid); + RecordSummary record = (RecordSummary) publicRecordController.getSummaryRecord(deactivatedUserOrcid).getValue(); assertEquals("Given Names Deactivated Family Name Deactivated", record.getName()); @@ -193,7 +193,7 @@ public void testGetRecordSummaryDeactivated() { @Test public void testGetRecordSummaryLocked() { - RecordSummary record = publicRecordController.getSummaryRecord(lockedUserOrcid); + RecordSummary record = (RecordSummary) publicRecordController.getSummaryRecord(lockedUserOrcid).getValue(); assertNotNull(record.getName()); assertEquals("Given Names Deactivated Family Name Deactivated", record.getName()); @@ -203,10 +203,17 @@ public void testGetRecordSummaryLocked() { @Test public void testGetRecordSummaryDeprecated() { - RecordSummary record = publicRecordController.getSummaryRecord(deprecatedUserOrcid); + RecordSummary record = (RecordSummary) publicRecordController.getSummaryRecord(deprecatedUserOrcid).getValue(); assertNull(record.getName()); assertEquals("deprecated", record.getStatus()); } + + @Test + public void testGetRecordSummaryPrivateName() { + RecordSummary record = (RecordSummary) publicRecordController.getSummaryRecord(unclaimedUserOrcid).getValue(); + + assertNull(record.getName()); + } }