<commit_before>/**
 * 
 */
package org.sakaiproject.evaluation.logic.scheduling;

import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.quartz.JobDataMap;
import org.quartz.JobDetail;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.sakaiproject.evaluation.logic.EvalEvaluationService;
import org.sakaiproject.evaluation.logic.EvalEvaluationSetupService;
import org.sakaiproject.evaluation.logic.EvalEvaluationSetupServiceImpl;
import org.sakaiproject.evaluation.model.EvalEvaluation;

/**
 * 
 *
 */
public class GroupMembershipSyncImpl implements GroupMembershipSync {
	
	private Log logger = LogFactory.getLog(GroupMembershipSyncImpl.class);
	
    private EvalEvaluationService evaluationService;
    public void setEvaluationService(EvalEvaluationService evaluationService) {
        this.evaluationService = evaluationService;
    }

    private EvalEvaluationSetupService evaluationSetupService;
    public void setEvaluationSetupService(EvalEvaluationSetupService evaluationSetupService) {
        this.evaluationSetupService = evaluationSetupService;
    }

	public void execute(JobExecutionContext context) throws JobExecutionException {
		logger.debug("GroupMembershipSync.execute()");
		JobDetail jobDetail = context.getJobDetail();
		JobDataMap data = jobDetail.getJobDataMap();
		String statusStr = (String) data.get(GroupMembershipSync.GROUP_MEMBERSHIP_SYNC_PROPNAME_STATE_LIST);
		if(statusStr == null || statusStr.trim().equals("")) {
			// better throw something?
		} else {
			String[] stateList = statusStr.trim().split(" ");

			for(String state : stateList) {
				List<EvalEvaluation> evals = evaluationService.getEvaluationsByState(state);
				logger.debug("====> " + state + " evals  ==> " + evals.size());
				 
				for(EvalEvaluation eval : evals) {
					if(this.evaluationSetupService instanceof EvalEvaluationSetupServiceImpl) {
						logger.debug("====> " + state + "          ==> " + eval.getEid() + " using impl");
						((EvalEvaluationSetupServiceImpl) this.evaluationSetupService).synchronizeUserAssignmentsForced(eval, null, true);
					} else {
						logger.debug("====> " + state + "          ==> " + eval.getEid() + " using api");
						this.evaluationSetupService.synchronizeUserAssignments(eval.getId(), null);
					}
				}
			}
		}
	}
	
	public void init() {
		logger.debug("init()");
	}

}<commit_msg>EVALSYS-1123 Catch IllegalStateException and log it if an error occues when synchronizing membership in a particular eval and continue to process other evals. Also fixed some of the logging messages.<commit_after>/**
 * 
 */
package org.sakaiproject.evaluation.logic.scheduling;

import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.quartz.JobDataMap;
import org.quartz.JobDetail;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.sakaiproject.evaluation.logic.EvalEvaluationService;
import org.sakaiproject.evaluation.logic.EvalEvaluationSetupService;
import org.sakaiproject.evaluation.logic.EvalEvaluationSetupServiceImpl;
import org.sakaiproject.evaluation.model.EvalEvaluation;

/**
 * 
 *
 */
public class GroupMembershipSyncImpl implements GroupMembershipSync {
	
	private Log logger = LogFactory.getLog(GroupMembershipSyncImpl.class);
	
    private EvalEvaluationService evaluationService;
    public void setEvaluationService(EvalEvaluationService evaluationService) {
        this.evaluationService = evaluationService;
    }

    private EvalEvaluationSetupService evaluationSetupService;
    public void setEvaluationSetupService(EvalEvaluationSetupService evaluationSetupService) {
        this.evaluationSetupService = evaluationSetupService;
    }

	public void execute(JobExecutionContext context) throws JobExecutionException {
		logger.debug("GroupMembershipSync.execute()");
		JobDetail jobDetail = context.getJobDetail();
		JobDataMap data = jobDetail.getJobDataMap();
		String statusStr = (String) data.get(GroupMembershipSync.GROUP_MEMBERSHIP_SYNC_PROPNAME_STATE_LIST);
		if(statusStr == null || statusStr.trim().equals("")) {
			// better throw something?
		} else {
			String[] stateList = statusStr.trim().split(" ");

			for(String state : stateList) {
				List<EvalEvaluation> evals = evaluationService.getEvaluationsByState(state);
				if(logger.isDebugEnabled()) {
					StringBuilder buf = new StringBuilder();
					buf.append("====> ");
					buf.append(state);
					buf.append(" evals  ==> ");
					buf.append(evals.size());
					logger.debug(buf.toString());
				}
				 
				for(EvalEvaluation eval : evals) {
					if(this.evaluationSetupService instanceof EvalEvaluationSetupServiceImpl) {
						if(logger.isDebugEnabled()) {
							StringBuilder buf = new StringBuilder();
							buf.append("====> ");
							buf.append(state);
							buf.append("          ==> ");
							buf.append(eval.getEid());
							buf.append(" using impl");
							logger.debug(buf.toString());
						}
						try {
							((EvalEvaluationSetupServiceImpl) this.evaluationSetupService).synchronizeUserAssignmentsForced(eval, null, true);
						} catch(IllegalStateException e) {
							StringBuilder buf = new StringBuilder();
							buf.append("Unable to user assignments for eval (");
							buf.append(eval.getId());
							buf.append(") due to IllegalStateException: ");
							buf.append(e.getMessage());
							logger.warn(buf.toString());
							
							// TODO: should update the state so it is not selected next time ??
						}
					} else {
						if(logger.isDebugEnabled()) {
							StringBuilder buf = new StringBuilder();
							buf.append("====> ");
							buf.append(state);
							buf.append("          ==> ");
							buf.append(eval.getEid());
							buf.append(" using api");
							logger.debug(buf.toString());
						}
						this.evaluationSetupService.synchronizeUserAssignments(eval.getId(), null);
					}
				}
			}
		}
	}
	
	public void init() {
		logger.debug("init()");
	}

}
{'fraction_non_alphanumeric': 0.1162215628090999, 'fraction_numerical': 0.0006594131223211342, 'mean_word_length': 4.081239530988275, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4631589', 'n_tokens_mistral': 2056, 'n_tokens_neox': 1676, 'n_words': 316}