Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add professional email source name to api responses #7142

Merged
merged 24 commits into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.orcid.api.common.util.ApiUtils;
import org.orcid.api.common.util.ElementUtils;
import org.orcid.api.memberV2.server.delegator.MemberV2ApiServiceDelegator;
import org.orcid.core.common.manager.EmailDomainManager;
import org.orcid.core.exception.DuplicatedGroupIdRecordException;
import org.orcid.core.exception.MismatchedPutCodeException;
import org.orcid.core.exception.OrcidAccessControlException;
Expand Down Expand Up @@ -57,6 +58,7 @@
import org.orcid.core.manager.read_only.ResearcherUrlManagerReadOnly;
import org.orcid.core.manager.read_only.WorkManagerReadOnly;
import org.orcid.core.utils.ContributorUtils;
import org.orcid.core.utils.SourceEntityUtils;
import org.orcid.core.utils.SourceUtils;
import org.orcid.core.version.impl.Api2_0_LastModifiedDatesHelper;
import org.orcid.jaxb.model.client_v2.ClientSummary;
Expand Down Expand Up @@ -98,6 +100,7 @@
import org.orcid.jaxb.model.record_v2.Work;
import org.orcid.jaxb.model.record_v2.WorkBulk;
import org.orcid.jaxb.model.search_v2.Search;
import org.orcid.persistence.jpa.entities.EmailDomainEntity;
import org.springframework.context.MessageSource;
import org.springframework.stereotype.Component;

Expand Down Expand Up @@ -231,6 +234,12 @@ public class MemberV2ApiServiceDelegatorImpl implements
@Resource
private ApiUtils apiUtils;

@Resource
private EmailDomainManager emailDomainManager;

@Resource
private SourceEntityUtils sourceEntityUtils;

@Override
public Response viewStatusText() {
return Response.ok(STATUS_OK_MESSAGE).build();
Expand Down Expand Up @@ -787,6 +796,8 @@ public Response viewEmails(String orcid) {
orcidSecurityManager.checkAndFilter(orcid, emails.getEmails(), ScopePathType.ORCID_BIO_READ_LIMITED);
}

processProfessionalEmails(emails);

ElementUtils.setPathToEmail(emails, orcid);
Api2_0_LastModifiedDatesHelper.calculateLastModified(emails);
sourceUtils.setSourceName(emails);
Expand Down Expand Up @@ -1101,6 +1112,19 @@ private void validateSearchParams(Map<String, List<String>> queryMap) {
}
}

private void processProfessionalEmails(Emails emails) {
for (Email email : emails.getEmails()) {
if (email.isVerified()) {
String domain = email.getEmail().split("@")[1];
EmailDomainEntity domainInfo = emailDomainManager.findByEmailDomain(domain);
// Set appropriate source name and source id for professional emails
if (domainInfo != null && domainInfo.getCategory().equals(EmailDomainEntity.DomainCategory.PROFESSIONAL)) {
email.setSource(sourceEntityUtils.convertEmailSourceToOrcidValidator(email.getSource()));
}
}
}
}

@Override
public Response viewClient(String clientId) {
orcidSecurityManager.checkScopes(ScopePathType.READ_PUBLIC);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.orcid.api.common.util.v3.ActivityUtils;
import org.orcid.api.common.util.v3.ElementUtils;
import org.orcid.api.memberV3.server.delegator.MemberV3ApiServiceDelegator;
import org.orcid.core.common.manager.EmailDomainManager;
import org.orcid.core.common.manager.SummaryManager;
import org.orcid.core.exception.DeactivatedException;
import org.orcid.core.exception.DuplicatedGroupIdRecordException;
Expand Down Expand Up @@ -128,6 +129,7 @@
import org.orcid.jaxb.model.v3.release.record.summary.Works;
import org.orcid.jaxb.model.v3.release.search.Search;
import org.orcid.jaxb.model.v3.release.search.expanded.ExpandedSearch;
import org.orcid.persistence.jpa.entities.EmailDomainEntity;
import org.springframework.context.MessageSource;
import org.springframework.stereotype.Component;

Expand Down Expand Up @@ -271,7 +273,13 @@ public class MemberV3ApiServiceDelegatorImpl implements

@Resource
private SummaryManager summaryManager;


@Resource
private EmailDomainManager emailDomainManager;

@Resource
private SourceEntityUtils sourceEntityUtils;

public Boolean getFilterVersionOfIdentifiers() {
return filterVersionOfIdentifiers;
}
Expand Down Expand Up @@ -877,6 +885,8 @@ public Response viewEmails(String orcid) {
orcidSecurityManager.checkAndFilter(orcid, emails.getEmails(), ScopePathType.ORCID_BIO_READ_LIMITED);
}

processProfessionalEmails(emails);

ElementUtils.setPathToEmail(emails, orcid);
Api3_0LastModifiedDatesHelper.calculateLastModified(emails);
sourceUtils.setSourceName(emails);
Expand Down Expand Up @@ -1217,6 +1227,19 @@ private void validateSearchParams(Map<String, List<String>> queryMap) {
}
}

