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 b01568ce7b..1f12355c0b 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 1edcad5339..70daa4569f 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 94a52a3104..c7753c9636 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 219308d641..496a7c0af3 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 e6bdae417f..22169d58f5 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 ddf3ff0b33..1bceb29f3a 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 5c0e8ddae8..650eeb0567 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 ce1c46a979..90119e0f9e 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));