Java Code Examples for org.quartz.JobDetail#getJobDataMap()

The following examples show how to use org.quartz.JobDetail#getJobDataMap() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EmailService.java    From quartz-manager with MIT License 8 votes vote down vote up
public void updateJob(String group, String name, JobDescriptor descriptor) {
	try {
		JobDetail oldJobDetail = scheduler.getJobDetail(jobKey(name, group));
		if(Objects.nonNull(oldJobDetail)) {
			JobDataMap jobDataMap = oldJobDetail.getJobDataMap();
			jobDataMap.put("subject", descriptor.getSubject());
			jobDataMap.put("messageBody", descriptor.getMessageBody());
			jobDataMap.put("to", descriptor.getTo());
			jobDataMap.put("cc", descriptor.getCc());
			jobDataMap.put("bcc", descriptor.getBcc());
			JobBuilder jb = oldJobDetail.getJobBuilder();
			JobDetail newJobDetail = jb.usingJobData(jobDataMap).storeDurably().build();
			scheduler.addJob(newJobDetail, true);
			log.info("Updated job with key - {}", newJobDetail.getKey());
			return;
		}
		log.warn("Could not find job with key - {}.{} to update", group, name);
	} catch (SchedulerException e) {
		log.error("Could not find job with key - {}.{} to update due to error - {}", group, name, e.getLocalizedMessage());
	}
}
 
Example 2
Source File: JobDataMapUtils.java    From quartz-glass with Apache License 2.0 6 votes vote down vote up
public static boolean jobDataMapEquals(JobDetail leftJobDetail, JobDetail rightJobDetail) {
    JobDataMap left = leftJobDetail.getJobDataMap();
    JobDataMap right = rightJobDetail.getJobDataMap();

    int leftKeys = 0;

    for (String key : left.getKeys()) {
        if (GlassConstants.POJO_JOB_META.equals(key)) continue;
        if (GlassConstants.GLASS_SCHEDULER.equals(key)) continue;

        ++leftKeys;
        if (!left.get(key).equals(right.get(key))) return false;
    }

    Set<String> rightKeySet = right.keySet();
    int rightKeys = rightKeySet.size();
    if (rightKeySet.contains(GlassConstants.POJO_JOB_META)) --rightKeys;
    if (rightKeySet.contains(GlassConstants.GLASS_SCHEDULER)) --rightKeys;

    return leftKeys == rightKeys;
}
 
Example 3
Source File: SchedulerTool.java    From sakai with Educational Community License v2.0 6 votes vote down vote up
/**
   * Convenience method for creating a JobDetail object from a JobBeanWrapper. The JobDetail object is
   * used to actually create a job within Quartz, and is also tracked by the {@link getJobDetail()} property
   * for use during the property editting process.
   *
   * @param job
   * @return JobDetail object constructed from the job argument
   */
private JobDetail createJobDetail (JobBeanWrapper job) {
    jobName = escapeEntities(jobName);
    JobDetail
        jd = JobBuilder.newJob(job.getJobClass())
            .withIdentity(jobName, Scheduler.DEFAULT_GROUP)
            .requestRecovery()
            .storeDurably()
            .build();
        
    JobDataMap
        map = jd.getJobDataMap();

    map.put(JobBeanWrapper.SPRING_BEAN_NAME, job.getBeanId());
    map.put(JobBeanWrapper.JOB_NAME, job.getJobName());

    return jd;
}
 
Example 4
Source File: RedisJobStore.java    From redis-quartz with MIT License 6 votes vote down vote up
/**
 * Stores job in redis.
 *
 * @param newJob the new job
 * @param replaceExisting the replace existing
 * @param jedis thread-safe redis connection
 * @throws ObjectAlreadyExistsException
 */
