<commit_before>package edu.duke.cabig.c3pr.domain.scheduler.runtime.job;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.quartz.Job;
import org.quartz.JobDataMap;
import org.quartz.JobDetail;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.quartz.Scheduler;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.orm.hibernate3.support.OpenSessionInViewInterceptor;
import org.springframework.web.context.request.ServletWebRequest;
import org.springframework.web.context.request.WebRequest;

import edu.duke.cabig.c3pr.constants.NotificationEventTypeEnum;
import edu.duke.cabig.c3pr.dao.PlannedNotificationDao;
import edu.duke.cabig.c3pr.domain.PlannedNotification;
import edu.duke.cabig.c3pr.utils.NotificationEmailService;

/**
 * This class serves as the Email sending job class scheduled by <code>scheduler</code>
 * component. 
 * @author <NAME>
 */
public abstract class ScheduledJob implements Job, ApplicationContextAware {

    protected static final Log logger = LogFactory.getLog(ScheduledJob.class);

    protected Scheduler scheduler;

    protected JobDetail jobDetail;

    protected JobExecutionContext jobContext;

    protected ApplicationContext applicationContext;
    
    private PlannedNotificationDao plannedNotificationDao;

    public ScheduledJob(){
    	super();
    }
    /**
     * @author <NAME>
     * All jobs must extend this class. this handles the hibernate session scope for the jobs.
     * 
     */
    public void execute(JobExecutionContext context) throws JobExecutionException {
        
       	logger.debug("Executing Scheduled Job");
        WebRequest webRequest = new ServletWebRequest(new MockHttpServletRequest()); 
    	OpenSessionInViewInterceptor interceptor = null;
    	
        try {
            // init the member variables
            scheduler = context.getScheduler();
            jobDetail = context.getJobDetail();
            applicationContext = (ApplicationContext) scheduler.getContext().get("applicationContext");

            plannedNotificationDao = (PlannedNotificationDao) applicationContext.getBean("plannedNotificationDao");
            
        	interceptor=(OpenSessionInViewInterceptor)applicationContext.getBean( "openSessionInViewInterceptor");
        	interceptor.preHandle(webRequest);
        	
            JobDataMap jobDataMap = jobDetail.getJobDataMap();
            Integer plannedNotificationId = jobDataMap.getInt("plannedNotificationId");            
            PlannedNotification plannedNotification = plannedNotificationDao.getInitializedPlannedNotificationById(plannedNotificationId, applicationContext);
            
            if(plannedNotification.getEventName().equals(NotificationEventTypeEnum.STUDY_STATUS_CHANGED_EVENT)){
            	try{
            		processJob(jobDataMap, applicationContext, plannedNotification);
            	}catch(JobExecutionException jee){<commit_msg>CPR-71:Scheduler work on notifications<commit_after>package edu.duke.cabig.c3pr.domain.scheduler.runtime.job;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.quartz.Job;
import org.quartz.JobDataMap;
import org.quartz.JobDetail;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.quartz.Scheduler;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.orm.hibernate3.support.OpenSessionInViewInterceptor;
import org.springframework.web.context.request.ServletWebRequest;
import org.springframework.web.context.request.WebRequest;

import edu.duke.cabig.c3pr.constants.NotificationEventTypeEnum;
import edu.duke.cabig.c3pr.dao.PlannedNotificationDao;
import edu.duke.cabig.c3pr.domain.PlannedNotification;
import edu.duke.cabig.c3pr.utils.NotificationEmailService;

/**
 * This class serves as the Email sending job class scheduled by <code>scheduler</code>
 * component. 
 * @author <NAME>
 */
public abstract class ScheduledJob implements Job, ApplicationContextAware {

    protected static final Log logger = LogFactory.getLog(ScheduledJob.class);

    protected Scheduler scheduler;

    protected JobDetail jobDetail;

    protected JobExecutionContext jobContext;

    protected ApplicationContext applicationContext;
    
    private PlannedNotificationDao plannedNotificationDao;

    public ScheduledJob(){
    	super();
    }
    /**
     * @author <NAME>
     * All jobs must extend this class. this handles the hibernate session scope for the jobs.
     * 
     */
    public void execute(JobExecutionContext context) throws JobExecutionException {
        
       	logger.debug("Executing Scheduled Job");
        WebRequest webRequest = new ServletWebRequest(new MockHttpServletRequest()); 
    	OpenSessionInViewInterceptor interceptor = null;
    	
        try {
            // init the member variables
            scheduler = context.getScheduler();
            jobDetail = context.getJobDetail();
            applicationContext = (ApplicationContext) scheduler.getContext().get("applicationContext");

            plannedNotificationDao = (PlannedNotificationDao) applicationContext.getBean("plannedNotificationDao");
            
        	interceptor=(OpenSessionInViewInterceptor)applicationContext.getBean( "openSessionInViewInterceptor");
        	interceptor.preHandle(webRequest);
        	
            JobDataMap jobDataMap = jobDetail.getJobDataMap();
            Integer plannedNotificationId = jobDataMap.getInt("plannedNotificationId");            
            PlannedNotification plannedNotification = plannedNotificationDao.getInitializedPlannedNotificationById(plannedNotificationId);
            
            if(plannedNotification.getEventName().equals(NotificationEventTypeEnum.STUDY_STATUS_CHANGED_EVENT)){
            	try{
            		processJob(jobDataMap, applicationContext, plannedNotification);
            	}catch(JobExecutionException jee){
{'fraction_non_alphanumeric': 0.0789431545236189, 'fraction_numerical': 0.0022417934347477983, 'mean_word_length': 4.020900321543408, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, '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': '7665599', 'n_tokens_mistral': 1613, 'n_tokens_neox': 1596, 'n_words': 307}