From f8949b8acc170f03e11d2ac3ba8d5855d9f5545a Mon Sep 17 00:00:00 2001 From: andrej romanov <50377758+auumgn@users.noreply.github.com> Date: Tue, 17 Sep 2024 18:44:43 +0300 Subject: [PATCH 1/2] new email domains should have a default profile visibility --- .../impl/ProfileEmailDomainManagerImpl.java | 40 +++---------------- 1 file changed, 6 insertions(+), 34 deletions(-) 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 index c2eb6ae2eb9..52f525d1ff0 100644 --- 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 @@ -6,10 +6,12 @@ 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.ProfileDao; import org.orcid.persistence.dao.ProfileEmailDomainDao; import org.orcid.persistence.jpa.entities.EmailDomainEntity; import org.orcid.persistence.jpa.entities.EmailEntity; import org.orcid.persistence.jpa.entities.ProfileEmailDomainEntity; +import org.orcid.persistence.jpa.entities.ProfileEntity; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.transaction.annotation.Transactional; @@ -34,7 +36,8 @@ public class ProfileEmailDomainManagerImpl extends ProfileEmailDomainManagerRead @Resource(name = "emailDaoReadOnly") protected EmailDao emailDaoReadOnly; - private static final String DEFAULT_DOMAIN_VISIBILITY = Visibility.PRIVATE.toString().toUpperCase(); + @Resource(name = "profileDaoReadOnly") + protected ProfileDao profileDaoReadOnly; @Transactional public void updateEmailDomains(String orcid, org.orcid.pojo.ajaxForm.Emails newEmails) { @@ -71,47 +74,16 @@ public void updateEmailDomains(String orcid, org.orcid.pojo.ajaxForm.Emails newE public void processDomain(String orcid, String email) { String domain = email.split("@")[1]; EmailDomainEntity domainInfo = emailDomainDao.findByEmailDomain(domain); - String domainVisibility = DEFAULT_DOMAIN_VISIBILITY; // 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) { // Verify the user doesn't have more emails with that domain - List existingEmails = emailDaoReadOnly.findByOrcid(orcid, System.currentTimeMillis()); - if(existingEmails != null && existingEmails.size() > 1) { - for(EmailEntity emailEntity : existingEmails) { - //If it is not the same emails that is being verified and it is verified - if(!email.equals(emailEntity.getEmail()) && emailEntity.getVerified()) { - try { - String emailEntityDomain = (emailEntity.getEmail() == null) ? null : (email.split("@")[1]); - // If one of the existing emails have the same domain as the email being verified check the visibility and select the less restrictive - if(domain.equals(emailEntityDomain)){ - String entityVisibility = emailEntity.getVisibility(); - domainVisibility = getLessRestrictiveVisibility(domainVisibility, entityVisibility); - } - } catch (Exception e) { - LOGGER.warn("Could not get email domain from email entity " + emailEntity.getEmail(), e); - } - } - } - } + ProfileEntity profile = profileDaoReadOnly.find(orcid); + String domainVisibility = profile.getActivitiesVisibilityDefault(); profileEmailDomainDao.addEmailDomain(orcid, domain, domainVisibility); } } } - - private String getLessRestrictiveVisibility(String a, String b) { - String visibility = DEFAULT_DOMAIN_VISIBILITY; - if(Visibility.PUBLIC.name().equals(a) || Visibility.PUBLIC.name().equals(b)) { - visibility = Visibility.PUBLIC.name(); - } else if(a.equals(b)) { - visibility = a; - } else if(Visibility.PRIVATE.name().equals(a)) { - visibility = b; - } else if(Visibility.PRIVATE.name().equals(b)) { - visibility = a; - } - return visibility; - } } From 1b96db4c9b2dbe3ad280c1e6783f56b43a012700 Mon Sep 17 00:00:00 2001 From: andrej romanov <50377758+auumgn@users.noreply.github.com> Date: Tue, 17 Sep 2024 19:01:22 +0300 Subject: [PATCH 2/2] use cache instead of database call --- .../manager/v3/impl/ProfileEmailDomainManagerImpl.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) 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 index 52f525d1ff0..ecbf129bd04 100644 --- 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 @@ -1,6 +1,7 @@ package org.orcid.core.manager.v3.impl; +import org.orcid.core.manager.ProfileEntityCacheManager; 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; @@ -36,8 +37,8 @@ public class ProfileEmailDomainManagerImpl extends ProfileEmailDomainManagerRead @Resource(name = "emailDaoReadOnly") protected EmailDao emailDaoReadOnly; - @Resource(name = "profileDaoReadOnly") - protected ProfileDao profileDaoReadOnly; + @Resource + private ProfileEntityCacheManager profileEntityCacheManager; @Transactional public void updateEmailDomains(String orcid, org.orcid.pojo.ajaxForm.Emails newEmails) { @@ -80,7 +81,7 @@ public void processDomain(String orcid, String email) { // ADD NEW DOMAIN IF ONE DOESN'T EXIST if (existingDomain == null) { // Verify the user doesn't have more emails with that domain - ProfileEntity profile = profileDaoReadOnly.find(orcid); + ProfileEntity profile = profileEntityCacheManager.retrieve(orcid); String domainVisibility = profile.getActivitiesVisibilityDefault(); profileEmailDomainDao.addEmailDomain(orcid, domain, domainVisibility); }