com.github.quartzwebui.service.strategy.TriggerServiceStrategy Maven / Gradle / Ivy
The newest version!
/**
* Licensed under the Apache License, Version 2.0 (the "License");
*/
package com.github.quartzwebui.service.strategy;
import com.github.quartzwebui.manager.web.QuartzWebUIManager;
import com.github.quartzwebui.service.JSONResult;
import com.github.quartzwebui.service.QuartzWebUIURL;
import com.github.quartzwebui.utils.Assert;
import com.github.quartzwebui.utils.StringUtils;
import org.quartz.CronScheduleBuilder;
import org.quartz.CronTrigger;
import org.quartz.JobDataMap;
import org.quartz.SchedulerException;
import org.quartz.Trigger;
import org.quartz.TriggerBuilder;
import java.util.Date;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
/**
* @author quxiucheng [[email protected]]
*/
public class TriggerServiceStrategy implements ServiceStrategy {
@Override
public JSONResult service(ServiceStrategyURL serviceStrategyURL, TriggerServiceStrategyParameter parameter) {
// 列出信息
String url = serviceStrategyURL.getURL();
if (QuartzWebUIURL.TriggerURL.INFO.getURL().equals(url)) {
return getInfo(parameter.getSchedulerName(), parameter.getJobName(), parameter.getJobGroup());
}
String schedulerName = parameter.getSchedulerName();
String triggerName = parameter.getTriggerName();
String triggerGroup = parameter.getTriggerGroup();
// 具体操作
// 添加
if (QuartzWebUIURL.TriggerURL.ADD.getURL().equals(url)) {
Map jobDataMap = parameter.getJobDataMap();
Map jobDataMapObj = new LinkedHashMap();
if (jobDataMap != null) {
jobDataMapObj.putAll(jobDataMap);
}
return addTrigger(schedulerName, parameter.getJobName(), parameter.getJobGroup(),
triggerName, triggerGroup, parameter.getCronExpression(),
parameter.getDescription(), parameter.getPriority(),
parameter.getStartDate(), parameter.getEndDate(), jobDataMapObj);
}
//重启
if (QuartzWebUIURL.TriggerURL.RESUME.getURL().equals(url)) {
return resumeTrigger(schedulerName, triggerName, triggerGroup);
}
//移除
if (QuartzWebUIURL.TriggerURL.REMOVE.getURL().equals(url)) {
return removeTrigger(schedulerName, triggerName, triggerGroup);
}
//暂停
if (QuartzWebUIURL.TriggerURL.PAUSE.getURL().equals(url)) {
return pauseTrigger(schedulerName, triggerName, triggerGroup);
}
//执行一次
if (QuartzWebUIURL.TriggerURL.RUN.getURL().equals(url)) {
return runTrigge(schedulerName, triggerName, triggerGroup);
}
// 404没有找到url
return JSONResult.build(JSONResult.RESULT_CODE_ERROR, "404 not found");
}
@Override
public TriggerServiceStrategyParameter newServiceStrategyParameterInstance() {
return new TriggerServiceStrategyParameter();
}
public JSONResult getInfo(String schedulerName, String jobName, String jobGroup) {
try {
Assert.notEmpty(schedulerName,"schedulerName can not be empty");
Assert.notEmpty(jobName,"jobName can not be empty");
Assert.notEmpty(jobGroup,"jobGroup can not be empty");
List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy