Skip to content

Commit

Permalink
fix: Remove field from response if its private
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielPalafox committed Aug 9, 2023
1 parent bb23c90 commit 18e4132
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand All @@ -332,27 +335,35 @@ 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) {
recordSummary.setStatus("deprecated");
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
Expand All @@ -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)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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());
Expand Down Expand Up @@ -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());

Expand All @@ -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());
Expand All @@ -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());
}
}

0 comments on commit 18e4132

Please sign in to comment.