Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: Add encourage user to add works to email events log #6949

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import org.orcid.persistence.dao.GenericDao;
import org.orcid.persistence.dao.NotificationDao;
import org.orcid.persistence.dao.ProfileDao;
import org.orcid.persistence.dao.ProfileEventDao;
import org.orcid.persistence.jpa.entities.ActionableNotificationEntity;
import org.orcid.persistence.jpa.entities.ClientDetailsEntity;
import org.orcid.persistence.jpa.entities.ClientRedirectUriEntity;
Expand Down Expand Up @@ -83,7 +84,7 @@ public class NotificationManagerImpl extends ManagerReadOnlyBaseImpl implements
private EncryptionManager encryptionManager;

@Resource
private GenericDao<ProfileEventEntity, Long> profileEventDao;
private ProfileEventDao profileEventDao;

@Resource
private ProfileDao profileDao;
Expand Down Expand Up @@ -128,7 +129,7 @@ public void setEncryptionManager(EncryptionManager encryptionManager) {
this.encryptionManager = encryptionManager;
}

public void setProfileEventDao(GenericDao<ProfileEventEntity, Long> profileEventDao) {
public void setProfileEventDao(ProfileEventDao profileEventDao) {
this.profileEventDao = profileEventDao;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
import org.orcid.core.manager.TwoFactorAuthenticationManager;
import org.orcid.core.manager.read_only.EmailManagerReadOnly;
import org.orcid.jaxb.model.record_v2.Email;
import org.orcid.persistence.dao.GenericDao;
import org.orcid.persistence.dao.ProfileDao;
import org.orcid.persistence.dao.ProfileEventDao;
import org.orcid.persistence.jpa.entities.ProfileEntity;
import org.orcid.persistence.jpa.entities.ProfileEventEntity;
import org.orcid.persistence.jpa.entities.ProfileEventType;
Expand All @@ -40,7 +40,7 @@ public class TwoFactorAuthenticationManagerImpl implements TwoFactorAuthenticati
private BackupCodeManager backupCodeManager;

@Resource
private GenericDao<ProfileEventEntity, Long> profileEventDao;
private ProfileEventDao profileEventDao;

@Resource
private ProfileDao profileDao;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
import org.orcid.persistence.dao.GenericDao;
import org.orcid.persistence.dao.NotificationDao;
import org.orcid.persistence.dao.ProfileDao;
import org.orcid.persistence.dao.ProfileEventDao;
import org.orcid.persistence.jpa.entities.ActionableNotificationEntity;
import org.orcid.persistence.jpa.entities.ClientDetailsEntity;
import org.orcid.persistence.jpa.entities.ClientRedirectUriEntity;
Expand Down Expand Up @@ -101,7 +102,7 @@ public class NotificationManagerImpl extends ManagerReadOnlyBaseImpl implements
private EncryptionManager encryptionManager;

@Resource
private GenericDao<ProfileEventEntity, Long> profileEventDao;
private ProfileEventDao profileEventDao;

@Resource
private ProfileDao profileDao;
Expand Down Expand Up @@ -175,7 +176,7 @@ public void setEncryptionManager(EncryptionManager encryptionManager) {
this.encryptionManager = encryptionManager;
}

public void setProfileEventDao(GenericDao<ProfileEventEntity, Long> profileEventDao) {
public void setProfileEventDao(ProfileEventDao profileEventDao) {
this.profileEventDao = profileEventDao;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@
import org.kohsuke.args4j.CmdLineException;
import org.kohsuke.args4j.CmdLineParser;
import org.kohsuke.args4j.Option;
import org.orcid.core.manager.NotificationManager;
import org.orcid.core.manager.TemplateManager;
import org.orcid.core.manager.impl.OrcidUrlManager;
import org.orcid.core.manager.v3.RecordNameManager;
import org.orcid.jaxb.model.notification_v2.NotificationType;
import org.orcid.persistence.dao.GenericDao;
import org.orcid.persistence.dao.NotificationDao;
import org.orcid.persistence.dao.ProfileDao;
import org.orcid.persistence.dao.ProfileEventDao;
import org.orcid.persistence.dao.impl.ProfileEventDaoImpl;
import org.orcid.persistence.jpa.entities.NotificationServiceAnnouncementEntity;
import org.orcid.persistence.jpa.entities.ProfileEntity;
import org.orcid.persistence.jpa.entities.ProfileEventEntity;
Expand Down Expand Up @@ -54,7 +55,7 @@ public class EmailFrequencyServiceAnnouncement2018 {

private TemplateManager templateManager;

private GenericDao<ProfileEventEntity, Long> profileEventDao;
private ProfileEventDao profileEventDao;

private NotificationDao notificationDao;

Expand Down Expand Up @@ -100,7 +101,7 @@ private void init() {
profileDaoReadOnly = (ProfileDao) context.getBean("profileDaoReadOnly");
messages = (MessageSource) context.getBean("messageSource");
templateManager = (TemplateManager) context.getBean("templateManager");
profileEventDao = (GenericDao) context.getBean("profileEventDao");
profileEventDao = (ProfileEventDao) context.getBean("profileEventDao");
notificationDao = (NotificationDao) context.getBean("notificationDao");
orcidUrlManager = (OrcidUrlManager) context.getBean("orcidUrlManager");
recordNameManager = (RecordNameManager) context.getBean("recordNameManagerV3");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
import org.kohsuke.args4j.CmdLineException;
import org.kohsuke.args4j.CmdLineParser;
import org.kohsuke.args4j.Option;
import org.orcid.persistence.dao.GenericDao;
import org.orcid.persistence.dao.ProfileDao;
import org.orcid.persistence.dao.ProfileEventDao;
import org.orcid.persistence.jpa.entities.ProfileEventEntity;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -37,7 +37,7 @@ public class ProfileEventManager {
private ProfileDao profileDao;

@Resource
private GenericDao<ProfileEventEntity, Long> profileEventDao;
private ProfileEventDao profileEventDao;

@Resource
private TransactionTemplate transactionTemplate;
Expand Down Expand Up @@ -136,11 +136,11 @@ public void setProfileDao(ProfileDao profileDao) {
this.profileDao = profileDao;
}

public GenericDao<ProfileEventEntity, Long> getProfileEventDao() {
public ProfileEventDao getProfileEventDao() {
return profileEventDao;
}

public void setProfileEventDao(GenericDao<ProfileEventEntity, Long> profileEventDao) {
public void setProfileEventDao(ProfileEventDao profileEventDao) {
this.profileEventDao = profileEventDao;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.orcid.persistence.dao.GenericDao;
import org.orcid.persistence.dao.NotificationDao;
import org.orcid.persistence.dao.ProfileDao;
import org.orcid.persistence.dao.ProfileEventDao;
import org.orcid.persistence.jpa.entities.EmailFrequencyEntity;
import org.orcid.persistence.jpa.entities.NotificationTipEntity;
import org.orcid.persistence.jpa.entities.ProfileEntity;
Expand All @@ -41,7 +42,7 @@ public abstract class QuarterlyNotificationsManager {

private static Logger LOG = LoggerFactory.getLogger(QuarterlyNotificationsManager.class);

private GenericDao<ProfileEventEntity, Long> profileEventDao;
private ProfileEventDao profileEventDao;

private ProfileDao profileDaoReadOnly;

Expand Down Expand Up @@ -89,7 +90,7 @@ public QuarterlyNotificationsManager(ProfileEventType created, ProfileEventType
notificationDao = (NotificationDao) context.getBean("notificationDao");
orcidUrlManager = (OrcidUrlManager) context.getBean("orcidUrlManager");
emailFrequencyDao = (EmailFrequencyDao) context.getBean("emailFrequencyDao");
profileEventDao = (GenericDao) context.getBean("profileEventDao");
profileEventDao = (ProfileEventDao) context.getBean("profileEventDao");
encryptionManager = (EncryptionManager) context.getBean("encryptionManager");
messages = (MessageSource) context.getBean("messageSource");
transactionTemplate = (TransactionTemplate) context.getBean("transactionTemplate");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
import org.orcid.persistence.dao.GenericDao;
import org.orcid.persistence.dao.NotificationDao;
import org.orcid.persistence.dao.ProfileDao;
import org.orcid.persistence.dao.ProfileEventDao;
import org.orcid.persistence.dao.impl.NotificationDaoImpl;
import org.orcid.persistence.jpa.entities.ClientDetailsEntity;
import org.orcid.persistence.jpa.entities.NotificationEntity;
Expand All @@ -80,7 +81,7 @@ public class NotificationManagerTest extends DBUnitTest {


@Mock
private GenericDao<ProfileEventEntity, Long> profileEventDao;
private ProfileEventDao profileEventDao;

@Mock
private SourceManager sourceManager;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.orcid.jaxb.model.record_v2.Email;
import org.orcid.persistence.dao.GenericDao;
import org.orcid.persistence.dao.ProfileDao;
import org.orcid.persistence.dao.ProfileEventDao;
import org.orcid.persistence.jpa.entities.ProfileEntity;
import org.orcid.persistence.jpa.entities.ProfileEventEntity;

Expand All @@ -49,7 +50,7 @@ public class TwoFactorAuthenticationManagerTest {
private ProfileDao profileDao;

@Mock
private GenericDao<ProfileEventEntity, Long> profileEventDao;
private ProfileEventDao profileEventDao;

@InjectMocks
private TwoFactorAuthenticationManagerImpl twoFactorAuthenticationManager;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
import org.orcid.persistence.dao.GenericDao;
import org.orcid.persistence.dao.NotificationDao;
import org.orcid.persistence.dao.ProfileDao;
import org.orcid.persistence.dao.ProfileEventDao;
import org.orcid.persistence.dao.impl.NotificationDaoImpl;
import org.orcid.persistence.jpa.entities.ClientDetailsEntity;
import org.orcid.persistence.jpa.entities.EmailEventEntity;
Expand All @@ -90,7 +91,7 @@ public class NotificationManagerTest extends DBUnitTest {
"/data/BiographyEntityData.xml");

@Mock
private GenericDao<ProfileEventEntity, Long> profileEventDao;
private ProfileEventDao profileEventDao;

@Mock
private SourceManager mockSourceManager;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,5 +164,5 @@ public interface ProfileDao extends GenericDao<ProfileEntity, String> {

boolean haveMemberPushedWorksOrAffiliationsToRecord(String orcid, String clientId);

public List<Pair<String, String>> findEmailsToSendAddWorksEmail();
public List<Pair<String, String>> findEmailsToSendAddWorksEmail(int profileCreatedNumberOfDaysAgo);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package org.orcid.persistence.dao;

import org.orcid.persistence.jpa.entities.ProfileEventEntity;
import org.orcid.persistence.jpa.entities.ProfileEventType;

/**
*
* @author Daniel Palafox
*
*/
public interface ProfileEventDao extends GenericDao<ProfileEventEntity, Long> {

boolean isAttemptSend(String orcid, ProfileEventType eventType);

}
Original file line number Diff line number Diff line change
Expand Up @@ -842,18 +842,19 @@ public boolean haveMemberPushedWorksOrAffiliationsToRecord(String orcid, String
}

@Override
public List<Pair<String, String>> findEmailsToSendAddWorksEmail() {
public List<Pair<String, String>> findEmailsToSendAddWorksEmail(int profileCreatedNumberOfDaysAgo) {
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("e.is_verified = true and e.is_primary = true and ");
qs.append("ef.send_quarterly_tips = true and ");
qs.append("w.orcid is null and ");
qs.append("CAST(p.date_created as date) = CAST(CURRENT_DATE - INTERVAL '");
qs.append(profileCreatedNumberOfDaysAgo);
qs.append("' day as date) ");
qs.append("GROUP BY e.email, p.orcid");

Query query = entityManager.createNativeQuery(qs.toString());
Expand All @@ -866,10 +867,4 @@ public List<Pair<String, String>> findEmailsToSendAddWorksEmail() {
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) ";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package org.orcid.persistence.dao.impl;

import org.orcid.persistence.dao.ProfileEventDao;
import org.orcid.persistence.jpa.entities.ProfileEventEntity;
import org.orcid.persistence.jpa.entities.ProfileEventType;

import javax.persistence.Query;
import java.math.BigInteger;
import java.util.List;

/**
*
* @author Daniel Palafox
*
*/
public class ProfileEventDaoImpl extends GenericDaoImpl<ProfileEventEntity, Long> implements ProfileEventDao {

public ProfileEventDaoImpl() { super(ProfileEventEntity.class); }

@Override
public boolean isAttemptSend(String orcid, ProfileEventType eventType) {
Query query = entityManager.createNativeQuery("select count(*) from profile_event where orcid=:orcid and profile_event_type=:eventType");
query.setParameter("orcid", orcid);
query.setParameter("eventType", eventType.toString());
Long result = ((BigInteger)query.getSingleResult()).longValue();
return (result != null && result > 0);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,5 @@ public enum EmailEventType {
VERIFY_EMAIL_7_DAYS_SENT_SKIPPED, /* we are going to skip notifying email address that where already in the system before launching this */
VERIFY_EMAIL_2_DAYS_SENT,
VERIFY_EMAIL_2_DAYS_SENT_SKIPPED,
VERIFY_EMAIL_TOO_OLD
;
VERIFY_EMAIL_TOO_OLD;
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,13 @@ public enum ProfileEventType {
EMAIL_VIS_2019_SENT, EMAIL_VIS_2019_SKIPPED, EMAIL_VIS_2019_FAILED,

// 2FA enable/disable events
PROFILE_2FA_ENABLED, PROFILE_2FA_DISABLED, PROFILE_2FA_DISABLED_BY_ADMIN;
PROFILE_2FA_ENABLED, PROFILE_2FA_DISABLED, PROFILE_2FA_DISABLED_BY_ADMIN,

//Send email to encourage users to add works to their record
ADD_WORKS_FIRST_REMINDER_SENT,
ADD_WORKS_FIRST_REMINDER_SENT_SKIPPED,
ADD_WORKS_SECOND_REMINDER_SENT,
ADD_WORKS_SECOND_REMINDER_SENT_SKIPPED,
ADD_WORKS_THIRD_REMINDER_SENT,
ADD_WORKS_THIRD_REMINDER_SENT_SKIPPED;
}
Original file line number Diff line number Diff line change
Expand Up @@ -207,9 +207,7 @@
<constructor-arg value="org.orcid.persistence.jpa.entities.CountryIsoEntity" />
</bean>

<bean id="profileEventDao" class="org.orcid.persistence.dao.impl.GenericDaoImpl">
<constructor-arg value="org.orcid.persistence.jpa.entities.ProfileEventEntity" />
</bean>
<bean id="profileEventDao" class="org.orcid.persistence.dao.impl.ProfileEventDaoImpl" />

<bean id="emailEventDao" class="org.orcid.persistence.dao.impl.GenericDaoImpl">
<constructor-arg value="org.orcid.persistence.jpa.entities.EmailEventEntity" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public class ProfileDaoTest extends DBUnitTest {
private ClientDetailsDao clientDetailsDao;

@Resource
private GenericDao<ProfileEventEntity, Long> profileEventDao;
private ProfileEventDao profileEventDao;

@Resource(name="entityManager")
protected EntityManager entityManager;
Expand Down Expand Up @@ -381,12 +381,12 @@ public void testDisable2FA() {

@Test
@Transactional
public void findEmailsToSendAddWorksEmail() {
public void findEmailsToSendAddWorksFirstAttemptEmail() {
String orcid = "4444-4444-4444-4441";

updateProfileWithDateCreated(orcid, LocalDateTime.now().minusDays(7).toDate());

List<Pair<String, String>> results = profileDao.findEmailsToSendAddWorksEmail();
List<Pair<String, String>> results = profileDao.findEmailsToSendAddWorksEmail(7);
assertNotNull(results);
assertEquals(1, results.size());
}
Expand Down
Loading