Skip to content

Commit

Permalink
Merge pull request #6929 from ORCID/send_7_28_verification_reminders_…
Browse files Browse the repository at this point in the history
…take2

Changed the code to use triples
  • Loading branch information
amontenegro authored Nov 14, 2023
2 parents aa1f1cb + c1bf046 commit 40f5454
Show file tree
Hide file tree
Showing 3 changed files with 166 additions and 128 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ public interface ProfileDao extends GenericDao<ProfileEntity, String> {
void updateLastModifiedDateAndIndexingStatusWithoutResult(String orcid, Date lastModified, IndexingStatus indexingStatus);

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


public List<Triple<String, Boolean, String>> findEmailsUnverifiedDaysByEventType(int daysUnverified, int tooOldNumberOfDays);

String retrieveOrcidType(String orcid);

List<Object[]> findInfoForDecryptionAnalysis();
Expand Down Expand Up @@ -156,10 +158,10 @@ public interface ProfileDao extends GenericDao<ProfileEntity, String> {
public List<Object[]> getSigninLock(String orcid);

public void startSigninLock(String orcid);

public void resetSigninLock(String orcid);

public void updateSigninLock(String orcid, Integer count);

boolean haveMemberPushedWorksOrAffiliationsToRecord(String orcid, String clientId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,15 @@
import org.springframework.beans.factory.annotation.Value;
import org.springframework.transaction.annotation.Transactional;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class ProfileDaoImpl extends GenericDaoImpl<ProfileEntity, String> implements ProfileDao {

private static final String PRIVATE_VISIBILITY = "PRIVATE";

private static final Logger LOGGER = LoggerFactory.getLogger(ProfileDaoImpl.class);

@Value("${org.orcid.postgres.query.timeout:30000}")
private Integer queryTimeout;

Expand Down Expand Up @@ -150,7 +155,31 @@ public List<Triple<String, Boolean, Date>> findEmailsUnverfiedDays(int daysUnver
results.add(pair);
});
return results;
}
}

@SuppressWarnings("unchecked")
@Override
public List<Triple<String, Boolean, String>> findEmailsUnverifiedDaysByEventType(int daysUnverified, int tooOldNumberOfDays) {
StringBuilder queryString = new StringBuilder("SELECT e.email, e.is_primary, 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 e.is_verified = false ");
queryString.append("and e.date_created between (now() - CAST('").append(tooOldNumberOfDays).append("' AS INTERVAL DAY)) and (now() - CAST('")
.append(daysUnverified).append("' AS INTERVAL DAY)) ");
queryString.append("and e.date_created < (now() - CAST('").append(daysUnverified).append("' AS INTERVAL DAY)) ");
queryString.append("and (e.source_id = e.orcid OR e.source_id is null)");
queryString.append(" ORDER BY e.last_modified");

Query query = entityManager.createNativeQuery(queryString.toString());
List<Object[]> dbInfo = query.getResultList();
List<Triple<String, Boolean, String>> results = new ArrayList<Triple<String, Boolean, String>>();
dbInfo.stream().forEach(element -> {
Triple<String, Boolean, String> pair = Triple.of((String) element[0], (Boolean) element[1], (String) element[2]);
results.add(pair);
});
return results;
}

@SuppressWarnings("unchecked")
@Override
Expand Down Expand Up @@ -785,7 +814,7 @@ public void startSigninLock(String orcid) {
query.executeUpdate();
return;
}

@Override
@Transactional
public void resetSigninLock(String orcid) {
Expand All @@ -809,18 +838,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

0 comments on commit 40f5454

Please sign in to comment.