From 1176ed903c93e88758b07626de6773f5d262d2af Mon Sep 17 00:00:00 2001 From: Daniel Palafox Date: Wed, 15 Nov 2023 19:36:43 -0500 Subject: [PATCH] fix: Add new email schedule to send email to encourage email to add works --- .tx/config | 5 ++ .../java/org/orcid/core/togglz/Features.java | 5 +- .../email_add_works_to_record_en.properties | 31 +++++++ .../email_add_works_to_record_lr.properties | 31 +++++++ .../email_add_works_to_record_rl.properties | 31 +++++++ .../email_add_works_to_record_xx.properties | 31 +++++++ .../i18n/email_subject_en.properties | 1 + .../src/main/resources/orcid-core-context.xml | 4 +- .../template/add_works_to_record_email.ftl | 35 ++++++++ .../add_works_to_record_email_html.ftl | 87 +++++++++++++++++++ .../org/orcid/persistence/dao/ProfileDao.java | 3 + .../persistence/dao/impl/ProfileDaoImpl.java | 34 ++++++++ .../orcid/persistence/dao/ProfileDaoTest.java | 25 +++++- .../email/cli/manager/EmailMessageSender.java | 2 + .../cli/manager/EmailMessageSenderImpl.java | 50 ++++++++++- .../resources/orcid-scheduler-context.xml | 2 +- .../cli/manager/EmailMessageSenderTest.java | 13 +++ .../email/example_add_works_to_record.html | 83 ++++++++++++++++++ .../email/example_add_works_to_record.txt | 29 +++++++ 19 files changed, 493 insertions(+), 9 deletions(-) create mode 100644 orcid-core/src/main/resources/i18n/email_add_works_to_record_en.properties create mode 100644 orcid-core/src/main/resources/i18n/email_add_works_to_record_lr.properties create mode 100644 orcid-core/src/main/resources/i18n/email_add_works_to_record_rl.properties create mode 100644 orcid-core/src/main/resources/i18n/email_add_works_to_record_xx.properties create mode 100644 orcid-core/src/main/resources/org/orcid/core/template/add_works_to_record_email.ftl create mode 100644 orcid-core/src/main/resources/org/orcid/core/template/add_works_to_record_email_html.ftl create mode 100644 orcid-scheduler-web/src/test/resources/email/example_add_works_to_record.html create mode 100644 orcid-scheduler-web/src/test/resources/email/example_add_works_to_record.txt diff --git a/.tx/config b/.tx/config index 1a5ab71540d..fcff569528d 100644 --- a/.tx/config +++ b/.tx/config @@ -175,3 +175,8 @@ source_file = orcid-core/src/main/resources/i18n/notification_share_en.propertie source_lang = en type = UNICODEPROPERTIES +[o:orcid-inc-1:p:registry:r:email-add-work] +file_filter = orcid-core/src/main/resources/i18n/email_add_works_to_record_.properties +source_file = orcid-core/src/main/resources/i18n/email_add_works_to_record_en.properties +source_lang = en +type = UNICODEPROPERTIES 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 dbb655fab98..6aea0666dea 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 @@ -153,7 +153,10 @@ public enum Features implements Feature { ENABLE_NEW_IDS, @Label("Send verification emails for 2, 7 and 28 days. If disabled 2 days only verification emails will be sent.") - SEND_ALL_VERIFICATION_EMAILS; + SEND_ALL_VERIFICATION_EMAILS, + + @Label("Send add works emails for 7, 28 and 90 days.") + SEND_ADD_WORKS_EMAILS; public boolean isActive() { return FeatureContext.getFeatureManager().isActive(this); diff --git a/orcid-core/src/main/resources/i18n/email_add_works_to_record_en.properties b/orcid-core/src/main/resources/i18n/email_add_works_to_record_en.properties new file mode 100644 index 00000000000..335c80e0e47 --- /dev/null +++ b/orcid-core/src/main/resources/i18n/email_add_works_to_record_en.properties @@ -0,0 +1,31 @@ +email.addWorks.subject=[ORCID] Add Research Outputs to your ORCID record + +email.addWorks.header.yourOrcidId=Your ORCID iD: +email.addWorks.header.yourOrcidRecordIs=Your ORCID record is +email.addWorks.header.dear=Dear + +email.addWorks.weHaveNoticed=We have noticed that you have not yet added any research outputs to your ORCID record. Adding these will help reduce your administrative burden when read and imported into other systems, ensure you are recognized for your research contributions, and disambiguate you from other researchers with the same name! +email.addWorks.getStarted=Get started with these popular ORCID integrations: +email.addWorks.belowAreLinks=Below are links to 4 popular ORCID integrations that allow you to sign in to your OCID record, grant permission to the service to add your selected research outputs to your ORCID record. + +email.addWorks.forAddingJournal=For adding journal articles: +email.addWorks.allowsYouToSearch=allows you to search and add works by title or DOI. + +email.addWorks.forAddingLife=For adding life sciences literature: +email.addWorks.allowsYouToImport=allows you to import works from the Europe PubMed database, which includes all articles indexed by PubMed Central. + +email.addWorks.forAddingMultiple=For adding multiple published articles: +email.addWorks.allowsYouToAddYourScopus=allows you to add your Scopus Author ID to your record as well as importing works associated with your Scopus Author ID. + +email.addWorks.allowsYouClaim=allows you to claim and import works from the Bielefeld Academic Search Engine. To use, you must first create a BASE user account. Recommended for authors of open access publications. + +email.addWorks.weHaveSeachAndLink=We have more `search and link` wizards available within +email.addWorks.yourOrcidRecord=your ORCID record + +email.addWorks.ifYouAreHavingTrouble=If you are having trouble adding your research outputs or you would like to know more about how to add data to your ORCID record, please visit our +email.addWorks.orcidHelpCenter=ORCID Help Center + +email.addWorks.footer.warmRegards=Warm Regards, +email.addWorks.footer.orcidSupportTeam=ORCID Support Team +email.addWorks.footer.youHaveReceivedThisEmail=You have received this email because you opted in to tips and features emails from ORCID. You can opt out of these at +email.addWorks.footer.accountSettings=account settings diff --git a/orcid-core/src/main/resources/i18n/email_add_works_to_record_lr.properties b/orcid-core/src/main/resources/i18n/email_add_works_to_record_lr.properties new file mode 100644 index 00000000000..5292d60d599 --- /dev/null +++ b/orcid-core/src/main/resources/i18n/email_add_works_to_record_lr.properties @@ -0,0 +1,31 @@ +email.addWorks.subject=LR + +email.addWorks.header.yourOrcidId=LR +email.addWorks.header.yourOrcidRecordIs=LR +email.addWorks.header.dear=LR + +email.addWorks.weHaveNoticed=LR +email.addWorks.getStarted=LR +email.addWorks.belowAreLinks=LR + +email.addWorks.forAddingJournal=LR +email.addWorks.allowsYouToSearch=LR + +email.addWorks.forAddingLife=LR +email.addWorks.allowsYouToImport=LR + +email.addWorks.forAddingMultiple=LR +email.addWorks.allowsYouToAddYourScopus=LR + +email.addWorks.allowsYouClaim=LR + +email.addWorks.weHaveSeachAndLink=LR +email.addWorks.yourOrcidRecord=LR + +email.addWorks.ifYouAreHavingTrouble=LR +email.addWorks.orcidHelpCenter=LR + +email.addWorks.footer.warmRegards=LR +email.addWorks.footer.orcidSupportTeam=LR +email.addWorks.footer.youHaveReceivedThisEmail=LR +email.addWorks.footer.accountSettings=LRa diff --git a/orcid-core/src/main/resources/i18n/email_add_works_to_record_rl.properties b/orcid-core/src/main/resources/i18n/email_add_works_to_record_rl.properties new file mode 100644 index 00000000000..2e803a6bc36 --- /dev/null +++ b/orcid-core/src/main/resources/i18n/email_add_works_to_record_rl.properties @@ -0,0 +1,31 @@ +email.addWorks.subject=RL + +email.addWorks.header.yourOrcidId=RL +email.addWorks.header.yourOrcidRecordIs=RL +email.addWorks.header.dear=RL + +email.addWorks.weHaveNoticed=RL +email.addWorks.getStarted=RL +email.addWorks.belowAreLinks=RL + +email.addWorks.forAddingJournal=RL +email.addWorks.allowsYouToSearch=RL + +email.addWorks.forAddingLife=RL +email.addWorks.allowsYouToImport=RL + +email.addWorks.forAddingMultiple=RL +email.addWorks.allowsYouToAddYourScopus=RL + +email.addWorks.allowsYouClaim=RL + +email.addWorks.weHaveSeachAndLink=RL +email.addWorks.yourOrcidRecord=RL + +email.addWorks.ifYouAreHavingTrouble=RL +email.addWorks.orcidHelpCenter=RL + +email.addWorks.footer.warmRegards=RL +email.addWorks.footer.orcidSupportTeam=RL +email.addWorks.footer.youHaveReceivedThisEmail=RL +email.addWorks.footer.accountSettings=RLa diff --git a/orcid-core/src/main/resources/i18n/email_add_works_to_record_xx.properties b/orcid-core/src/main/resources/i18n/email_add_works_to_record_xx.properties new file mode 100644 index 00000000000..170bcfd6ba4 --- /dev/null +++ b/orcid-core/src/main/resources/i18n/email_add_works_to_record_xx.properties @@ -0,0 +1,31 @@ +email.addWorks.subject=XX + +email.addWorks.header.yourOrcidId=XX +email.addWorks.header.yourOrcidRecordIs=XX +email.addWorks.header.dear=XX + +email.addWorks.weHaveNoticed=XX +email.addWorks.getStarted=XX +email.addWorks.belowAreLinks=XX + +email.addWorks.forAddingJournal=XX +email.addWorks.allowsYouToSearch=XX + +email.addWorks.forAddingLife=XX +email.addWorks.allowsYouToImport=XX + +email.addWorks.forAddingMultiple=XX +email.addWorks.allowsYouToAddYourScopus=XX + +email.addWorks.allowsYouClaim=XX + +email.addWorks.weHaveSeachAndLink=XX +email.addWorks.yourOrcidRecord=XX + +email.addWorks.ifYouAreHavingTrouble=XX +email.addWorks.orcidHelpCenter=XX + +email.addWorks.footer.warmRegards=XX +email.addWorks.footer.orcidSupportTeam=XX +email.addWorks.footer.youHaveReceivedThisEmail=XX +email.addWorks.footer.accountSettings=XXa diff --git a/orcid-core/src/main/resources/i18n/email_subject_en.properties b/orcid-core/src/main/resources/i18n/email_subject_en.properties index a9f3f3188b5..126f893efbc 100644 --- a/orcid-core/src/main/resources/i18n/email_subject_en.properties +++ b/orcid-core/src/main/resources/i18n/email_subject_en.properties @@ -19,3 +19,4 @@ email.subject.auto_deprecate=[ORCID] An account has been deprecated email.subject.reactivation=[ORCID] Reactivating your ORCID record email.subject.register.welcome=[ORCID] Welcome to ORCID email.subject.delegate.recipient=[ORCID] You've made an Account Delegate! +email.subject.add_works=[ORCID] Add Research Outputs to your ORCID record diff --git a/orcid-core/src/main/resources/orcid-core-context.xml b/orcid-core/src/main/resources/orcid-core-context.xml index 5b0c52ac219..257f53a8821 100644 --- a/orcid-core/src/main/resources/orcid-core-context.xml +++ b/orcid-core/src/main/resources/orcid-core-context.xml @@ -772,14 +772,14 @@ - + - + diff --git a/orcid-core/src/main/resources/org/orcid/core/template/add_works_to_record_email.ftl b/orcid-core/src/main/resources/org/orcid/core/template/add_works_to_record_email.ftl new file mode 100644 index 00000000000..e42de3d44f0 --- /dev/null +++ b/orcid-core/src/main/resources/org/orcid/core/template/add_works_to_record_email.ftl @@ -0,0 +1,35 @@ +<#import "email_macros.ftl" as emailMacros /> +<@emailMacros.msg "email.addWorks.header.yourOrcidId" /> ${orcidId} +<@emailMacros.msg "email.addWorks.header.yourOrcidRecordIs" /> ${baseUri}/${orcidId} + +<@emailMacros.msg "email.common.dear" /> ${emailName} + +<@emailMacros.msg "email.addWorks.weHaveNoticed" /> + + +<@emailMacros.msg "email.addWorks.getStarted" /> + + +<@emailMacros.msg "email.addWorks.belowAreLinks" /> + + +<@emailMacros.msg "email.addWorks.forAddingJournal" /><@emailMacros.space />Crossref Metadata Search<@emailMacros.space /><@emailMacros.msg "email.addWorks.allowsYouToSearch" /> + +<@emailMacros.msg "email.addWorks.forAddingLife" /><@emailMacros.space />Europe PubMed Central<@emailMacros.space /><@emailMacros.msg "email.addWorks.allowsYouToImport" /> + +<@emailMacros.msg "email.addWorks.forAddingMultiple" /><@emailMacros.space />Scopus<@emailMacros.space /><@emailMacros.msg "email.addWorks.allowsYouToAddYourScopus" /> + +BASE (Bielefeld Academic Search Engine)<@emailMacros.space /><@emailMacros.msg "email.addWorks.allowsYouClaim" /> + +<@emailMacros.msg "email.addWorks.weHaveSeachAndLink" /><@emailMacros.space /><@emailMacros.msg "email.addWorks.yourOrcidRecord" />. + +<@emailMacros.msg "email.addWorks.ifYouAreHavingTrouble" /><@emailMacros.space /><@emailMacros.msg "email.addWorks.orcidHelpCenter" />. + +<@emailMacros.msg "email.addWorks.footer.warmRegards" /> + +<@emailMacros.msg "email.addWorks.footer.orcidSupportTeam" /> + +https://support.orcid.org + +<@emailMacros.msg "email.addWorks.footer.youHaveReceivedThisEmail" /><@emailMacros.space /><@emailMacros.msg "email.addWorks.footer.accountSettings" />. +<@emailMacros.msg "email.common.email.preferences" /> | <@emailMacros.msg "email.common.privacy_policy" /> | <@emailMacros.msg "email.common.address1" /> | <@emailMacros.msg "email.common.address2" /> | ORCID.org diff --git a/orcid-core/src/main/resources/org/orcid/core/template/add_works_to_record_email_html.ftl b/orcid-core/src/main/resources/org/orcid/core/template/add_works_to_record_email_html.ftl new file mode 100644 index 00000000000..1cdacf538da --- /dev/null +++ b/orcid-core/src/main/resources/org/orcid/core/template/add_works_to_record_email_html.ftl @@ -0,0 +1,87 @@ +<#import "email_macros.ftl" as emailMacros /> +<#escape x as x?html> + + + + ${subject} + + +
+
+

+ <@emailMacros.msg "email.addWorks.header.yourOrcidId" /> ${orcidId} +
+ <@emailMacros.msg "email.addWorks.header.yourOrcidRecordIs" /> ${baseUri}/${orcidId} +

+

<@emailMacros.msg "email.common.dear" /><@emailMacros.space />${emailName}

+
+
+

<@emailMacros.msg "email.addWorks.weHaveNoticed" />

+

<@emailMacros.msg "email.addWorks.getStarted" />

+

<@emailMacros.msg "email.addWorks.belowAreLinks" />

+

<@emailMacros.msg "email.addWorks.forAddingJournal" /><@emailMacros.space />Crossref Metadata Search<@emailMacros.space /><@emailMacros.msg "email.addWorks.allowsYouToSearch" />

+

<@emailMacros.msg "email.addWorks.forAddingLife" /><@emailMacros.space />Europe PubMed Central<@emailMacros.space /><@emailMacros.msg "email.addWorks.allowsYouToImport" />

+

<@emailMacros.msg "email.addWorks.forAddingMultiple" /><@emailMacros.space />Scopus<@emailMacros.space /><@emailMacros.msg "email.addWorks.allowsYouToAddYourScopus" /> +

+

BASE (Bielefeld Academic Search Engine)<@emailMacros.space /><@emailMacros.msg "email.addWorks.allowsYouClaim" />

+

<@emailMacros.msg "email.addWorks.weHaveSeachAndLink" /><@emailMacros.space /><@emailMacros.msg "email.addWorks.yourOrcidRecord" />.

+

<@emailMacros.msg "email.addWorks.ifYouAreHavingTrouble" /><@emailMacros.space /><@emailMacros.msg "email.addWorks.orcidHelpCenter" />.

+

<@emailMacros.msg "email.addWorks.footer.warmRegards" /> +
+ <@emailMacros.msg "email.addWorks.footer.orcidSupportTeam" /> +

+ https://support.orcid.org +
+ +
+ + + diff --git a/orcid-persistence/src/main/java/org/orcid/persistence/dao/ProfileDao.java b/orcid-persistence/src/main/java/org/orcid/persistence/dao/ProfileDao.java index 1737562b61a..74672ae5f68 100644 --- a/orcid-persistence/src/main/java/org/orcid/persistence/dao/ProfileDao.java +++ b/orcid-persistence/src/main/java/org/orcid/persistence/dao/ProfileDao.java @@ -4,6 +4,7 @@ import java.util.Date; import java.util.List; +import org.apache.commons.lang3.tuple.Pair; import org.apache.commons.lang3.tuple.Triple; import org.orcid.persistence.jpa.entities.EmailEventType; import org.orcid.persistence.jpa.entities.IndexingStatus; @@ -162,4 +163,6 @@ public interface ProfileDao extends GenericDao { public void updateSigninLock(String orcid, Integer count); boolean haveMemberPushedWorksOrAffiliationsToRecord(String orcid, String clientId); + + public List> findEmailsToSendAddWorksEmail(); } 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 baf0d02de86..4fa6d93a215 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 @@ -10,6 +10,7 @@ import javax.persistence.Query; import javax.persistence.TypedQuery; +import org.apache.commons.lang3.tuple.Pair; import org.apache.commons.lang3.tuple.Triple; import org.orcid.persistence.aop.UpdateProfileLastModifiedAndIndexingStatus; import org.orcid.persistence.dao.ProfileDao; @@ -826,4 +827,37 @@ public boolean haveMemberPushedWorksOrAffiliationsToRecord(String orcid, String return false; } + @Override + public List> findEmailsToSendAddWorksEmail() { + StringBuilder qs = new StringBuilder("SELECT e.email, p.orcid FROM email e "); + qs.append("LEFT JOIN email_frequency ef ON e.orcid = ef.orcid "); + qs.append("LEFT OUTER JOIN work w ON e.orcid = w.orcid "); + qs.append("JOIN profile p on p.orcid = e.orcid and p.claimed = true AND p.deprecated_date is null AND "); + qs.append("p.profile_deactivation_date is null AND p.account_expiry is null "); + qs.append("WHERE "); + qs.append(getWorkCreatedNumberOfDaysAgo("7")); + qs.append("OR "); + qs.append(getWorkCreatedNumberOfDaysAgo("28")); + qs.append("OR "); + qs.append(getWorkCreatedNumberOfDaysAgo("90")); + qs.append("GROUP BY e.email, p.orcid"); + + System.out.println(qs.toString()); + + Query query = entityManager.createNativeQuery(qs.toString()); + List dbInfo = query.getResultList(); + List> results = new ArrayList>(); + dbInfo.stream().forEach(element -> { + Pair pair = Pair.of((String) element[0], (String) element[1]); + results.add(pair); + }); + return results; + } + + private String getWorkCreatedNumberOfDaysAgo(String days) { + return "e.is_verified = true and e.is_primary = true and\n" + + " ef.send_quarterly_tips = true and\n" + + " w.orcid is null and\n" + + " CAST(p.date_created as date) = CAST(CURRENT_DATE - INTERVAL '"+ days +"' day as date) "; + } } 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 96e6551b8e9..fb57542955f 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 @@ -17,6 +17,7 @@ import javax.persistence.EntityManager; import javax.persistence.Query; +import org.apache.commons.lang3.tuple.Pair; import org.apache.commons.lang3.tuple.Triple; import org.dbunit.dataset.DataSetException; import org.joda.time.LocalDateTime; @@ -71,12 +72,12 @@ public class ProfileDaoTest extends DBUnitTest { @BeforeClass public static void initDBUnitData() throws Exception { initDBUnitData(Arrays.asList("/data/SubjectEntityData.xml", "/data/SourceClientDetailsEntityData.xml", - "/data/ProfileEntityData.xml", "/data/RecordNameEntityData.xml")); + "/data/ProfileEntityData.xml", "/data/RecordNameEntityData.xml", "/data/WorksEntityData.xml")); } @AfterClass public static void removeDBUnitData() throws Exception { - removeDBUnitData(Arrays.asList("/data/RecordNameEntityData.xml", "/data/ProfileEntityData.xml", "/data/SubjectEntityData.xml")); + removeDBUnitData(Arrays.asList("/data/WorksEntityData.xml", "/data/RecordNameEntityData.xml", "/data/ProfileEntityData.xml", "/data/SubjectEntityData.xml")); } @Before @@ -439,6 +440,18 @@ public void findEmailsUnverfiedDaysTest() throws IllegalAccessException { assertNotNull(results); assertTrue(results.isEmpty()); } + + @Test + @Transactional + public void findEmailsToSendAddWorksEmail() { + String orcid = "4444-4444-4444-4441"; + + updateProfileWithDateCreated(orcid, LocalDateTime.now().minusDays(7).toDate()); + + List> results = profileDao.findEmailsToSendAddWorksEmail(); + assertNotNull(results); + assertEquals(1, results.size()); + } private int insertEmailWithDateCreated(String email, String emailHash, String orcid, boolean isVerified, Date dateCreated) { Query q = entityManager.createNativeQuery( @@ -456,4 +469,12 @@ private int insertEmailWithDateCreated(String email, String emailHash, String or q.setParameter("lastModified", dateCreated); return q.executeUpdate(); } + + private int updateProfileWithDateCreated(String orcid, Date dateCreated) { + Query q = entityManager.createNativeQuery( + "UPDATE profile set date_created = :dateCreated where orcid = :orcid"); + q.setParameter("orcid", orcid); + q.setParameter("dateCreated", dateCreated); + return q.executeUpdate(); + } } diff --git a/orcid-scheduler-web/src/main/java/org/orcid/scheduler/email/cli/manager/EmailMessageSender.java b/orcid-scheduler-web/src/main/java/org/orcid/scheduler/email/cli/manager/EmailMessageSender.java index f121d3e471c..c19673054d7 100644 --- a/orcid-scheduler-web/src/main/java/org/orcid/scheduler/email/cli/manager/EmailMessageSender.java +++ b/orcid-scheduler-web/src/main/java/org/orcid/scheduler/email/cli/manager/EmailMessageSender.java @@ -21,4 +21,6 @@ public interface EmailMessageSender { void sendEmailMessages(); void processUnverifiedEmails2Days(); + + EmailMessage createAddWorksToRecordEmail(String email, String orcid); } diff --git a/orcid-scheduler-web/src/main/java/org/orcid/scheduler/email/cli/manager/EmailMessageSenderImpl.java b/orcid-scheduler-web/src/main/java/org/orcid/scheduler/email/cli/manager/EmailMessageSenderImpl.java index c4deda62955..5d8c8ee3336 100644 --- a/orcid-scheduler-web/src/main/java/org/orcid/scheduler/email/cli/manager/EmailMessageSenderImpl.java +++ b/orcid-scheduler-web/src/main/java/org/orcid/scheduler/email/cli/manager/EmailMessageSenderImpl.java @@ -24,6 +24,7 @@ import org.apache.commons.codec.binary.Base64; import org.apache.commons.lang3.LocaleUtils; import org.apache.commons.lang3.time.DurationFormatUtils; +import org.apache.commons.lang3.tuple.Pair; import org.apache.commons.lang3.tuple.Triple; import org.joda.time.LocalDateTime; import org.orcid.core.constants.EmailConstants; @@ -591,7 +592,7 @@ synchronized public void processUnverifiedEmails2Days() { } } while (!elements.isEmpty()); } - + synchronized public void processUnverifiedEmails7Days() { if(Features.SEND_ALL_VERIFICATION_EMAILS.isActive()) { @@ -635,7 +636,17 @@ synchronized public void processUnverifiedEmails28Days() { } while (!elements.isEmpty()); } } - + + synchronized public void addWorksToRecord() { + if (Features.SEND_ADD_WORKS_EMAILS.isActive()) { + LOGGER.info("About to process send emails to encourage user to add works"); + List> elements = profileDaoReadOnly.findEmailsToSendAddWorksEmail(); + for (Pair element: elements) { + sendAddWorksToRecordEmail(element.getLeft(), element.getRight()); + } + } + } + private void processUnverifiedEmailsInTransaction(final String email, final Boolean isPrimaryEmail, EmailEventType eventSent, EmailEventType eventSkipped) { transactionTemplate.execute(new TransactionCallbackWithoutResult() { @Override @@ -678,5 +689,38 @@ private void sendVerificationReminderEmail(String userOrcid, String email, Boole String body = templateManager.processTemplate("verification_email_v2.ftl", templateParams); String htmlBody = templateManager.processTemplate("verification_email_html_v2.ftl", templateParams); mailGunManager.sendEmail(EmailConstants.DO_NOT_REPLY_VERIFY_ORCID_ORG, email, subject, body, htmlBody); - } + } + + @Override + public EmailMessage createAddWorksToRecordEmail(String email, String orcid) { + ProfileEntity profile = profileEntityCacheManager.retrieve(orcid); + Locale locale = getUserLocaleFromProfileEntity(profile); + + String subject = messages.getMessage("email.subject.add_works", null, locale); + String emailName = recordNameManagerV3.deriveEmailFriendlyName(orcid); + Map params = new HashMap<>(); + params.put("locale", locale); + params.put("messages", messages); + params.put("subject", subject); + params.put("messageArgs", new Object[0]); + params.put("emailName", emailName); + params.put("orcidId", orcid); + params.put("baseUri", orcidUrlManager.getBaseUrl()); + + // Generate body from template + String body = templateManager.processTemplate("add_works_to_record_email.ftl", params, locale); + String htmlBody = templateManager.processTemplate("add_works_to_record_email_html.ftl", params, locale); + + EmailMessage emailMessage = new EmailMessage(); + + emailMessage.setSubject(subject); + emailMessage.setBodyText(body); + emailMessage.setBodyHtml(htmlBody); + return emailMessage; + } + + private void sendAddWorksToRecordEmail(String email, String orcid) { + EmailMessage addWorksMessage = createAddWorksToRecordEmail(email, orcid); + mailGunManager.sendEmail(EmailConstants.DO_NOT_REPLY_VERIFY_ORCID_ORG, email, addWorksMessage.getSubject(), addWorksMessage.getBodyText(), addWorksMessage.getBodyHtml()); + } } diff --git a/orcid-scheduler-web/src/main/resources/orcid-scheduler-context.xml b/orcid-scheduler-web/src/main/resources/orcid-scheduler-context.xml index aaecc64f895..565133c8c26 100644 --- a/orcid-scheduler-web/src/main/resources/orcid-scheduler-context.xml +++ b/orcid-scheduler-web/src/main/resources/orcid-scheduler-context.xml @@ -38,7 +38,7 @@ - + diff --git a/orcid-scheduler-web/src/test/java/org/orcid/scheduler/email/cli/manager/EmailMessageSenderTest.java b/orcid-scheduler-web/src/test/java/org/orcid/scheduler/email/cli/manager/EmailMessageSenderTest.java index 1503a853764..21554165d8e 100644 --- a/orcid-scheduler-web/src/test/java/org/orcid/scheduler/email/cli/manager/EmailMessageSenderTest.java +++ b/orcid-scheduler-web/src/test/java/org/orcid/scheduler/email/cli/manager/EmailMessageSenderTest.java @@ -133,6 +133,19 @@ public void testCreateDigest() throws IOException { assertEquals(expectedBodyText, text); } + @Test + public void testAddWorksToRecordEmail() throws IOException { + EmailMessage emailMessage = emailMessageSender.createAddWorksToRecordEmail("email@orcid.org", "0000-0000-0000-0000"); + assertNotNull(emailMessage); + String text = emailMessage.getBodyText(); + String html = emailMessage.getBodyHtml(); + String expectedBodyText = IOUtils.toString(EmailMessageSenderTest.class.getClassLoader().getResourceAsStream("email/example_add_works_to_record.txt")); + String expectedBodyHtml = IOUtils.toString(EmailMessageSenderTest.class.getClassLoader().getResourceAsStream("email/example_add_works_to_record.html")); + assertEquals("[ORCID] Add Research Outputs to your ORCID record", emailMessage.getSubject()); + assertEquals(expectedBodyText, text); + assertEquals(expectedBodyHtml, html); + } + private List generateNotifications() { List notifications = new ArrayList<>(); diff --git a/orcid-scheduler-web/src/test/resources/email/example_add_works_to_record.html b/orcid-scheduler-web/src/test/resources/email/example_add_works_to_record.html new file mode 100644 index 00000000000..7c08d13fefd --- /dev/null +++ b/orcid-scheduler-web/src/test/resources/email/example_add_works_to_record.html @@ -0,0 +1,83 @@ + + + + [ORCID] Add Research Outputs to your ORCID record + + +
+
+

+ Your ORCID iD: 0000-0000-0000-0000 +
+ Your ORCID record is https://testserver.orcid.org/0000-0000-0000-0000 +

+

Dear John Watson

+
+
+

We have noticed that you have not yet added any research outputs to your ORCID record. Adding these will help reduce your administrative burden when read and imported into other systems, ensure you are recognized for your research contributions, and disambiguate you from other researchers with the same name!

+

Get started with these popular ORCID integrations:

+

Below are links to 4 popular ORCID integrations that allow you to sign in to your OCID record, grant permission to the service to add your selected research outputs to your ORCID record.

+

For adding journal articles: Crossref Metadata Search allows you to search and add works by title or DOI.

+

For adding life sciences literature: Europe PubMed Central allows you to import works from the Europe PubMed database, which includes all articles indexed by PubMed Central.

+

For adding multiple published articles: Scopus allows you to add your Scopus Author ID to your record as well as importing works associated with your Scopus Author ID. +

+

BASE (Bielefeld Academic Search Engine) allows you to claim and import works from the Bielefeld Academic Search Engine. To use, you must first create a BASE user account. Recommended for authors of open access publications.

+

We have more `search and link` wizards available within your ORCID record.

+

If you are having trouble adding your research outputs or you would like to know more about how to add data to your ORCID record, please visit our ORCID Help Center.

+

Warm Regards, +
+ORCID Support Team

+ https://support.orcid.org +
+ +
+ + diff --git a/orcid-scheduler-web/src/test/resources/email/example_add_works_to_record.txt b/orcid-scheduler-web/src/test/resources/email/example_add_works_to_record.txt new file mode 100644 index 00000000000..979c9a62b75 --- /dev/null +++ b/orcid-scheduler-web/src/test/resources/email/example_add_works_to_record.txt @@ -0,0 +1,29 @@ +Your ORCID iD: 0000-0000-0000-0000 +Your ORCID record is https://testserver.orcid.org/0000-0000-0000-0000 + +Dear John Watson + +We have noticed that you have not yet added any research outputs to your ORCID record. Adding these will help reduce your administrative burden when read and imported into other systems, ensure you are recognized for your research contributions, and disambiguate you from other researchers with the same name! + +Get started with these popular ORCID integrations: + +Below are links to 4 popular ORCID integrations that allow you to sign in to your OCID record, grant permission to the service to add your selected research outputs to your ORCID record. + +For adding journal articles: Crossref Metadata Search allows you to search and add works by title or DOI. + +For adding life sciences literature: Europe PubMed Central allows you to import works from the Europe PubMed database, which includes all articles indexed by PubMed Central. + +For adding multiple published articles: Scopus allows you to add your Scopus Author ID to your record as well as importing works associated with your Scopus Author ID. + +BASE (Bielefeld Academic Search Engine) allows you to claim and import works from the Bielefeld Academic Search Engine. To use, you must first create a BASE user account. Recommended for authors of open access publications. + +We have more `search and link` wizards available within your ORCID record. + +If you are having trouble adding your research outputs or you would like to know more about how to add data to your ORCID record, please visit our ORCID Help Center. + +Warm Regards, +ORCID Support Team +https://support.orcid.org + +You have received this email because you opted in to tips and features emails from ORCID. You can opt out of these at account settings. +email preferences | privacy policy | ORCID, Inc. | 10411 Motor City Drive, Suite 750, Bethesda, MD 20817, USA | ORCID.org