com.github.quartzwebui.service.strategy.ValidateServiceStrategy 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 org.quartz.CronExpression;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
/**
* @author quxiucheng [[email protected]]
*/
public class ValidateServiceStrategy implements ServiceStrategy {
/**
* 业务处理
* @param serviceStrategyURL 处理URL类
* @param parameter 参数
* @return 返回JSON数据
*/
public JSONResult service(ServiceStrategyURL serviceStrategyURL, ValidateServiceStrategyParameter parameter) {
// 核查class名称
if (QuartzWebUIURL.ValidateURL.VALIDATE_CLASS.getURL().equals(serviceStrategyURL.getURL())) {
return validateClass(parameter.getClassName());
}
// 核查class并且获取classInfo
if (QuartzWebUIURL.ValidateURL.VALIDATE_CLASSINFO.getURL().equals(serviceStrategyURL.getURL())) {
return validateClassInfo(parameter.getClassName());
}
// 核查class时候为另一个子类型
if (QuartzWebUIURL.ValidateURL.VALIDATE_ASSIGNABLE.getURL().equals(serviceStrategyURL.getURL())) {
return validateAssignable(parameter.getClassName(), parameter.getAssignableClassName());
}
//校验job是否存在
if (QuartzWebUIURL.ValidateURL.VALIDATE_JOB.getURL().equals(serviceStrategyURL.getURL())) {
return validateJob(parameter.getSchedulerName(), parameter.getJobName(), parameter.getJobGroup());
}
//校验trigger是否存在
if (QuartzWebUIURL.ValidateURL.VALIDATE_TRIGGER.getURL().equals(serviceStrategyURL.getURL())) {
return validateTrigger(parameter.getSchedulerName(), parameter.getTriggerName(), parameter.getTriggerGroup());
}
//校验cron表达式是否正确
if (QuartzWebUIURL.ValidateURL.VALIDATE_CRONEXPRESSION.getURL().equals(serviceStrategyURL.getURL())) {
return validateCronExpression(parameter.getCronExpression());
}
return JSONResult.build(JSONResult.RESULT_CODE_ERROR, "404 not found");
}
public ValidateServiceStrategyParameter newServiceStrategyParameterInstance() {
return new ValidateServiceStrategyParameter();
}
/**
* 核查className是否合法
* @param className class名称
* @return 返回JSON数据
*/
public JSONResult validateClass(String className){
try {
Assert.notEmpty(className, "className can not be empty");
boolean check = QuartzWebUIManager.checkClass(className);
Map result = new LinkedHashMap();
result.put("result", check);
return JSONResult.build(JSONResult.RESULT_CODE_SUCCESS, result);
} catch (Exception e) {
e.printStackTrace();
return JSONResult.build(JSONResult.RESULT_CODE_ERROR, e.getMessage());
}
}
/**
* 核查className是否合法,并获取名称
* @param className class名
* @return JSON数据
*/
public JSONResult validateClassInfo(String className){
try {
Assert.notEmpty(className, "className can not be empty");
Map result = new LinkedHashMap();
Class clazz = QuartzWebUIManager.getClass(className);
boolean classResult;
if (clazz != null) {
// 是否继承 job类
if (org.quartz.Job.class.isAssignableFrom(clazz)) {
result.put("jobType", JobServiceStrategyParameter.JobType.JOB.getDictValue());
} else {
result.put("jobType", JobServiceStrategyParameter.JobType.NOJOB.getDictValue());
List> constructorInfo = QuartzWebUIManager.getConstructorInfo(clazz);
// 方法信息
List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy