Search in sources :

Example 1 with EmailEventEntity

use of org.orcid.persistence.jpa.entities.EmailEventEntity in project ORCID-Source by ORCID.

the class NotificationManagerTest method processUnverifiedEmails7DaysTest.

@Test
public void processUnverifiedEmails7DaysTest() {
    List<Pair<String, Date>> emails = new ArrayList<Pair<String, Date>>();
    Pair<String, Date> tooOld1 = Pair.of("tooOld1@test.orcid.org", LocalDateTime.now().minusDays(15).toDate());
    Pair<String, Date> tooOld2 = Pair.of("tooOld2@test.orcid.org", LocalDateTime.now().minusDays(20).toDate());
    Pair<String, Date> ok1 = Pair.of("michael@bentine.com", LocalDateTime.now().minusDays(7).toDate());
    Pair<String, Date> ok2 = Pair.of("spike@milligan.com", LocalDateTime.now().minusDays(14).toDate());
    emails.add(ok1);
    emails.add(ok2);
    emails.add(tooOld1);
    emails.add(tooOld2);
    when(mockProfileDaoReadOnly.findEmailsUnverfiedDays(Matchers.anyInt(), Matchers.anyInt(), Matchers.any())).thenReturn(emails).thenReturn(new ArrayList<Pair<String, Date>>());
    notificationManager.processUnverifiedEmails7Days();
    verify(mockEmailEventDao, times(1)).persist(new EmailEventEntity("michael@bentine.com", EmailEventType.VERIFY_EMAIL_7_DAYS_SENT));
    verify(mockEmailEventDao, times(1)).persist(new EmailEventEntity("spike@milligan.com", EmailEventType.VERIFY_EMAIL_7_DAYS_SENT));
    verify(mockEmailEventDao, times(1)).persist(new EmailEventEntity("tooOld1@test.orcid.org", EmailEventType.VERIFY_EMAIL_TOO_OLD));
    verify(mockEmailEventDao, times(1)).persist(new EmailEventEntity("tooOld2@test.orcid.org", EmailEventType.VERIFY_EMAIL_TOO_OLD));
}
Also used : ArrayList(java.util.ArrayList) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) EmailEventEntity(org.orcid.persistence.jpa.entities.EmailEventEntity) Date(java.util.Date) Pair(org.apache.commons.lang3.tuple.Pair) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Example 2 with EmailEventEntity

use of org.orcid.persistence.jpa.entities.EmailEventEntity in project ORCID-Source by ORCID.

the class NotificationManagerImpl method processUnverifiedEmails7DaysInTransaction.