private void storeJob(JobDetail newJob, boolean replaceExisting, Jedis jedis)
		throws ObjectAlreadyExistsException {
	String jobHashKey = createJobHashKey(newJob.getKey().getGroup(), newJob.getKey().getName());
	String jobDataMapHashKey = createJobDataMapHashKey(newJob.getKey().getGroup(), newJob.getKey().getName());
	String jobGroupSetKey = createJobGroupSetKey(newJob.getKey().getGroup());
	
	if (jedis.exists(jobHashKey) && !replaceExisting)
		throw new ObjectAlreadyExistsException(newJob);
				
     Map<String, String> jobDetails = new HashMap<>();
	jobDetails.put(DESCRIPTION, newJob.getDescription() != null ? newJob.getDescription() : "");
	jobDetails.put(JOB_CLASS, newJob.getJobClass().getName());
	jobDetails.put(IS_DURABLE, Boolean.toString(newJob.isDurable()));
	jobDetails.put(BLOCKED_BY, "");
	jobDetails.put(BLOCK_TIME, "");
	jedis.hmset(jobHashKey, jobDetails);
	
	if (newJob.getJobDataMap() != null && !newJob.getJobDataMap().isEmpty())
		jedis.hmset(jobDataMapHashKey, getStringDataMap(newJob.getJobDataMap()));			
	
	jedis.sadd(JOBS_SET, jobHashKey);
	jedis.sadd(JOB_GROUPS_SET, jobGroupSetKey);
	jedis.sadd(jobGroupSetKey, jobHashKey);
}
 
Example 5
Source File: SchedulerTool.java    From sakai with Educational Community License v2.0 6 votes vote down vote up
/**
   * Convenience method for creating a JobDetail object from a JobBeanWrapper. The JobDetail object is
   * used to actually create a job within Quartz, and is also tracked by the {@link getJobDetail()} property
   * for use during the property editting process.
   *
   * @param job
   * @return JobDetail object constructed from the job argument
   */
private JobDetail createJobDetail (JobBeanWrapper job) {
    jobName = escapeEntities(jobName);
    JobDetail
        jd = JobBuilder.newJob(job.getJobClass())
            .withIdentity(jobName, Scheduler.DEFAULT_GROUP)
            .requestRecovery()
            .storeDurably()
            .build();
        
    JobDataMap
        map = jd.getJobDataMap();

    map.put(JobBeanWrapper.SPRING_BEAN_NAME, job.getBeanId());
    map.put(JobBeanWrapper.JOB_NAME, job.getJobName());

    return jd;
}
 
Example 6
Source File: Jobs.java    From quartz-glass with Apache License 2.0 5 votes vote down vote up
public static GlassJob glassJob(JobDetail jobDetail) {
    JobDataMap jobDataMap = jobDetail.getJobDataMap();
    PojoJobMeta pojoJobMeta = (PojoJobMeta) jobDataMap.get(GlassConstants.POJO_JOB_META);
    if (pojoJobMeta == null) return jobDetail.getJobClass().getAnnotation(GlassJob.class);

    return pojoJobMeta.getTargetClass().getAnnotation(GlassJob.class);
}
 
Example 7
Source File: SchedulerUtil.java    From SuitAgent with Apache License 2.0 5 votes vote down vote up
/**
 * 执行计划任务
 * @param job
 * @param trigger
 * @return
 * @throws SchedulerException
 */
public static ScheduleJobResult executeScheduleJob(JobDetail job, Trigger trigger) throws SchedulerException {
    ScheduleJobResult scheduleJobResult = new ScheduleJobResult();
    //判断是否满足计划任务的创建条件
    if(job.getKey() == null || trigger.getKey() == null || job.getJobDataMap() == null){
        scheduleJobResult.setScheduleJobStatus(ScheduleJobStatus.FAILED);
        //不满足计划任务的创建条件,返回scheduleJobResult值类
        return scheduleJobResult;
    }
    scheduleJobResult.setJobDetail(job);
    scheduleJobResult.setTrigger(trigger);
    //开始分配计划任务
    Scheduler scheduler  = SchedulerFactory.getScheduler();
    //开始判断是否存在相同的计划任务
    if(scheduler.checkExists(job.getKey())){
        log.info("存在相同的计划任务:{}",job.getKey());
        scheduler.deleteJob(job.getKey());
        scheduleJobResult.setJobKey(job.getKey());
        scheduleJobResult.setTriggerKey(trigger.getKey());
        scheduleJobResult.setScheduleJobStatus(ScheduleJobStatus.ISEXIST);
        scheduler.scheduleJob(job,trigger);
        scheduler.start();
    }else{
        scheduler.scheduleJob(job,trigger);
        scheduler.start();
        scheduleJobResult.setJobKey(job.getKey());
        scheduleJobResult.setTriggerKey(trigger.getKey());
        scheduleJobResult.setScheduleJobStatus(ScheduleJobStatus.SUCCESS);
    }
    //计划任务分配成功
    return scheduleJobResult;
}
 
