From 06d7026131720bebf28e883cdf030be6442830c0 Mon Sep 17 00:00:00 2001 From: andrej romanov <50377758+auumgn@users.noreply.github.com> Date: Sat, 10 Aug 2024 18:43:47 +0300 Subject: [PATCH] Add email domains (#7063) * fix typos * add db table * add togglz * add email domain logic * improve new domain logic * add another toggle * improve readability, add transactions, cleanup * remove todo * add indexes to profile email domain table * fix new domain visibility bug --- .../common/manager/EmailDomainManager.java | 2 +- .../manager/impl/EmailDomainManagerImpl.java | 6 +- .../impl/PeerReviewManagerReadOnlyImpl.java | 2 +- .../manager/v3/ProfileEmailDomainManager.java | 16 + .../manager/v3/impl/EmailManagerImpl.java | 26 +- .../impl/ProfileEmailDomainManagerImpl.java | 78 +++ .../ProfileEmailDomainManagerReadOnly.java | 16 + ...ProfileEmailDomainManagerReadOnlyImpl.java | 32 + .../java/org/orcid/core/togglz/Features.java | 8 +- .../java/org/orcid/pojo/ajaxForm/Emails.java | 16 +- .../pojo/ajaxForm/ProfileEmailDomain.java | 79 +++ .../src/main/resources/orcid-core-context.xml | 16 +- .../manager/EmailDomainManagerTest.java | 22 +- .../orcid/persistence/dao/EmailDomainDao.java | 2 +- .../dao/ProfileEmailDomainDao.java | 19 + .../dao/impl/EmailDomainDaoImpl.java | 2 +- .../dao/impl/ProfileEmailDomainDaoImpl.java | 89 +++ .../entities/ProfileEmailDomainEntity.java | 73 ++ .../main/resources/META-INF/persistence.xml | 1 + .../src/main/resources/db-master.xml | 641 +++++++++--------- .../create_profile_email_domain_table.xml | 64 ++ .../resources/orcid-persistence-context.xml | 10 +- .../loader/cli/EmailDomainLoader.java | 2 +- .../controllers/EmailDomainController.java | 4 +- .../controllers/ManageProfileController.java | 55 +- .../controllers/PublicRecordController.java | 19 +- 26 files changed, 925 insertions(+), 375 deletions(-) create mode 100644 orcid-core/src/main/java/org/orcid/core/manager/v3/ProfileEmailDomainManager.java create mode 100644 orcid-core/src/main/java/org/orcid/core/manager/v3/impl/ProfileEmailDomainManagerImpl.java create mode 100644 orcid-core/src/main/java/org/orcid/core/manager/v3/read_only/ProfileEmailDomainManagerReadOnly.java create mode 100644 orcid-core/src/main/java/org/orcid/core/manager/v3/read_only/impl/ProfileEmailDomainManagerReadOnlyImpl.java create mode 100644 orcid-core/src/main/java/org/orcid/pojo/ajaxForm/ProfileEmailDomain.java create mode 100644 orcid-persistence/src/main/java/org/orcid/persistence/dao/ProfileEmailDomainDao.java create mode 100644 orcid-persistence/src/main/java/org/orcid/persistence/dao/impl/ProfileEmailDomainDaoImpl.java create mode 100644 orcid-persistence/src/main/java/org/orcid/persistence/jpa/entities/ProfileEmailDomainEntity.java create mode 100644 orcid-persistence/src/main/resources/db/updates/create_profile_email_domain_table.xml diff --git a/orcid-core/src/main/java/org/orcid/core/common/manager/EmailDomainManager.java b/orcid-core/src/main/java/org/orcid/core/common/manager/EmailDomainManager.java index 167e25e2d2f..838e3a0c4f9 100644 --- a/orcid-core/src/main/java/org/orcid/core/common/manager/EmailDomainManager.java +++ b/orcid-core/src/main/java/org/orcid/core/common/manager/EmailDomainManager.java @@ -10,7 +10,7 @@ public interface EmailDomainManager { boolean updateCategory(long id, EmailDomainEntity.DomainCategory category); - EmailDomainEntity findByEmailDoman(String emailDomain); + EmailDomainEntity findByEmailDomain(String emailDomain); List findByCategory(EmailDomainEntity.DomainCategory category); diff --git a/orcid-core/src/main/java/org/orcid/core/common/manager/impl/EmailDomainManagerImpl.java b/orcid-core/src/main/java/org/orcid/core/common/manager/impl/EmailDomainManagerImpl.java index dcfe88f952b..73f34bd4ca8 100644 --- a/orcid-core/src/main/java/org/orcid/core/common/manager/impl/EmailDomainManagerImpl.java +++ b/orcid-core/src/main/java/org/orcid/core/common/manager/impl/EmailDomainManagerImpl.java @@ -48,11 +48,11 @@ public boolean updateCategory(long id, DomainCategory category) { } @Override - public EmailDomainEntity findByEmailDoman(String emailDomain) { + public EmailDomainEntity findByEmailDomain(String emailDomain) { if (emailDomain == null || emailDomain.isBlank()) { throw new IllegalArgumentException("Email Domain must not be empty"); } - return emailDomainDaoReadOnly.findByEmailDoman(emailDomain); + return emailDomainDaoReadOnly.findByEmailDomain(emailDomain); } @Override @@ -65,7 +65,7 @@ public List findByCategory(DomainCategory category) { @Override public STATUS createOrUpdateEmailDomain(String emailDomain, String rorId) { - EmailDomainEntity existingEntity = emailDomainDaoReadOnly.findByEmailDoman(emailDomain); + EmailDomainEntity existingEntity = emailDomainDaoReadOnly.findByEmailDomain(emailDomain); if(existingEntity != null) { if(!rorId.equals(existingEntity.getRorId())) { boolean updated = emailDomainDao.updateRorId(existingEntity.getId(), rorId); diff --git a/orcid-core/src/main/java/org/orcid/core/manager/read_only/impl/PeerReviewManagerReadOnlyImpl.java b/orcid-core/src/main/java/org/orcid/core/manager/read_only/impl/PeerReviewManagerReadOnlyImpl.java index cc1d26c72cc..54a8362bf22 100644 --- a/orcid-core/src/main/java/org/orcid/core/manager/read_only/impl/PeerReviewManagerReadOnlyImpl.java +++ b/orcid-core/src/main/java/org/orcid/core/manager/read_only/impl/PeerReviewManagerReadOnlyImpl.java @@ -51,7 +51,7 @@ public List findPeerReviews(String orcid) { } /** - * Get the list of peer reivews that belongs to a user + * Get the list of peer reviews that belongs to a user * * @param userOrcid * @param lastModified diff --git a/orcid-core/src/main/java/org/orcid/core/manager/v3/ProfileEmailDomainManager.java b/orcid-core/src/main/java/org/orcid/core/manager/v3/ProfileEmailDomainManager.java new file mode 100644 index 00000000000..93a8eb19c6f --- /dev/null +++ b/orcid-core/src/main/java/org/orcid/core/manager/v3/ProfileEmailDomainManager.java @@ -0,0 +1,16 @@ +package org.orcid.core.manager.v3; + +import org.orcid.core.manager.v3.read_only.ProfileEmailDomainManagerReadOnly; +import org.orcid.persistence.jpa.entities.EmailEntity; + +import java.util.List; + +/** + * + * @author Andrej Romanov + * + */ +public interface ProfileEmailDomainManager extends ProfileEmailDomainManagerReadOnly { + void updateEmailDomains(String orcid, org.orcid.pojo.ajaxForm.Emails emails); + void processDomain(String orcid, String email); +} diff --git a/orcid-core/src/main/java/org/orcid/core/manager/v3/impl/EmailManagerImpl.java b/orcid-core/src/main/java/org/orcid/core/manager/v3/impl/EmailManagerImpl.java index f79c7ce3955..87a4f3347df 100644 --- a/orcid-core/src/main/java/org/orcid/core/manager/v3/impl/EmailManagerImpl.java +++ b/orcid-core/src/main/java/org/orcid/core/manager/v3/impl/EmailManagerImpl.java @@ -10,8 +10,10 @@ import org.apache.commons.lang3.StringUtils; import org.orcid.core.manager.EncryptionManager; import org.orcid.core.manager.v3.EmailManager; +import org.orcid.core.manager.v3.ProfileEmailDomainManager; import org.orcid.core.manager.v3.SourceManager; import org.orcid.core.manager.v3.read_only.impl.EmailManagerReadOnlyImpl; +import org.orcid.core.togglz.Features; import org.orcid.jaxb.model.v3.release.common.Visibility; import org.orcid.jaxb.model.v3.release.record.Email; import org.orcid.persistence.aop.UpdateProfileLastModifiedAndIndexingStatus; @@ -38,6 +40,9 @@ public class EmailManagerImpl extends EmailManagerReadOnlyImpl implements EmailM @Resource(name = "sourceManagerV3") private SourceManager sourceManager; + @Resource(name = "profileEmailDomainManager") + private ProfileEmailDomainManager profileEmailDomainManager; + @Resource private TransactionTemplate transactionTemplate; @@ -62,9 +67,14 @@ public void removeEmail(String orcid, String email) { } @Override + @Transactional @UpdateProfileLastModifiedAndIndexingStatus public boolean verifyEmail(String orcid, String email) { - return emailDao.verifyEmail(email); + boolean result = emailDao.verifyEmail(email); + if (result && Features.EMAIL_DOMAINS.isActive()) { + profileEmailDomainManager.processDomain(orcid, email); + } + return result; } @Override @@ -72,7 +82,12 @@ public boolean verifyEmail(String orcid, String email) { public boolean verifyPrimaryEmail(String orcid) { try { String primaryEmail = emailDao.findPrimaryEmail(orcid).getEmail(); - return emailDao.verifyEmail(primaryEmail); + + boolean result = emailDao.verifyEmail(primaryEmail); + if (result && Features.EMAIL_DOMAINS.isActive()) { + profileEmailDomainManager.processDomain(orcid, primaryEmail); + } + return result; } catch (javax.persistence.NoResultException nre) { String alternativePrimaryEmail = emailDao.findNewestVerifiedOrNewestEmail(orcid); emailDao.updatePrimary(orcid, alternativePrimaryEmail); @@ -99,12 +114,17 @@ public boolean moveEmailToOtherAccount(String email, String origin, String desti } @Override + @Transactional public boolean verifySetCurrentAndPrimary(String orcid, String email) { if (PojoUtil.isEmpty(orcid) || PojoUtil.isEmpty(email)) { throw new IllegalArgumentException("orcid or email param is empty or null"); } - return emailDao.updateVerifySetCurrentAndPrimary(orcid, email); + boolean result = emailDao.updateVerifySetCurrentAndPrimary(orcid, email); + if (result && Features.EMAIL_DOMAINS.isActive()) { + profileEmailDomainManager.processDomain(orcid, email); + } + return result; } /*** diff --git a/orcid-core/src/main/java/org/orcid/core/manager/v3/impl/ProfileEmailDomainManagerImpl.java b/orcid-core/src/main/java/org/orcid/core/manager/v3/impl/ProfileEmailDomainManagerImpl.java new file mode 100644 index 00000000000..dbb8db060e3 --- /dev/null +++ b/orcid-core/src/main/java/org/orcid/core/manager/v3/impl/ProfileEmailDomainManagerImpl.java @@ -0,0 +1,78 @@ +package org.orcid.core.manager.v3.impl; + + +import org.orcid.core.manager.v3.ProfileEmailDomainManager; +import org.orcid.core.manager.v3.read_only.impl.ProfileEmailDomainManagerReadOnlyImpl; +import org.orcid.jaxb.model.v3.release.common.Visibility; +import org.orcid.persistence.dao.EmailDao; +import org.orcid.persistence.dao.EmailDomainDao; +import org.orcid.persistence.dao.ProfileEmailDomainDao; +import org.orcid.persistence.jpa.entities.EmailDomainEntity; +import org.orcid.persistence.jpa.entities.ProfileEmailDomainEntity; +import org.springframework.transaction.annotation.Transactional; + +import javax.annotation.Resource; +import java.util.*; + +/** + * + * @author Andrej Romanov + * + */ +public class ProfileEmailDomainManagerImpl extends ProfileEmailDomainManagerReadOnlyImpl implements ProfileEmailDomainManager { + @Resource + protected ProfileEmailDomainDao profileEmailDomainDao; + + @Resource + protected EmailDomainDao emailDomainDao; + + @Resource + protected EmailDao emailDao; + + private static final String DEFAULT_DOMAIN_VISIBILITY = Visibility.PRIVATE.toString().toUpperCase(); + + @Transactional + public void updateEmailDomains(String orcid, org.orcid.pojo.ajaxForm.Emails newEmails) { + List existingEmailDomains = profileEmailDomainDao.findByOrcid(orcid); + + if (existingEmailDomains != null) { + // VISIBILITY UPDATE FOR EXISTING DOMAINS + for (org.orcid.pojo.ajaxForm.ProfileEmailDomain emailDomain : newEmails.getEmailDomains()) { + for (ProfileEmailDomainEntity existingEmailDomain : existingEmailDomains) { + if (existingEmailDomain.getEmailDomain().equals(emailDomain.getValue())) { + if (!existingEmailDomain.getVisibility().equals(emailDomain.getVisibility())) { + profileEmailDomainDao.updateVisibility(orcid, emailDomain.getValue(), emailDomain.getVisibility()); + } + } + } + } + + // REMOVE DOMAINS + for (ProfileEmailDomainEntity existingEmailDomain : existingEmailDomains) { + boolean deleteEmail = true; + for (org.orcid.pojo.ajaxForm.ProfileEmailDomain emailDomain : newEmails.getEmailDomains()) { + if (existingEmailDomain.getEmailDomain().equals(emailDomain.getValue())) { + deleteEmail = false; + break; + } + } + if (deleteEmail) { + profileEmailDomainDao.removeEmailDomain(orcid, existingEmailDomain.getEmailDomain()); + } + } + } + } + + public void processDomain(String orcid, String email) { + String domain = email.split("@")[1]; + EmailDomainEntity domainInfo = emailDomainDao.findByEmailDomain(domain); + // Check if email is professional + if (domainInfo != null && domainInfo.getCategory().equals(EmailDomainEntity.DomainCategory.PROFESSIONAL)) { + ProfileEmailDomainEntity existingDomain = profileEmailDomainDao.findByEmailDomain(orcid, domain); + // ADD NEW DOMAIN IF ONE DOESN'T EXIST + if (existingDomain == null) { + profileEmailDomainDao.addEmailDomain(orcid, domain, DEFAULT_DOMAIN_VISIBILITY); + } + } + } +} diff --git a/orcid-core/src/main/java/org/orcid/core/manager/v3/read_only/ProfileEmailDomainManagerReadOnly.java b/orcid-core/src/main/java/org/orcid/core/manager/v3/read_only/ProfileEmailDomainManagerReadOnly.java new file mode 100644 index 00000000000..aa0212332e9 --- /dev/null +++ b/orcid-core/src/main/java/org/orcid/core/manager/v3/read_only/ProfileEmailDomainManagerReadOnly.java @@ -0,0 +1,16 @@ +package org.orcid.core.manager.v3.read_only; + + +import org.orcid.persistence.jpa.entities.ProfileEmailDomainEntity; + +import java.util.List; + +/** + * + * @author Andrej Romanov + * + */ +public interface ProfileEmailDomainManagerReadOnly { + List getEmailDomains(String orcid); + List getPublicEmailDomains(String orcid); +} diff --git a/orcid-core/src/main/java/org/orcid/core/manager/v3/read_only/impl/ProfileEmailDomainManagerReadOnlyImpl.java b/orcid-core/src/main/java/org/orcid/core/manager/v3/read_only/impl/ProfileEmailDomainManagerReadOnlyImpl.java new file mode 100644 index 00000000000..dc97b2fb9c1 --- /dev/null +++ b/orcid-core/src/main/java/org/orcid/core/manager/v3/read_only/impl/ProfileEmailDomainManagerReadOnlyImpl.java @@ -0,0 +1,32 @@ +package org.orcid.core.manager.v3.read_only.impl; + + +import org.orcid.core.manager.read_only.impl.ManagerReadOnlyBaseImpl; +import org.orcid.core.manager.v3.read_only.ProfileEmailDomainManagerReadOnly; +import org.orcid.persistence.dao.ProfileEmailDomainDao; +import org.orcid.persistence.jpa.entities.ProfileEmailDomainEntity; + +import javax.annotation.Resource; +import java.util.List; + +/** + * + * @author Andrej Romanov + * + */ +public class ProfileEmailDomainManagerReadOnlyImpl extends ManagerReadOnlyBaseImpl implements ProfileEmailDomainManagerReadOnly { + @Resource + protected ProfileEmailDomainDao profileEmailDomainDao; + + public void setProfileEmailDomainDao(ProfileEmailDomainDao profileEmailDomainDao) { + this.profileEmailDomainDao = profileEmailDomainDao; + } + + public List getEmailDomains(String orcid) { + return profileEmailDomainDao.findByOrcid(orcid); + }; + + public List getPublicEmailDomains(String orcid) { + return profileEmailDomainDao.findPublicEmailDomains(orcid); + }; +} diff --git a/orcid-core/src/main/java/org/orcid/core/togglz/Features.java b/orcid-core/src/main/java/org/orcid/core/togglz/Features.java index 3bfe0bac62a..0151c946ae3 100644 --- a/orcid-core/src/main/java/org/orcid/core/togglz/Features.java +++ b/orcid-core/src/main/java/org/orcid/core/togglz/Features.java @@ -59,7 +59,13 @@ public enum Features implements Feature { PAPI_EVENTS, @Label("Enable summary endpoint in the Members API") - MAPI_SUMMARY_ENDPOINT; + MAPI_SUMMARY_ENDPOINT, + + @Label("Enable email domains") + EMAIL_DOMAINS, + + @Label("Enable email domains in the UI") + EMAIL_DOMAINS_UI; public boolean isActive() { return FeatureContext.getFeatureManager().isActive(this); diff --git a/orcid-core/src/main/java/org/orcid/pojo/ajaxForm/Emails.java b/orcid-core/src/main/java/org/orcid/pojo/ajaxForm/Emails.java index 2b78d0ba155..1ea3ad73889 100644 --- a/orcid-core/src/main/java/org/orcid/pojo/ajaxForm/Emails.java +++ b/orcid-core/src/main/java/org/orcid/pojo/ajaxForm/Emails.java @@ -1,16 +1,20 @@ package org.orcid.pojo.ajaxForm; +import org.orcid.core.togglz.Features; +import org.orcid.persistence.jpa.entities.ProfileEmailDomainEntity; + import java.util.ArrayList; import java.util.List; public class Emails implements ErrorsInterface { private List emails = null; + private List emailDomains = null; @SuppressWarnings("unused") private static final long serialVersionUID = 1L; private List errors = new ArrayList(); - public static Emails valueOf(org.orcid.jaxb.model.v3.release.record.Emails e) { + public static Emails valueOf(org.orcid.jaxb.model.v3.release.record.Emails e, List domains) { Emails emails = new Emails(); if (e != null && !e.getEmails().isEmpty()) { emails.setEmails(new ArrayList()); @@ -18,6 +22,12 @@ public static Emails valueOf(org.orcid.jaxb.model.v3.release.record.Emails e) { emails.getEmails().add(Email.valueOf(v3Email)); } } + if (domains != null && !domains.isEmpty() && Features.EMAIL_DOMAINS.isActive()) { + emails.setEmailDomains(new ArrayList()); + for (ProfileEmailDomainEntity domain : domains) { + emails.getEmailDomains().add(ProfileEmailDomain.valueOf(domain)); + } + } return emails; } @@ -46,4 +56,8 @@ public List getEmails() { public void setEmails(List emails) { this.emails = emails; } + + public List getEmailDomains() { return emailDomains; } + + public void setEmailDomains(List emailDomains) { this.emailDomains = emailDomains;} } diff --git a/orcid-core/src/main/java/org/orcid/pojo/ajaxForm/ProfileEmailDomain.java b/orcid-core/src/main/java/org/orcid/pojo/ajaxForm/ProfileEmailDomain.java new file mode 100644 index 00000000000..3ac0d064246 --- /dev/null +++ b/orcid-core/src/main/java/org/orcid/pojo/ajaxForm/ProfileEmailDomain.java @@ -0,0 +1,79 @@ +package org.orcid.pojo.ajaxForm; + +import org.orcid.persistence.jpa.entities.ProfileEmailDomainEntity; + +import java.time.LocalDate; +import java.time.ZoneId; + +public class ProfileEmailDomain { + + protected String value; + + protected String visibility; + + private Date createdDate; + + private Date lastModified; + + public static ProfileEmailDomain valueOf(ProfileEmailDomainEntity ed) { + ProfileEmailDomain emailDomain = new ProfileEmailDomain(); + + if (ed != null) { + emailDomain.setValue(ed.getEmailDomain()); + emailDomain.setVisibility(ed.getVisibility()); + + if (ed.getDateCreated() != null) { + Date createdDate = new Date(); + LocalDate date = ed.getDateCreated().toInstant().atZone(ZoneId.systemDefault()).toLocalDate(); + createdDate.setYear(String.valueOf(date.getYear())); + createdDate.setMonth(String.valueOf(date.getMonth())); + createdDate.setDay(String.valueOf(date.getDayOfMonth())); + createdDate.setTimestamp(ed.getDateCreated().toInstant().toEpochMilli()); + emailDomain.setCreatedDate(createdDate); + } + + if (ed.getLastModified() != null) { + Date lastModifiedDate = new Date(); + LocalDate date = ed.getLastModified().toInstant().atZone(ZoneId.systemDefault()).toLocalDate(); + lastModifiedDate.setYear(String.valueOf(date.getYear())); + lastModifiedDate.setMonth(String.valueOf(date.getMonth())); + lastModifiedDate.setDay(String.valueOf(date.getDayOfMonth())); + emailDomain.setLastModified(lastModifiedDate); + } + } + return emailDomain; + } + + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + + public String getVisibility() { + return visibility; + } + + public void setVisibility(String visibility) { + this.visibility = visibility; + } + + public Date getCreatedDate() { + return createdDate; + } + + public void setCreatedDate(Date createdDate) { + this.createdDate = createdDate; + } + + public Date getLastModified() { + return lastModified; + } + + public void setLastModified(Date lastModified) { + this.lastModified = lastModified; + } +} diff --git a/orcid-core/src/main/resources/orcid-core-context.xml b/orcid-core/src/main/resources/orcid-core-context.xml index 5bf56885446..3402d3db718 100644 --- a/orcid-core/src/main/resources/orcid-core-context.xml +++ b/orcid-core/src/main/resources/orcid-core-context.xml @@ -499,9 +499,19 @@ - - - + + + + + + + + + + + + + diff --git a/orcid-core/src/test/java/org/orcid/core/common/manager/EmailDomainManagerTest.java b/orcid-core/src/test/java/org/orcid/core/common/manager/EmailDomainManagerTest.java index 5a89982de1a..5eb7cde5b30 100644 --- a/orcid-core/src/test/java/org/orcid/core/common/manager/EmailDomainManagerTest.java +++ b/orcid-core/src/test/java/org/orcid/core/common/manager/EmailDomainManagerTest.java @@ -50,8 +50,8 @@ public void before() { when(emailDomainDaoReadOnlyMock.findByCategory(eq(DomainCategory.PERSONAL))).thenReturn(List.of(e1, e2)); when(emailDomainDaoReadOnlyMock.findByCategory(eq(DomainCategory.PROFESSIONAL))).thenReturn(List.of(e3)); - when(emailDomainDaoReadOnlyMock.findByEmailDoman("gmail.com")).thenReturn(e1); - when(emailDomainDaoReadOnlyMock.findByEmailDoman("orcid.org")).thenReturn(e3); + when(emailDomainDaoReadOnlyMock.findByEmailDomain("gmail.com")).thenReturn(e1); + when(emailDomainDaoReadOnlyMock.findByEmailDomain("orcid.org")).thenReturn(e3); when(emailDomainDaoMock.createEmailDomain(eq("new.domain"), eq(DomainCategory.PROFESSIONAL), eq("https://ror.org/0"))).thenReturn(new EmailDomainEntity("new.domain", DomainCategory.PROFESSIONAL, "https://ror.org/0")); when(emailDomainDaoMock.updateRorId(1000L, "https://ror.org/0")).thenReturn(true); @@ -95,23 +95,23 @@ public void updateCategoryTest() { } @Test(expected = IllegalArgumentException.class) - public void findByEmailDoman_NullDomainTest() { - edm.findByEmailDoman(null); + public void findByEmailDomain_NullDomainTest() { + edm.findByEmailDomain(null); } @Test(expected = IllegalArgumentException.class) - public void findByEmailDoman_EmptyDomainTest() { - edm.findByEmailDoman(" "); + public void findByEmailDomain_EmptyDomainTest() { + edm.findByEmailDomain(" "); } @Test - public void findByEmailDoman_NothingFoundTest() { - assertNull(edm.findByEmailDoman("other.com")); + public void findByEmailDomain_NothingFoundTest() { + assertNull(edm.findByEmailDomain("other.com")); } @Test - public void findByEmailDomanTest() { - EmailDomainEntity ede = edm.findByEmailDoman("gmail.com"); + public void findByEmailDomainTest() { + EmailDomainEntity ede = edm.findByEmailDomain("gmail.com"); assertNotNull(ede); assertEquals("gmail.com", ede.getEmailDomain()); assertEquals(DomainCategory.PERSONAL, ede.getCategory()); @@ -119,7 +119,7 @@ public void findByEmailDomanTest() { @Test(expected = IllegalArgumentException.class) public void findByCategory_NullCategoryTest() { - edm.findByEmailDoman(null); + edm.findByEmailDomain(null); } @Test diff --git a/orcid-persistence/src/main/java/org/orcid/persistence/dao/EmailDomainDao.java b/orcid-persistence/src/main/java/org/orcid/persistence/dao/EmailDomainDao.java index 93ea7a3bc35..9c7dc02e213 100644 --- a/orcid-persistence/src/main/java/org/orcid/persistence/dao/EmailDomainDao.java +++ b/orcid-persistence/src/main/java/org/orcid/persistence/dao/EmailDomainDao.java @@ -13,7 +13,7 @@ public interface EmailDomainDao extends GenericDao { boolean updateRorId(long id, String rorId); - EmailDomainEntity findByEmailDoman(String emailDomain); + EmailDomainEntity findByEmailDomain(String emailDomain); List findByCategory(EmailDomainEntity.DomainCategory category); } diff --git a/orcid-persistence/src/main/java/org/orcid/persistence/dao/ProfileEmailDomainDao.java b/orcid-persistence/src/main/java/org/orcid/persistence/dao/ProfileEmailDomainDao.java new file mode 100644 index 00000000000..679b40dde21 --- /dev/null +++ b/orcid-persistence/src/main/java/org/orcid/persistence/dao/ProfileEmailDomainDao.java @@ -0,0 +1,19 @@ +package org.orcid.persistence.dao; + +import org.orcid.persistence.jpa.entities.ProfileEmailDomainEntity; + +import java.util.List; + +public interface ProfileEmailDomainDao extends GenericDao { + ProfileEmailDomainEntity addEmailDomain(String orcid, String emailDomain, String visibility); + + void removeEmailDomain(String orcid, String emailDomain); + + boolean updateVisibility(String orcid, String emailDomain, String visibility); + + List findByOrcid(String orcid); + + List findPublicEmailDomains(String orcid); + + ProfileEmailDomainEntity findByEmailDomain(String orcid, String emailDomain); +} \ No newline at end of file diff --git a/orcid-persistence/src/main/java/org/orcid/persistence/dao/impl/EmailDomainDaoImpl.java b/orcid-persistence/src/main/java/org/orcid/persistence/dao/impl/EmailDomainDaoImpl.java index 6c75eec184f..c23525ea716 100644 --- a/orcid-persistence/src/main/java/org/orcid/persistence/dao/impl/EmailDomainDaoImpl.java +++ b/orcid-persistence/src/main/java/org/orcid/persistence/dao/impl/EmailDomainDaoImpl.java @@ -65,7 +65,7 @@ public boolean updateRorId(long id, String rorId) { } @Override - public EmailDomainEntity findByEmailDoman(String emailDomain) { + public EmailDomainEntity findByEmailDomain(String emailDomain) { TypedQuery query = entityManager.createQuery("from EmailDomainEntity where emailDomain = :emailDomain", EmailDomainEntity.class); query.setParameter("emailDomain", emailDomain); try { diff --git a/orcid-persistence/src/main/java/org/orcid/persistence/dao/impl/ProfileEmailDomainDaoImpl.java b/orcid-persistence/src/main/java/org/orcid/persistence/dao/impl/ProfileEmailDomainDaoImpl.java new file mode 100644 index 00000000000..9a8bffd0b4e --- /dev/null +++ b/orcid-persistence/src/main/java/org/orcid/persistence/dao/impl/ProfileEmailDomainDaoImpl.java @@ -0,0 +1,89 @@ +package org.orcid.persistence.dao.impl; + +import org.orcid.persistence.aop.UpdateProfileLastModifiedAndIndexingStatus; +import org.orcid.persistence.dao.ProfileEmailDomainDao; +import org.orcid.persistence.jpa.entities.ProfileEmailDomainEntity; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.transaction.annotation.Transactional; + +import javax.persistence.NoResultException; +import javax.persistence.Query; +import javax.persistence.TypedQuery; +import java.util.List; + +public class ProfileEmailDomainDaoImpl extends GenericDaoImpl implements ProfileEmailDomainDao { + + private static final Logger LOG = LoggerFactory.getLogger(ProfileEmailDomainDaoImpl.class); + + public ProfileEmailDomainDaoImpl() { + super(ProfileEmailDomainEntity.class); + } + + @Override + @Transactional + @UpdateProfileLastModifiedAndIndexingStatus + public ProfileEmailDomainEntity addEmailDomain(String orcid, String emailDomain, String visibility) { + ProfileEmailDomainEntity e = new ProfileEmailDomainEntity(); + e.setEmailDomain(emailDomain); + e.setOrcid(orcid); + e.setVisibility(visibility); + entityManager.persist(e); + return e; + } + + @Override + @Transactional + @UpdateProfileLastModifiedAndIndexingStatus + public void removeEmailDomain(String orcid, String emailDomain) { + String deleteEmail = "delete from profile_email_domain where orcid = :orcid and trim(lower(email_domain)) = trim(lower(:emailDomain))"; + + Query query = entityManager.createNativeQuery(deleteEmail); + query.setParameter("emailDomain", emailDomain); + query.setParameter("orcid", orcid); + query.executeUpdate(); + } + + @Override + @Transactional + @UpdateProfileLastModifiedAndIndexingStatus + public boolean updateVisibility(String orcid, String emailDomain, String visibility) { + Query query = entityManager.createNativeQuery("UPDATE profile_email_domain SET visibility=:visibility, last_modified = now() WHERE orcid = :orcid and email_domain = :emailDomain"); + query.setParameter("orcid", orcid); + query.setParameter("emailDomain", emailDomain); + query.setParameter("visibility", visibility); + return query.executeUpdate() > 0; + } + + @Override + public List findByOrcid(String orcid) { + TypedQuery query = entityManager.createQuery("from ProfileEmailDomainEntity where orcid = :orcid", ProfileEmailDomainEntity.class); + query.setParameter("orcid", orcid); + List results = query.getResultList(); + return results.isEmpty() ? null : results; + } + + @Override + public List findPublicEmailDomains(String orcid) { + TypedQuery query = entityManager.createQuery("from ProfileEmailDomainEntity where orcid = :orcid and visibility = 'PUBLIC'", ProfileEmailDomainEntity.class); + query.setParameter("orcid", orcid); + List results = query.getResultList(); + return results.isEmpty() ? null : results; + } + + @Override + public ProfileEmailDomainEntity findByEmailDomain(String orcid, String emailDomain) { + TypedQuery query = entityManager.createQuery("from ProfileEmailDomainEntity where orcid = :orcid and emailDomain = :emailDomain", ProfileEmailDomainEntity.class); + query.setParameter("orcid", orcid); + query.setParameter("emailDomain", emailDomain); + try { + return query.getSingleResult(); + } catch(NoResultException nre) { + // Ignore this exception + } catch(Exception e) { + // Propagate any other exception + throw e; + } + return null; + } +} diff --git a/orcid-persistence/src/main/java/org/orcid/persistence/jpa/entities/ProfileEmailDomainEntity.java b/orcid-persistence/src/main/java/org/orcid/persistence/jpa/entities/ProfileEmailDomainEntity.java new file mode 100644 index 00000000000..00d53d26cba --- /dev/null +++ b/orcid-persistence/src/main/java/org/orcid/persistence/jpa/entities/ProfileEmailDomainEntity.java @@ -0,0 +1,73 @@ +package org.orcid.persistence.jpa.entities; + +import javax.persistence.*; +import java.util.Objects; + +/** + * + * @author Andrej Romanov + * + */ +@Entity +@Table(name = "profile_email_domain") +public class ProfileEmailDomainEntity extends BaseEntity { + private static final long serialVersionUID = 1L; + private Long id; + private String orcid; + private String emailDomain; + private String visibility; + + @Id + @Column(name = "id") + @GeneratedValue(strategy = GenerationType.AUTO, generator = "event_seq") + @SequenceGenerator(name = "profile_email_domain_seq", sequenceName = "profile_email_domain_seq", allocationSize = 1) + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + @Column(name = "orcid") + public String getOrcid() { + return orcid; + } + + public void setOrcid(String orcid) { + this.orcid = orcid; + } + + @Column(name = "email_domain") + public String getEmailDomain() { + return emailDomain; + } + + public void setEmailDomain(String emailDomain) { + this.emailDomain = emailDomain; + } + + @Column(name = "visibility") + public String getVisibility() { + return visibility; + } + + public void setVisibility(String visibility) { + this.visibility = visibility; + } + + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + ProfileEmailDomainEntity other = (ProfileEmailDomainEntity) obj; + return Objects.equals(emailDomain, other.emailDomain) && Objects.equals(orcid, other.orcid) + && Objects.equals(id, other.id) && Objects.equals(visibility, other.visibility); + } + +} diff --git a/orcid-persistence/src/main/resources/META-INF/persistence.xml b/orcid-persistence/src/main/resources/META-INF/persistence.xml index 418d0cfa39d..e92cdc61d71 100644 --- a/orcid-persistence/src/main/resources/META-INF/persistence.xml +++ b/orcid-persistence/src/main/resources/META-INF/persistence.xml @@ -63,6 +63,7 @@ org.orcid.persistence.jpa.entities.EventEntity org.orcid.persistence.jpa.entities.EventStatsEntity org.orcid.persistence.jpa.entities.EmailDomainEntity + org.orcid.persistence.jpa.entities.ProfileEmailDomainEntity org.orcid.persistence.jpa.entities.ClientDetailsEntity diff --git a/orcid-persistence/src/main/resources/db-master.xml b/orcid-persistence/src/main/resources/db-master.xml index d0865c4510a..c2e1fa5b644 100644 --- a/orcid-persistence/src/main/resources/db-master.xml +++ b/orcid-persistence/src/main/resources/db-master.xml @@ -1,324 +1,332 @@ + xmlns="http://www.liquibase.org/xml/ns/dbchangelog" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-2.0.xsd"> - - - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -345,22 +353,22 @@ - - + + - - + + - - - - - + + + + + - - + + @@ -375,14 +383,14 @@ - + - + @@ -392,5 +400,6 @@ + - + \ No newline at end of file diff --git a/orcid-persistence/src/main/resources/db/updates/create_profile_email_domain_table.xml b/orcid-persistence/src/main/resources/db/updates/create_profile_email_domain_table.xml new file mode 100644 index 00000000000..9c403245e97 --- /dev/null +++ b/orcid-persistence/src/main/resources/db/updates/create_profile_email_domain_table.xml @@ -0,0 +1,64 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + create index profile_email_domain_orcid_index on profile_email_domain(orcid); + + + + + + + + + create index profile_email_domain_index on profile_email_domain(email_domain); + + + + + SELECT 1 FROM pg_roles WHERE rolname='orcidro' + + GRANT SELECT ON profile_email_domain to orcidro; + + + diff --git a/orcid-persistence/src/main/resources/orcid-persistence-context.xml b/orcid-persistence/src/main/resources/orcid-persistence-context.xml index cedd58617ac..d57dde50df1 100644 --- a/orcid-persistence/src/main/resources/orcid-persistence-context.xml +++ b/orcid-persistence/src/main/resources/orcid-persistence-context.xml @@ -81,8 +81,14 @@ - - + + + + + + + + diff --git a/orcid-scheduler-web/src/main/java/org/orcid/scheduler/loader/cli/EmailDomainLoader.java b/orcid-scheduler-web/src/main/java/org/orcid/scheduler/loader/cli/EmailDomainLoader.java index f7517c6a436..d01ee877f4f 100644 --- a/orcid-scheduler-web/src/main/java/org/orcid/scheduler/loader/cli/EmailDomainLoader.java +++ b/orcid-scheduler-web/src/main/java/org/orcid/scheduler/loader/cli/EmailDomainLoader.java @@ -76,7 +76,7 @@ private void process() { for (List row : emailDomainData) { String elementDomain = row.get(0); String elementCategory = row.get(1); - EmailDomainEntity ede = emailDomainManager.findByEmailDoman(elementDomain); + EmailDomainEntity ede = emailDomainManager.findByEmailDomain(elementDomain); EmailDomainEntity.DomainCategory category = EmailDomainEntity.DomainCategory.valueOf(elementCategory.toUpperCase()); if(ede == null) { try { diff --git a/orcid-web/src/main/java/org/orcid/frontend/web/controllers/EmailDomainController.java b/orcid-web/src/main/java/org/orcid/frontend/web/controllers/EmailDomainController.java index e1ca2aabad4..fe252420836 100644 --- a/orcid-web/src/main/java/org/orcid/frontend/web/controllers/EmailDomainController.java +++ b/orcid-web/src/main/java/org/orcid/frontend/web/controllers/EmailDomainController.java @@ -36,7 +36,7 @@ public class EmailDomainController { return response; } domain = OrcidStringUtils.stripHtml(domain); - EmailDomainEntity ede = emailDomainManager.findByEmailDoman(domain); + EmailDomainEntity ede = emailDomainManager.findByEmailDomain(domain); if(ede == null) { ObjectNode response = mapper.createObjectNode(); response.put("category", EmailDomainEntity.DomainCategory.UNDEFINED.name()); @@ -60,7 +60,7 @@ public class EmailDomainController { } domain = OrcidStringUtils.stripHtml(domain); - EmailDomainEntity ede = emailDomainManager.findByEmailDoman(domain); + EmailDomainEntity ede = emailDomainManager.findByEmailDomain(domain); if(ede != null) { String rorId = ede.getRorId(); if(rorId != null && !rorId.isBlank()) { diff --git a/orcid-web/src/main/java/org/orcid/frontend/web/controllers/ManageProfileController.java b/orcid-web/src/main/java/org/orcid/frontend/web/controllers/ManageProfileController.java index 09b7c3618da..bf7696cb5db 100644 --- a/orcid-web/src/main/java/org/orcid/frontend/web/controllers/ManageProfileController.java +++ b/orcid-web/src/main/java/org/orcid/frontend/web/controllers/ManageProfileController.java @@ -19,6 +19,7 @@ import org.codehaus.jettison.json.JSONException; import org.codehaus.jettison.json.JSONObject; import org.jasypt.exceptions.EncryptionOperationNotPossibleException; +import org.orcid.core.adapter.impl.MapperFacadeFactory; import org.orcid.core.constants.EmailConstants; import org.orcid.core.manager.AdminManager; import org.orcid.core.manager.EncryptionManager; @@ -26,14 +27,13 @@ import org.orcid.core.manager.ProfileEntityCacheManager; import org.orcid.core.manager.TwoFactorAuthenticationManager; import org.orcid.core.manager.UserConnectionManager; -import org.orcid.core.manager.v3.AddressManager; -import org.orcid.core.manager.v3.BiographyManager; -import org.orcid.core.manager.v3.GivenPermissionToManager; -import org.orcid.core.manager.v3.RecordNameManager; +import org.orcid.core.manager.v3.*; +import org.orcid.core.manager.v3.read_only.ProfileEmailDomainManagerReadOnly; import org.orcid.core.manager.v3.read_only.EmailManagerReadOnly; import org.orcid.core.manager.v3.read_only.GivenPermissionToManagerReadOnly; import org.orcid.core.manager.v3.read_only.ProfileEntityManagerReadOnly; import org.orcid.core.manager.v3.read_only.RecordNameManagerReadOnly; +import org.orcid.core.togglz.Features; import org.orcid.core.utils.JsonUtils; import org.orcid.core.utils.OrcidStringUtils; import org.orcid.core.utils.v3.OrcidIdentifierUtils; @@ -45,6 +45,7 @@ import org.orcid.jaxb.model.v3.release.record.Emails; import org.orcid.jaxb.model.v3.release.record.Name; import org.orcid.persistence.jpa.entities.EmailEntity; +import org.orcid.persistence.jpa.entities.ProfileEmailDomainEntity; import org.orcid.persistence.jpa.entities.ProfileEntity; import org.orcid.persistence.jpa.entities.UserconnectionEntity; import org.orcid.pojo.AddEmail; @@ -55,17 +56,10 @@ import org.orcid.pojo.EmailFrequencyOptions; import org.orcid.pojo.ManageDelegate; import org.orcid.pojo.ManageSocialAccount; -import org.orcid.pojo.ajaxForm.AddressForm; -import org.orcid.pojo.ajaxForm.AddressesForm; -import org.orcid.pojo.ajaxForm.BiographyForm; -import org.orcid.pojo.ajaxForm.EditEmail; -import org.orcid.pojo.ajaxForm.Email; -import org.orcid.pojo.ajaxForm.Errors; -import org.orcid.pojo.ajaxForm.NamesForm; -import org.orcid.pojo.ajaxForm.PojoUtil; -import org.orcid.pojo.ajaxForm.Text; -import org.orcid.pojo.ajaxForm.Visibility; +import org.orcid.pojo.ajaxForm.*; import org.orcid.utils.alerting.SlackManager; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.stereotype.Controller; import org.springframework.validation.MapBindingResult; import org.springframework.validation.ObjectError; @@ -100,8 +94,14 @@ public class ManageProfileController extends BaseWorkspaceController { @Resource private GivenPermissionToManager givenPermissionToManager; - @Resource(name = "emailManagerReadOnlyV3") + @Resource(name = "emailManagerReadOnlyV3") private EmailManagerReadOnly emailManagerReadOnly; + + @Resource(name = "profileEmailDomainManagerReadOnly") + private ProfileEmailDomainManagerReadOnly profileEmailDomainManagerReadOnly; + + @Resource(name = "profileEmailDomainManager") + private ProfileEmailDomainManager profileEmailDomainManager; @Resource private UserConnectionManager userConnectionManager; @@ -138,7 +138,7 @@ public class ManageProfileController extends BaseWorkspaceController { @Resource private SlackManager slackManager; - + @RequestMapping public ModelAndView manageProfile() { return new ModelAndView("manage"); @@ -530,17 +530,23 @@ public ModelAndView confirmDeactivateOrcidAccount(HttpServletRequest request, Ht @RequestMapping(value = "/emails.json", method = RequestMethod.GET) public @ResponseBody org.orcid.pojo.ajaxForm.Emails getEmails(HttpServletRequest request) { - Emails v2Emails = emailManager.getEmails(getCurrentUserOrcid()); - return org.orcid.pojo.ajaxForm.Emails.valueOf(v2Emails); + Emails v2Emails = emailManager.getEmails(getCurrentUserOrcid()); + + List emailDomains = null; + if (Features.EMAIL_DOMAINS.isActive()) { + emailDomains = profileEmailDomainManagerReadOnly.getEmailDomains(getCurrentUserOrcid()); + } + return org.orcid.pojo.ajaxForm.Emails.valueOf(v2Emails, emailDomains); } @RequestMapping(value = "/emails.json", method = RequestMethod.POST) - public @ResponseBody org.orcid.pojo.ajaxForm.Emails setEmails(HttpServletRequest request, @RequestBody org.orcid.pojo.ajaxForm.Emails newEmailSet) { - Emails oldEmailSet = emailManager.getEmails(getCurrentUserOrcid()); + public @ResponseBody org.orcid.pojo.ajaxForm.Emails setEmails(HttpServletRequest request, @RequestBody org.orcid.pojo.ajaxForm.Emails newEmailSet) { + Emails oldEmailSet = emailManager.getEmails(getCurrentUserOrcid()); List deletedEmails = new ArrayList(); List newEmails = new ArrayList(); String orcid = getCurrentUserOrcid(); List errors = new ArrayList(); + for (org.orcid.pojo.ajaxForm.Email newJsonEmail : newEmailSet.getEmails()) { boolean isNewEmail = true; for (org.orcid.jaxb.model.v3.release.record.Email oldJsonEmail: oldEmailSet.getEmails()) { @@ -597,7 +603,12 @@ public ModelAndView confirmDeactivateOrcidAccount(HttpServletRequest request, Ht } Emails updatedSet = emailManager.getEmails(getCurrentUserOrcid()); - org.orcid.pojo.ajaxForm.Emails emailsResponse = org.orcid.pojo.ajaxForm.Emails.valueOf(updatedSet); + List updatedDomains = null; + if (Features.EMAIL_DOMAINS.isActive()) { + profileEmailDomainManager.updateEmailDomains(orcid, newEmailSet); + updatedDomains = profileEmailDomainManagerReadOnly.getEmailDomains(getCurrentUserOrcid()); + } + org.orcid.pojo.ajaxForm.Emails emailsResponse = org.orcid.pojo.ajaxForm.Emails.valueOf(updatedSet, updatedDomains); emailsResponse.setErrors(errors); return emailsResponse; } @@ -978,7 +989,7 @@ public ModelAndView authorizeDelegatesRequest(@RequestParam("key") String key) { if (params.containsKey(AdminManager.MANAGED_USER_PARAM) && params.containsKey(AdminManager.TRUSTED_USER_PARAM)) { String managedOrcid = params.get(AdminManager.MANAGED_USER_PARAM); String trustedOrcid = params.get(AdminManager.TRUSTED_USER_PARAM); - // Check if managed user is the same than the logged user + // Check if managed user is the same as the logged user if (managedOrcid.equals(getEffectiveUserOrcid())) { // Check if the managed user email is verified, if not, // verify it diff --git a/orcid-web/src/main/java/org/orcid/frontend/web/controllers/PublicRecordController.java b/orcid-web/src/main/java/org/orcid/frontend/web/controllers/PublicRecordController.java index 04945c894a5..733c6f3dfcc 100644 --- a/orcid-web/src/main/java/org/orcid/frontend/web/controllers/PublicRecordController.java +++ b/orcid-web/src/main/java/org/orcid/frontend/web/controllers/PublicRecordController.java @@ -1,6 +1,7 @@ package org.orcid.frontend.web.controllers; import java.util.ArrayList; +import java.util.List; import java.util.Map; import java.util.stream.Collectors; @@ -14,11 +15,7 @@ import org.orcid.core.exception.OrcidNoResultException; import org.orcid.core.exception.OrcidNotClaimedException; import org.orcid.core.manager.ProfileEntityCacheManager; -import org.orcid.core.manager.v3.read_only.AddressManagerReadOnly; -import org.orcid.core.manager.v3.read_only.ExternalIdentifierManagerReadOnly; -import org.orcid.core.manager.v3.read_only.PersonalDetailsManagerReadOnly; -import org.orcid.core.manager.v3.read_only.ProfileKeywordManagerReadOnly; -import org.orcid.core.manager.v3.read_only.ResearcherUrlManagerReadOnly; +import org.orcid.core.manager.v3.read_only.*; import org.orcid.core.togglz.Features; import org.orcid.jaxb.model.message.OrcidType; import org.orcid.jaxb.model.v3.release.record.Addresses; @@ -32,6 +29,7 @@ import org.orcid.jaxb.model.v3.release.record.PersonalDetails; import org.orcid.jaxb.model.v3.release.record.ResearcherUrls; import org.orcid.persistence.jpa.entities.EventType; +import org.orcid.persistence.jpa.entities.ProfileEmailDomainEntity; import org.orcid.persistence.jpa.entities.ProfileEntity; import org.orcid.pojo.PublicRecord; import org.orcid.pojo.ajaxForm.AddressForm; @@ -71,6 +69,9 @@ public class PublicRecordController extends BaseWorkspaceController { @Resource(name = "externalIdentifierManagerReadOnlyV3") private ExternalIdentifierManagerReadOnly externalIdentifierManagerReadOnly; + @Resource(name = "profileEmailDomainManagerReadOnly") + private ProfileEmailDomainManagerReadOnly profileEmailDomainManagerReadOnly; + @Resource private EventManager eventManager; @@ -195,8 +196,14 @@ PublicRecord getRecord(String orcid) { Emails filteredEmails = new Emails(); filteredEmails.setEmails(new ArrayList<>(publicEmails.getEmails().stream().filter(Email::isVerified).collect(Collectors.toList()))); + + // Fill email domains + List emailDomains = null; + if (Features.EMAIL_DOMAINS.isActive()) { + emailDomains = profileEmailDomainManagerReadOnly.getPublicEmailDomains(getCurrentUserOrcid()); + } - publicRecord.setEmails(org.orcid.pojo.ajaxForm.Emails.valueOf(filteredEmails)); + publicRecord.setEmails(org.orcid.pojo.ajaxForm.Emails.valueOf(filteredEmails, emailDomains)); // Fill external identifiers PersonExternalIdentifiers publicPersonExternalIdentifiers;