Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
auumgn committed Nov 20, 2024
1 parent e305df8 commit 0066898
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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()));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Distinction, Education, Employment, PersonExternalIdentifier, InvitedPosition, Funding, GroupIdRecord, Membership, OtherName, PeerReview, Qualification, ResearcherUrl, Service, Work, WorkBulk, Address, Keyword, ResearchResource> {
Expand Down Expand Up @@ -279,6 +277,9 @@ public class MemberV3ApiServiceDelegatorImpl implements
@Resource
private EmailDomainManager emailDomainManager;

@Resource
private SourceEntityUtils sourceEntityUtils;

public Boolean getFilterVersionOfIdentifiers() {
return filterVersionOfIdentifiers;
}
Expand Down Expand Up @@ -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()));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {

Expand All @@ -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;
}
Expand Down Expand Up @@ -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()));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {

Expand All @@ -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;
}
Expand Down Expand Up @@ -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()));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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));
Expand Down

0 comments on commit 0066898

Please sign in to comment.