Example 8
Source File: AbstractJob.java    From boubei-tss with Apache License 2.0 5 votes vote down vote up
public void execute(JobExecutionContext context) throws JobExecutionException {
  	initContext(); 
auto = true; 
  	
  	JobDetail aJob = context.getJobDetail();
  	String jobName = aJob.getKey().getName();
  	
  	JobDataMap dataMap = aJob.getJobDataMap();
  	String jobConfig = (String) dataMap.get(jobName);
  	Long jobID = (Long) dataMap.get(jobName + "-ID");
      
      log.info("Job[" + jobName + "] starting...");
      
      excuting(jobName, jobConfig, jobID);
  }
 
Example 9
Source File: SchedulerServiceImplTest.java    From kfs with GNU Affero General Public License v3.0 5 votes vote down vote up
protected void scheduleJob(String groupName, String jobName, int startStep, int endStep, Date startTime, String requestorEmailAddress, Map<String,String> additionalJobData ) {
    Scheduler scheduler = (Scheduler) SpringContext.getService("scheduler");
    try {
        JobDetail jobDetail = scheduler.getJobDetail(jobName, groupName);
        if ( jobDetail == null ) {
            fail( "Unable to retrieve JobDetail object for " + groupName + " : " + jobName );
        }
        if ( jobDetail.getJobDataMap() == null ) {
            jobDetail.setJobDataMap( new JobDataMap() );
        }
        jobDetail.getJobDataMap().put(SchedulerService.JOB_STATUS_PARAMETER, SchedulerService.SCHEDULED_JOB_STATUS_CODE);
        scheduler.addJob(jobDetail, true);

        SimpleTriggerDescriptor trigger = new SimpleTriggerDescriptor(jobName+startTime, groupName, jobName, SpringContext.getBean(DateTimeService.class));
        trigger.setStartTime(startTime);
        Trigger qTrigger = trigger.getTrigger();
        qTrigger.getJobDataMap().put(JobListener.REQUESTOR_EMAIL_ADDRESS_KEY, requestorEmailAddress);
        qTrigger.getJobDataMap().put(Job.JOB_RUN_START_STEP, String.valueOf(startStep));
        qTrigger.getJobDataMap().put(Job.JOB_RUN_END_STEP, String.valueOf(endStep));
        if ( additionalJobData != null ) {
            qTrigger.getJobDataMap().putAll(additionalJobData);
        }
        scheduler.scheduleJob(qTrigger);
    }
    catch (SchedulerException e) {
        throw new RuntimeException("Caught exception while scheduling job: " + jobName, e);
    }
}
 
Example 10
Source File: JobTrigger.java    From spring-cloud-shop with MIT License 5 votes vote down vote up
/**
 * 更新定时任务
 *
 * @param scheduler      the scheduler
 * @param jobName        the job name
 * @param jobGroup       the job group
 * @param cronExpression the cron expression
 * @param param          the param
 */
private static void updateJob(Scheduler scheduler, String jobName, String jobGroup, String cronExpression, Object param) throws SchedulerException {

    // 同步或异步
    Class<? extends Job> jobClass = JobQuartzJobBean.class;
    JobDetail jobDetail = scheduler.getJobDetail(getJobKey(jobName, jobGroup));

    jobDetail = jobDetail.getJobBuilder().ofType(jobClass).build();

    // 更新参数 实际测试中发现无法更新
    JobDataMap jobDataMap = jobDetail.getJobDataMap();
    jobDataMap.put("JobAdapter", param);
    jobDetail.getJobBuilder().usingJobData(jobDataMap);

    TriggerKey triggerKey = getTriggerKey(jobName, jobGroup);

    // 表达式调度构建器
    CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule(cronExpression);

    CronTrigger trigger = (CronTrigger) scheduler.getTrigger(triggerKey);

    // 按新的cronExpression表达式重新构建trigger
    trigger = trigger.getTriggerBuilder().withIdentity(triggerKey).withSchedule(scheduleBuilder).build();
    Trigger.TriggerState triggerState = scheduler.getTriggerState(trigger.getKey());
    // 忽略状态为PAUSED的任务,解决集群环境中在其他机器设置定时任务为PAUSED状态后,集群环境启动另一台主机时定时任务全被唤醒的bug
    if (!JobEnums.PAUSE.name().equalsIgnoreCase(triggerState.name())) {
        // 按新的trigger重新设置job执行
        scheduler.rescheduleJob(triggerKey, trigger);
    }
}
 
