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

Changed the code to use triples #6929

Merged
merged 2 commits into from
Nov 14, 2023
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 @@ -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