private void processProfessionalEmails(Emails emails) {
for (Email email : emails.getEmails()) {
if (email.isVerified()) {
String domain = email.getEmail().split("@")[1];
EmailDomainEntity domainInfo = emailDomainManager.findByEmailDomain(domain);
// Set appropriate source name and source id for professional emails
if (domainInfo != null && domainInfo.getCategory().equals(EmailDomainEntity.DomainCategory.PROFESSIONAL)) {
email.setSource(sourceEntityUtils.convertEmailSourceToOrcidValidator(email.getSource()));
}
}
}
}

@Override
public Response viewClient(String clientId) {
orcidSecurityManager.checkScopes(ScopePathType.READ_PUBLIC);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,12 @@ public void testReadPublicScope_Emails() {
assertNotNull(email);
assertEquals("/0000-0000-0000-0003/email", email.getPath());
Utils.verifyLastModified(email.getLastModifiedDate());
assertEquals(3, email.getEmails().size());
assertEquals(4, email.getEmails().size());
boolean found1 = false;
boolean found2 = false;
boolean found3 = false;
boolean found4 = false;

for (Email element : email.getEmails()) {
Utils.verifyLastModified(element.getLastModifiedDate());
if (element.getEmail().equals("[email protected]")) {
Expand All @@ -100,14 +102,18 @@ public void testReadPublicScope_Emails() {
found2 = true;
} else if (element.getEmail().equals("[email protected]")) {
found3 = true;
} else {
} else if (element.getEmail().equals("[email protected]")) {
found4 = true;
}
else {
fail("Invalid put code " + element.getPutCode());
}

}
assertTrue(found1);
assertTrue(found2);
assertTrue(found3);
assertTrue(found4);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public void testViewPerson() {
Emails email = p.getEmails();
assertNotNull(email);
Utils.verifyLastModified(email.getLastModifiedDate());
assertEquals(4, email.getEmails().size());
assertEquals(5, email.getEmails().size());

found1 = false;
found2 = false;
Expand All @@ -164,6 +164,8 @@ public void testViewPerson() {
found3 = true;
} else if (element.getEmail().equals("[email protected]")) {
found4 = true;
} else if (element.getEmail().equals("[email protected]")) {
found5 = true;
} else {
fail("Invalid email " + element.getEmail());
}
Expand All @@ -173,6 +175,7 @@ public void testViewPerson() {
assertTrue(found2);
assertTrue(found3);
assertTrue(found4);
assertTrue(found5);

// External identifiers
assertNotNull(p.getExternalIdentifiers());
Expand Down Expand Up @@ -356,12 +359,14 @@ private void testPerson(Person p, String orcid) {
Emails email = p.getEmails();
assertNotNull(email);
Utils.verifyLastModified(email.getLastModifiedDate());
assertEquals(3, email.getEmails().size());
assertEquals(4, email.getEmails().size());
assertEquals("[email protected]", email.getEmails().get(0).getEmail());
assertEquals("[email protected]", email.getEmails().get(1).getEmail());

found1 = false;
found2 = false;
found3 = false;
found4 = false;

for (Email element : email.getEmails()) {
if (element.getEmail().equals("[email protected]")) {
Expand All @@ -370,6 +375,8 @@ private void testPerson(Person p, String orcid) {
found2 = true;
} else if (element.getEmail().equals("[email protected]")) {
found3 = true;
} else if (element.getEmail().equals("[email protected]")) {
found4 = true;
} else {
fail("Invalid email " + element.getEmail());
}
Expand All @@ -378,6 +385,7 @@ private void testPerson(Person p, String orcid) {
assertTrue(found1);
assertTrue(found2);
assertTrue(found3);
assertTrue(found4);

// External identifiers
assertNotNull(p.getExternalIdentifiers());
Expand Down Expand Up @@ -514,9 +522,9 @@ public void testReadPrivateEmails_OtherThingsJustPublic_Person() {
Emails email = p.getEmails();
assertNotNull(email);
Utils.verifyLastModified(email.getLastModifiedDate());
assertEquals(4, email.getEmails().size());
assertEquals(5, email.getEmails().size());

boolean found1 = false, found2 = false, found3 = false, found4 = false;
boolean found1 = false, found2 = false, found3 = false, found4 = false, found5 = false;

for (Email element : email.getEmails()) {
if (element.getEmail().equals("[email protected]")) {
Expand All @@ -527,6 +535,8 @@ public void testReadPrivateEmails_OtherThingsJustPublic_Person() {
found3 = true;
} else if (element.getEmail().equals("[email protected]")) {
found4 = true;
} else if (element.getEmail().equals("[email protected]")) {
found5 = true;
} else {
fail("Invalid email " + element.getEmail());
}
Expand All @@ -536,6 +546,7 @@ public void testReadPrivateEmails_OtherThingsJustPublic_Person() {
assertTrue(found2);
assertTrue(found3);
assertTrue(found4);
assertTrue(found5);
this.assertAllPublicButEmails(p);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public class MemberV2ApiServiceDelegator_ReadRecordTest extends DBUnitTest {
"/data/Oauth2TokenDetailsData.xml", "/data/OrgsEntityData.xml", "/data/ProfileFundingEntityData.xml", "/data/OrgAffiliationEntityData.xml",
"/data/PeerReviewEntityData.xml", "/data/GroupIdRecordEntityData.xml", "/data/RecordNameEntityData.xml", "/data/BiographyEntityData.xml");

// Now on, for any new test, PLAESE USER THIS ORCID ID
// Now on, for any new test, PLEASE USER THIS ORCID ID
protected final String ORCID = "0000-0000-0000-0003";

@Resource(name = "memberV2ApiServiceDelegator")
Expand Down Expand Up @@ -223,21 +223,34 @@ public void testViewRecord() {
assertNotNull(person.getEmails());
Utils.verifyLastModified(person.getEmails().getLastModifiedDate());
assertEquals("/0000-0000-0000-0003/email", person.getEmails().getPath());
assertEquals(4, person.getEmails().getEmails().size());
assertEquals(5, person.getEmails().getEmails().size());
for (Email email : person.getEmails().getEmails()) {
Utils.verifyLastModified(email.getLastModifiedDate());
if (email.getEmail().equals("[email protected]")) {
assertEquals("APP-5555555555555555", email.getSource().retrieveSourcePath());
assertEquals(Visibility.PUBLIC.value(), email.getVisibility().value());
assertNull(email.getSource().getSourceOrcid());
assertEquals(org.orcid.jaxb.model.common_v2.Visibility.PUBLIC.value(), email.getVisibility().value());
assertEquals("Source Client 1", email.getSource().getSourceName().getContent());
} else if (email.getEmail().equals("[email protected]")) {
assertEquals("APP-5555555555555555", email.getSource().retrieveSourcePath());
assertEquals(Visibility.LIMITED.value(), email.getVisibility().value());
assertNull(email.getSource().getSourceOrcid());
assertEquals(org.orcid.jaxb.model.common_v2.Visibility.LIMITED.value(), email.getVisibility().value());
assertEquals("Source Client 1", email.getSource().getSourceName().getContent());
} else if (email.getEmail().equals("[email protected]")) {
assertEquals("APP-5555555555555555", email.getSource().retrieveSourcePath());
assertEquals(Visibility.PRIVATE.value(), email.getVisibility().value());
assertNull(email.getSource().getSourceOrcid());
assertEquals(org.orcid.jaxb.model.common_v2.Visibility.PRIVATE.value(), email.getVisibility().value());
assertEquals("Source Client 1", email.getSource().getSourceName().getContent());
} else if (email.getEmail().equals("[email protected]")) {
assertEquals("0000-0000-0000-0003", email.getSource().retrieveSourcePath());
assertEquals(Visibility.LIMITED.value(), email.getVisibility().value());
assertNotNull(email.getSource().getSourceOrcid());
assertEquals(org.orcid.jaxb.model.common_v2.Visibility.LIMITED.value(), email.getVisibility().value());
assertEquals("Credit Name", email.getSource().getSourceName().getContent());
} else if (email.getEmail().equals("[email protected]")) {
assertEquals("0000-0000-0000-0000", email.getSource().retrieveSourcePath());
assertNull(email.getSource().getSourceOrcid());
assertEquals(org.orcid.jaxb.model.common_v2.Visibility.PUBLIC.value(), email.getVisibility().value());
assertEquals("ORCID email validation", email.getSource().getSourceName().getContent());
} else {
fail("Invalid email found: " + email.getEmail());
}
Expand Down Expand Up @@ -842,12 +855,13 @@ private void testPerson(Person p, String orcid) {
Emails email = p.getEmails();
assertNotNull(email);
Utils.verifyLastModified(email.getLastModifiedDate());
assertEquals(3, email.getEmails().size());
assertEquals(4, email.getEmails().size());
assertEquals("[email protected]", email.getEmails().get(0).getEmail());

found1 = false;
found2 = false;
found3 = false;
found4 = false;

for (Email element : email.getEmails()) {
if (element.getEmail().equals("[email protected]")) {
Expand All @@ -856,6 +870,8 @@ private void testPerson(Person p, String orcid) {
found2 = true;
} else if (element.getEmail().equals("[email protected]")) {
found3 = true;
} else if (element.getEmail().equals("[email protected]")) {
found4 = true;
} else {
fail("Invalid email " + element.getEmail());
}
Expand All @@ -864,6 +880,7 @@ private void testPerson(Person p, String orcid) {
assertTrue(found1);
assertTrue(found2);
assertTrue(found3);
assertTrue(found4);

// External identifiers
assertNotNull(p.getExternalIdentifiers());
Expand Down Expand Up @@ -1004,9 +1021,9 @@ public void testReadPrivateEmails_OtherThingsJustPublic_Record() {
Emails email = p.getEmails();
assertNotNull(email);
Utils.verifyLastModified(email.getLastModifiedDate());
assertEquals(4, email.getEmails().size());
assertEquals(5, email.getEmails().size());

boolean found1 = false, found2 = false, found3 = false, found4 = false;
boolean found1 = false, found2 = false, found3 = false, found4 = false, found5 = false;

for (Email element : email.getEmails()) {
if (element.getEmail().equals("[email protected]")) {
Expand All @@ -1017,6 +1034,8 @@ public void testReadPrivateEmails_OtherThingsJustPublic_Record() {
found3 = true;
} else if (element.getEmail().equals("[email protected]")) {
found4 = true;
} else if (element.getEmail().equals("[email protected]")) {
found5 = true;
} else {
fail("Invalid email " + element.getEmail());
}
Expand All @@ -1026,6 +1045,8 @@ public void testReadPrivateEmails_OtherThingsJustPublic_Record() {
assertTrue(found2);
assertTrue(found3);
assertTrue(found4);
assertTrue(found5);


this.assertAllPublicButEmails(p);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,11 @@ public void testReadPublicScope_Emails() {
assertNotNull(email);
assertEquals("/0000-0000-0000-0003/email", email.getPath());
Utils.verifyLastModified(email.getLastModifiedDate());
assertEquals(3, email.getEmails().size());
assertEquals(4, email.getEmails().size());
boolean found1 = false;
boolean found2 = false;
boolean found3 = false;
boolean found4 = false;
for (Email element : email.getEmails()) {
Utils.verifyLastModified(element.getLastModifiedDate());
if (element.getEmail().equals("[email protected]")) {
Expand All @@ -111,6 +112,8 @@ public void testReadPublicScope_Emails() {
found2 = true;
} else if (element.getEmail().equals("[email protected]")) {
found3 = true;
} else if (element.getEmail().equals("[email protected]")) {
found4 = true;
} else {
fail("Invalid put code " + element.getPutCode());
}
Expand All @@ -119,6 +122,7 @@ public void testReadPublicScope_Emails() {
assertTrue(found1);
assertTrue(found2);
assertTrue(found3);
assertTrue(found4);
}

@Test
Expand Down
Loading