Skip to content

Commit

Permalink
Merge pull request #6794 from ORCID/8639-spam-autolockspam-cli-changes
Browse files Browse the repository at this point in the history
Changes to cli to support sending notification emails and only lock unverified, unlocked records
  • Loading branch information
amontenegro authored Jun 6, 2023
2 parents d6b1307 + 6a9513d commit 2beb7c5
Show file tree
Hide file tree
Showing 2 changed files with 1,227 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.orcid.core.cli;
package org.orcid.frontend.cli;

import java.io.FileReader;
import java.io.IOException;
Expand All @@ -17,6 +17,9 @@
import org.orcid.core.manager.v3.NotificationManager;
import org.orcid.core.manager.v3.ProfileEntityManager;
import org.orcid.core.togglz.OrcidTogglzConfiguration;
import org.orcid.core.utils.OrcidStringUtils;
import org.orcid.frontend.email.RecordEmailSender;
import org.orcid.persistence.jpa.entities.ProfileEntity;
import org.orcid.pojo.ajaxForm.PojoUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -48,6 +51,9 @@ public class AutoLockSpamRecords {

@Resource
private ProfileEntityCacheManager profileEntityCacheManager;

@Resource
private RecordEmailSender recordEmailSender;

public static void main(String[] args) {
AutoLockSpamRecords autolockSpamRecords = new AutoLockSpamRecords();
Expand Down Expand Up @@ -84,14 +90,21 @@ private void autolockRecords(List<String> toLock) {
System.out.println("Start for batch: " + System.currentTimeMillis() + " to lock batch is: " + toLock.size());
for (String orcidId : toLock) {
try {
System.out.println("Processing orcidId: " + orcidId);
profileEntityManager.findByOrcid(orcidId);
//check if is not already locked
profileEntityManager.lockProfile(orcidId, LockReason.SPAM_AUTO.getLabel(), "ML Detected", "");

lastOrcidProcessed = orcidId;
LOG.info("Processing orcidId: " + orcidId);
if(OrcidStringUtils.isValidOrcid(orcidId)) {
ProfileEntity profileEntity = profileEntityManager.findByOrcid(orcidId);
//only lock account was not reviewed and not already locked
if(!profileEntity.isReviewed() && profileEntity.isAccountNonLocked()) {
boolean wasLocked = profileEntityManager.lockProfile(orcidId, LockReason.SPAM_AUTO.getLabel(), "ML Detected", "");
if(wasLocked) {
recordEmailSender.sendOrcidLockedEmail(orcidId);
}
}
lastOrcidProcessed = orcidId;
}
} catch (Exception e) {
LOG.error("Exception when locking spam record " + orcidId, e);
LOG.info("LastOrcid processed is: " + lastOrcidProcessed);
e.printStackTrace();
}
}
Expand All @@ -102,10 +115,11 @@ private void autolockRecords(List<String> toLock) {

@SuppressWarnings("resource")
private void init() {
ApplicationContext context = new ClassPathXmlApplicationContext("orcid-core-context.xml");
ApplicationContext context = new ClassPathXmlApplicationContext("orcid-core-context-spam.xml");
profileEntityManager = (ProfileEntityManager) context.getBean("profileEntityManagerV3");
profileEntityCacheManager = (ProfileEntityCacheManager) context.getBean("profileEntityCacheManager");
notificationManager = (NotificationManager) context.getBean("notificationManagerV3");
recordEmailSender = (RecordEmailSender) context.getBean("recordEmailSender");
bootstrapTogglz(context.getBean(OrcidTogglzConfiguration.class));
}

Expand All @@ -127,7 +141,7 @@ private ArrayList<String> getAllSpamIDs() throws IOException {
while (iterator.hasNext()) {
keyVals = iterator.next();
Object[] keys = keyVals.keySet().toArray();
spamList.add(keyVals.get(keys[5]));
spamList.add(keyVals.get(keys[0]));
}
return spamList;
}
Expand All @@ -146,5 +160,6 @@ private static void bootstrapTogglz(OrcidTogglzConfiguration togglzConfig) {
FeatureManager featureManager = new FeatureManagerBuilder().togglzConfig(togglzConfig).build();
ContextClassLoaderFeatureManagerProvider.bind(featureManager);
}


}
Loading

0 comments on commit 2beb7c5

Please sign in to comment.