Example 11
Source File: SchedulerUtil.java    From OpenFalcon-SuitAgent with Apache License 2.0 5 votes vote down vote up
/**
 * 执行计划任务
 * @param job
 * @param trigger
 * @return
 * @throws SchedulerException
 */
public static ScheduleJobResult executeScheduleJob(JobDetail job, Trigger trigger) throws SchedulerException {
    ScheduleJobResult scheduleJobResult = new ScheduleJobResult();
    //判断是否满足计划任务的创建条件
    if(job.getKey() == null || trigger.getKey() == null || job.getJobDataMap() == null){
        scheduleJobResult.setScheduleJobStatus(ScheduleJobStatus.FAILED);
        //不满足计划任务的创建条件,返回scheduleJobResult值类
        return scheduleJobResult;
    }
    scheduleJobResult.setJobDetail(job);
    scheduleJobResult.setTrigger(trigger);
    //开始分配计划任务
    Scheduler scheduler  = SchedulerFactory.getScheduler();
    //开始判断是否存在相同的计划任务
    if(scheduler.checkExists(job.getKey())){
        log.info("存在相同的计划任务:{}",job.getKey());
        scheduler.deleteJob(job.getKey());
        scheduleJobResult.setJobKey(job.getKey());
        scheduleJobResult.setTriggerKey(trigger.getKey());
        scheduleJobResult.setScheduleJobStatus(ScheduleJobStatus.ISEXIST);
        scheduler.scheduleJob(job,trigger);
        scheduler.start();
    }else{
        scheduler.scheduleJob(job,trigger);
        scheduler.start();
        scheduleJobResult.setJobKey(job.getKey());
        scheduleJobResult.setTriggerKey(trigger.getKey());
        scheduleJobResult.setScheduleJobStatus(ScheduleJobStatus.SUCCESS);
    }
    //计划任务分配成功
    return scheduleJobResult;
}
 
Example 12
Source File: QuartzTaskUtils.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Saves {@link TaskConfiguration} back to the given {@link JobDetail}.
 */
public static void updateJobData(final JobDetail jobDetail, final TaskConfiguration taskConfiguration) {
  JobDataMap jobDataMap = jobDetail.getJobDataMap();
  taskConfiguration.asMap().forEach((key, value) -> {
    if (!value.equals(jobDataMap.get(key))) {
      jobDataMap.put(key, value); // only touch jobDataMap if value actually changed
    }
  });
}
 
Example 13
Source File: SakaiJob.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
private JobDetail createJobDetail(JobBeanWrapper job, String jobName) {
    JobDetail jd = JobBuilder.newJob(job.getJobClass()).withIdentity(new JobKey(jobName, Scheduler.DEFAULT_GROUP)).storeDurably().requestRecovery().build();
    JobDataMap map = jd.getJobDataMap();

    map.put(JobBeanWrapper.SPRING_BEAN_NAME, job.getBeanId());
    map.put(JobBeanWrapper.JOB_NAME, job.getJobName());

    return jd;
}
 
Example 14
Source File: SchedulerAdapter.java    From iaf with Apache License 2.0 4 votes vote down vote up
/**
 * Get all jobgroups, jobs within this group, the jobdetail and the
 * associated triggers in XML format.
 */
