Skip to content

Commit

Permalink
add professional email source name to api responses
Browse files Browse the repository at this point in the history
  • Loading branch information
auumgn committed Nov 19, 2024
1 parent b770d20 commit da73277
Show file tree
Hide file tree
Showing 8 changed files with 89 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -98,6 +100,7 @@
import org.orcid.jaxb.model.record_v2.Work;
import org.orcid.jaxb.model.record_v2.WorkBulk;
import org.orcid.jaxb.model.search_v2.Search;
import org.orcid.persistence.jpa.entities.EmailDomainEntity;
import org.springframework.context.MessageSource;
import org.springframework.stereotype.Component;

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

@Resource
private EmailDomainManager emailDomainManager;

@Override
public Response viewStatusText() {
return Response.ok(STATUS_OK_MESSAGE).build();
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.orcid.api.common.util.v3.ActivityUtils;
import org.orcid.api.common.util.v3.ElementUtils;
import org.orcid.api.memberV3.server.delegator.MemberV3ApiServiceDelegator;
import org.orcid.core.common.manager.EmailDomainManager;
import org.orcid.core.common.manager.SummaryManager;
import org.orcid.core.exception.DeactivatedException;
import org.orcid.core.exception.DuplicatedGroupIdRecordException;
Expand Down Expand Up @@ -128,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<Distinction, Education, Employment, PersonExternalIdentifier, InvitedPosition, Funding, GroupIdRecord, Membership, OtherName, PeerReview, Qualification, ResearcherUrl, Service, Work, WorkBulk, Address, Keyword, ResearchResource> {
Expand Down Expand Up @@ -271,7 +275,10 @@ public class MemberV3ApiServiceDelegatorImpl implements

@Resource
private SummaryManager summaryManager;


@Resource
private EmailDomainManager emailDomainManager;

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

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

Expand All @@ -47,6 +51,8 @@ public class PersonDetailsManagerReadOnlyImpl extends ManagerReadOnlyBaseImpl im

protected BiographyManagerReadOnly biographyManager;

private EmailDomainManager emailDomainManager;

public void setAddressManager(AddressManagerReadOnly addressManager) {
this.addressManager = addressManager;
}
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -124,6 +134,16 @@ public Person getPersonDetails(String orcid) {
if (emails.getEmails() != null) {
Emails filteredEmails = new Emails();
filteredEmails.setEmails(new ArrayList<Email>(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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {

Expand All @@ -47,6 +51,8 @@ public class PersonDetailsManagerReadOnlyImpl extends ManagerReadOnlyBaseImpl im

protected BiographyManagerReadOnly biographyManager;

protected EmailDomainManager emailDomainManager;

public void setAddressManager(AddressManagerReadOnly addressManager) {
this.addressManager = addressManager;
}
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -129,6 +139,16 @@ public Person getPersonDetails(String orcid, boolean includeUnverifiedEmails) {
} else {
filteredEmails.setEmails(new ArrayList<Email>(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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@

import java.util.List;

import static org.orcid.core.constants.EmailConstants.ORCID_EMAIL_VALIDATION;

public class SourceUtils {
private SourceNameCacheManager sourceNameCacheManager;

Expand All @@ -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));
Expand Down
2 changes: 2 additions & 0 deletions orcid-core/src/main/resources/orcid-core-context.xml
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@
<property name="emailManager" ref="emailManagerReadOnly"/>
<property name="recordNameManager" ref="recordNameManagerReadOnly"/>
<property name="biographyManager" ref="biographyManagerReadOnly"/>
<property name="emailDomainManager" ref="emailDomainManager"/>
<property name="profileLastModifiedAspect" ref="profileLastModifiedAspectReadOnly" />
</bean>

Expand Down Expand Up @@ -599,6 +600,7 @@
<property name="emailManager" ref="emailManagerReadOnlyV3"/>
<property name="recordNameManager" ref="recordNameManagerReadOnlyV3"/>
<property name="biographyManager" ref="biographyManagerReadOnlyV3"/>
<property name="emailDomainManager" ref="emailDomainManager"/>
<property name="profileLastModifiedAspect" ref="profileLastModifiedAspectReadOnly" />
</bean>

Expand Down

0 comments on commit da73277

Please sign in to comment.