From 28879e79fc615c54fab83c0a9affeeae304d5a08 Mon Sep 17 00:00:00 2001 From: amontenegro Date: Wed, 15 Nov 2023 19:29:03 -0600 Subject: [PATCH] Looks like it is working now --- .../persistence/dao/impl/ProfileDaoImpl.java | 6 +-- .../orcid/persistence/dao/ProfileDaoTest.java | 39 ++++++------------- 2 files changed, 15 insertions(+), 30 deletions(-) diff --git a/orcid-persistence/src/main/java/org/orcid/persistence/dao/impl/ProfileDaoImpl.java b/orcid-persistence/src/main/java/org/orcid/persistence/dao/impl/ProfileDaoImpl.java index cec2dbc4834..88a08c3b939 100644 --- a/orcid-persistence/src/main/java/org/orcid/persistence/dao/impl/ProfileDaoImpl.java +++ b/orcid-persistence/src/main/java/org/orcid/persistence/dao/impl/ProfileDaoImpl.java @@ -30,16 +30,16 @@ public class ProfileDaoImpl extends GenericDaoImpl implem private static final Logger LOGGER = LoggerFactory.getLogger(ProfileDaoImpl.class); - private static final String FIND_EMAILS_TO_SEND_VERIFICATION_REMINTER = "SELECT e.orcid, e.email, e.is_verified" + private static final String FIND_EMAILS_TO_SEND_VERIFICATION_REMINTER = "SELECT e.orcid, e.email, e.is_primary " + "FROM email e, profile p " + "WHERE e.is_verified = false " + " AND p.orcid = e.orcid " + " AND p.deprecated_date is null " + " AND p.profile_deactivation_date is null " + " AND p.account_expiry is null " - + " AND e.date_created BETWEEN (DATE_TRUNC('day', now()) - CAST('{RANGE_START}' AS INTERVAL DAY)) AND (DATE_TRUNC('day', now()) - CAST('{RANGE_END}' AS INTERVAL DAY))" + + " AND e.date_created BETWEEN (DATE_TRUNC('day', now()) - CAST('{RANGE_START}' AS INTERVAL DAY)) AND (DATE_TRUNC('day', now()) - CAST('{RANGE_END}' AS INTERVAL DAY)) " + " AND NOT EXISTS " - + " (SELECT x.email FROM email_event x WHERE x.email = e.email AND email_event_type IN ('{EVENT_SENT}'))" + + " (SELECT x.email FROM email_event x WHERE x.email = e.email AND email_event_type IN ('{EVENT_SENT}')) " + "order by e.last_modified"; @Value("${org.orcid.postgres.query.timeout:30000}") diff --git a/orcid-persistence/src/test/java/org/orcid/persistence/dao/ProfileDaoTest.java b/orcid-persistence/src/test/java/org/orcid/persistence/dao/ProfileDaoTest.java index 0eaf5017474..c1d8d0565af 100644 --- a/orcid-persistence/src/test/java/org/orcid/persistence/dao/ProfileDaoTest.java +++ b/orcid-persistence/src/test/java/org/orcid/persistence/dao/ProfileDaoTest.java @@ -16,6 +16,7 @@ import javax.persistence.EntityManager; import javax.persistence.Query; +import org.apache.commons.lang3.tuple.Triple; import org.dbunit.dataset.DataSetException; import org.joda.time.LocalDateTime; import org.junit.AfterClass; @@ -24,11 +25,11 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.orcid.persistence.jpa.entities.EmailEventEntity; +import org.orcid.persistence.jpa.entities.EmailEventType; import org.orcid.persistence.jpa.entities.IndexingStatus; import org.orcid.persistence.jpa.entities.ProfileEntity; import org.orcid.persistence.jpa.entities.ProfileEventEntity; import org.orcid.persistence.jpa.entities.ProfileEventType; -import org.orcid.persistence.util.Quadruple; import org.orcid.test.DBUnitTest; import org.orcid.test.OrcidJUnit4ClassRunner; import org.springframework.test.annotation.Rollback; @@ -407,41 +408,25 @@ public void findEmailsUnverfiedDaysTest() throws IllegalAccessException { assertEquals(1, insertEmailWithDateCreated("verified_2@test.orcid.org", "896dea808bbf69bde1b177f27800e84d17763860bffde1dfd8ef200e79ff9971", orcid, true, LocalDateTime.now().minusDays(7).toDate())); // Created 15 days ago and verified - assertEquals(1, insertEmailWithDateCreated("verified_3@test.orcid.org", "f98cce12446df199b852583ce677ecf9870ebe1b58df21bc4e7b01dea67daf01", orcid, true, LocalDateTime.now().minusDays(15).toDate())); + assertEquals(1, insertEmailWithDateCreated("verified_3@test.orcid.org", "f98cce12446df199b852583ce677ecf9870ebe1b58df21bc4e7b01dea67daf01", orcid, true, LocalDateTime.now().minusDays(28).toDate())); - List> results = profileDao.findEmailsUnverfiedDays(2); + List> results = profileDao.findEmailsUnverfiedDays(2, EmailEventType.VERIFY_EMAIL_2_DAYS_SENT); assertNotNull(results); assertEquals(1, results.size()); - assertEquals(orcid, results.get(0).getFirst()); - assertEquals("unverified_2@test.orcid.org", results.get(0).getSecond()); + assertEquals(orcid, results.get(0).getLeft()); + assertEquals("unverified_2@test.orcid.org", results.get(0).getMiddle()); - results = profileDao.findEmailsUnverfiedDays(7); + results = profileDao.findEmailsUnverfiedDays(7, EmailEventType.VERIFY_EMAIL_7_DAYS_SENT); assertNotNull(results); assertEquals(1, results.size()); - assertEquals(orcid, results.get(0).getFirst()); - assertEquals("unverified_3@test.orcid.org", results.get(0).getSecond()); + assertEquals(orcid, results.get(0).getLeft()); + assertEquals("unverified_3@test.orcid.org", results.get(0).getMiddle()); - results = profileDao.findEmailsUnverfiedDays(15); + results = profileDao.findEmailsUnverfiedDays(28, EmailEventType.VERIFY_EMAIL_28_DAYS_SENT); assertNotNull(results); assertEquals(1, results.size()); - assertEquals(orcid, results.get(0).getFirst()); - assertEquals("unverified_4@test.orcid.org", results.get(0).getSecond()); - - results = profileDao.findEmailsUnverfiedDays(6); - assertNotNull(results); - assertTrue(results.isEmpty()); - - results = profileDao.findEmailsUnverfiedDays(8); - assertNotNull(results); - assertTrue(results.isEmpty()); - - results = profileDao.findEmailsUnverfiedDays(14); - assertNotNull(results); - assertTrue(results.isEmpty()); - - results = profileDao.findEmailsUnverfiedDays(16); - assertNotNull(results); - assertTrue(results.isEmpty()); + assertEquals(orcid, results.get(0).getLeft()); + assertEquals("unverified_4@test.orcid.org", results.get(0).getMiddle()); } private int insertEmailWithDateCreated(String email, String emailHash, String orcid, boolean isVerified, Date dateCreated) {