3636import org .orcid .core .manager .v3 .NotificationManager ;
3737import org .orcid .core .manager .v3 .RecordNameManager ;
3838import org .orcid .core .manager .v3 .read_only .EmailManagerReadOnly ;
39+ import org .orcid .core .togglz .Features ;
3940import org .orcid .core .utils .VerifyEmailUtils ;
4041import org .orcid .jaxb .model .common .ActionType ;
4142import org .orcid .jaxb .model .common .AvailableLocales ;
@@ -82,7 +83,11 @@ public class EmailMessageSenderImpl implements EmailMessageSender {
8283
8384 ExecutorService pool ;
8485
85- private int verifyReminderAfterDays = 2 ;
86+ private int verifyReminderAfterTwoDays = 2 ;
87+
88+ private int verifyReminderAfterSevenDays = 7 ;
89+
90+ private int verifyReminderAfterTwentyEightDays = 28 ;
8691
8792 @ Resource
8893 private NotificationDao notificationDao ;
@@ -141,8 +146,10 @@ public class EmailMessageSenderImpl implements EmailMessageSender {
141146 @ Value ("${org.notifications.max_elements_to_show:20}" )
142147 private Integer maxNotificationsToShowPerClient ;
143148
144- @ Value ("${org.orcid.core.email.verify.tooOld:15}" )
145- private int emailTooOld ;
149+ @ Value ("${org.orcid.core.email.verify.tooOld:45}" )
150+ private int emailTooOld ;
151+
152+ private int emailTooOldLegacy = 15 ;
146153
147154 public EmailMessageSenderImpl (@ Value ("${org.notifications.service_announcements.maxThreads:8}" ) Integer maxThreads ,
148155 @ Value ("${org.notifications.service_announcements.maxRetry:3}" ) Integer maxRetry ) {
@@ -563,13 +570,17 @@ private String getHtmlBody(NotificationAdministrative notificationAdministrative
563570
564571 @ Override
565572 synchronized public void processUnverifiedEmails2Days () {
566- LOGGER .info ("About to process unverIfied emails for reminder" );
573+ LOGGER .info ("About to process unverIfied emails for 2 days reminder" );
567574 List <Pair <String , Date >> elements = Collections .<Pair <String , Date >> emptyList ();
568575 do {
569- elements = profileDaoReadOnly .findEmailsUnverfiedDays (verifyReminderAfterDays , 100 );
570- LOGGER .info ("Got batch of {} profiles with unverified emails for reminder" , elements .size ());
576+ elements = profileDaoReadOnly .findEmailsUnverfiedDays (verifyReminderAfterTwoDays , 100 );
577+ LOGGER .info ("Got batch of {} profiles with unverified emails for 2 days reminder" , elements .size ());
571578 LocalDateTime now = LocalDateTime .now ();
572- Date tooOld = now .minusDays (emailTooOld ).toDate ();
579+ //togglz here
580+ Date tooOld = now .minusDays (emailTooOldLegacy ).toDate ();
581+ if (Features .SEND_ALL_VERIFICATION_EMAILS .isActive ()) {
582+ tooOld = now .minusDays (emailTooOld ).toDate ();
583+ }
573584 for (Pair <String , Date > element : elements ) {
574585 if (element .getRight () == null || element .getRight ().after (tooOld )) {
575586 processUnverifiedEmails2DaysInTransaction (element .getLeft ());
@@ -580,7 +591,70 @@ synchronized public void processUnverifiedEmails2Days() {
580591 }
581592 } while (!elements .isEmpty ());
582593 }
583-
594+
595+
596+ synchronized public void processUnverifiedEmails7Days () {
597+ if (Features .SEND_ALL_VERIFICATION_EMAILS .isActive ()) {
598+ LOGGER .info ("About to process unverIfied emails for 7 days reminder" );
599+ List <Pair <String , Date >> elements = Collections .<Pair <String , Date >> emptyList ();
600+ do {
601+ elements = profileDaoReadOnly .findEmailsUnverfiedDays (verifyReminderAfterSevenDays , 100 );
602+ LOGGER .info ("Got batch of {} profiles with unverified emails for 7 days reminder" , elements .size ());
603+ LocalDateTime now = LocalDateTime .now ();
604+ Date tooOld = now .minusDays (emailTooOld ).toDate ();
605+ for (Pair <String , Date > element : elements ) {
606+ if (element .getRight () == null || element .getRight ().after (tooOld )) {
607+ processUnverifiedEmailsInTransaction (element .getLeft (), EmailEventType .VERIFY_EMAIL_7_DAYS_SENT , EmailEventType .VERIFY_EMAIL_7_DAYS_SENT_SKIPPED );
608+ } else {
609+ // Mark is as too old to send the verification email
610+ markUnverifiedEmailAsTooOld (element .getLeft ());
611+ }
612+ }
613+ } while (!elements .isEmpty ());
614+ }
615+ }
616+
617+
618+ synchronized public void processUnverifiedEmails28Days () {
619+ if (Features .SEND_ALL_VERIFICATION_EMAILS .isActive ()) {
620+ LOGGER .info ("About to process unverIfied emails for 28 days reminder" );
621+ List <Pair <String , Date >> elements = Collections .<Pair <String , Date >> emptyList ();
622+ do {
623+ elements = profileDaoReadOnly .findEmailsUnverfiedDays (verifyReminderAfterTwentyEightDays , 100 );
624+ LOGGER .info ("Got batch of {} profiles with unverified emails for 28 days reminder" , elements .size ());
625+ LocalDateTime now = LocalDateTime .now ();
626+ Date tooOld = now .minusDays (emailTooOld ).toDate ();
627+ for (Pair <String , Date > element : elements ) {
628+ if (element .getRight () == null || element .getRight ().after (tooOld )) {
629+ processUnverifiedEmailsInTransaction (element .getLeft (),EmailEventType .VERIFY_EMAIL_28_DAYS_SENT , EmailEventType .VERIFY_EMAIL_28_DAYS_SENT_SKIPPED );
630+ } else {
631+ // Mark is as too old to send the verification email
632+ markUnverifiedEmailAsTooOld (element .getLeft ());
633+ }
634+ }
635+ } while (!elements .isEmpty ());
636+ }
637+ }
638+
639+ private void processUnverifiedEmailsInTransaction (final String email , EmailEventType eventSent , EmailEventType eventSkipped ) {
640+ transactionTemplate .execute (new TransactionCallbackWithoutResult () {
641+ @ Override
642+ @ Transactional
643+ protected void doInTransactionWithoutResult (TransactionStatus status ) {
644+ try {
645+ String userOrcid = emailManagerReadOnly .findOrcidIdByEmail (email );
646+ sendVerificationReminderEmail (userOrcid , email );
647+ emailEventDao .persist (new EmailEventEntity (email , eventSent ));
648+ emailEventDao .flush ();
649+ } catch (Exception e ) {
650+ LOGGER .error ("Unable to send unverified email reminder to email: " + email , e );
651+ emailEventDao .persist (new EmailEventEntity (email , eventSkipped ));
652+ emailEventDao .flush ();
653+ }
654+ }
655+ });
656+ }
657+
584658 private void processUnverifiedEmails2DaysInTransaction (final String email ) {
585659 transactionTemplate .execute (new TransactionCallbackWithoutResult () {
586660 @ Override
0 commit comments