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 @@ +