public XmlBuilder getJobGroupNamesWithJobsToXml(Scheduler theScheduler, IbisManager ibisManager) {
	XmlBuilder xbRoot = new XmlBuilder("jobGroups");

	try {
		// process groups
		List<String> jgnames = theScheduler.getJobGroupNames();

		for (int i = 0; i < jgnames.size(); i++) {
			XmlBuilder el = new XmlBuilder("jobGroup");
			String jobGroupName = jgnames.get(i);
			el.addAttribute("name", jobGroupName);

			// process jobs within group
			XmlBuilder jb = new XmlBuilder("jobs");
			Set<JobKey> jobKeys = theScheduler.getJobKeys(GroupMatcher.jobGroupEquals(jobGroupName));

			for (JobKey jobKey : jobKeys) {
				XmlBuilder jn = new XmlBuilder("job");
				String jobName = jobKey.getName();
				jn.addAttribute("name", jobName);

				// details for job
				JobDetail jobDetail = theScheduler.getJobDetail(jobKey);
				XmlBuilder jd = jobDetailToXmlBuilder(jobDetail);
				jn.addSubElement(jd);

				// get the triggers for this job
				List<? extends Trigger> triggers = theScheduler.getTriggersOfJob(jobKey);
				XmlBuilder tr = getJobTriggers(triggers);
				jn.addSubElement(tr);


				JobDataMap jobDataMap = jobDetail.getJobDataMap();
				XmlBuilder datamap = jobDataMapToXmlBuilder(jobDataMap);
				jn.addSubElement(datamap);
				jb.addSubElement(jn);

				JobDef jobDef = null;
				if(ibisManager != null) {
					for (Configuration configuration : ibisManager.getConfigurations()) {
						jobDef = configuration.getScheduledJob(jobName);
						if (jobDef != null) {
							break;
						}
					}
				}
				XmlBuilder ms = getJobMessages(jobDef);
				jn.addSubElement(ms);
				XmlBuilder jrs= getJobRunStatistics(jobDef);
				jn.addSubElement(jrs);
			}
			el.addSubElement(jb);
			xbRoot.addSubElement(el);
		}
	} catch (SchedulerException se) {
		log.error(se);
	}

	return xbRoot;
}
 
Example 15
Source File: Jobs.java    From quartz-glass with Apache License 2.0 4 votes vote down vote up
public static Class<?> jobCass(JobDetail jobDetail) {
    JobDataMap jobDataMap = jobDetail.getJobDataMap();
    PojoJobMeta pojoJobMeta = (PojoJobMeta) jobDataMap.get(GlassConstants.POJO_JOB_META);
    return pojoJobMeta == null ? jobDetail.getJobClass() : pojoJobMeta.getTargetClass();
}
 
Example 16
Source File: SchedulerTool.java    From sakai with Educational Community License v2.0 4 votes vote down vote up
/**
   * This method runs internally to refresh the set of ConfigurablePropertyWrappers whenever
   * {@link #setConfigurableJobBeanWrapper(ConfigurableJobBeanWrapper)} or
   * {@link #setJobDetail(JobDetail)} is called. {@link getConfigurableJobBeanWrapper()} must not be null
   * for this operation to succeed.
   */
private void refreshProperties ()
{
    final ConfigurableJobBeanWrapper
        job = getConfigurableJobBeanWrapper();

    if (job == null)
    {
        configurableJobProperties = null;
        return;
    }
    
    final Set<ConfigurableJobProperty>
        props = job.getConfigurableJobProperties();

    final JobDetail
        jd = getJobDetail();

    final JobDataMap
        dataMap = (jd != null) ? jd.getJobDataMap() : null;


    if (configurableJobResources == null)
    {
        log.error ("No resource bundle provided for jobs of type: {}. Labels will not be rendered correctly in the scheduler UI", job.getJobName());
    }


    //create a List of jobs, b/c JSF can't handle Sets as a backing bean for a dataTable
    if (props != null)
    {
        configurableJobProperties = new LinkedList<ConfigurablePropertyWrapper>();

        for (ConfigurableJobProperty prop : props)
        {
            ConfigurablePropertyWrapper
                wrapper = new ConfigurablePropertyWrapper();
            String
                value = null;

            wrapper.setJobProperty(prop);

            if (dataMap == null || (value = (String) dataMap.get(prop.getLabelResourceKey())) == null)
            {
                wrapper.setValue (prop.getDefaultValue());
            }
            else
            {
                wrapper.setValue (value);
            }

            configurableJobProperties.add(wrapper);


            if (configurableJobResources != null)
            {
                //check for resource strings for label and desc - warn if they are not present
                final ConfigurableJobProperty
                    property = wrapper.getJobProperty();
                final String
                    labelKey = property.getLabelResourceKey(),
                    descKey = property.getDescriptionResourceKey();

                if (labelKey == null)
                {
                    log.error ("No resource key provided for property label - NullPointerExceptions may occur in scheduler when processing jobs {}", job.getJobName());
                }
                else if (configurableJobResources.get(labelKey) == null)
                {
                    log.warn("No resource string provided for the property label key '{}' for the job {}", labelKey, job.getJobName());
                }

                if (descKey == null)
                {
                    log.warn ("No resource key provided for property description in job {}", job.getJobName());
                }
                else if (configurableJobResources.get(descKey) == null)
                {
                    log.warn("No resource string provided for the property description key '{}' for the job {}", descKey, job.getJobName());
                }
            }
        }
    }
}
 
