From da732775d4c90da75af3e000cba3106a610e41f8 Mon Sep 17 00:00:00 2001 From: andrej romanov <50377758+auumgn@users.noreply.github.com> Date: Tue, 19 Nov 2024 22:37:20 +0200 Subject: [PATCH 01/23] add professional email source name to api responses --- .../impl/MemberV2ApiServiceDelegatorImpl.java | 17 ++++++++++++++++ .../impl/MemberV3ApiServiceDelegatorImpl.java | 20 ++++++++++++++++++- .../orcid/core/constants/EmailConstants.java | 4 +++- .../PersonDetailsManagerReadOnlyImpl.java | 20 +++++++++++++++++++ .../PersonDetailsManagerReadOnlyImpl.java | 20 +++++++++++++++++++ .../org/orcid/core/utils/SourceUtils.java | 5 ++++- .../org/orcid/core/utils/v3/SourceUtils.java | 5 ++++- .../src/main/resources/orcid-core-context.xml | 2 ++ 8 files changed, 89 insertions(+), 4 deletions(-) diff --git a/orcid-api-web/src/main/java/org/orcid/api/memberV2/server/delegator/impl/MemberV2ApiServiceDelegatorImpl.java b/orcid-api-web/src/main/java/org/orcid/api/memberV2/server/delegator/impl/MemberV2ApiServiceDelegatorImpl.java index 5777518cca2..b01568ce7ba 100644 --- a/orcid-api-web/src/main/java/org/orcid/api/memberV2/server/delegator/impl/MemberV2ApiServiceDelegatorImpl.java +++ b/orcid-api-web/src/main/java/org/orcid/api/memberV2/server/delegator/impl/MemberV2ApiServiceDelegatorImpl.java @@ -1,6 +1,7 @@ package org.orcid.api.memberV2.server.delegator.impl; import static org.orcid.core.api.OrcidApiConstants.STATUS_OK_MESSAGE; +import static org.orcid.core.constants.EmailConstants.ORCID_EMAIL_VALIDATION; import java.util.ArrayList; import java.util.Arrays; @@ -18,6 +19,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; @@ -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; @@ -231,6 +234,9 @@ public class MemberV2ApiServiceDelegatorImpl implements @Resource private ApiUtils apiUtils; + @Resource + private EmailDomainManager emailDomainManager; + @Override public Response viewStatusText() { return Response.ok(STATUS_OK_MESSAGE).build(); @@ -787,6 +793,17 @@ public Response viewEmails(String orcid) { orcidSecurityManager.checkAndFilter(orcid, emails.getEmails(), ScopePathType.ORCID_BIO_READ_LIMITED); } + for (Email email : emails.getEmails()) { + if (email.isVerified()) { + String domain = email.getEmail().split("@")[1]; + EmailDomainEntity domainInfo = emailDomainManager.findByEmailDomain(domain); + // Set appropriate source name for professional emails + if (domainInfo != null && domainInfo.getCategory().equals(EmailDomainEntity.DomainCategory.PROFESSIONAL)) { + email.getSource().getSourceName().setContent(ORCID_EMAIL_VALIDATION); + } + } + } + ElementUtils.setPathToEmail(emails, orcid); Api2_0_LastModifiedDatesHelper.calculateLastModified(emails); sourceUtils.setSourceName(emails); diff --git a/orcid-api-web/src/main/java/org/orcid/api/memberV3/server/delegator/impl/MemberV3ApiServiceDelegatorImpl.java b/orcid-api-web/src/main/java/org/orcid/api/memberV3/server/delegator/impl/MemberV3ApiServiceDelegatorImpl.java index aebd8cf6873..1edcad53394 100644 --- a/orcid-api-web/src/main/java/org/orcid/api/memberV3/server/delegator/impl/MemberV3ApiServiceDelegatorImpl.java +++ b/orcid-api-web/src/main/java/org/orcid/api/memberV3/server/delegator/impl/MemberV3ApiServiceDelegatorImpl.java @@ -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; @@ -128,9 +129,12 @@ 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; +import static org.orcid.core.constants.EmailConstants.ORCID_EMAIL_VALIDATION; + @Component public class MemberV3ApiServiceDelegatorImpl implements MemberV3ApiServiceDelegator { @@ -271,7 +275,10 @@ public class MemberV3ApiServiceDelegatorImpl implements @Resource private SummaryManager summaryManager; - + + @Resource + private EmailDomainManager emailDomainManager; + public Boolean getFilterVersionOfIdentifiers() { return filterVersionOfIdentifiers; } @@ -877,6 +884,17 @@ public Response viewEmails(String orcid) { orcidSecurityManager.checkAndFilter(orcid, emails.getEmails(), ScopePathType.ORCID_BIO_READ_LIMITED); } + for (Email email : emails.getEmails()) { + if (email.isVerified()) { + String domain = email.getEmail().split("@")[1]; + EmailDomainEntity domainInfo = emailDomainManager.findByEmailDomain(domain); + // Set appropriate source name for professional emails + if (domainInfo != null && domainInfo.getCategory().equals(EmailDomainEntity.DomainCategory.PROFESSIONAL)) { + email.getSource().getSourceName().setContent(ORCID_EMAIL_VALIDATION); + } + } + } + ElementUtils.setPathToEmail(emails, orcid); Api3_0LastModifiedDatesHelper.calculateLastModified(emails); sourceUtils.setSourceName(emails); diff --git a/orcid-core/src/main/java/org/orcid/core/constants/EmailConstants.java b/orcid-core/src/main/java/org/orcid/core/constants/EmailConstants.java index b7e4f673930..94a52a31040 100644 --- a/orcid-core/src/main/java/org/orcid/core/constants/EmailConstants.java +++ b/orcid-core/src/main/java/org/orcid/core/constants/EmailConstants.java @@ -8,7 +8,9 @@ public class EmailConstants { * session attribute that is used to see if we should check and notify the * user if their primary email ins't verified. */ - public static String CHECK_EMAIL_VALIDATED = "CHECK_EMAIL_VALIDATED"; + public static String CHECK_EMAIL_VALIDATED = "CHECK_EMAIL_VALIDATED"; + + public static final String ORCID_EMAIL_VALIDATION = "ORCID email validation"; public static final int MAX_EMAIL_COUNT = 30; diff --git a/orcid-core/src/main/java/org/orcid/core/manager/read_only/impl/PersonDetailsManagerReadOnlyImpl.java b/orcid-core/src/main/java/org/orcid/core/manager/read_only/impl/PersonDetailsManagerReadOnlyImpl.java index 404dd3267bf..219308d6418 100644 --- a/orcid-core/src/main/java/org/orcid/core/manager/read_only/impl/PersonDetailsManagerReadOnlyImpl.java +++ b/orcid-core/src/main/java/org/orcid/core/manager/read_only/impl/PersonDetailsManagerReadOnlyImpl.java @@ -3,6 +3,7 @@ import java.util.ArrayList; import java.util.stream.Collectors; +import org.orcid.core.common.manager.EmailDomainManager; import org.orcid.core.manager.read_only.AddressManagerReadOnly; import org.orcid.core.manager.read_only.BiographyManagerReadOnly; import org.orcid.core.manager.read_only.EmailManagerReadOnly; @@ -28,6 +29,9 @@ import org.orcid.jaxb.model.record_v2.PersonExternalIdentifiers; import org.orcid.jaxb.model.record_v2.ResearcherUrl; import org.orcid.jaxb.model.record_v2.ResearcherUrls; +import org.orcid.persistence.jpa.entities.EmailDomainEntity; + +import static org.orcid.core.constants.EmailConstants.ORCID_EMAIL_VALIDATION; public class PersonDetailsManagerReadOnlyImpl extends ManagerReadOnlyBaseImpl implements PersonDetailsManagerReadOnly { @@ -47,6 +51,8 @@ public class PersonDetailsManagerReadOnlyImpl extends ManagerReadOnlyBaseImpl im protected BiographyManagerReadOnly biographyManager; + private EmailDomainManager emailDomainManager; + public void setAddressManager(AddressManagerReadOnly addressManager) { this.addressManager = addressManager; } @@ -79,6 +85,10 @@ public void setBiographyManager(BiographyManagerReadOnly biographyManager) { this.biographyManager = biographyManager; } + public void setEmailDomainManager(EmailDomainManager emailDomainManager) { + this.emailDomainManager = emailDomainManager; + } + @Override public Person getPersonDetails(String orcid) { Person person = new Person(); @@ -124,6 +134,16 @@ public Person getPersonDetails(String orcid) { if (emails.getEmails() != null) { Emails filteredEmails = new Emails(); filteredEmails.setEmails(new ArrayList(emails.getEmails().stream().filter(e -> e.isVerified()).collect(Collectors.toList()))); + for (Email email : filteredEmails.getEmails()) { + if (email.isVerified()) { + String domain = email.getEmail().split("@")[1]; + EmailDomainEntity domainInfo = emailDomainManager.findByEmailDomain(domain); + // Set appropriate source name for professional emails + if (domainInfo != null && domainInfo.getCategory().equals(EmailDomainEntity.DomainCategory.PROFESSIONAL)) { + email.getSource().getSourceName().setContent(ORCID_EMAIL_VALIDATION); + } + } + } person.setEmails(filteredEmails); } return person; diff --git a/orcid-core/src/main/java/org/orcid/core/manager/v3/read_only/impl/PersonDetailsManagerReadOnlyImpl.java b/orcid-core/src/main/java/org/orcid/core/manager/v3/read_only/impl/PersonDetailsManagerReadOnlyImpl.java index 9788f371603..e6bdae417f7 100644 --- a/orcid-core/src/main/java/org/orcid/core/manager/v3/read_only/impl/PersonDetailsManagerReadOnlyImpl.java +++ b/orcid-core/src/main/java/org/orcid/core/manager/v3/read_only/impl/PersonDetailsManagerReadOnlyImpl.java @@ -3,6 +3,7 @@ import java.util.ArrayList; import java.util.stream.Collectors; +import org.orcid.core.common.manager.EmailDomainManager; import org.orcid.core.manager.v3.read_only.AddressManagerReadOnly; import org.orcid.core.manager.v3.read_only.BiographyManagerReadOnly; import org.orcid.core.manager.v3.read_only.EmailManagerReadOnly; @@ -28,6 +29,9 @@ import org.orcid.jaxb.model.v3.release.record.PersonExternalIdentifiers; import org.orcid.jaxb.model.v3.release.record.ResearcherUrl; import org.orcid.jaxb.model.v3.release.record.ResearcherUrls; +import org.orcid.persistence.jpa.entities.EmailDomainEntity; + +import static org.orcid.core.constants.EmailConstants.ORCID_EMAIL_VALIDATION; public class PersonDetailsManagerReadOnlyImpl extends ManagerReadOnlyBaseImpl implements PersonDetailsManagerReadOnly { @@ -47,6 +51,8 @@ public class PersonDetailsManagerReadOnlyImpl extends ManagerReadOnlyBaseImpl im protected BiographyManagerReadOnly biographyManager; + protected EmailDomainManager emailDomainManager; + public void setAddressManager(AddressManagerReadOnly addressManager) { this.addressManager = addressManager; } @@ -79,6 +85,10 @@ public void setBiographyManager(BiographyManagerReadOnly biographyManager) { this.biographyManager = biographyManager; } + public void setEmailDomainManager(EmailDomainManager emailDomainManager) { + this.emailDomainManager = emailDomainManager; + } + @Override public Person getPersonDetails(String orcid, boolean includeUnverifiedEmails) { Person person = new Person(); @@ -129,6 +139,16 @@ public Person getPersonDetails(String orcid, boolean includeUnverifiedEmails) { } else { filteredEmails.setEmails(new ArrayList(emails.getEmails().stream().filter(e -> e.isVerified()).collect(Collectors.toList()))); } + for (Email email : filteredEmails.getEmails()) { + if (email.isVerified()) { + String domain = email.getEmail().split("@")[1]; + EmailDomainEntity domainInfo = emailDomainManager.findByEmailDomain(domain); + // Set appropriate source name for professional emails + if (domainInfo != null && domainInfo.getCategory().equals(EmailDomainEntity.DomainCategory.PROFESSIONAL)) { + email.getSource().getSourceName().setContent(ORCID_EMAIL_VALIDATION); + } + } + } person.setEmails(filteredEmails); } return person; diff --git a/orcid-core/src/main/java/org/orcid/core/utils/SourceUtils.java b/orcid-core/src/main/java/org/orcid/core/utils/SourceUtils.java index 0f519650717..02c86d6080b 100644 --- a/orcid-core/src/main/java/org/orcid/core/utils/SourceUtils.java +++ b/orcid-core/src/main/java/org/orcid/core/utils/SourceUtils.java @@ -39,6 +39,8 @@ import org.orcid.jaxb.model.record_v2.WorkBulk; import org.orcid.pojo.ajaxForm.PojoUtil; +import static org.orcid.core.constants.EmailConstants.ORCID_EMAIL_VALIDATION; + public class SourceUtils { private SourceNameCacheManager sourceNameCacheManager; @@ -51,7 +53,8 @@ public void setSourceName(SourceAware sourceAware) { Source source = sourceAware.getSource(); if (source != null) { String sourceId = source.retrieveSourcePath(); - if (!PojoUtil.isEmpty(sourceId)) { + String providedSourceName = source.getSourceName().getContent(); + if (!PojoUtil.isEmpty(sourceId) && !providedSourceName.equals(ORCID_EMAIL_VALIDATION)) { String sourceName = sourceNameCacheManager.retrieve(sourceId); if (!PojoUtil.isEmpty(sourceName)) { source.setSourceName(new SourceName(sourceName)); diff --git a/orcid-core/src/main/java/org/orcid/core/utils/v3/SourceUtils.java b/orcid-core/src/main/java/org/orcid/core/utils/v3/SourceUtils.java index 35c8dc4dc1d..42285b62fd2 100644 --- a/orcid-core/src/main/java/org/orcid/core/utils/v3/SourceUtils.java +++ b/orcid-core/src/main/java/org/orcid/core/utils/v3/SourceUtils.java @@ -48,6 +48,8 @@ import java.util.List; +import static org.orcid.core.constants.EmailConstants.ORCID_EMAIL_VALIDATION; + public class SourceUtils { private SourceNameCacheManager sourceNameCacheManager; @@ -60,7 +62,8 @@ public void setSourceName(SourceAware sourceAware) { Source source = sourceAware.getSource(); if (source != null) { String sourceId = source.retrieveSourcePath(); - if (!PojoUtil.isEmpty(sourceId)) { + String providedSourceName = source.getSourceName().getContent(); + if (!PojoUtil.isEmpty(sourceId) && !providedSourceName.equals(ORCID_EMAIL_VALIDATION)) { String sourceName = sourceNameCacheManager.retrieve(sourceId); if (!PojoUtil.isEmpty(sourceName)) { source.setSourceName(new SourceName(sourceName)); diff --git a/orcid-core/src/main/resources/orcid-core-context.xml b/orcid-core/src/main/resources/orcid-core-context.xml index 3402d3db718..3e8fe56325b 100644 --- a/orcid-core/src/main/resources/orcid-core-context.xml +++ b/orcid-core/src/main/resources/orcid-core-context.xml @@ -251,6 +251,7 @@ + @@ -599,6 +600,7 @@ + From b53a8ae4048cf80ff6c14a6359bcf1e649e788dd Mon Sep 17 00:00:00 2001 From: andrej romanov <50377758+auumgn@users.noreply.github.com> Date: Tue, 19 Nov 2024 22:51:47 +0200 Subject: [PATCH 02/23] add null check --- .../java/org/orcid/core/utils/SourceUtils.java | 14 ++++++++------ .../java/org/orcid/core/utils/v3/SourceUtils.java | 14 ++++++++------ 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/orcid-core/src/main/java/org/orcid/core/utils/SourceUtils.java b/orcid-core/src/main/java/org/orcid/core/utils/SourceUtils.java index 02c86d6080b..5c0e8ddae85 100644 --- a/orcid-core/src/main/java/org/orcid/core/utils/SourceUtils.java +++ b/orcid-core/src/main/java/org/orcid/core/utils/SourceUtils.java @@ -54,12 +54,14 @@ public void setSourceName(SourceAware sourceAware) { if (source != null) { String sourceId = source.retrieveSourcePath(); String providedSourceName = source.getSourceName().getContent(); - if (!PojoUtil.isEmpty(sourceId) && !providedSourceName.equals(ORCID_EMAIL_VALIDATION)) { - String sourceName = sourceNameCacheManager.retrieve(sourceId); - if (!PojoUtil.isEmpty(sourceName)) { - source.setSourceName(new SourceName(sourceName)); - } else { - source.setSourceName(null); + if (!PojoUtil.isEmpty(sourceId)) { + if (providedSourceName != null && !providedSourceName.equals(ORCID_EMAIL_VALIDATION)) { + String sourceName = sourceNameCacheManager.retrieve(sourceId); + if (!PojoUtil.isEmpty(sourceName)) { + source.setSourceName(new SourceName(sourceName)); + } else { + source.setSourceName(null); + } } } } diff --git a/orcid-core/src/main/java/org/orcid/core/utils/v3/SourceUtils.java b/orcid-core/src/main/java/org/orcid/core/utils/v3/SourceUtils.java index 42285b62fd2..ce1c46a9793 100644 --- a/orcid-core/src/main/java/org/orcid/core/utils/v3/SourceUtils.java +++ b/orcid-core/src/main/java/org/orcid/core/utils/v3/SourceUtils.java @@ -63,12 +63,14 @@ public void setSourceName(SourceAware sourceAware) { if (source != null) { String sourceId = source.retrieveSourcePath(); String providedSourceName = source.getSourceName().getContent(); - if (!PojoUtil.isEmpty(sourceId) && !providedSourceName.equals(ORCID_EMAIL_VALIDATION)) { - String sourceName = sourceNameCacheManager.retrieve(sourceId); - if (!PojoUtil.isEmpty(sourceName)) { - source.setSourceName(new SourceName(sourceName)); - } else { - source.setSourceName(null); + if (!PojoUtil.isEmpty(sourceId)) { + if (providedSourceName != null && !providedSourceName.equals(ORCID_EMAIL_VALIDATION)) { + String sourceName = sourceNameCacheManager.retrieve(sourceId); + if (!PojoUtil.isEmpty(sourceName)) { + source.setSourceName(new SourceName(sourceName)); + } else { + source.setSourceName(null); + } } } } From e305df8e0ef4cca935bb150ebaf1f3b015fdc461 Mon Sep 17 00:00:00 2001 From: andrej romanov <50377758+auumgn@users.noreply.github.com> Date: Wed, 20 Nov 2024 19:02:26 +0200 Subject: [PATCH 03/23] update tests --- ...rV2ApiServiceDelegator_ReadRecordTest.java | 13 +++++++++-- .../main/java/org/orcid/test/DBUnitTest.java | 3 ++- .../main/resources/data/ProfileEntityData.xml | 23 +++++++++++++++++-- 3 files changed, 34 insertions(+), 5 deletions(-) diff --git a/orcid-api-web/src/test/java/org/orcid/api/memberV2/server/delegator/MemberV2ApiServiceDelegator_ReadRecordTest.java b/orcid-api-web/src/test/java/org/orcid/api/memberV2/server/delegator/MemberV2ApiServiceDelegator_ReadRecordTest.java index 5f42ab91375..db65c7b9882 100644 --- a/orcid-api-web/src/test/java/org/orcid/api/memberV2/server/delegator/MemberV2ApiServiceDelegator_ReadRecordTest.java +++ b/orcid-api-web/src/test/java/org/orcid/api/memberV2/server/delegator/MemberV2ApiServiceDelegator_ReadRecordTest.java @@ -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") @@ -223,21 +223,30 @@ 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("public_0000-0000-0000-0003@test.orcid.org")) { assertEquals("APP-5555555555555555", email.getSource().retrieveSourcePath()); assertEquals(Visibility.PUBLIC.value(), email.getVisibility().value()); + assertEquals("Source Client 1", email.getSource().getSourceName().getContent()); } else if (email.getEmail().equals("limited_0000-0000-0000-0003@test.orcid.org")) { assertEquals("APP-5555555555555555", email.getSource().retrieveSourcePath()); assertEquals(Visibility.LIMITED.value(), email.getVisibility().value()); + assertEquals("Source Client 1", email.getSource().getSourceName().getContent()); } else if (email.getEmail().equals("private_0000-0000-0000-0003@test.orcid.org")) { assertEquals("APP-5555555555555555", email.getSource().retrieveSourcePath()); assertEquals(Visibility.PRIVATE.value(), email.getVisibility().value()); + assertEquals("Source Client 1", email.getSource().getSourceName().getContent()); } else if (email.getEmail().equals("self_limited_0000-0000-0000-0003@test.orcid.org")) { assertEquals("0000-0000-0000-0003", email.getSource().retrieveSourcePath()); assertEquals(Visibility.LIMITED.value(), email.getVisibility().value()); + assertEquals("Credit Name", email.getSource().getSourceName().getContent()); + } else if (email.getEmail().equals("public_0000-0000-0000-0003@orcid.org")) { + assertEquals("0000-0000-0000-0000", email.getSource().retrieveSourcePath()); + assertNull(email.getSource().getSourceOrcid()); + assertEquals(Visibility.PUBLIC.value(), email.getVisibility().value()); + assertEquals("ORCID email validation", email.getSource().getSourceName().getContent()); } else { fail("Invalid email found: " + email.getEmail()); } diff --git a/orcid-test/src/main/java/org/orcid/test/DBUnitTest.java b/orcid-test/src/main/java/org/orcid/test/DBUnitTest.java index 470ba8ab1ae..14f3160ca27 100644 --- a/orcid-test/src/main/java/org/orcid/test/DBUnitTest.java +++ b/orcid-test/src/main/java/org/orcid/test/DBUnitTest.java @@ -39,7 +39,7 @@ public class DBUnitTest { private static final String TEST_CORE_CONTEXT = "classpath:test-core-context.xml"; private static final String[] tables = new String[] { "profile", "orcid_social", "profile_event", "work", "researcher_url", - "given_permission_to", "external_identifier", "email", "email_event", "biography", "record_name", "other_name", "profile_keyword", "profile_patent", + "given_permission_to", "external_identifier", "email", "email_domain", "email_event", "biography", "record_name", "other_name", "profile_keyword", "profile_patent", "org_disambiguated", "org_disambiguated_external_identifier", "org", "org_affiliation_relation", "profile_funding", "funding_external_identifier", "address", "institution", "affiliation", "notification", "client_details", "client_secret", "oauth2_token_detail", "custom_email", "webhook", "granted_authority", "orcid_props", "peer_review", "peer_review_subject", "shibboleth_account", "group_id_record", "invalid_record_data_changes", @@ -134,6 +134,7 @@ private static void cleanClientSourcedProfiles(IDatabaseConnection connection) t dataSet.addTable("profile_event"); dataSet.addTable("researcher_url"); dataSet.addTable("email"); + dataSet.addTable("email_domain"); dataSet.addTable("email_event"); dataSet.addTable("external_identifier"); dataSet.addTable("org"); diff --git a/orcid-test/src/main/resources/data/ProfileEntityData.xml b/orcid-test/src/main/resources/data/ProfileEntityData.xml index c2efa79aed1..11c74d195ba 100644 --- a/orcid-test/src/main/resources/data/ProfileEntityData.xml +++ b/orcid-test/src/main/resources/data/ProfileEntityData.xml @@ -1826,7 +1826,7 @@ client_source_id="APP-5555555555555555" date_created="2016-01-01 00:00:00.00" last_modified="2016-01-01 00:00:00.00" - /> + /> + /> + + + + From 006689869c2311e67f973e196b4bd009c303b278 Mon Sep 17 00:00:00 2001 From: andrej romanov <50377758+auumgn@users.noreply.github.com> Date: Wed, 20 Nov 2024 19:02:37 +0200 Subject: [PATCH 04/23] refactor --- .../impl/MemberV2ApiServiceDelegatorImpl.java | 9 +++-- .../impl/MemberV3ApiServiceDelegatorImpl.java | 9 +++-- .../orcid/core/constants/EmailConstants.java | 4 +- .../PersonDetailsManagerReadOnlyImpl.java | 10 +++-- .../PersonDetailsManagerReadOnlyImpl.java | 10 +++-- .../orcid/core/utils/SourceEntityUtils.java | 40 +++++++++++++++++++ .../org/orcid/core/utils/SourceUtils.java | 4 +- .../org/orcid/core/utils/v3/SourceUtils.java | 4 +- 8 files changed, 72 insertions(+), 18 deletions(-) diff --git a/orcid-api-web/src/main/java/org/orcid/api/memberV2/server/delegator/impl/MemberV2ApiServiceDelegatorImpl.java b/orcid-api-web/src/main/java/org/orcid/api/memberV2/server/delegator/impl/MemberV2ApiServiceDelegatorImpl.java index b01568ce7ba..1f12355c0b9 100644 --- a/orcid-api-web/src/main/java/org/orcid/api/memberV2/server/delegator/impl/MemberV2ApiServiceDelegatorImpl.java +++ b/orcid-api-web/src/main/java/org/orcid/api/memberV2/server/delegator/impl/MemberV2ApiServiceDelegatorImpl.java @@ -1,7 +1,6 @@ package org.orcid.api.memberV2.server.delegator.impl; import static org.orcid.core.api.OrcidApiConstants.STATUS_OK_MESSAGE; -import static org.orcid.core.constants.EmailConstants.ORCID_EMAIL_VALIDATION; import java.util.ArrayList; import java.util.Arrays; @@ -59,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; @@ -237,6 +237,9 @@ public class MemberV2ApiServiceDelegatorImpl implements @Resource private EmailDomainManager emailDomainManager; + @Resource + private SourceEntityUtils sourceEntityUtils; + @Override public Response viewStatusText() { return Response.ok(STATUS_OK_MESSAGE).build(); @@ -797,9 +800,9 @@ public Response viewEmails(String orcid) { if (email.isVerified()) { String domain = email.getEmail().split("@")[1]; EmailDomainEntity domainInfo = emailDomainManager.findByEmailDomain(domain); - // Set appropriate source name for professional emails + // Set appropriate source name and source id for professional emails if (domainInfo != null && domainInfo.getCategory().equals(EmailDomainEntity.DomainCategory.PROFESSIONAL)) { - email.getSource().getSourceName().setContent(ORCID_EMAIL_VALIDATION); + email.setSource(sourceEntityUtils.convertEmailSourceToOrcidValidator(email.getSource())); } } } diff --git a/orcid-api-web/src/main/java/org/orcid/api/memberV3/server/delegator/impl/MemberV3ApiServiceDelegatorImpl.java b/orcid-api-web/src/main/java/org/orcid/api/memberV3/server/delegator/impl/MemberV3ApiServiceDelegatorImpl.java index 1edcad53394..70daa4569fd 100644 --- a/orcid-api-web/src/main/java/org/orcid/api/memberV3/server/delegator/impl/MemberV3ApiServiceDelegatorImpl.java +++ b/orcid-api-web/src/main/java/org/orcid/api/memberV3/server/delegator/impl/MemberV3ApiServiceDelegatorImpl.java @@ -133,8 +133,6 @@ import org.springframework.context.MessageSource; import org.springframework.stereotype.Component; -import static org.orcid.core.constants.EmailConstants.ORCID_EMAIL_VALIDATION; - @Component public class MemberV3ApiServiceDelegatorImpl implements MemberV3ApiServiceDelegator { @@ -279,6 +277,9 @@ public class MemberV3ApiServiceDelegatorImpl implements @Resource private EmailDomainManager emailDomainManager; + @Resource + private SourceEntityUtils sourceEntityUtils; + public Boolean getFilterVersionOfIdentifiers() { return filterVersionOfIdentifiers; } @@ -888,9 +889,9 @@ public Response viewEmails(String orcid) { if (email.isVerified()) { String domain = email.getEmail().split("@")[1]; EmailDomainEntity domainInfo = emailDomainManager.findByEmailDomain(domain); - // Set appropriate source name for professional emails + // Set appropriate source name and source id for professional emails if (domainInfo != null && domainInfo.getCategory().equals(EmailDomainEntity.DomainCategory.PROFESSIONAL)) { - email.getSource().getSourceName().setContent(ORCID_EMAIL_VALIDATION); + email.setSource(sourceEntityUtils.convertEmailSourceToOrcidValidator(email.getSource())); } } } diff --git a/orcid-core/src/main/java/org/orcid/core/constants/EmailConstants.java b/orcid-core/src/main/java/org/orcid/core/constants/EmailConstants.java index 94a52a31040..c7753c96364 100644 --- a/orcid-core/src/main/java/org/orcid/core/constants/EmailConstants.java +++ b/orcid-core/src/main/java/org/orcid/core/constants/EmailConstants.java @@ -10,7 +10,9 @@ public class EmailConstants { */ public static String CHECK_EMAIL_VALIDATED = "CHECK_EMAIL_VALIDATED"; - public static final String ORCID_EMAIL_VALIDATION = "ORCID email validation"; + public static final String ORCID_EMAIL_VALIDATOR_CLIENT_NAME = "ORCID email validation"; + + public static final String ORCID_EMAIL_VALIDATOR_CLIENT_ID = "0000-0000-0000-0000"; public static final int MAX_EMAIL_COUNT = 30; diff --git a/orcid-core/src/main/java/org/orcid/core/manager/read_only/impl/PersonDetailsManagerReadOnlyImpl.java b/orcid-core/src/main/java/org/orcid/core/manager/read_only/impl/PersonDetailsManagerReadOnlyImpl.java index 219308d6418..496a7c0af38 100644 --- a/orcid-core/src/main/java/org/orcid/core/manager/read_only/impl/PersonDetailsManagerReadOnlyImpl.java +++ b/orcid-core/src/main/java/org/orcid/core/manager/read_only/impl/PersonDetailsManagerReadOnlyImpl.java @@ -13,6 +13,7 @@ import org.orcid.core.manager.read_only.ProfileKeywordManagerReadOnly; import org.orcid.core.manager.read_only.RecordNameManagerReadOnly; import org.orcid.core.manager.read_only.ResearcherUrlManagerReadOnly; +import org.orcid.core.utils.SourceEntityUtils; import org.orcid.jaxb.model.common_v2.Visibility; import org.orcid.jaxb.model.record_v2.Address; import org.orcid.jaxb.model.record_v2.Addresses; @@ -31,7 +32,7 @@ import org.orcid.jaxb.model.record_v2.ResearcherUrls; import org.orcid.persistence.jpa.entities.EmailDomainEntity; -import static org.orcid.core.constants.EmailConstants.ORCID_EMAIL_VALIDATION; +import javax.annotation.Resource; public class PersonDetailsManagerReadOnlyImpl extends ManagerReadOnlyBaseImpl implements PersonDetailsManagerReadOnly { @@ -53,6 +54,9 @@ public class PersonDetailsManagerReadOnlyImpl extends ManagerReadOnlyBaseImpl im private EmailDomainManager emailDomainManager; + @Resource + private SourceEntityUtils sourceEntityUtils; + public void setAddressManager(AddressManagerReadOnly addressManager) { this.addressManager = addressManager; } @@ -138,9 +142,9 @@ public Person getPersonDetails(String orcid) { if (email.isVerified()) { String domain = email.getEmail().split("@")[1]; EmailDomainEntity domainInfo = emailDomainManager.findByEmailDomain(domain); - // Set appropriate source name for professional emails + // Set appropriate source name and source id for professional emails if (domainInfo != null && domainInfo.getCategory().equals(EmailDomainEntity.DomainCategory.PROFESSIONAL)) { - email.getSource().getSourceName().setContent(ORCID_EMAIL_VALIDATION); + email.setSource(sourceEntityUtils.convertEmailSourceToOrcidValidator(email.getSource())); } } } diff --git a/orcid-core/src/main/java/org/orcid/core/manager/v3/read_only/impl/PersonDetailsManagerReadOnlyImpl.java b/orcid-core/src/main/java/org/orcid/core/manager/v3/read_only/impl/PersonDetailsManagerReadOnlyImpl.java index e6bdae417f7..22169d58f50 100644 --- a/orcid-core/src/main/java/org/orcid/core/manager/v3/read_only/impl/PersonDetailsManagerReadOnlyImpl.java +++ b/orcid-core/src/main/java/org/orcid/core/manager/v3/read_only/impl/PersonDetailsManagerReadOnlyImpl.java @@ -13,6 +13,7 @@ import org.orcid.core.manager.v3.read_only.ProfileKeywordManagerReadOnly; import org.orcid.core.manager.v3.read_only.RecordNameManagerReadOnly; import org.orcid.core.manager.v3.read_only.ResearcherUrlManagerReadOnly; +import org.orcid.core.utils.SourceEntityUtils; import org.orcid.jaxb.model.v3.release.common.Visibility; import org.orcid.jaxb.model.v3.release.record.Address; import org.orcid.jaxb.model.v3.release.record.Addresses; @@ -31,7 +32,7 @@ import org.orcid.jaxb.model.v3.release.record.ResearcherUrls; import org.orcid.persistence.jpa.entities.EmailDomainEntity; -import static org.orcid.core.constants.EmailConstants.ORCID_EMAIL_VALIDATION; +import javax.annotation.Resource; public class PersonDetailsManagerReadOnlyImpl extends ManagerReadOnlyBaseImpl implements PersonDetailsManagerReadOnly { @@ -53,6 +54,9 @@ public class PersonDetailsManagerReadOnlyImpl extends ManagerReadOnlyBaseImpl im protected EmailDomainManager emailDomainManager; + @Resource + protected SourceEntityUtils sourceEntityUtils; + public void setAddressManager(AddressManagerReadOnly addressManager) { this.addressManager = addressManager; } @@ -143,9 +147,9 @@ public Person getPersonDetails(String orcid, boolean includeUnverifiedEmails) { if (email.isVerified()) { String domain = email.getEmail().split("@")[1]; EmailDomainEntity domainInfo = emailDomainManager.findByEmailDomain(domain); - // Set appropriate source name for professional emails + // Set appropriate source name and source id for professional emails if (domainInfo != null && domainInfo.getCategory().equals(EmailDomainEntity.DomainCategory.PROFESSIONAL)) { - email.getSource().getSourceName().setContent(ORCID_EMAIL_VALIDATION); + email.setSource(sourceEntityUtils.convertEmailSourceToOrcidValidator(email.getSource())); } } } diff --git a/orcid-core/src/main/java/org/orcid/core/utils/SourceEntityUtils.java b/orcid-core/src/main/java/org/orcid/core/utils/SourceEntityUtils.java index ddf3ff0b336..1bceb29f3a6 100644 --- a/orcid-core/src/main/java/org/orcid/core/utils/SourceEntityUtils.java +++ b/orcid-core/src/main/java/org/orcid/core/utils/SourceEntityUtils.java @@ -17,11 +17,17 @@ import org.orcid.persistence.jpa.entities.SourceAwareEntity; import org.orcid.persistence.jpa.entities.SourceEntity; +import static org.orcid.core.constants.EmailConstants.ORCID_EMAIL_VALIDATOR_CLIENT_ID; +import static org.orcid.core.constants.EmailConstants.ORCID_EMAIL_VALIDATOR_CLIENT_NAME; + public class SourceEntityUtils { @Resource(name = "recordNameManagerReadOnlyV3") private RecordNameManagerReadOnly recordNameManagerReadOnlyV3; + @Resource + private OrcidUrlManager orcidUrlManager; + public String getSourceName(SourceEntity sourceEntity) { if (sourceEntity.getCachedSourceName() != null) { return sourceEntity.getCachedSourceName(); @@ -226,4 +232,38 @@ public static boolean isTheSameForPermissionChecking(Source activeSource, Source Source existing = extractSourceFromEntity(existingEntity, clientDetailsEntityCacheManager); return existing.equals(activeSource); } + + /** + * Convert source-orcid to source-client-id populated with ORCID email validator details + * + * @param source + * @return + */ + public Source convertEmailSourceToOrcidValidator(Source source) { + source.setSourceOrcid(null); + source.getSourceName().setContent(ORCID_EMAIL_VALIDATOR_CLIENT_NAME); + SourceClientId sourceClientId = new SourceClientId(ORCID_EMAIL_VALIDATOR_CLIENT_ID); + sourceClientId.setPath(ORCID_EMAIL_VALIDATOR_CLIENT_ID); + sourceClientId.setHost(orcidUrlManager.getBaseHost()); + sourceClientId.setUri(orcidUrlManager.getBaseUrl() + "/client/" + ORCID_EMAIL_VALIDATOR_CLIENT_ID); + source.setSourceClientId(sourceClientId); + return source; + } + + /** + * Convert source-orcid to source-client-id populated with ORCID email validator details + * + * @param source + * @return + */ + public org.orcid.jaxb.model.common_v2.Source convertEmailSourceToOrcidValidator(org.orcid.jaxb.model.common_v2.Source source) { + source.setSourceOrcid(null); + source.getSourceName().setContent(ORCID_EMAIL_VALIDATOR_CLIENT_NAME); + org.orcid.jaxb.model.common_v2.SourceClientId sourceClientId = new org.orcid.jaxb.model.common_v2.SourceClientId(ORCID_EMAIL_VALIDATOR_CLIENT_ID); + sourceClientId.setPath(ORCID_EMAIL_VALIDATOR_CLIENT_ID); + sourceClientId.setHost(orcidUrlManager.getBaseHost()); + sourceClientId.setUri(orcidUrlManager.getBaseUrl() + "/client/" + ORCID_EMAIL_VALIDATOR_CLIENT_ID); + source.setSourceClientId(sourceClientId); + return source; + } } diff --git a/orcid-core/src/main/java/org/orcid/core/utils/SourceUtils.java b/orcid-core/src/main/java/org/orcid/core/utils/SourceUtils.java index 5c0e8ddae85..650eeb05673 100644 --- a/orcid-core/src/main/java/org/orcid/core/utils/SourceUtils.java +++ b/orcid-core/src/main/java/org/orcid/core/utils/SourceUtils.java @@ -39,7 +39,7 @@ import org.orcid.jaxb.model.record_v2.WorkBulk; import org.orcid.pojo.ajaxForm.PojoUtil; -import static org.orcid.core.constants.EmailConstants.ORCID_EMAIL_VALIDATION; +import static org.orcid.core.constants.EmailConstants.ORCID_EMAIL_VALIDATOR_CLIENT_NAME; public class SourceUtils { private SourceNameCacheManager sourceNameCacheManager; @@ -55,7 +55,7 @@ public void setSourceName(SourceAware sourceAware) { String sourceId = source.retrieveSourcePath(); String providedSourceName = source.getSourceName().getContent(); if (!PojoUtil.isEmpty(sourceId)) { - if (providedSourceName != null && !providedSourceName.equals(ORCID_EMAIL_VALIDATION)) { + if (providedSourceName != null && !providedSourceName.equals(ORCID_EMAIL_VALIDATOR_CLIENT_NAME)) { String sourceName = sourceNameCacheManager.retrieve(sourceId); if (!PojoUtil.isEmpty(sourceName)) { source.setSourceName(new SourceName(sourceName)); diff --git a/orcid-core/src/main/java/org/orcid/core/utils/v3/SourceUtils.java b/orcid-core/src/main/java/org/orcid/core/utils/v3/SourceUtils.java index ce1c46a9793..90119e0f9ea 100644 --- a/orcid-core/src/main/java/org/orcid/core/utils/v3/SourceUtils.java +++ b/orcid-core/src/main/java/org/orcid/core/utils/v3/SourceUtils.java @@ -48,7 +48,7 @@ import java.util.List; -import static org.orcid.core.constants.EmailConstants.ORCID_EMAIL_VALIDATION; +import static org.orcid.core.constants.EmailConstants.ORCID_EMAIL_VALIDATOR_CLIENT_NAME; public class SourceUtils { private SourceNameCacheManager sourceNameCacheManager; @@ -64,7 +64,7 @@ public void setSourceName(SourceAware sourceAware) { String sourceId = source.retrieveSourcePath(); String providedSourceName = source.getSourceName().getContent(); if (!PojoUtil.isEmpty(sourceId)) { - if (providedSourceName != null && !providedSourceName.equals(ORCID_EMAIL_VALIDATION)) { + if (providedSourceName != null && !providedSourceName.equals(ORCID_EMAIL_VALIDATOR_CLIENT_NAME)) { String sourceName = sourceNameCacheManager.retrieve(sourceId); if (!PojoUtil.isEmpty(sourceName)) { source.setSourceName(new SourceName(sourceName)); From 7f2d2b38890875f8e8b9892dbc191677b42657b4 Mon Sep 17 00:00:00 2001 From: andrej romanov <50377758+auumgn@users.noreply.github.com> Date: Wed, 20 Nov 2024 19:06:39 +0200 Subject: [PATCH 05/23] update tests --- ...rV2ApiServiceDelegator_ReadRecordTest.java | 14 +++++++---- ...rV3ApiServiceDelegator_ReadRecordTest.java | 23 +++++++++++++++---- 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/orcid-api-web/src/test/java/org/orcid/api/memberV2/server/delegator/MemberV2ApiServiceDelegator_ReadRecordTest.java b/orcid-api-web/src/test/java/org/orcid/api/memberV2/server/delegator/MemberV2ApiServiceDelegator_ReadRecordTest.java index db65c7b9882..21629f64516 100644 --- a/orcid-api-web/src/test/java/org/orcid/api/memberV2/server/delegator/MemberV2ApiServiceDelegator_ReadRecordTest.java +++ b/orcid-api-web/src/test/java/org/orcid/api/memberV2/server/delegator/MemberV2ApiServiceDelegator_ReadRecordTest.java @@ -228,24 +228,28 @@ public void testViewRecord() { Utils.verifyLastModified(email.getLastModifiedDate()); if (email.getEmail().equals("public_0000-0000-0000-0003@test.orcid.org")) { 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("limited_0000-0000-0000-0003@test.orcid.org")) { 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("private_0000-0000-0000-0003@test.orcid.org")) { 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("self_limited_0000-0000-0000-0003@test.orcid.org")) { 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("public_0000-0000-0000-0003@orcid.org")) { assertEquals("0000-0000-0000-0000", email.getSource().retrieveSourcePath()); assertNull(email.getSource().getSourceOrcid()); - assertEquals(Visibility.PUBLIC.value(), email.getVisibility().value()); + 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()); diff --git a/orcid-api-web/src/test/java/org/orcid/api/memberV3/server/delegator/MemberV3ApiServiceDelegator_ReadRecordTest.java b/orcid-api-web/src/test/java/org/orcid/api/memberV3/server/delegator/MemberV3ApiServiceDelegator_ReadRecordTest.java index 65c5508cc1e..bb8ecf57165 100644 --- a/orcid-api-web/src/test/java/org/orcid/api/memberV3/server/delegator/MemberV3ApiServiceDelegator_ReadRecordTest.java +++ b/orcid-api-web/src/test/java/org/orcid/api/memberV3/server/delegator/MemberV3ApiServiceDelegator_ReadRecordTest.java @@ -235,21 +235,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("public_0000-0000-0000-0003@test.orcid.org")) { 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("limited_0000-0000-0000-0003@test.orcid.org")) { 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("private_0000-0000-0000-0003@test.orcid.org")) { 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("self_limited_0000-0000-0000-0003@test.orcid.org")) { 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("public_0000-0000-0000-0003@orcid.org")) { + 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()); } From 75f20b1b5cdd55233a4fb43631e9525b36139a87 Mon Sep 17 00:00:00 2001 From: andrej romanov <50377758+auumgn@users.noreply.github.com> Date: Wed, 20 Nov 2024 19:25:40 +0200 Subject: [PATCH 06/23] fix tests --- .../PublicV2ApiServiceDelegatorTest.java | 30 +++++++++++-------- 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/orcid-pub-web/src/test/java/org/orcid/api/publicV2/server/PublicV2ApiServiceDelegatorTest.java b/orcid-pub-web/src/test/java/org/orcid/api/publicV2/server/PublicV2ApiServiceDelegatorTest.java index c29e07a5684..7b6e283e743 100644 --- a/orcid-pub-web/src/test/java/org/orcid/api/publicV2/server/PublicV2ApiServiceDelegatorTest.java +++ b/orcid-pub-web/src/test/java/org/orcid/api/publicV2/server/PublicV2ApiServiceDelegatorTest.java @@ -1,11 +1,5 @@ package org.orcid.api.publicV2.server; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.ArrayList; @@ -21,10 +15,7 @@ import javax.ws.rs.WebApplicationException; import javax.ws.rs.core.Response; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.*; import org.junit.runner.RunWith; import org.mockito.Matchers; import org.mockito.Mockito; @@ -105,6 +96,8 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.google.common.collect.Sets; +import static org.junit.Assert.*; + @RunWith(OrcidJUnit4ClassRunner.class) @ContextConfiguration(locations = { "classpath:test-orcid-t1-web-context.xml" }) public class PublicV2ApiServiceDelegatorTest extends DBUnitTest { @@ -559,15 +552,23 @@ public void testViewEmails() { assertNotNull(emails.getLastModifiedDate()); assertNotNull(emails.getLastModifiedDate().getValue()); assertNotNull(emails.getEmails()); - assertEquals(1, emails.getEmails().size()); + assertEquals(2, emails.getEmails().size()); Email email = emails.getEmails().get(0); + Email email2 = emails.getEmails().get(1); assertNotNull(email.getLastModifiedDate()); assertNotNull(email.getLastModifiedDate().getValue()); + assertNotNull(email2.getLastModifiedDate()); + assertNotNull(email2.getLastModifiedDate().getValue()); assertEquals("public_0000-0000-0000-0003@test.orcid.org", email.getEmail()); + assertEquals("public_0000-0000-0000-0003@orcid.org", email2.getEmail()); assertTrue(email.isCurrent()); assertTrue(email.isPrimary()); assertTrue(email.isVerified()); + assertTrue(email2.isCurrent()); + assertFalse(email2.isPrimary()); + assertTrue(email2.isVerified()); assertEquals(Visibility.PUBLIC.value(), email.getVisibility().value()); + assertEquals(Visibility.PUBLIC.value(), email2.getVisibility().value()); assertEquals("/0000-0000-0000-0003/email", emails.getPath()); assertEquals("APP-5555555555555555", email.getSource().retrieveSourcePath()); } @@ -1290,13 +1291,18 @@ private void validatePerson(Person person) { assertNotNull(person.getEmails()); assertNotNull(person.getEmails().getLastModifiedDate()); assertNotNull(person.getEmails().getLastModifiedDate().getValue()); - assertEquals(1, person.getEmails().getEmails().size()); + assertEquals(2, person.getEmails().getEmails().size()); Email email = person.getEmails().getEmails().get(0); + Email email2 = person.getEmails().getEmails().get(1); assertEquals("public_0000-0000-0000-0003@test.orcid.org", email.getEmail()); + assertEquals("public_0000-0000-0000-0003@orcid.org", email2.getEmail()); assertNotNull(email.getLastModifiedDate()); assertNotNull(email.getLastModifiedDate().getValue()); + assertNotNull(email2.getLastModifiedDate()); + assertNotNull(email2.getLastModifiedDate().getValue()); assertEquals("APP-5555555555555555", email.getSource().retrieveSourcePath()); assertEquals(Visibility.PUBLIC.value(), email.getVisibility().value()); + assertEquals(Visibility.PUBLIC.value(), email2.getVisibility().value()); assertNotNull(person.getExternalIdentifiers()); assertNotNull(person.getExternalIdentifiers().getLastModifiedDate()); assertNotNull(person.getExternalIdentifiers().getLastModifiedDate().getValue()); From 3acf91dfdbd42f6d5544699b73fc1fefebd2652f Mon Sep 17 00:00:00 2001 From: andrej romanov <50377758+auumgn@users.noreply.github.com> Date: Wed, 20 Nov 2024 19:27:46 +0200 Subject: [PATCH 07/23] fix more tests --- .../server/PublicV3ApiServiceDelegatorTest.java | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/orcid-pub-web/src/test/java/org/orcid/api/publicV3/server/PublicV3ApiServiceDelegatorTest.java b/orcid-pub-web/src/test/java/org/orcid/api/publicV3/server/PublicV3ApiServiceDelegatorTest.java index b088b09c2c6..408dd2b1a25 100644 --- a/orcid-pub-web/src/test/java/org/orcid/api/publicV3/server/PublicV3ApiServiceDelegatorTest.java +++ b/orcid-pub-web/src/test/java/org/orcid/api/publicV3/server/PublicV3ApiServiceDelegatorTest.java @@ -579,15 +579,23 @@ public void testViewEmails() { assertNotNull(emails.getLastModifiedDate()); assertNotNull(emails.getLastModifiedDate().getValue()); assertNotNull(emails.getEmails()); - assertEquals(1, emails.getEmails().size()); + assertEquals(2, emails.getEmails().size()); Email email = emails.getEmails().get(0); + Email email2 = emails.getEmails().get(1); assertNotNull(email.getLastModifiedDate()); assertNotNull(email.getLastModifiedDate().getValue()); + assertNotNull(email2.getLastModifiedDate()); + assertNotNull(email2.getLastModifiedDate().getValue()); assertEquals("public_0000-0000-0000-0003@test.orcid.org", email.getEmail()); + assertEquals("public_0000-0000-0000-0003@orcid.org", email2.getEmail()); assertTrue(email.isCurrent()); assertTrue(email.isPrimary()); assertTrue(email.isVerified()); + assertTrue(email2.isCurrent()); + assertFalse(email2.isPrimary()); + assertTrue(email2.isVerified()); assertEquals(Visibility.PUBLIC.value(), email.getVisibility().value()); + assertEquals(Visibility.PUBLIC.value(), email2.getVisibility().value()); assertEquals("/0000-0000-0000-0003/email", emails.getPath()); assertEquals("APP-5555555555555555", email.getSource().retrieveSourcePath()); } @@ -1814,13 +1822,18 @@ private void validatePerson(Person person) { assertNotNull(person.getEmails()); assertNotNull(person.getEmails().getLastModifiedDate()); assertNotNull(person.getEmails().getLastModifiedDate().getValue()); - assertEquals(1, person.getEmails().getEmails().size()); + assertEquals(2, person.getEmails().getEmails().size()); Email email = person.getEmails().getEmails().get(0); + Email email2 = person.getEmails().getEmails().get(1); assertEquals("public_0000-0000-0000-0003@test.orcid.org", email.getEmail()); + assertEquals("public_0000-0000-0000-0003@orcid.org", email2.getEmail()); assertNotNull(email.getLastModifiedDate()); assertNotNull(email.getLastModifiedDate().getValue()); + assertNotNull(email2.getLastModifiedDate()); + assertNotNull(email2.getLastModifiedDate().getValue()); assertEquals("APP-5555555555555555", email.getSource().retrieveSourcePath()); assertEquals(Visibility.PUBLIC.value(), email.getVisibility().value()); + assertEquals(Visibility.PUBLIC.value(), email2.getVisibility().value()); assertNotNull(person.getExternalIdentifiers()); assertNotNull(person.getExternalIdentifiers().getLastModifiedDate()); assertNotNull(person.getExternalIdentifiers().getLastModifiedDate().getValue()); From 8ff4ba5841f8b3df6d5e613a7bff75572c37962b Mon Sep 17 00:00:00 2001 From: andrej romanov <50377758+auumgn@users.noreply.github.com> Date: Wed, 20 Nov 2024 19:56:04 +0200 Subject: [PATCH 08/23] refactor --- .../impl/MemberV2ApiServiceDelegatorImpl.java | 24 +++++---- .../impl/MemberV3ApiServiceDelegatorImpl.java | 24 +++++---- .../PersonDetailsManagerReadOnlyImpl.java | 26 +++++---- .../PersonDetailsManagerReadOnlyImpl.java | 26 +++++---- .../impl/PublicV2ApiServiceDelegatorImpl.java | 45 ++++++++-------- .../impl/PublicV3ApiServiceDelegatorImpl.java | 54 +++++++++---------- 6 files changed, 107 insertions(+), 92 deletions(-) diff --git a/orcid-api-web/src/main/java/org/orcid/api/memberV2/server/delegator/impl/MemberV2ApiServiceDelegatorImpl.java b/orcid-api-web/src/main/java/org/orcid/api/memberV2/server/delegator/impl/MemberV2ApiServiceDelegatorImpl.java index 1f12355c0b9..48ea536fa30 100644 --- a/orcid-api-web/src/main/java/org/orcid/api/memberV2/server/delegator/impl/MemberV2ApiServiceDelegatorImpl.java +++ b/orcid-api-web/src/main/java/org/orcid/api/memberV2/server/delegator/impl/MemberV2ApiServiceDelegatorImpl.java @@ -796,16 +796,7 @@ public Response viewEmails(String orcid) { orcidSecurityManager.checkAndFilter(orcid, emails.getEmails(), ScopePathType.ORCID_BIO_READ_LIMITED); } - 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())); - } - } - } + processProfessionalEmails(emails); ElementUtils.setPathToEmail(emails, orcid); Api2_0_LastModifiedDatesHelper.calculateLastModified(emails); @@ -1121,6 +1112,19 @@ private void validateSearchParams(Map> 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); diff --git a/orcid-api-web/src/main/java/org/orcid/api/memberV3/server/delegator/impl/MemberV3ApiServiceDelegatorImpl.java b/orcid-api-web/src/main/java/org/orcid/api/memberV3/server/delegator/impl/MemberV3ApiServiceDelegatorImpl.java index 70daa4569fd..64c5828c38f 100644 --- a/orcid-api-web/src/main/java/org/orcid/api/memberV3/server/delegator/impl/MemberV3ApiServiceDelegatorImpl.java +++ b/orcid-api-web/src/main/java/org/orcid/api/memberV3/server/delegator/impl/MemberV3ApiServiceDelegatorImpl.java @@ -885,16 +885,7 @@ public Response viewEmails(String orcid) { orcidSecurityManager.checkAndFilter(orcid, emails.getEmails(), ScopePathType.ORCID_BIO_READ_LIMITED); } - 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())); - } - } - } + processProfessionalEmails(emails); ElementUtils.setPathToEmail(emails, orcid); Api3_0LastModifiedDatesHelper.calculateLastModified(emails); @@ -1236,6 +1227,19 @@ private void validateSearchParams(Map> 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); diff --git a/orcid-core/src/main/java/org/orcid/core/manager/read_only/impl/PersonDetailsManagerReadOnlyImpl.java b/orcid-core/src/main/java/org/orcid/core/manager/read_only/impl/PersonDetailsManagerReadOnlyImpl.java index 496a7c0af38..392fcc71f89 100644 --- a/orcid-core/src/main/java/org/orcid/core/manager/read_only/impl/PersonDetailsManagerReadOnlyImpl.java +++ b/orcid-core/src/main/java/org/orcid/core/manager/read_only/impl/PersonDetailsManagerReadOnlyImpl.java @@ -138,17 +138,7 @@ public Person getPersonDetails(String orcid) { if (emails.getEmails() != null) { Emails filteredEmails = new Emails(); filteredEmails.setEmails(new ArrayList(emails.getEmails().stream().filter(e -> e.isVerified()).collect(Collectors.toList()))); - for (Email email : filteredEmails.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())); - } - } - } - person.setEmails(filteredEmails); + person.setEmails(processProfessionalEmails(filteredEmails)); } return person; } @@ -206,9 +196,23 @@ public Person getPublicPersonDetails(String orcid) { if (emails.getEmails() != null) { Emails filteredEmails = new Emails(); filteredEmails.setEmails(new ArrayList(emails.getEmails())); + processProfessionalEmails(filteredEmails); person.setEmails(filteredEmails); } return person; } + + 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())); + } + } + } + } } diff --git a/orcid-core/src/main/java/org/orcid/core/manager/v3/read_only/impl/PersonDetailsManagerReadOnlyImpl.java b/orcid-core/src/main/java/org/orcid/core/manager/v3/read_only/impl/PersonDetailsManagerReadOnlyImpl.java index 22169d58f50..4b927ca61c5 100644 --- a/orcid-core/src/main/java/org/orcid/core/manager/v3/read_only/impl/PersonDetailsManagerReadOnlyImpl.java +++ b/orcid-core/src/main/java/org/orcid/core/manager/v3/read_only/impl/PersonDetailsManagerReadOnlyImpl.java @@ -143,17 +143,7 @@ public Person getPersonDetails(String orcid, boolean includeUnverifiedEmails) { } else { filteredEmails.setEmails(new ArrayList(emails.getEmails().stream().filter(e -> e.isVerified()).collect(Collectors.toList()))); } - for (Email email : filteredEmails.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())); - } - } - } - person.setEmails(filteredEmails); + person.setEmails(processProfessionalEmails(filteredEmails)); } return person; } @@ -211,9 +201,23 @@ public Person getPublicPersonDetails(String orcid) { if (emails.getEmails() != null) { Emails filteredEmails = new Emails(); filteredEmails.setEmails(new ArrayList(emails.getEmails())); + processProfessionalEmails(filteredEmails); person.setEmails(filteredEmails); } return person; } + + 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())); + } + } + } + } } diff --git a/orcid-pub-web/src/main/java/org/orcid/api/publicV2/server/delegator/impl/PublicV2ApiServiceDelegatorImpl.java b/orcid-pub-web/src/main/java/org/orcid/api/publicV2/server/delegator/impl/PublicV2ApiServiceDelegatorImpl.java index ab2db9a891b..d4bd9809268 100644 --- a/orcid-pub-web/src/main/java/org/orcid/api/publicV2/server/delegator/impl/PublicV2ApiServiceDelegatorImpl.java +++ b/orcid-pub-web/src/main/java/org/orcid/api/publicV2/server/delegator/impl/PublicV2ApiServiceDelegatorImpl.java @@ -15,6 +15,7 @@ import org.orcid.api.common.writer.citeproc.WorkToCiteprocTranslator; import org.orcid.api.publicV2.server.delegator.PublicV2ApiServiceDelegator; import org.orcid.api.publicV2.server.security.PublicAPISecurityManagerV2; +import org.orcid.core.common.manager.EmailDomainManager; import org.orcid.core.common.manager.EventManager; import org.orcid.core.exception.OrcidBadRequestException; import org.orcid.core.exception.OrcidNoResultException; @@ -46,6 +47,7 @@ import org.orcid.core.togglz.Features; import org.orcid.core.utils.ContributorUtils; import org.orcid.core.utils.OrcidRequestUtil; +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; @@ -63,28 +65,9 @@ import org.orcid.jaxb.model.record.summary_v2.PeerReviews; import org.orcid.jaxb.model.record.summary_v2.WorkSummary; import org.orcid.jaxb.model.record.summary_v2.Works; -import org.orcid.jaxb.model.record_v2.Address; -import org.orcid.jaxb.model.record_v2.Addresses; -import org.orcid.jaxb.model.record_v2.Biography; -import org.orcid.jaxb.model.record_v2.Education; -import org.orcid.jaxb.model.record_v2.Emails; -import org.orcid.jaxb.model.record_v2.Employment; -import org.orcid.jaxb.model.record_v2.Funding; -import org.orcid.jaxb.model.record_v2.Keyword; -import org.orcid.jaxb.model.record_v2.Keywords; -import org.orcid.jaxb.model.record_v2.OtherName; -import org.orcid.jaxb.model.record_v2.OtherNames; -import org.orcid.jaxb.model.record_v2.PeerReview; -import org.orcid.jaxb.model.record_v2.Person; -import org.orcid.jaxb.model.record_v2.PersonExternalIdentifier; -import org.orcid.jaxb.model.record_v2.PersonExternalIdentifiers; -import org.orcid.jaxb.model.record_v2.PersonalDetails; -import org.orcid.jaxb.model.record_v2.Record; -import org.orcid.jaxb.model.record_v2.ResearcherUrl; -import org.orcid.jaxb.model.record_v2.ResearcherUrls; -import org.orcid.jaxb.model.record_v2.Work; -import org.orcid.jaxb.model.record_v2.WorkBulk; +import org.orcid.jaxb.model.record_v2.*; import org.orcid.jaxb.model.search_v2.Search; +import org.orcid.persistence.jpa.entities.EmailDomainEntity; import org.orcid.persistence.jpa.entities.ProfileEntity; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; @@ -194,6 +177,12 @@ public class PublicV2ApiServiceDelegatorImpl @Resource private EventManager eventManager; + + @Resource + private EmailDomainManager emailDomainManager; + + @Resource + private SourceEntityUtils sourceEntityUtils; @Value("${org.orcid.core.baseUri}") private String baseUrl; @@ -437,6 +426,7 @@ public Response viewResearcherUrl(String orcid, Long putCode) { public Response viewEmails(String orcid) { Emails emails = emailManagerReadOnly.getPublicEmails(orcid); publicAPISecurityManagerV2.filter(emails); + processProfessionalEmails(emails); ElementUtils.setPathToEmail(emails, orcid); Api2_0_LastModifiedDatesHelper.calculateLastModified(emails); sourceUtilsReadOnly.setSourceName(emails); @@ -631,6 +621,19 @@ private void validateRows(Map> 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) { ClientSummary client = clientManagerReadOnly.getSummary(clientId); diff --git a/orcid-pub-web/src/main/java/org/orcid/api/publicV3/server/delegator/impl/PublicV3ApiServiceDelegatorImpl.java b/orcid-pub-web/src/main/java/org/orcid/api/publicV3/server/delegator/impl/PublicV3ApiServiceDelegatorImpl.java index a1da0abcd31..61350aa5bde 100644 --- a/orcid-pub-web/src/main/java/org/orcid/api/publicV3/server/delegator/impl/PublicV3ApiServiceDelegatorImpl.java +++ b/orcid-pub-web/src/main/java/org/orcid/api/publicV3/server/delegator/impl/PublicV3ApiServiceDelegatorImpl.java @@ -16,6 +16,7 @@ import org.orcid.api.common.writer.citeproc.V3WorkToCiteprocTranslator; import org.orcid.api.publicV3.server.delegator.PublicV3ApiServiceDelegator; import org.orcid.api.publicV3.server.security.PublicAPISecurityManagerV3; +import org.orcid.core.common.manager.EmailDomainManager; import org.orcid.core.common.manager.EventManager; import org.orcid.core.exception.OrcidBadRequestException; import org.orcid.core.exception.OrcidNoResultException; @@ -48,6 +49,7 @@ import org.orcid.core.oauth.openid.OpenIDConnectKeyService; import org.orcid.core.togglz.Features; import org.orcid.core.utils.OrcidRequestUtil; +import org.orcid.core.utils.SourceEntityUtils; import org.orcid.core.utils.v3.ContributorUtils; import org.orcid.core.utils.v3.SourceUtils; import org.orcid.core.version.impl.Api3_0LastModifiedDatesHelper; @@ -56,34 +58,7 @@ import org.orcid.jaxb.model.v3.release.common.Visibility; import org.orcid.jaxb.model.v3.release.groupid.GroupIdRecord; import org.orcid.jaxb.model.v3.release.groupid.GroupIdRecords; -import org.orcid.jaxb.model.v3.release.record.Address; -import org.orcid.jaxb.model.v3.release.record.Addresses; -import org.orcid.jaxb.model.v3.release.record.Biography; -import org.orcid.jaxb.model.v3.release.record.Distinction; -import org.orcid.jaxb.model.v3.release.record.Education; -import org.orcid.jaxb.model.v3.release.record.Emails; -import org.orcid.jaxb.model.v3.release.record.Employment; -import org.orcid.jaxb.model.v3.release.record.ExternalID; -import org.orcid.jaxb.model.v3.release.record.Funding; -import org.orcid.jaxb.model.v3.release.record.InvitedPosition; -import org.orcid.jaxb.model.v3.release.record.Keyword; -import org.orcid.jaxb.model.v3.release.record.Keywords; -import org.orcid.jaxb.model.v3.release.record.Membership; -import org.orcid.jaxb.model.v3.release.record.OtherName; -import org.orcid.jaxb.model.v3.release.record.OtherNames; -import org.orcid.jaxb.model.v3.release.record.PeerReview; -import org.orcid.jaxb.model.v3.release.record.Person; -import org.orcid.jaxb.model.v3.release.record.PersonExternalIdentifier; -import org.orcid.jaxb.model.v3.release.record.PersonExternalIdentifiers; -import org.orcid.jaxb.model.v3.release.record.PersonalDetails; -import org.orcid.jaxb.model.v3.release.record.Qualification; -import org.orcid.jaxb.model.v3.release.record.Record; -import org.orcid.jaxb.model.v3.release.record.ResearchResource; -import org.orcid.jaxb.model.v3.release.record.ResearcherUrl; -import org.orcid.jaxb.model.v3.release.record.ResearcherUrls; -import org.orcid.jaxb.model.v3.release.record.Service; -import org.orcid.jaxb.model.v3.release.record.Work; -import org.orcid.jaxb.model.v3.release.record.WorkBulk; +import org.orcid.jaxb.model.v3.release.record.*; import org.orcid.jaxb.model.v3.release.record.summary.ActivitiesSummary; import org.orcid.jaxb.model.v3.release.record.summary.DistinctionSummary; import org.orcid.jaxb.model.v3.release.record.summary.Distinctions; @@ -109,6 +84,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.orcid.persistence.jpa.entities.ProfileEntity; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; @@ -216,11 +192,17 @@ public class PublicV3ApiServiceDelegatorImpl @Resource private EventManager eventManager; + @Resource + private EmailDomainManager emailDomainManager; + + @Resource + private SourceEntityUtils sourceEntityUtils; + @Value("${org.orcid.core.baseUri}") private String baseUrl; private Boolean filterVersionOfIdentifiers = false; - + public Boolean getFilterVersionOfIdentifiers() { return filterVersionOfIdentifiers; } @@ -512,6 +494,7 @@ public Response viewResearcherUrl(String orcid, Long putCode) { public Response viewEmails(String orcid) { checkProfileStatus(orcid); Emails emails = emailManagerReadOnly.getPublicEmails(orcid); + processProfessionalEmails(emails); publicAPISecurityManagerV3.filter(emails); ElementUtils.setPathToEmail(emails, orcid); Api3_0LastModifiedDatesHelper.calculateLastModified(emails); @@ -733,6 +716,19 @@ private void validateRows(Map> 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) { ClientSummary summary = clientDetailsManagerReadOnly.getClientSummary(clientId); From 45e30b417b10d307b08f157297cb2397e08f6a76 Mon Sep 17 00:00:00 2001 From: andrej romanov <50377758+auumgn@users.noreply.github.com> Date: Wed, 20 Nov 2024 20:02:45 +0200 Subject: [PATCH 09/23] fix issues --- .../read_only/impl/PersonDetailsManagerReadOnlyImpl.java | 3 ++- .../v3/read_only/impl/PersonDetailsManagerReadOnlyImpl.java | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/orcid-core/src/main/java/org/orcid/core/manager/read_only/impl/PersonDetailsManagerReadOnlyImpl.java b/orcid-core/src/main/java/org/orcid/core/manager/read_only/impl/PersonDetailsManagerReadOnlyImpl.java index 392fcc71f89..95142163c7d 100644 --- a/orcid-core/src/main/java/org/orcid/core/manager/read_only/impl/PersonDetailsManagerReadOnlyImpl.java +++ b/orcid-core/src/main/java/org/orcid/core/manager/read_only/impl/PersonDetailsManagerReadOnlyImpl.java @@ -138,7 +138,8 @@ public Person getPersonDetails(String orcid) { if (emails.getEmails() != null) { Emails filteredEmails = new Emails(); filteredEmails.setEmails(new ArrayList(emails.getEmails().stream().filter(e -> e.isVerified()).collect(Collectors.toList()))); - person.setEmails(processProfessionalEmails(filteredEmails)); + processProfessionalEmails(filteredEmails); + person.setEmails(filteredEmails); } return person; } diff --git a/orcid-core/src/main/java/org/orcid/core/manager/v3/read_only/impl/PersonDetailsManagerReadOnlyImpl.java b/orcid-core/src/main/java/org/orcid/core/manager/v3/read_only/impl/PersonDetailsManagerReadOnlyImpl.java index 4b927ca61c5..f41687b6ee7 100644 --- a/orcid-core/src/main/java/org/orcid/core/manager/v3/read_only/impl/PersonDetailsManagerReadOnlyImpl.java +++ b/orcid-core/src/main/java/org/orcid/core/manager/v3/read_only/impl/PersonDetailsManagerReadOnlyImpl.java @@ -143,7 +143,8 @@ public Person getPersonDetails(String orcid, boolean includeUnverifiedEmails) { } else { filteredEmails.setEmails(new ArrayList(emails.getEmails().stream().filter(e -> e.isVerified()).collect(Collectors.toList()))); } - person.setEmails(processProfessionalEmails(filteredEmails)); + processProfessionalEmails(filteredEmails); + person.setEmails(filteredEmails); } return person; } From 68989d34d7fb5626f5cb6f2f78e752ef5e94f2e4 Mon Sep 17 00:00:00 2001 From: andrej romanov <50377758+auumgn@users.noreply.github.com> Date: Wed, 20 Nov 2024 20:18:25 +0200 Subject: [PATCH 10/23] add assertions --- .../server/PublicV2ApiServiceDelegatorTest.java | 10 ++++++++++ .../server/PublicV3ApiServiceDelegatorTest.java | 10 ++++++++++ 2 files changed, 20 insertions(+) diff --git a/orcid-pub-web/src/test/java/org/orcid/api/publicV2/server/PublicV2ApiServiceDelegatorTest.java b/orcid-pub-web/src/test/java/org/orcid/api/publicV2/server/PublicV2ApiServiceDelegatorTest.java index 7b6e283e743..8e784e8b5a0 100644 --- a/orcid-pub-web/src/test/java/org/orcid/api/publicV2/server/PublicV2ApiServiceDelegatorTest.java +++ b/orcid-pub-web/src/test/java/org/orcid/api/publicV2/server/PublicV2ApiServiceDelegatorTest.java @@ -571,6 +571,11 @@ public void testViewEmails() { assertEquals(Visibility.PUBLIC.value(), email2.getVisibility().value()); assertEquals("/0000-0000-0000-0003/email", emails.getPath()); assertEquals("APP-5555555555555555", email.getSource().retrieveSourcePath()); + assertEquals("Source Client 1", email.getSource().getSourceName().getContent()); + assertNull(email.getSource().getSourceOrcid()); + assertEquals("0000-0000-0000-0000", email2.getSource().retrieveSourcePath()); + assertEquals("ORCID email validation", email2.getSource().getSourceName().getContent()); + assertNull(email2.getSource().getSourceOrcid()); } @Test @@ -1301,6 +1306,11 @@ private void validatePerson(Person person) { assertNotNull(email2.getLastModifiedDate()); assertNotNull(email2.getLastModifiedDate().getValue()); assertEquals("APP-5555555555555555", email.getSource().retrieveSourcePath()); + assertEquals("Source Client 1", email.getSource().getSourceName().getContent()); + assertNull(email.getSource().getSourceOrcid()); + assertEquals("0000-0000-0000-0000", email2.getSource().retrieveSourcePath()); + assertEquals("ORCID email validation", email2.getSource().getSourceName().getContent()); + assertNull(email2.getSource().getSourceOrcid()); assertEquals(Visibility.PUBLIC.value(), email.getVisibility().value()); assertEquals(Visibility.PUBLIC.value(), email2.getVisibility().value()); assertNotNull(person.getExternalIdentifiers()); diff --git a/orcid-pub-web/src/test/java/org/orcid/api/publicV3/server/PublicV3ApiServiceDelegatorTest.java b/orcid-pub-web/src/test/java/org/orcid/api/publicV3/server/PublicV3ApiServiceDelegatorTest.java index 408dd2b1a25..75c3d0220a8 100644 --- a/orcid-pub-web/src/test/java/org/orcid/api/publicV3/server/PublicV3ApiServiceDelegatorTest.java +++ b/orcid-pub-web/src/test/java/org/orcid/api/publicV3/server/PublicV3ApiServiceDelegatorTest.java @@ -598,6 +598,11 @@ public void testViewEmails() { assertEquals(Visibility.PUBLIC.value(), email2.getVisibility().value()); assertEquals("/0000-0000-0000-0003/email", emails.getPath()); assertEquals("APP-5555555555555555", email.getSource().retrieveSourcePath()); + assertEquals("Source Client 1", email.getSource().getSourceName().getContent()); + assertNull(email.getSource().getSourceOrcid()); + assertEquals("0000-0000-0000-0000", email2.getSource().retrieveSourcePath()); + assertEquals("ORCID email validation", email2.getSource().getSourceName().getContent()); + assertNull(email2.getSource().getSourceOrcid()); } @Test @@ -1832,6 +1837,11 @@ private void validatePerson(Person person) { assertNotNull(email2.getLastModifiedDate()); assertNotNull(email2.getLastModifiedDate().getValue()); assertEquals("APP-5555555555555555", email.getSource().retrieveSourcePath()); + assertNull(email.getSource().getSourceOrcid()); + assertEquals("Source Client 1", email.getSource().getSourceName().getContent()); + assertEquals("0000-0000-0000-0000", email2.getSource().retrieveSourcePath()); + assertNull(email2.getSource().getSourceOrcid()); + assertEquals("ORCID email validation", email2.getSource().getSourceName().getContent()); assertEquals(Visibility.PUBLIC.value(), email.getVisibility().value()); assertEquals(Visibility.PUBLIC.value(), email2.getVisibility().value()); assertNotNull(person.getExternalIdentifiers()); From d1d5b373d12f06394ba419a812fb04b8ea99a9fe Mon Sep 17 00:00:00 2001 From: andrej romanov <50377758+auumgn@users.noreply.github.com> Date: Wed, 20 Nov 2024 20:19:17 +0200 Subject: [PATCH 11/23] fix tests --- .../web/controllers/PublicRecordControllerLegacyTest.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/orcid-web/src/test/java/org/orcid/frontend/web/controllers/PublicRecordControllerLegacyTest.java b/orcid-web/src/test/java/org/orcid/frontend/web/controllers/PublicRecordControllerLegacyTest.java index 7da841d7dab..291e08f649a 100644 --- a/orcid-web/src/test/java/org/orcid/frontend/web/controllers/PublicRecordControllerLegacyTest.java +++ b/orcid-web/src/test/java/org/orcid/frontend/web/controllers/PublicRecordControllerLegacyTest.java @@ -113,9 +113,11 @@ public void testGetPublicRecord() { assertNotNull(record.getWebsite()); assertNotNull(record.getEmails()); - assertEquals(1, record.getEmails().getEmails().size()); + assertEquals(2, record.getEmails().getEmails().size()); assertEquals("public_0000-0000-0000-0003@test.orcid.org", record.getEmails().getEmails().get(0).getValue()); + assertEquals("public_0000-0000-0000-0003@test.orcid.org", record.getEmails().getEmails().get(1).getValue()); assertEquals(Visibility.PUBLIC, record.getEmails().getEmails().get(0).getVisibility()); + assertEquals(Visibility.PUBLIC, record.getEmails().getEmails().get(1).getVisibility()); assertNotNull(record.getExternalIdentifier()); assertEquals(3, record.getExternalIdentifier().getExternalIdentifiers().size()); From c4c30aedb8f1d1b5af237d5819c202c8139af395 Mon Sep 17 00:00:00 2001 From: andrej romanov <50377758+auumgn@users.noreply.github.com> Date: Wed, 20 Nov 2024 20:30:18 +0200 Subject: [PATCH 12/23] fix more tests --- .../PublicProfileControllerTest.java | 20 ++++++++++++------- .../PublicRecordControllerLegacyTest.java | 2 +- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/orcid-web/src/test/java/org/orcid/frontend/web/controllers/PublicProfileControllerTest.java b/orcid-web/src/test/java/org/orcid/frontend/web/controllers/PublicProfileControllerTest.java index 8a93b59925c..732d52f5a58 100644 --- a/orcid-web/src/test/java/org/orcid/frontend/web/controllers/PublicProfileControllerTest.java +++ b/orcid-web/src/test/java/org/orcid/frontend/web/controllers/PublicProfileControllerTest.java @@ -1,9 +1,6 @@ package org.orcid.frontend.web.controllers; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; +import static org.junit.Assert.*; import static org.mockito.ArgumentMatchers.anyLong; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.eq; @@ -191,12 +188,21 @@ public void testGetPersonDetails() { assertNotNull(personDetails.getPublicGroupedEmails()); Map> emails = personDetails.getPublicGroupedEmails(); assertNotNull(emails); - assertEquals(1, emails.keySet().size()); - assertTrue(emails.containsKey("public_0000-0000-0000-0003@test.orcid.org")); + assertEquals(2, emails.keySet().size()); + assertTrue(emails.containsKey("public_0000-0000-0000-0003@test.orcid.org")); + assertTrue(emails.containsKey("public_0000-0000-0000-0003@orcid.org")); List publicEmails = emails.get("public_0000-0000-0000-0003@test.orcid.org"); assertEquals("public_0000-0000-0000-0003@test.orcid.org", publicEmails.get(0).getEmail()); + assertEquals("public_0000-0000-0000-0003@orcid.org", publicEmails.get(1).getEmail()); assertEquals(Visibility.PUBLIC, publicEmails.get(0).getVisibility()); - + assertEquals(Visibility.PUBLIC, publicEmails.get(0).getVisibility()); + assertEquals("APP-5555555555555555", publicEmails.get(0).getSource().retrieveSourcePath()); + assertEquals("Source Client 1", publicEmails.get(0).getSource().getSourceName().getContent()); + assertNull(publicEmails.get(0).getSource().getSourceOrcid()); + assertEquals("0000-0000-0000-0000", publicEmails.get(1).getSource().retrieveSourcePath()); + assertEquals("ORCID email validation", publicEmails.get(1).getSource().getSourceName().getContent()); + assertNull(publicEmails.get(1).getSource().getSourceOrcid()); + assertNotNull(personDetails.getPublicGroupedPersonExternalIdentifiers()); Map> extIds = personDetails.getPublicGroupedPersonExternalIdentifiers(); assertNotNull(extIds); diff --git a/orcid-web/src/test/java/org/orcid/frontend/web/controllers/PublicRecordControllerLegacyTest.java b/orcid-web/src/test/java/org/orcid/frontend/web/controllers/PublicRecordControllerLegacyTest.java index 291e08f649a..beeb3e14e1e 100644 --- a/orcid-web/src/test/java/org/orcid/frontend/web/controllers/PublicRecordControllerLegacyTest.java +++ b/orcid-web/src/test/java/org/orcid/frontend/web/controllers/PublicRecordControllerLegacyTest.java @@ -115,7 +115,7 @@ public void testGetPublicRecord() { assertNotNull(record.getEmails()); assertEquals(2, record.getEmails().getEmails().size()); assertEquals("public_0000-0000-0000-0003@test.orcid.org", record.getEmails().getEmails().get(0).getValue()); - assertEquals("public_0000-0000-0000-0003@test.orcid.org", record.getEmails().getEmails().get(1).getValue()); + assertEquals("public_0000-0000-0000-0003@orcid.org", record.getEmails().getEmails().get(1).getValue()); assertEquals(Visibility.PUBLIC, record.getEmails().getEmails().get(0).getVisibility()); assertEquals(Visibility.PUBLIC, record.getEmails().getEmails().get(1).getVisibility()); From 3c8e90a725408188c5b64b985bacf4ad82322c67 Mon Sep 17 00:00:00 2001 From: andrej romanov <50377758+auumgn@users.noreply.github.com> Date: Wed, 20 Nov 2024 20:35:19 +0200 Subject: [PATCH 13/23] test fix --- .../PublicProfileControllerTest.java | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/orcid-web/src/test/java/org/orcid/frontend/web/controllers/PublicProfileControllerTest.java b/orcid-web/src/test/java/org/orcid/frontend/web/controllers/PublicProfileControllerTest.java index 732d52f5a58..2baeed682fe 100644 --- a/orcid-web/src/test/java/org/orcid/frontend/web/controllers/PublicProfileControllerTest.java +++ b/orcid-web/src/test/java/org/orcid/frontend/web/controllers/PublicProfileControllerTest.java @@ -191,17 +191,18 @@ public void testGetPersonDetails() { assertEquals(2, emails.keySet().size()); assertTrue(emails.containsKey("public_0000-0000-0000-0003@test.orcid.org")); assertTrue(emails.containsKey("public_0000-0000-0000-0003@orcid.org")); - List publicEmails = emails.get("public_0000-0000-0000-0003@test.orcid.org"); - assertEquals("public_0000-0000-0000-0003@test.orcid.org", publicEmails.get(0).getEmail()); - assertEquals("public_0000-0000-0000-0003@orcid.org", publicEmails.get(1).getEmail()); - assertEquals(Visibility.PUBLIC, publicEmails.get(0).getVisibility()); - assertEquals(Visibility.PUBLIC, publicEmails.get(0).getVisibility()); - assertEquals("APP-5555555555555555", publicEmails.get(0).getSource().retrieveSourcePath()); - assertEquals("Source Client 1", publicEmails.get(0).getSource().getSourceName().getContent()); - assertNull(publicEmails.get(0).getSource().getSourceOrcid()); - assertEquals("0000-0000-0000-0000", publicEmails.get(1).getSource().retrieveSourcePath()); - assertEquals("ORCID email validation", publicEmails.get(1).getSource().getSourceName().getContent()); - assertNull(publicEmails.get(1).getSource().getSourceOrcid()); + List email1 = emails.get("public_0000-0000-0000-0003@test.orcid.org"); + List email2 = emails.get("public_0000-0000-0000-0003@orcid.org"); + assertEquals("public_0000-0000-0000-0003@test.orcid.org", email1.get(0).getEmail()); + assertEquals("public_0000-0000-0000-0003@orcid.org", email2.get(0).getEmail()); + assertEquals(Visibility.PUBLIC, email1.get(0).getVisibility()); + assertEquals(Visibility.PUBLIC, email2.get(0).getVisibility()); + assertEquals("APP-5555555555555555", email1.get(0).getSource().retrieveSourcePath()); + assertEquals("Source Client 1", email1.get(0).getSource().getSourceName().getContent()); + assertNull(email1.get(0).getSource().getSourceOrcid()); + assertEquals("0000-0000-0000-0000", email2.get(0).getSource().retrieveSourcePath()); + assertEquals("ORCID email validation", email2.get(0).getSource().getSourceName().getContent()); + assertNull(email2.get(0).getSource().getSourceOrcid()); assertNotNull(personDetails.getPublicGroupedPersonExternalIdentifiers()); Map> extIds = personDetails.getPublicGroupedPersonExternalIdentifiers(); From 5f863350d11c9ea2c571cc4934553d54190d0e64 Mon Sep 17 00:00:00 2001 From: andrej romanov <50377758+auumgn@users.noreply.github.com> Date: Wed, 20 Nov 2024 20:50:52 +0200 Subject: [PATCH 14/23] fix more tests --- .../frontend/web/controllers/PublicProfileControllerTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/orcid-web/src/test/java/org/orcid/frontend/web/controllers/PublicProfileControllerTest.java b/orcid-web/src/test/java/org/orcid/frontend/web/controllers/PublicProfileControllerTest.java index 2baeed682fe..a1b69cd1bca 100644 --- a/orcid-web/src/test/java/org/orcid/frontend/web/controllers/PublicProfileControllerTest.java +++ b/orcid-web/src/test/java/org/orcid/frontend/web/controllers/PublicProfileControllerTest.java @@ -200,8 +200,8 @@ public void testGetPersonDetails() { assertEquals("APP-5555555555555555", email1.get(0).getSource().retrieveSourcePath()); assertEquals("Source Client 1", email1.get(0).getSource().getSourceName().getContent()); assertNull(email1.get(0).getSource().getSourceOrcid()); - assertEquals("0000-0000-0000-0000", email2.get(0).getSource().retrieveSourcePath()); - assertEquals("ORCID email validation", email2.get(0).getSource().getSourceName().getContent()); + assertEquals("APP-5555555555555555", email2.get(0).getSource().retrieveSourcePath()); + assertEquals("Source Client 1", email2.get(0).getSource().getSourceName().getContent()); assertNull(email2.get(0).getSource().getSourceOrcid()); assertNotNull(personDetails.getPublicGroupedPersonExternalIdentifiers()); From 0d41e742a9a5de848950cd841aa4fd99ecdc0d6e Mon Sep 17 00:00:00 2001 From: andrej romanov <50377758+auumgn@users.noreply.github.com> Date: Wed, 20 Nov 2024 21:06:56 +0200 Subject: [PATCH 15/23] actually fix the test --- .../web/controllers/PublicProfileControllerTest.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/orcid-web/src/test/java/org/orcid/frontend/web/controllers/PublicProfileControllerTest.java b/orcid-web/src/test/java/org/orcid/frontend/web/controllers/PublicProfileControllerTest.java index a1b69cd1bca..a95abc2f5cc 100644 --- a/orcid-web/src/test/java/org/orcid/frontend/web/controllers/PublicProfileControllerTest.java +++ b/orcid-web/src/test/java/org/orcid/frontend/web/controllers/PublicProfileControllerTest.java @@ -200,9 +200,9 @@ public void testGetPersonDetails() { assertEquals("APP-5555555555555555", email1.get(0).getSource().retrieveSourcePath()); assertEquals("Source Client 1", email1.get(0).getSource().getSourceName().getContent()); assertNull(email1.get(0).getSource().getSourceOrcid()); - assertEquals("APP-5555555555555555", email2.get(0).getSource().retrieveSourcePath()); - assertEquals("Source Client 1", email2.get(0).getSource().getSourceName().getContent()); - assertNull(email2.get(0).getSource().getSourceOrcid()); + assertEquals("0000-0000-0000-0003", email2.get(0).getSource().retrieveSourcePath()); + assertEquals("Credit Name", email2.get(0).getSource().getSourceName().getContent()); + assertNotNull(email2.get(0).getSource().getSourceOrcid()); assertNotNull(personDetails.getPublicGroupedPersonExternalIdentifiers()); Map> extIds = personDetails.getPublicGroupedPersonExternalIdentifiers(); From c17bb8a2e29c8d0830c6f15944a63fcf7c3f8cd6 Mon Sep 17 00:00:00 2001 From: andrej romanov <50377758+auumgn@users.noreply.github.com> Date: Wed, 20 Nov 2024 21:22:31 +0200 Subject: [PATCH 16/23] more test fixes --- .../MemberV2ApiServiceDelegator_EmailsTest.java | 10 ++++++++-- ...berV2ApiServiceDelegator_ReadPersonTest.java | 9 ++++++++- ...berV2ApiServiceDelegator_ReadRecordTest.java | 4 ++++ .../MemberV3ApiServiceDelegator_EmailsTest.java | 6 +++++- ...berV3ApiServiceDelegator_ReadPersonTest.java | 17 ++++++++++++----- 5 files changed, 37 insertions(+), 9 deletions(-) diff --git a/orcid-api-web/src/test/java/org/orcid/api/memberV2/server/delegator/MemberV2ApiServiceDelegator_EmailsTest.java b/orcid-api-web/src/test/java/org/orcid/api/memberV2/server/delegator/MemberV2ApiServiceDelegator_EmailsTest.java index 25d8e13026e..3768a1cb475 100644 --- a/orcid-api-web/src/test/java/org/orcid/api/memberV2/server/delegator/MemberV2ApiServiceDelegator_EmailsTest.java +++ b/orcid-api-web/src/test/java/org/orcid/api/memberV2/server/delegator/MemberV2ApiServiceDelegator_EmailsTest.java @@ -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("public_0000-0000-0000-0003@test.orcid.org")) { @@ -100,7 +102,10 @@ public void testReadPublicScope_Emails() { found2 = true; } else if (element.getEmail().equals("private_0000-0000-0000-0003@test.orcid.org")) { found3 = true; - } else { + } else if (element.getEmail().equals("public_0000-0000-0000-0003@orcid.org")) { + found4 = true; + } + else { fail("Invalid put code " + element.getPutCode()); } @@ -108,6 +113,7 @@ public void testReadPublicScope_Emails() { assertTrue(found1); assertTrue(found2); assertTrue(found3); + assertTrue(found4); } @Test diff --git a/orcid-api-web/src/test/java/org/orcid/api/memberV2/server/delegator/MemberV2ApiServiceDelegator_ReadPersonTest.java b/orcid-api-web/src/test/java/org/orcid/api/memberV2/server/delegator/MemberV2ApiServiceDelegator_ReadPersonTest.java index 0a5bd4d75da..8d0c99e434c 100644 --- a/orcid-api-web/src/test/java/org/orcid/api/memberV2/server/delegator/MemberV2ApiServiceDelegator_ReadPersonTest.java +++ b/orcid-api-web/src/test/java/org/orcid/api/memberV2/server/delegator/MemberV2ApiServiceDelegator_ReadPersonTest.java @@ -154,6 +154,7 @@ public void testViewPerson() { found2 = false; found3 = false; found4 = false; + found5 = false; for (Email element : email.getEmails()) { if (element.getEmail().equals("public_0000-0000-0000-0003@test.orcid.org")) { @@ -164,6 +165,8 @@ public void testViewPerson() { found3 = true; } else if (element.getEmail().equals("self_limited_0000-0000-0000-0003@test.orcid.org")) { found4 = true; + } else if (element.getEmail().equals("public_0000-0000-0000-0003@orcid.org")) { + found5 = true; } else { fail("Invalid email " + element.getEmail()); } @@ -173,6 +176,7 @@ public void testViewPerson() { assertTrue(found2); assertTrue(found3); assertTrue(found4); + assertTrue(found5); // External identifiers assertNotNull(p.getExternalIdentifiers()); @@ -516,7 +520,7 @@ public void testReadPrivateEmails_OtherThingsJustPublic_Person() { Utils.verifyLastModified(email.getLastModifiedDate()); assertEquals(4, 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("public_0000-0000-0000-0003@test.orcid.org")) { @@ -527,6 +531,8 @@ public void testReadPrivateEmails_OtherThingsJustPublic_Person() { found3 = true; } else if (element.getEmail().equals("self_limited_0000-0000-0000-0003@test.orcid.org")) { found4 = true; + } else if (element.getEmail().equals("public_0000-0000-0000-0003@orcid.org")) { + found5 = true; } else { fail("Invalid email " + element.getEmail()); } @@ -536,6 +542,7 @@ public void testReadPrivateEmails_OtherThingsJustPublic_Person() { assertTrue(found2); assertTrue(found3); assertTrue(found4); + assertTrue(found5); this.assertAllPublicButEmails(p); } diff --git a/orcid-api-web/src/test/java/org/orcid/api/memberV2/server/delegator/MemberV2ApiServiceDelegator_ReadRecordTest.java b/orcid-api-web/src/test/java/org/orcid/api/memberV2/server/delegator/MemberV2ApiServiceDelegator_ReadRecordTest.java index 21629f64516..c90c48de86a 100644 --- a/orcid-api-web/src/test/java/org/orcid/api/memberV2/server/delegator/MemberV2ApiServiceDelegator_ReadRecordTest.java +++ b/orcid-api-web/src/test/java/org/orcid/api/memberV2/server/delegator/MemberV2ApiServiceDelegator_ReadRecordTest.java @@ -861,6 +861,7 @@ private void testPerson(Person p, String orcid) { found1 = false; found2 = false; found3 = false; + found4 = false; for (Email element : email.getEmails()) { if (element.getEmail().equals("public_0000-0000-0000-0003@test.orcid.org")) { @@ -869,6 +870,8 @@ private void testPerson(Person p, String orcid) { found2 = true; } else if (element.getEmail().equals("private_0000-0000-0000-0003@test.orcid.org")) { found3 = true; + } else if (element.getEmail().equals("public_0000-0000-0000-0003@orcid.org")) { + found4 = true; } else { fail("Invalid email " + element.getEmail()); } @@ -877,6 +880,7 @@ private void testPerson(Person p, String orcid) { assertTrue(found1); assertTrue(found2); assertTrue(found3); + assertTrue(found4); // External identifiers assertNotNull(p.getExternalIdentifiers()); diff --git a/orcid-api-web/src/test/java/org/orcid/api/memberV3/server/delegator/MemberV3ApiServiceDelegator_EmailsTest.java b/orcid-api-web/src/test/java/org/orcid/api/memberV3/server/delegator/MemberV3ApiServiceDelegator_EmailsTest.java index bff3f1a21a6..08f209368cd 100644 --- a/orcid-api-web/src/test/java/org/orcid/api/memberV3/server/delegator/MemberV3ApiServiceDelegator_EmailsTest.java +++ b/orcid-api-web/src/test/java/org/orcid/api/memberV3/server/delegator/MemberV3ApiServiceDelegator_EmailsTest.java @@ -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("public_0000-0000-0000-0003@test.orcid.org")) { @@ -111,6 +112,8 @@ public void testReadPublicScope_Emails() { found2 = true; } else if (element.getEmail().equals("private_0000-0000-0000-0003@test.orcid.org")) { found3 = true; + } if (element.getEmail().equals("public_0000-0000-0000-0003@orcid.org")) { + found4 = true; } else { fail("Invalid put code " + element.getPutCode()); } @@ -119,6 +122,7 @@ public void testReadPublicScope_Emails() { assertTrue(found1); assertTrue(found2); assertTrue(found3); + assertTrue(found4); } @Test diff --git a/orcid-api-web/src/test/java/org/orcid/api/memberV3/server/delegator/MemberV3ApiServiceDelegator_ReadPersonTest.java b/orcid-api-web/src/test/java/org/orcid/api/memberV3/server/delegator/MemberV3ApiServiceDelegator_ReadPersonTest.java index ed43bc74c25..c355b465201 100644 --- a/orcid-api-web/src/test/java/org/orcid/api/memberV3/server/delegator/MemberV3ApiServiceDelegator_ReadPersonTest.java +++ b/orcid-api-web/src/test/java/org/orcid/api/memberV3/server/delegator/MemberV3ApiServiceDelegator_ReadPersonTest.java @@ -160,6 +160,7 @@ public void testViewPerson() { found2 = false; found3 = false; found4 = false; + found5 = false; for (Email element : email.getEmails()) { if (element.getEmail().equals("public_0000-0000-0000-0003@test.orcid.org")) { @@ -170,6 +171,8 @@ public void testViewPerson() { found3 = true; } else if (element.getEmail().equals("self_limited_0000-0000-0000-0003@test.orcid.org")) { found4 = true; + } else if (element.getEmail().equals("public_0000-0000-0000-0003@orcid.org")) { + found5 = true; } else { fail("Invalid email " + element.getEmail()); } @@ -179,6 +182,7 @@ public void testViewPerson() { assertTrue(found2); assertTrue(found3); assertTrue(found4); + assertTrue(found5); // External identifiers assertNotNull(p.getExternalIdentifiers()); @@ -521,19 +525,21 @@ public void testReadPrivateEmails_OtherThingsJustPublic_Person() { 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("public_0000-0000-0000-0003@test.orcid.org")) { found1 = true; - } else if (element.getEmail().equals("limited_0000-0000-0000-0003@test.orcid.org")) { + } else if (element.getEmail().equals("public_0000-0000-0000-0003@orcid.org")) { found2 = true; - } else if (element.getEmail().equals("private_0000-0000-0000-0003@test.orcid.org")) { + } else if (element.getEmail().equals("limited_0000-0000-0000-0003@test.orcid.org")) { found3 = true; - } else if (element.getEmail().equals("self_limited_0000-0000-0000-0003@test.orcid.org")) { + } else if (element.getEmail().equals("private_0000-0000-0000-0003@test.orcid.org")) { found4 = true; + } else if (element.getEmail().equals("self_limited_0000-0000-0000-0003@test.orcid.org")) { + found5 = true; } else { fail("Invalid email " + element.getEmail()); } @@ -543,6 +549,7 @@ public void testReadPrivateEmails_OtherThingsJustPublic_Person() { assertTrue(found2); assertTrue(found3); assertTrue(found4); + assertTrue(found5); this.assertAllPublicButEmails(p); } From 4bec69d73f619196c0e7d92d8625000c068925a7 Mon Sep 17 00:00:00 2001 From: andrej romanov <50377758+auumgn@users.noreply.github.com> Date: Wed, 20 Nov 2024 21:36:51 +0200 Subject: [PATCH 17/23] more tests --- .../MemberV2ApiServiceDelegator_ReadPersonTest.java | 12 ++++++++---- .../MemberV2ApiServiceDelegator_ReadRecordTest.java | 10 +++++++--- .../MemberV3ApiServiceDelegator_ReadPersonTest.java | 8 ++++++-- .../MemberV3ApiServiceDelegator_ReadRecordTest.java | 13 ++++++++++--- 4 files changed, 31 insertions(+), 12 deletions(-) diff --git a/orcid-api-web/src/test/java/org/orcid/api/memberV2/server/delegator/MemberV2ApiServiceDelegator_ReadPersonTest.java b/orcid-api-web/src/test/java/org/orcid/api/memberV2/server/delegator/MemberV2ApiServiceDelegator_ReadPersonTest.java index 8d0c99e434c..863aefb1011 100644 --- a/orcid-api-web/src/test/java/org/orcid/api/memberV2/server/delegator/MemberV2ApiServiceDelegator_ReadPersonTest.java +++ b/orcid-api-web/src/test/java/org/orcid/api/memberV2/server/delegator/MemberV2ApiServiceDelegator_ReadPersonTest.java @@ -148,13 +148,12 @@ 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; found3 = false; found4 = false; - found5 = false; for (Email element : email.getEmails()) { if (element.getEmail().equals("public_0000-0000-0000-0003@test.orcid.org")) { @@ -360,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("public_0000-0000-0000-0003@test.orcid.org", email.getEmails().get(0).getEmail()); + assertEquals("public_0000-0000-0000-0003@orcid.org", email.getEmails().get(1).getEmail()); found1 = false; found2 = false; found3 = false; + found4 = false; for (Email element : email.getEmails()) { if (element.getEmail().equals("public_0000-0000-0000-0003@test.orcid.org")) { @@ -374,6 +375,8 @@ private void testPerson(Person p, String orcid) { found2 = true; } else if (element.getEmail().equals("private_0000-0000-0000-0003@test.orcid.org")) { found3 = true; + } else if (element.getEmail().equals("public_0000-0000-0000-0003@orcid.org")) { + found4 = true; } else { fail("Invalid email " + element.getEmail()); } @@ -382,6 +385,7 @@ private void testPerson(Person p, String orcid) { assertTrue(found1); assertTrue(found2); assertTrue(found3); + assertTrue(found4); // External identifiers assertNotNull(p.getExternalIdentifiers()); @@ -518,7 +522,7 @@ 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, found5 = false; diff --git a/orcid-api-web/src/test/java/org/orcid/api/memberV2/server/delegator/MemberV2ApiServiceDelegator_ReadRecordTest.java b/orcid-api-web/src/test/java/org/orcid/api/memberV2/server/delegator/MemberV2ApiServiceDelegator_ReadRecordTest.java index c90c48de86a..411910f718e 100644 --- a/orcid-api-web/src/test/java/org/orcid/api/memberV2/server/delegator/MemberV2ApiServiceDelegator_ReadRecordTest.java +++ b/orcid-api-web/src/test/java/org/orcid/api/memberV2/server/delegator/MemberV2ApiServiceDelegator_ReadRecordTest.java @@ -855,7 +855,7 @@ 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("public_0000-0000-0000-0003@test.orcid.org", email.getEmails().get(0).getEmail()); found1 = false; @@ -1021,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("public_0000-0000-0000-0003@test.orcid.org")) { @@ -1034,6 +1034,8 @@ public void testReadPrivateEmails_OtherThingsJustPublic_Record() { found3 = true; } else if (element.getEmail().equals("self_limited_0000-0000-0000-0003@test.orcid.org")) { found4 = true; + } else if (element.getEmail().equals("public_0000-0000-0000-0003@orcid.org")) { + found5 = true; } else { fail("Invalid email " + element.getEmail()); } @@ -1043,6 +1045,8 @@ public void testReadPrivateEmails_OtherThingsJustPublic_Record() { assertTrue(found2); assertTrue(found3); assertTrue(found4); + assertTrue(found5); + this.assertAllPublicButEmails(p); } diff --git a/orcid-api-web/src/test/java/org/orcid/api/memberV3/server/delegator/MemberV3ApiServiceDelegator_ReadPersonTest.java b/orcid-api-web/src/test/java/org/orcid/api/memberV3/server/delegator/MemberV3ApiServiceDelegator_ReadPersonTest.java index c355b465201..3a70f980461 100644 --- a/orcid-api-web/src/test/java/org/orcid/api/memberV3/server/delegator/MemberV3ApiServiceDelegator_ReadPersonTest.java +++ b/orcid-api-web/src/test/java/org/orcid/api/memberV3/server/delegator/MemberV3ApiServiceDelegator_ReadPersonTest.java @@ -154,7 +154,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; @@ -366,12 +366,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("public_0000-0000-0000-0003@test.orcid.org", email.getEmails().get(0).getEmail()); found1 = false; found2 = false; found3 = false; + found4= false; for (Email element : email.getEmails()) { if (element.getEmail().equals("public_0000-0000-0000-0003@test.orcid.org")) { @@ -380,6 +381,8 @@ private void testPerson(Person p, String orcid) { found2 = true; } else if (element.getEmail().equals("private_0000-0000-0000-0003@test.orcid.org")) { found3 = true; + } else if (element.getEmail().equals("public_0000-0000-0000-0003@orcid.org")) { + found4 = true; } else { fail("Invalid email " + element.getEmail()); } @@ -388,6 +391,7 @@ private void testPerson(Person p, String orcid) { assertTrue(found1); assertTrue(found2); assertTrue(found3); + assertTrue(found4); // External identifiers assertNotNull(p.getExternalIdentifiers()); diff --git a/orcid-api-web/src/test/java/org/orcid/api/memberV3/server/delegator/MemberV3ApiServiceDelegator_ReadRecordTest.java b/orcid-api-web/src/test/java/org/orcid/api/memberV3/server/delegator/MemberV3ApiServiceDelegator_ReadRecordTest.java index bb8ecf57165..48ad1611ad1 100644 --- a/orcid-api-web/src/test/java/org/orcid/api/memberV3/server/delegator/MemberV3ApiServiceDelegator_ReadRecordTest.java +++ b/orcid-api-web/src/test/java/org/orcid/api/memberV3/server/delegator/MemberV3ApiServiceDelegator_ReadRecordTest.java @@ -1063,12 +1063,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("public_0000-0000-0000-0003@test.orcid.org", email.getEmails().get(0).getEmail()); found1 = false; found2 = false; found3 = false; + found4 = false; for (Email element : email.getEmails()) { if (element.getEmail().equals("public_0000-0000-0000-0003@test.orcid.org")) { @@ -1077,6 +1078,8 @@ private void testPerson(Person p, String orcid) { found2 = true; } else if (element.getEmail().equals("private_0000-0000-0000-0003@test.orcid.org")) { found3 = true; + } else if (element.getEmail().equals("public_0000-0000-0000-0003@orcid.org")) { + found4 = true; } else { fail("Invalid email " + element.getEmail()); } @@ -1085,6 +1088,7 @@ private void testPerson(Person p, String orcid) { assertTrue(found1); assertTrue(found2); assertTrue(found3); + assertTrue(found4); // External identifiers assertNotNull(p.getExternalIdentifiers()); @@ -1224,9 +1228,9 @@ public void testReadPrivateEmails_OtherThingsJustPublic_Record() { 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("public_0000-0000-0000-0003@test.orcid.org")) { @@ -1237,6 +1241,8 @@ public void testReadPrivateEmails_OtherThingsJustPublic_Record() { found3 = true; } else if (element.getEmail().equals("self_limited_0000-0000-0000-0003@test.orcid.org")) { found4 = true; + } else if (element.getEmail().equals("public_0000-0000-0000-0003@orcid.org")) { + found5 = true; } else { fail("Invalid email " + element.getEmail()); } @@ -1246,6 +1252,7 @@ public void testReadPrivateEmails_OtherThingsJustPublic_Record() { assertTrue(found2); assertTrue(found3); assertTrue(found4); + assertTrue(found5); this.assertAllPublicButEmails(p); } From c1c64ac7e0dd99566642c75b93e697908b72324f Mon Sep 17 00:00:00 2001 From: andrej romanov <50377758+auumgn@users.noreply.github.com> Date: Wed, 20 Nov 2024 21:44:55 +0200 Subject: [PATCH 18/23] fix test --- .../delegator/MemberV3ApiServiceDelegator_EmailsTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/orcid-api-web/src/test/java/org/orcid/api/memberV3/server/delegator/MemberV3ApiServiceDelegator_EmailsTest.java b/orcid-api-web/src/test/java/org/orcid/api/memberV3/server/delegator/MemberV3ApiServiceDelegator_EmailsTest.java index 08f209368cd..2319a2fdcb6 100644 --- a/orcid-api-web/src/test/java/org/orcid/api/memberV3/server/delegator/MemberV3ApiServiceDelegator_EmailsTest.java +++ b/orcid-api-web/src/test/java/org/orcid/api/memberV3/server/delegator/MemberV3ApiServiceDelegator_EmailsTest.java @@ -112,7 +112,7 @@ public void testReadPublicScope_Emails() { found2 = true; } else if (element.getEmail().equals("private_0000-0000-0000-0003@test.orcid.org")) { found3 = true; - } if (element.getEmail().equals("public_0000-0000-0000-0003@orcid.org")) { + } else if (element.getEmail().equals("public_0000-0000-0000-0003@orcid.org")) { found4 = true; } else { fail("Invalid put code " + element.getPutCode()); From de303cd3a24c34a469b99a1434ba51173edd5238 Mon Sep 17 00:00:00 2001 From: andrej romanov <50377758+auumgn@users.noreply.github.com> Date: Thu, 21 Nov 2024 13:18:53 +0200 Subject: [PATCH 19/23] add null check and refactor for readability --- .../org/orcid/core/utils/SourceUtils.java | 40 +++++++++++-------- .../org/orcid/core/utils/v3/SourceUtils.java | 40 +++++++++++-------- 2 files changed, 48 insertions(+), 32 deletions(-) diff --git a/orcid-core/src/main/java/org/orcid/core/utils/SourceUtils.java b/orcid-core/src/main/java/org/orcid/core/utils/SourceUtils.java index 650eeb05673..160f691d697 100644 --- a/orcid-core/src/main/java/org/orcid/core/utils/SourceUtils.java +++ b/orcid-core/src/main/java/org/orcid/core/utils/SourceUtils.java @@ -49,22 +49,30 @@ public void setSourceNameCacheManager(SourceNameCacheManager sourceNameCacheMana } public void setSourceName(SourceAware sourceAware) { - if (sourceAware != null) { - Source source = sourceAware.getSource(); - if (source != null) { - String sourceId = source.retrieveSourcePath(); - String providedSourceName = source.getSourceName().getContent(); - if (!PojoUtil.isEmpty(sourceId)) { - if (providedSourceName != null && !providedSourceName.equals(ORCID_EMAIL_VALIDATOR_CLIENT_NAME)) { - String sourceName = sourceNameCacheManager.retrieve(sourceId); - if (!PojoUtil.isEmpty(sourceName)) { - source.setSourceName(new SourceName(sourceName)); - } else { - source.setSourceName(null); - } - } - } - } + if (sourceAware == null) { + return; + } + + Source source = sourceAware.getSource(); + if (source == null) { + return; + } + + String sourceId = source.retrieveSourcePath(); + if (PojoUtil.isEmpty(sourceId)) { + return; + } + + String providedSourceName = source.getSourceName() != null ? source.getSourceName().getContent() : null; + if (providedSourceName == null || providedSourceName.equals(ORCID_EMAIL_VALIDATOR_CLIENT_NAME)) { + return; + } + + String sourceName = sourceNameCacheManager.retrieve(sourceId); + if (!PojoUtil.isEmpty(sourceName)) { + source.setSourceName(new SourceName(sourceName)); + } else { + source.setSourceName(null); } } diff --git a/orcid-core/src/main/java/org/orcid/core/utils/v3/SourceUtils.java b/orcid-core/src/main/java/org/orcid/core/utils/v3/SourceUtils.java index 90119e0f9ea..d046d8c37f8 100644 --- a/orcid-core/src/main/java/org/orcid/core/utils/v3/SourceUtils.java +++ b/orcid-core/src/main/java/org/orcid/core/utils/v3/SourceUtils.java @@ -58,22 +58,30 @@ public void setSourceNameCacheManager(SourceNameCacheManager sourceNameCacheMana } public void setSourceName(SourceAware sourceAware) { - if (sourceAware != null) { - Source source = sourceAware.getSource(); - if (source != null) { - String sourceId = source.retrieveSourcePath(); - String providedSourceName = source.getSourceName().getContent(); - if (!PojoUtil.isEmpty(sourceId)) { - if (providedSourceName != null && !providedSourceName.equals(ORCID_EMAIL_VALIDATOR_CLIENT_NAME)) { - String sourceName = sourceNameCacheManager.retrieve(sourceId); - if (!PojoUtil.isEmpty(sourceName)) { - source.setSourceName(new SourceName(sourceName)); - } else { - source.setSourceName(null); - } - } - } - } + if (sourceAware == null) { + return; + } + + Source source = sourceAware.getSource(); + if (source == null) { + return; + } + + String sourceId = source.retrieveSourcePath(); + if (PojoUtil.isEmpty(sourceId)) { + return; + } + + String providedSourceName = source.getSourceName() != null ? source.getSourceName().getContent() : null; + if (providedSourceName == null || providedSourceName.equals(ORCID_EMAIL_VALIDATOR_CLIENT_NAME)) { + return; + } + + String sourceName = sourceNameCacheManager.retrieve(sourceId); + if (!PojoUtil.isEmpty(sourceName)) { + source.setSourceName(new SourceName(sourceName)); + } else { + source.setSourceName(null); } } From 47960a6a1d36e46e8a8b1f95cb580418a89c02c5 Mon Sep 17 00:00:00 2001 From: andrej romanov <50377758+auumgn@users.noreply.github.com> Date: Thu, 21 Nov 2024 13:50:20 +0200 Subject: [PATCH 20/23] fix more tests --- orcid-core/src/main/resources/orcid-core-context.xml | 1 + .../core/manager/v3/EmailManagerReadOnlyTest.java | 10 +++++++--- .../core/manager/v3/PersonDetailsManagerTest.java | 2 +- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/orcid-core/src/main/resources/orcid-core-context.xml b/orcid-core/src/main/resources/orcid-core-context.xml index 3e8fe56325b..c7e4ba0f06e 100644 --- a/orcid-core/src/main/resources/orcid-core-context.xml +++ b/orcid-core/src/main/resources/orcid-core-context.xml @@ -588,6 +588,7 @@ + diff --git a/orcid-core/src/test/java/org/orcid/core/manager/v3/EmailManagerReadOnlyTest.java b/orcid-core/src/test/java/org/orcid/core/manager/v3/EmailManagerReadOnlyTest.java index 41f5f656ddf..f382472d194 100644 --- a/orcid-core/src/test/java/org/orcid/core/manager/v3/EmailManagerReadOnlyTest.java +++ b/orcid-core/src/test/java/org/orcid/core/manager/v3/EmailManagerReadOnlyTest.java @@ -80,8 +80,8 @@ public void getEmailsTest() { Emails emails = emailManagerReadOnly.getEmails("0000-0000-0000-0003"); assertNotNull(emails); assertNotNull(emails.getEmails()); - assertEquals(5, emails.getEmails().size()); - boolean found1 = false, found2 = false, found3 = false, found4=false, found5 = false; + assertEquals(6, emails.getEmails().size()); + boolean found1 = false, found2 = false, found3 = false, found4=false, found5 = false, found6 = false; for(Email email : emails.getEmails()) { if(email.getEmail().equals("public_0000-0000-0000-0003@test.orcid.org")) { found1 = true; @@ -93,6 +93,8 @@ public void getEmailsTest() { found4 = true; } else if(email.getEmail().equals("self_private_0000-0000-0000-0003@test.orcid.org")) { found5 = true; + } else if(email.getEmail().equals("public_0000-0000-0000-0003@orcid.org")) { + found6 = true; } else { fail("Invalid email found: " + email.getEmail()); } @@ -102,6 +104,7 @@ public void getEmailsTest() { assertTrue(found3); assertTrue(found4); assertTrue(found5); + assertTrue(found6); } @Test @@ -109,8 +112,9 @@ public void getPublicEmailsTest() { Emails emails = emailManagerReadOnly.getPublicEmails("0000-0000-0000-0003"); assertNotNull(emails); assertNotNull(emails.getEmails()); - assertEquals(1, emails.getEmails().size()); + assertEquals(2, emails.getEmails().size()); assertEquals("public_0000-0000-0000-0003@test.orcid.org", emails.getEmails().get(0).getEmail()); + assertEquals("public_0000-0000-0000-0003@orcid.org", emails.getEmails().get(1).getEmail()); } @Test diff --git a/orcid-core/src/test/java/org/orcid/core/manager/v3/PersonDetailsManagerTest.java b/orcid-core/src/test/java/org/orcid/core/manager/v3/PersonDetailsManagerTest.java index 9636e3397ba..6d318dcfa2b 100644 --- a/orcid-core/src/test/java/org/orcid/core/manager/v3/PersonDetailsManagerTest.java +++ b/orcid-core/src/test/java/org/orcid/core/manager/v3/PersonDetailsManagerTest.java @@ -72,7 +72,7 @@ public void testGetPersonDetails() { assertNotNull(person.getEmails()); assertNotNull(person.getEmails().getEmails()); - assertEquals(4, person.getEmails().getEmails().size()); + assertEquals(5, person.getEmails().getEmails().size()); for (Email email : person.getEmails().getEmails()) { assertTrue(email.isVerified()); From 30aab86b97b6733d57c829831076f81bec225de6 Mon Sep 17 00:00:00 2001 From: andrej romanov <50377758+auumgn@users.noreply.github.com> Date: Thu, 21 Nov 2024 14:04:49 +0200 Subject: [PATCH 21/23] more tests --- .../test/java/org/orcid/core/manager/RecordManagerTest.java | 2 +- .../org/orcid/core/manager/v3/PersonDetailsManagerTest.java | 5 +++-- .../java/org/orcid/core/manager/v3/RecordManagerTest.java | 3 ++- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/orcid-core/src/test/java/org/orcid/core/manager/RecordManagerTest.java b/orcid-core/src/test/java/org/orcid/core/manager/RecordManagerTest.java index 1ca728e4e01..d34233d81a5 100644 --- a/orcid-core/src/test/java/org/orcid/core/manager/RecordManagerTest.java +++ b/orcid-core/src/test/java/org/orcid/core/manager/RecordManagerTest.java @@ -75,7 +75,7 @@ public void testGetRecord() { assertNotNull(person.getEmails()); assertNotNull(person.getEmails().getEmails()); - assertEquals(4, person.getEmails().getEmails().size()); + assertEquals(5, person.getEmails().getEmails().size()); assertNotNull(person.getBiography()); assertEquals(Visibility.PUBLIC, person.getBiography().getVisibility()); diff --git a/orcid-core/src/test/java/org/orcid/core/manager/v3/PersonDetailsManagerTest.java b/orcid-core/src/test/java/org/orcid/core/manager/v3/PersonDetailsManagerTest.java index 6d318dcfa2b..0a88608dcde 100644 --- a/orcid-core/src/test/java/org/orcid/core/manager/v3/PersonDetailsManagerTest.java +++ b/orcid-core/src/test/java/org/orcid/core/manager/v3/PersonDetailsManagerTest.java @@ -99,7 +99,7 @@ public void testGetPersonDetailsIncludeUnverifiedEmails() { assertNotNull(person.getEmails()); assertNotNull(person.getEmails().getEmails()); - assertEquals(5, person.getEmails().getEmails().size()); + assertEquals(6, person.getEmails().getEmails().size()); } @Test @@ -136,8 +136,9 @@ public void testGetPublicPersonDetails() { assertNotNull(person.getEmails()); assertNotNull(person.getEmails().getEmails()); - assertEquals(1, person.getEmails().getEmails().size()); + assertEquals(2, person.getEmails().getEmails().size()); assertEquals("public_0000-0000-0000-0003@test.orcid.org", person.getEmails().getEmails().get(0).getEmail()); + assertEquals("public_0000-0000-0000-0003@orcid.org", person.getEmails().getEmails().get(1).getEmail()); assertNotNull(person.getBiography()); assertEquals(Visibility.PUBLIC, person.getBiography().getVisibility()); diff --git a/orcid-core/src/test/java/org/orcid/core/manager/v3/RecordManagerTest.java b/orcid-core/src/test/java/org/orcid/core/manager/v3/RecordManagerTest.java index 05a7b8e07e2..0f63f168ceb 100644 --- a/orcid-core/src/test/java/org/orcid/core/manager/v3/RecordManagerTest.java +++ b/orcid-core/src/test/java/org/orcid/core/manager/v3/RecordManagerTest.java @@ -174,8 +174,9 @@ public void testGetPublicRecord() { assertNotNull(person.getEmails()); assertNotNull(person.getEmails().getEmails()); - assertEquals(1, person.getEmails().getEmails().size()); + assertEquals(2, person.getEmails().getEmails().size()); assertEquals("public_0000-0000-0000-0003@test.orcid.org", person.getEmails().getEmails().get(0).getEmail()); + assertEquals("public_0000-0000-0000-0003@orcid.org", person.getEmails().getEmails().get(1).getEmail()); assertNotNull(person.getBiography()); assertEquals(Visibility.PUBLIC, person.getBiography().getVisibility()); From 8b205f82f9663f77b8797dc5305b965e7b9056fc Mon Sep 17 00:00:00 2001 From: andrej romanov <50377758+auumgn@users.noreply.github.com> Date: Thu, 21 Nov 2024 14:16:41 +0200 Subject: [PATCH 22/23] more tests --- orcid-core/src/main/resources/orcid-core-context.xml | 1 + .../test/java/org/orcid/core/manager/v3/RecordManagerTest.java | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/orcid-core/src/main/resources/orcid-core-context.xml b/orcid-core/src/main/resources/orcid-core-context.xml index c7e4ba0f06e..ebccc63371a 100644 --- a/orcid-core/src/main/resources/orcid-core-context.xml +++ b/orcid-core/src/main/resources/orcid-core-context.xml @@ -239,6 +239,7 @@ + diff --git a/orcid-core/src/test/java/org/orcid/core/manager/v3/RecordManagerTest.java b/orcid-core/src/test/java/org/orcid/core/manager/v3/RecordManagerTest.java index 0f63f168ceb..c4d74779dee 100644 --- a/orcid-core/src/test/java/org/orcid/core/manager/v3/RecordManagerTest.java +++ b/orcid-core/src/test/java/org/orcid/core/manager/v3/RecordManagerTest.java @@ -76,7 +76,7 @@ public void testGetRecord() { assertNotNull(person.getEmails()); assertNotNull(person.getEmails().getEmails()); - assertEquals(4, person.getEmails().getEmails().size()); + assertEquals(5, person.getEmails().getEmails().size()); assertNotNull(person.getBiography()); assertEquals(Visibility.PUBLIC, person.getBiography().getVisibility()); From 678c7498d7985d99d6de2eed1ea848bdd737915c Mon Sep 17 00:00:00 2001 From: andrej romanov <50377758+auumgn@users.noreply.github.com> Date: Thu, 21 Nov 2024 14:25:56 +0200 Subject: [PATCH 23/23] more tests --- .../org/orcid/core/manager/PersonDetailsManagerTest.java | 5 +++-- .../test/java/org/orcid/core/manager/RecordManagerTest.java | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/orcid-core/src/test/java/org/orcid/core/manager/PersonDetailsManagerTest.java b/orcid-core/src/test/java/org/orcid/core/manager/PersonDetailsManagerTest.java index c89c437befe..0026d89a7a1 100644 --- a/orcid-core/src/test/java/org/orcid/core/manager/PersonDetailsManagerTest.java +++ b/orcid-core/src/test/java/org/orcid/core/manager/PersonDetailsManagerTest.java @@ -71,7 +71,7 @@ public void testGetPersonDetails() { assertNotNull(person.getEmails()); assertNotNull(person.getEmails().getEmails()); - assertEquals(4, person.getEmails().getEmails().size()); + assertEquals(5, person.getEmails().getEmails().size()); for (Email email : person.getEmails().getEmails()) { assertTrue(email.isVerified()); @@ -125,8 +125,9 @@ public void testGetPublicPersonDetails() { assertNotNull(person.getEmails()); assertNotNull(person.getEmails().getEmails()); - assertEquals(1, person.getEmails().getEmails().size()); + assertEquals(2, person.getEmails().getEmails().size()); assertEquals("public_0000-0000-0000-0003@test.orcid.org", person.getEmails().getEmails().get(0).getEmail()); + assertEquals("public_0000-0000-0000-0003@orcid.org", person.getEmails().getEmails().get(1).getEmail()); assertNotNull(person.getBiography()); assertEquals(Visibility.PUBLIC, person.getBiography().getVisibility()); diff --git a/orcid-core/src/test/java/org/orcid/core/manager/RecordManagerTest.java b/orcid-core/src/test/java/org/orcid/core/manager/RecordManagerTest.java index d34233d81a5..8feb18f9245 100644 --- a/orcid-core/src/test/java/org/orcid/core/manager/RecordManagerTest.java +++ b/orcid-core/src/test/java/org/orcid/core/manager/RecordManagerTest.java @@ -152,8 +152,9 @@ public void testGetPublicRecord() { assertNotNull(person.getEmails()); assertNotNull(person.getEmails().getEmails()); - assertEquals(1, person.getEmails().getEmails().size()); + assertEquals(2, person.getEmails().getEmails().size()); assertEquals("public_0000-0000-0000-0003@test.orcid.org", person.getEmails().getEmails().get(0).getEmail()); + assertEquals("public_0000-0000-0000-0003@orcid.org", person.getEmails().getEmails().get(1).getEmail()); assertNotNull(person.getBiography()); assertEquals(Visibility.PUBLIC, person.getBiography().getVisibility());