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

Fixed the multiple send email for 7, 28 days #6928

Closed
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 @@ -2,6 +2,7 @@

import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

import org.apache.commons.lang3.tuple.Pair;
Expand Down Expand Up @@ -78,7 +79,7 @@ public interface ProfileDao extends GenericDao<ProfileEntity, String> {

public List<Pair<String, Date>> findEmailsUnverfiedDays(int daysUnverified, int maxResults);

public List<Pair<String, Date>> findEmailsUnverifiedDaysAndEventType(int daysUnverified, int maxResults, List<EmailEventType> eventTypes);
public HashMap<String, HashMap<String, Date>> findEmailsUnverifiedDaysByEventType(int daysUnverified, int daysTooOld);

String retrieveOrcidType(String orcid);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
Expand All @@ -22,11 +23,14 @@
import org.orcid.persistence.jpa.entities.ProfileEntity;
import org.orcid.persistence.jpa.entities.ProfileEventEntity;
import org.orcid.persistence.jpa.entities.ProfileEventType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;

public class ProfileDaoImpl extends GenericDaoImpl<ProfileEntity, String> implements ProfileDao {
private static final Logger LOGGER = LoggerFactory.getLogger(ProfileDaoImpl.class);

private static final String PRIVATE_VISIBILITY = "PRIVATE";

Expand Down Expand Up @@ -156,34 +160,34 @@ public List<Pair<String, Date>> findEmailsUnverfiedDays(int daysUnverified, int
});
return results;
}

@SuppressWarnings("unchecked")
@Override
public List<Pair<String, Date>> findEmailsUnverifiedDaysAndEventType(int daysUnverified, int maxResults, List<EmailEventType> eventTypes) {
List<String> stringList = eventTypes.stream().map(Optional::ofNullable) //Stream<Optional<..>>
.map(opt -> opt.orElse(null))
.map(Objects::toString)
.map(opt -> "'"+opt+"'")
.collect(Collectors.toList());

String eventsTypeStr = StringUtils.collectionToCommaDelimitedString(stringList);
StringBuilder queryString = new StringBuilder("SELECT e.email, e.date_created FROM email e ");
public HashMap<String, HashMap<String, Date>> findEmailsUnverifiedDaysByEventType(int daysUnverified, int daysTooOld) {
StringBuilder queryString = new StringBuilder("SELECT e.email, e.date_created, ev.email_event_type FROM email e ");
queryString.append("LEFT JOIN email_event ev ON e.email = ev.email ");
queryString.append("JOIN profile p on p.orcid = e.orcid and p.claimed = true ");
queryString.append("AND p.deprecated_date is null AND p.profile_deactivation_date is null AND p.account_expiry is null ");
queryString.append("where (ev.email IS NULL or email_event_type NOT IN ("+ eventsTypeStr+"))" + "and e.is_verified = false ");
queryString.append("and e.date_created < (now() - CAST('").append(daysUnverified).append("' AS INTERVAL DAY)) ");
queryString.append("where ev.email IS NOT NULL and e.date_created between (now() - CAST('").append(daysTooOld).append("' AS INTERVAL DAY)) and (now() - CAST('")
.append(daysUnverified).append("' AS INTERVAL DAY)) ");
queryString.append("and (e.source_id = e.orcid OR e.source_id is null)");
queryString.append(" GROUP BY e.email, e.date_created, e.last_modified");
queryString.append(" GROUP BY e.email, e.date_created, e.last_modified, ev.email_event_type");
queryString.append(" ORDER BY e.last_modified");
Query query = entityManager.createNativeQuery(queryString.toString());
query.setMaxResults(maxResults);
LOGGER.debug("Unverified Emails Query by Event Type " + query.toString());
List<Object[]> dbInfo = query.getResultList();
List<Pair<String, Date>> results = new ArrayList<Pair<String, Date>>();
HashMap<String, HashMap<String, Date>> results = new HashMap<String, HashMap<String, Date>>();

dbInfo.stream().forEach(element -> {
Pair<String, Date> pair = Pair.of((String) element[0], (Date) element[1]);
results.add(pair);
String email = (String) element[0];
HashMap<String, Date> evMap = new HashMap<String, Date>();
if (results.containsKey(email)) {
evMap = results.get(email);
evMap.put((String) element[2], (Date) element[1]);
}
results.put(email, evMap);
});

return results;
}

Expand Down Expand Up @@ -820,7 +824,7 @@ public void startSigninLock(String orcid) {
query.executeUpdate();
return;
}

@Override
@Transactional
public void resetSigninLock(String orcid) {
Expand All @@ -844,18 +848,18 @@ public void updateSigninLock(String orcid, Integer count) {
query.executeUpdate();
return;
}

public boolean haveMemberPushedWorksOrAffiliationsToRecord(String orcid, String clientId) {
try {
String queryString = "select p.orcid from profile p where p.orcid = :orcid and ( exists (select 1 from work w where w.orcid = p.orcid and w.client_source_id = :clientId) or exists (select 1 from org_affiliation_relation o where o.orcid = p.orcid and o.client_source_id = :clientId));";
Query query = entityManager.createNativeQuery(queryString);
query.setParameter("orcid", orcid);
query.setParameter("clientId", clientId);
String result = (String) query.getSingleResult();
if(orcid.equals(result)) {
if (orcid.equals(result)) {
return true;
}
} catch(NoResultException nre) {
}
} catch (NoResultException nre) {
return false;
}
return false;
Expand Down
Loading