Example 17
Source File: SchedulerServiceSupplier.java    From Knowage-Server with GNU Affero General Public License v3.0 4 votes vote down vote up
/**
 * Serialize job detail.
 * 
 * @param job the job
 * 
 * @return the string
 * 
 * @throws SourceBeanException the source bean exception
 */
public  String serializeJobDetail(JobDetail job) throws SourceBeanException {
	StringBuffer buffer = new StringBuffer("<JOB_DETAIL ");
	String jobName = job.getName();
	String jobGroupName = job.getGroup();
	String jobDescription = job.getDescription();
	String jobClassName = job.getJobClass().getName();
	String jobDurability = job.isDurable() ? "true" : "false";
	String jobRequestRecovery = job.requestsRecovery() ? "true" : "false";
	String jobVolatility = job.isVolatile() ? "true" : "false";
	JobDataMap jobDataMap = job.getJobDataMap();
	buffer.append(" jobName=\"" + (jobName != null ? jobName : "") + "\"");
	buffer.append(" jobGroupName=\"" + (jobGroupName != null ? jobGroupName : "") + "\"");
	buffer.append(" jobDescription=\"" + (jobDescription != null ? jobDescription : "") + "\"");
	buffer.append(" jobClass=\"" + (jobClassName != null ? jobClassName : "") + "\"");
	buffer.append(" jobDurability=\"" + jobDurability + "\"");
	buffer.append(" jobRequestRecovery=\"" + jobRequestRecovery + "\"");
	buffer.append(" jobVolatility=\"" + jobVolatility + "\"");
	buffer.append(" >");
	buffer.append("<JOB_PARAMETERS>");
	if (jobDataMap != null && !jobDataMap.isEmpty()) {
		String[] keys = jobDataMap.getKeys();
		if (keys != null && keys.length > 0) {
			for (int i = 0; i < keys.length; i++) {
				buffer.append("<JOB_PARAMETER ");
				String key = keys[i];
				String value = jobDataMap.getString(key);
				if (value == null) {
					SpagoBITracer.warning("SCHEDULER", this.getClass().getName(), "loadJobDetailIntoResponse", 
					"Job parameter '" + key + "' has no String value!!");	
				}
				buffer.append(" name=\"" + key + "\"");
				buffer.append(" value=\"" + value + "\"");
				buffer.append(" />");
			}
		}
	}
	buffer.append("</JOB_PARAMETERS>");
	buffer.append("</JOB_DETAIL>");
	return buffer.toString();
}
 
