<commit_before>package org.phoenixctms.ctsms.executable;

import java.util.Iterator;

import org.phoenixctms.ctsms.domain.Job;
import org.phoenixctms.ctsms.domain.JobDao;
import org.phoenixctms.ctsms.domain.PasswordDao;
import org.phoenixctms.ctsms.domain.User;
import org.phoenixctms.ctsms.domain.UserDao;
import org.phoenixctms.ctsms.security.Authenticator;
import org.phoenixctms.ctsms.security.CryptoUtil;
import org.phoenixctms.ctsms.service.user.UserService;
import org.phoenixctms.ctsms.util.CoreUtil;
import org.phoenixctms.ctsms.util.JobOutput;
import org.phoenixctms.ctsms.vo.AuthenticationVO;
import org.phoenixctms.ctsms.vo.UserOutVO;
import org.springframework.beans.factory.annotation.Autowired;

public class JobRunner {

	@Autowired
	private UserDao userDao;
	@Autowired
	private JobDao jobDao;
	@Autowired
	private PasswordDao passwordDao;
	@Autowired
	private UserService userService;
	private JobOutput jobOutput;
	private Authenticator authenticator;

	public JobRunner() {
	}

	public long processJobs(AuthenticationVO auth, Boolean daily, Boolean weekly, Boolean monthly) throws Exception {
		UserOutVO userVO = userService.getUser(auth, userDao.searchUniqueName(auth.getUsername()).getId(), null, null, null);
		jobOutput.println("department: " + userVO.getDepartment().getName());
		String plainDepartmentPassword = CryptoUtil.decryptDepartmentPassword(authenticator.authenticate(auth, false), auth.getPassword());
		long count = 0l;
		Iterator<Job> jobsIt = jobDao.findPending(userVO.getDepartment().getId(), daily, weekly, monthly).iterator();
		while (jobsIt.hasNext()) {
			Job job = jobsIt.next();
			jobOutput.println("running job ID " + Long.toString(job.getId()));
			User jobUser = job.getModifiedUser();
			AuthenticationVO jobUserAuth = new AuthenticationVO();
			jobUserAuth.setUsername(jobUser.getName());
			jobUserAuth.setPassword(CryptoUtil.decryptPassword(passwordDao.findLastPassword(jobUser.getId()), plainDepartmentPassword));
			CoreUtil.launchJob(jobUserAuth, job, true);
			count += 1l;
		}
		jobOutput.println(count + " jobs executed");
		return count;
	}

	public void setAuthenticator(Authenticator authenticator) {
		this.authenticator = authenticator;
	}

	public void setJobOutput(JobOutput jobOutput) {
		this.jobOutput = jobOutput;
	}
}
<commit_msg>slurp NPE for invalid user for dbtools jobrunner tasks<commit_after>package org.phoenixctms.ctsms.executable;

import java.util.Iterator;

import org.phoenixctms.ctsms.domain.Job;
import org.phoenixctms.ctsms.domain.JobDao;
import org.phoenixctms.ctsms.domain.PasswordDao;
import org.phoenixctms.ctsms.domain.User;
import org.phoenixctms.ctsms.domain.UserDao;
import org.phoenixctms.ctsms.security.Authenticator;
import org.phoenixctms.ctsms.security.CryptoUtil;
import org.phoenixctms.ctsms.service.user.UserService;
import org.phoenixctms.ctsms.util.CoreUtil;
import org.phoenixctms.ctsms.util.JobOutput;
import org.phoenixctms.ctsms.vo.AuthenticationVO;
import org.phoenixctms.ctsms.vo.UserOutVO;
import org.springframework.beans.factory.annotation.Autowired;

public class JobRunner {

	@Autowired
	private UserDao userDao;
	@Autowired
	private JobDao jobDao;
	@Autowired
	private PasswordDao passwordDao;
	@Autowired
	private UserService userService;
	private JobOutput jobOutput;
	private Authenticator authenticator;

	public JobRunner() {
	}

	public long processJobs(AuthenticationVO auth, Boolean daily, Boolean weekly, Boolean monthly) throws Exception {
		UserOutVO userVO = null;
		try {
			userVO = userService.getUser(auth, userDao.searchUniqueName(auth.getUsername()).getId(), null, null, null);
			jobOutput.println("department: " + userVO.getDepartment().getName());
		} catch (Exception e) {
		}
		String plainDepartmentPassword = CryptoUtil.decryptDepartmentPassword(authenticator.authenticate(auth, false), auth.getPassword());
		long count = 0l;
		Iterator<Job> jobsIt = jobDao.findPending(userVO.getDepartment().getId(), daily, weekly, monthly).iterator();
		while (jobsIt.hasNext()) {
			Job job = jobsIt.next();
			jobOutput.println("running job ID " + Long.toString(job.getId()));
			User jobUser = job.getModifiedUser();
			AuthenticationVO jobUserAuth = new AuthenticationVO();
			jobUserAuth.setUsername(jobUser.getName());
			jobUserAuth.setPassword(CryptoUtil.decryptPassword(passwordDao.findLastPassword(jobUser.getId()), plainDepartmentPassword));
			CoreUtil.launchJob(jobUserAuth, job, true);
			count += 1l;
		}
		jobOutput.println(count + " jobs executed");
		return count;
	}

	public void setAuthenticator(Authenticator authenticator) {
		this.authenticator = authenticator;
	}

	public void setJobOutput(JobOutput jobOutput) {
		this.jobOutput = jobOutput;
	}
}

{'fraction_non_alphanumeric': 0.1087972800679983, 'fraction_numerical': 0.0008499787505312367, 'mean_word_length': 5.983679525222552, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '1463323', 'n_tokens_mistral': 1569, 'n_tokens_neox': 1550, 'n_words': 280}