Skip to content

Commit

Permalink
removed affiliation check added bio + researcherUrl check (#7018)
Browse files Browse the repository at this point in the history
  • Loading branch information
Camelia-Orcid authored Apr 5, 2024
1 parent 274b7de commit bceb608
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,21 @@

import javax.annotation.Resource;

import org.apache.commons.lang.StringUtils;
import org.orcid.core.admin.LockReason;
import org.orcid.core.manager.ProfileEntityCacheManager;
import org.orcid.core.manager.AffiliationsManager;

import org.orcid.core.manager.v3.BiographyManager;
import org.orcid.core.manager.v3.NotificationManager;
import org.orcid.core.manager.v3.ProfileEntityManager;
import org.orcid.core.manager.v3.ResearcherUrlManager;
import org.orcid.core.togglz.OrcidTogglzConfiguration;
import org.orcid.core.utils.OrcidStringUtils;
import org.orcid.jaxb.model.record_v2.Affiliation;

import org.orcid.jaxb.model.v3.release.record.Biography;
import org.orcid.jaxb.model.v3.release.record.ResearcherUrls;
import org.orcid.persistence.dao.OrcidOauth2TokenDetailDao;
import org.orcid.persistence.jpa.entities.ProfileEntity;
import org.orcid.pojo.ajaxForm.PojoUtil;
import org.orcid.scheduler.autospam.AutospamEmailSender;
import org.orcid.utils.alerting.SlackManager;
import org.slf4j.Logger;
Expand Down Expand Up @@ -102,9 +106,15 @@ public class AutoLockSpamRecords {

@Resource
private AutospamEmailSender autospamEmailSender;

@Resource
private AffiliationsManager affiliationsManager;


@Resource(name = "biographyManagerV3")
private BiographyManager biographyManager;

@Resource(name = "researcherUrlManagerV3")
private ResearcherUrlManager researcherUrlManager;



// for running spam manually
public static void main(String[] args) {
Expand Down Expand Up @@ -135,21 +145,22 @@ private void autolockRecords(List<String> toLock) {
// and not have an auth token

if (profileEntity != null && !profileEntity.isReviewed() && profileEntity.isAccountNonLocked() && !orcidOauthDao.hasToken(orcidId)) {
List<Affiliation> affiliations = affiliationsManager.getAffiliations(orcidId);
// Lock only if doesn't have any affiliations
if (affiliations == null || affiliations.size() < 1) {
boolean wasLocked = profileEntityManager.lockProfile(orcidId, LockReason.SPAM_AUTO.getLabel(), "ML Detected", "");
//check if it has biography
Biography bio= biographyManager.getBiography(orcidId);
ResearcherUrls researcherUrls = researcherUrlManager.getResearcherUrls(orcidId);

if(( bio !=null && StringUtils.isNotBlank(bio.getContent()) || (researcherUrls != null && researcherUrls.getResearcherUrls() != null && researcherUrls.getResearcherUrls().size() > 0))){
boolean wasLocked = profileEntityManager.lockProfile(orcidId, LockReason.SPAM_AUTO.getLabel(), "ML Detected", "");
if (wasLocked) {
autospamEmailSender.sendOrcidLockedEmail(orcidId);
accountsLocked++;
}
}
}
}
lastOrcidProcessed = orcidId;
}
} catch (Exception e) {
LOG.error("Exception when locking spam record " + orcidId, e);
slackManager.sendAlert("Exception when locking spam record " + orcidId + ". LastOrcid processed is: " + lastOrcidProcessed, slackChannel, slackUser, webhookUrl);
LOG.info("LastOrcid processed is: " + lastOrcidProcessed);
e.printStackTrace();
}
Expand Down Expand Up @@ -197,7 +208,8 @@ private void init() {
notificationManager = (NotificationManager) context.getBean("notificationManagerV3");
autospamEmailSender = (AutospamEmailSender) context.getBean("autospamEmailSender");
orcidOauthDao = (OrcidOauth2TokenDetailDao) context.getBean("orcidOauth2TokenDetailDao");
affiliationsManager = (AffiliationsManager) context.getBean("affiliationsManager");
biographyManager = (BiographyManager) context.getBean("biographyManagerV3");
researcherUrlManager = (ResearcherUrlManager) context.getBean("researcherUrlManagerV3");
bootstrapTogglz(context.getBean(OrcidTogglzConfiguration.class));
}

Expand Down
5 changes: 3 additions & 2 deletions properties/development.properties
Original file line number Diff line number Diff line change
Expand Up @@ -249,9 +249,10 @@ org.orcid.message-listener.s3.secretKey=xx
org.orcid.scheduler.aws.bucket=auto-spam-qa
org.orcid.scheduler.aws.file=orcidspam.csv
org.orcid.scheduler.autospam.enabled=false
org.orcid.scheduler.autospam.file=orcidspam.csv
org.orcid.scheduler.autospam.daily.batch=1
org.orcid.scheduler.autospam.file=/Users/camdum/Desktop/orcidspam.csv
org.orcid.scheduler.autospam.daily.batch=20000
org.orcid.scheduler.autospam.process=0 0 0 * * MON
org.orcid.scheduler.autospam.enabled=true

# Slack
org.orcid.core.autospam.slackChannel=collab-spam-reports
Expand Down

0 comments on commit bceb608

Please sign in to comment.