private void processUnverifiedEmails7DaysInTransaction(final String email) {
    transactionTemplate.execute(new TransactionCallbackWithoutResult() {

        @Override
        @Transactional
        protected void doInTransactionWithoutResult(TransactionStatus status) {
            try {
                String userOrcid = emailManager.findOrcidIdByEmail(email);
                sendVerificationReminderEmail(userOrcid, email);
                emailEventDao.persist(new EmailEventEntity(email, EmailEventType.VERIFY_EMAIL_7_DAYS_SENT));
                emailEventDao.flush();
            } catch (Exception e) {
                LOGGER.error("Unable to send unverified email reminder to email: " + email, e);
                emailEventDao.persist(new EmailEventEntity(email, EmailEventType.VERIFY_EMAIL_7_DAYS_SENT_SKIPPED));
                emailEventDao.flush();
            }
        }
    });
}
Also used : TransactionStatus(org.springframework.transaction.TransactionStatus) EmailEventEntity(org.orcid.persistence.jpa.entities.EmailEventEntity) TransactionCallbackWithoutResult(org.springframework.transaction.support.TransactionCallbackWithoutResult) NoSuchMessageException(org.springframework.context.NoSuchMessageException) WrongSourceException(org.orcid.core.exception.WrongSourceException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) OrcidNotificationAlreadyReadException(org.orcid.core.exception.OrcidNotificationAlreadyReadException) OrcidNotFoundException(org.orcid.core.exception.OrcidNotFoundException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with EmailEventEntity

use of org.orcid.persistence.jpa.entities.EmailEventEntity in project ORCID-Source by ORCID.

the class ProfileDaoTest method findEmailsUnverfiedDaysTest.

@Test
@Transactional
@Rollback(true)
public void findEmailsUnverfiedDaysTest() {
    String orcid = "9999-9999-9999-999X";
    ProfileEntity profile = new ProfileEntity();
    profile.setId(orcid);
    profile.setClaimed(true);
    profileDao.persist(profile);
    // Created today
    EmailEntity unverified_1 = new EmailEntity();
    unverified_1.setDateCreated(new Date());
    unverified_1.setLastModified(new Date());
    unverified_1.setProfile(profile);
    unverified_1.setVerified(false);
    unverified_1.setVisibility(Visibility.PUBLIC);
    unverified_1.setPrimary(false);
    unverified_1.setCurrent(true);
    unverified_1.setId("unverified_1@test.orcid.org");
    // Created a week ago
    EmailEntity unverified_2 = new EmailEntity();
    unverified_2.setDateCreated(LocalDateTime.now().minusDays(7).toDate());
    unverified_2.setLastModified(LocalDateTime.now().minusDays(7).toDate());
    unverified_2.setProfile(profile);
    unverified_2.setVerified(false);
    unverified_2.setVisibility(Visibility.PUBLIC);
    unverified_2.setPrimary(false);
    unverified_2.setCurrent(true);
    unverified_2.setId("unverified_2@test.orcid.org");
    // Created 15 days ago
    EmailEntity unverified_3 = new EmailEntity();
    unverified_3.setDateCreated(LocalDateTime.now().minusDays(15).toDate());
    unverified_3.setLastModified(LocalDateTime.now().minusDays(15).toDate());
    unverified_3.setProfile(profile);
    unverified_3.setVerified(false);
    unverified_3.setVisibility(Visibility.PUBLIC);
    unverified_3.setPrimary(false);
    unverified_3.setCurrent(true);
    unverified_3.setId("unverified_3@test.orcid.org");
    // Created 7 days ago and verified
    EmailEntity verified_1 = new EmailEntity();
    verified_1.setDateCreated(LocalDateTime.now().minusDays(7).toDate());
    verified_1.setLastModified(LocalDateTime.now().minusDays(7).toDate());
    verified_1.setProfile(profile);
    verified_1.setVerified(true);
    verified_1.setVisibility(Visibility.PUBLIC);
    verified_1.setPrimary(false);
    verified_1.setCurrent(true);
    verified_1.setId("verified_1@test.orcid.org");
    // Created 15 days ago and verified
    EmailEntity verified_2 = new EmailEntity();
    verified_2.setDateCreated(LocalDateTime.now().minusDays(15).toDate());
    verified_2.setLastModified(LocalDateTime.now().minusDays(15).toDate());
    verified_2.setProfile(profile);
    verified_2.setVerified(true);
    verified_2.setVisibility(Visibility.PUBLIC);
    verified_2.setPrimary(false);
    verified_2.setCurrent(true);
    verified_2.setId("verified_2@test.orcid.org");
    emailDao.removeAll();
    emailDao.persist(unverified_1);
    emailDao.persist(unverified_2);
    emailDao.persist(unverified_3);
    emailDao.persist(verified_1);
    emailDao.persist(verified_2);
    List<Pair<String, Date>> results = profileDao.findEmailsUnverfiedDays(7, 100, EmailEventType.VERIFY_EMAIL_7_DAYS_SENT);
    assertNotNull(results);
    assertEquals(2, results.size());
    boolean found1 = false, found2 = false;
    for (Pair<String, Date> element : results) {
        assertNotNull(element.getRight());
        if (element.getLeft().equals("unverified_2@test.orcid.org")) {
            found1 = true;
        } else if (element.getLeft().equals("unverified_3@test.orcid.org")) {
            found2 = true;
        } else {
            fail("Unexpected email id: " + element.getRight());
        }
    }
    assertTrue(found1);
    assertTrue(found2);
    // Put an email event on 'unverified_2@test.orcid.org' and verify there is only one result
    emailEventDao.persist(new EmailEventEntity("unverified_2@test.orcid.org", EmailEventType.VERIFY_EMAIL_7_DAYS_SENT));
    results = profileDao.findEmailsUnverfiedDays(7, 100, EmailEventType.VERIFY_EMAIL_7_DAYS_SENT);
    assertNotNull(results);
    assertEquals(1, results.size());
    assertEquals("unverified_3@test.orcid.org", results.get(0).getLeft());
    // Put an email event on 'unverified_3@test.orcid.org' and verify there is no result anymore
    emailEventDao.persist(new EmailEventEntity("unverified_3@test.orcid.org", EmailEventType.VERIFY_EMAIL_TOO_OLD));
    results = profileDao.findEmailsUnverfiedDays(7, 100, EmailEventType.VERIFY_EMAIL_7_DAYS_SENT);
    assertNotNull(results);
    assertTrue(results.isEmpty());
}
Also used : EmailEntity(org.orcid.persistence.jpa.entities.EmailEntity) EmailEventEntity(org.orcid.persistence.jpa.entities.EmailEventEntity) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) Date(java.util.Date) Pair(org.apache.commons.lang3.tuple.Pair) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test) Rollback(org.springframework.test.annotation.Rollback) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

EmailEventEntity (org.orcid.persistence.jpa.entities.EmailEventEntity)3 Date (java.util.Date)2 Pair (org.apache.commons.lang3.tuple.Pair)2 Test (org.junit.Test)2 DBUnitTest (org.orcid.test.DBUnitTest)2 Transactional (org.springframework.transaction.annotation.Transactional)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 ArrayList (java.util.ArrayList)1 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)1 OrcidNotFoundException (org.orcid.core.exception.OrcidNotFoundException)1 OrcidNotificationAlreadyReadException (org.orcid.core.exception.OrcidNotificationAlreadyReadException)1 WrongSourceException (org.orcid.core.exception.WrongSourceException)1 EmailEntity (org.orcid.persistence.jpa.entities.EmailEntity)1 ProfileEntity (org.orcid.persistence.jpa.entities.ProfileEntity)1 NoSuchMessageException (org.springframework.context.NoSuchMessageException)1 Rollback (org.springframework.test.annotation.Rollback)1 TransactionStatus (org.springframework.transaction.TransactionStatus)1 TransactionCallbackWithoutResult (org.springframework.transaction.support.TransactionCallbackWithoutResult)1