Example 18
Source File: EmailNotificationsController.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
/**
    * Renders a page listing all scheduled emails.
    */
   @RequestMapping("/showScheduledEmails")
   public String showScheduledEmails(HttpServletRequest request, HttpServletResponse response)
    throws IOException, ServletException, SchedulerException {

TreeSet<EmailScheduleMessageJobDTO> scheduleList = new TreeSet<>();
Long lessonId = WebUtil.readLongParam(request, AttributeNames.PARAM_LESSON_ID, true);
boolean isLessonNotifications = (lessonId != null);
Integer organisationId = WebUtil.readIntParam(request, AttributeNames.PARAM_ORGANISATION_ID, true);
if (isLessonNotifications) {
    if (!securityService.isLessonMonitor(lessonId, getCurrentUser().getUserID(),
	    "show scheduled lesson email notifications", false)) {
	response.sendError(HttpServletResponse.SC_FORBIDDEN, "The user is not a monitor in the lesson");
	return null;
    }
} else {
    if (!securityService.isGroupMonitor(organisationId, getCurrentUser().getUserID(),
	    "show scheduled course email notifications", false)) {
	response.sendError(HttpServletResponse.SC_FORBIDDEN, "The user is not a monitor in the organisation");
	return null;
    }
}

Set<TriggerKey> triggerKeys = scheduler
	.getTriggerKeys(GroupMatcher.triggerGroupEquals(Scheduler.DEFAULT_GROUP));
for (TriggerKey triggerKey : triggerKeys) {
    String triggerName = triggerKey.getName();
    if (triggerName.startsWith(EmailNotificationsController.TRIGGER_PREFIX_NAME)) {
	Trigger trigger = scheduler.getTrigger(triggerKey);
	JobDetail jobDetail = scheduler.getJobDetail(trigger.getJobKey());
	JobDataMap jobDataMap = jobDetail.getJobDataMap();

	// filter triggers
	if (isLessonNotifications) {
	    Object jobLessonId = jobDataMap.get(AttributeNames.PARAM_LESSON_ID);
	    if ((jobLessonId == null) || (!lessonId.equals(jobLessonId))) {
		continue;
	    }
	} else {
	    Object jobOrganisationId = jobDataMap.get(AttributeNames.PARAM_ORGANISATION_ID);
	    if ((jobOrganisationId == null) || (!organisationId.equals(jobOrganisationId))) {
		continue;
	    }
	}

	Date triggerDate = trigger.getNextFireTime();
	String emailBody = WebUtil.convertNewlines((String) jobDataMap.get("emailBody"));
	int searchType = (Integer) jobDataMap.get("searchType");
	EmailScheduleMessageJobDTO emailScheduleJobDTO = new EmailScheduleMessageJobDTO();
	emailScheduleJobDTO.setTriggerName(triggerName);
	emailScheduleJobDTO.setTriggerDate(triggerDate);
	emailScheduleJobDTO.setEmailBody(emailBody);
	emailScheduleJobDTO.setSearchType(searchType);
	scheduleList.add(emailScheduleJobDTO);
    }
}

request.setAttribute("scheduleList", scheduleList);
request.setAttribute(AttributeNames.PARAM_LESSON_ID, lessonId);
request.setAttribute(AttributeNames.PARAM_ORGANISATION_ID, organisationId);

return "emailnotifications/scheduledEmailList";
   }
 
Example 19
Source File: ShowScheduler.java    From iaf with Apache License 2.0 4 votes vote down vote up
private Map<String, Object> getJobData(JobKey jobKey, boolean expanded) throws SchedulerException {
	Map<String, Object> jobData = new HashMap<String, Object>();
	Scheduler scheduler = getScheduler();
	String jobName = jobKey.getName();
	JobDetail job = scheduler.getJobDetail(jobKey);

	jobData.put("fullName", job.getKey().getGroup() + "." + job.getKey().getName());
	jobData.put("name", job.getKey().getName());
	jobData.put("group", job.getKey().getGroup());
	String description = "-";
	if (StringUtils.isNotEmpty(job.getDescription()))
		description = job.getDescription();
	jobData.put("description", description);
	jobData.put("stateful", job.isPersistJobDataAfterExecution() && job.isConcurrentExectionDisallowed());
	jobData.put("durable",job.isDurable());
	jobData.put("jobClass", job.getJobClass().getSimpleName());

	if(job instanceof IbisJobDetail) {
		jobData.put("type", ((IbisJobDetail) job).getJobType());
	}

	TriggerState state = scheduler.getTriggerState(TriggerKey.triggerKey(jobName, jobKey.getGroup()));
	jobData.put("state", state.name());

	jobData.put("triggers", getJobTriggers(scheduler.getTriggersOfJob(jobKey)));
	jobData.put("messages", getJobMessages(job));

	JobDataMap jobMap = job.getJobDataMap();
	jobData.put("properties", getJobData(jobMap));

	if(expanded) {
		JobDef jobDef = (JobDef) jobMap.get(ConfiguredJob.JOBDEF_KEY);
		jobData.put("adapter", jobDef.getAdapterName());
		jobData.put("receiver", jobDef.getReceiverName());
		jobData.put("message", jobDef.getMessage());
		
		Locker locker = jobDef.getLocker();
		if(locker != null) {
			jobData.put("locker", true);
			jobData.put("lockkey", locker.getObjectId());
		} else {
			jobData.put("locker", false);
		}
	}

	return jobData;
}
 
Example 20
Source File: JobServiceImpl.java    From griffin with Apache License 2.0 4 votes vote down vote up
private void setJobDataMap(JobDetail jd, AbstractJob job) {
    JobDataMap jobDataMap = jd.getJobDataMap();
    jobDataMap.put(GRIFFIN_JOB_ID, job.getId().toString());
}