use of com.jeeagile.core.exception.AgileFrameException in project jeeagile by jeeagile.
the class AgileGeneratorTableServiceImpl method downloadCode.
@Override
public byte[] downloadCode(List<String> agileGeneratorTableIdList) {
try {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
ZipOutputStream zipOutputStream = new ZipOutputStream(outputStream);
for (String agileGeneratorTableId : agileGeneratorTableIdList) {
AgileGeneratorTableInfo agileGeneratorTableInfo = this.selectTableInfoById(agileGeneratorTableId);
if (agileGeneratorTableInfo != null && AgileStringUtil.isNotEmpty(agileGeneratorTableInfo.getId())) {
AgileGeneratorUtil.generatorCode(agileGeneratorTableInfo, zipOutputStream);
}
}
IOUtils.close(zipOutputStream);
return outputStream.toByteArray();
} catch (Exception ex) {
throw new AgileFrameException("代码生成异常!");
}
}
use of com.jeeagile.core.exception.AgileFrameException in project jeeagile by jeeagile.
the class AgileAbstractJob method invokeMethod.
/**
* 调用任务方法
*
* @param bean 目标对象
* @param agileQuartzJob 任务调度对象
*/
private void invokeMethod(Object bean, AgileQuartzJob agileQuartzJob) throws SecurityException, IllegalArgumentException {
List<Method> methodList = filterMethod(bean, agileQuartzJob.getMethodName());
// 判断方法是否存在,如果不存在则暂停执行任务
if (methodList == null || methodList.isEmpty()) {
AgileScheduleUtil.pauseJob(agileQuartzJob);
throw new AgileFrameException("任务代码《" + agileQuartzJob.getJobCode() + "》执行方法不存在,请核实!");
}
// 获取方法个数,用于对比执行的是那个方法
int methodParamCount = 0;
if (AgileStringUtil.isNotEmpty(agileQuartzJob.getMethodParam())) {
methodParamCount = agileQuartzJob.getMethodParam().split("&").length;
}
// 对比参数个数确定要执行的方法
Method invokeMethod = null;
for (Method method : methodList) {
if (method.getParameterCount() == methodParamCount) {
invokeMethod = method;
}
}
if (invokeMethod == null) {
log.warn("设定参数与要执行方法的参数个数不符,将随机获取一个方法进行执行!");
invokeMethod = methodList.get(0);
}
if (invokeMethod.getParameterCount() == 0) {
if (AgileStringUtil.isNotEmpty(agileQuartzJob.getMethodParam())) {
log.warn("任务要执行方法属于无参方法,但任务设定了参数,请核实!");
}
ReflectionUtils.invokeMethod(invokeMethod, bean);
} else {
Object[] methodParams = getMethodParams(invokeMethod, agileQuartzJob.getMethodParam());
ReflectionUtils.invokeMethod(invokeMethod, bean, methodParams);
}
}
use of com.jeeagile.core.exception.AgileFrameException in project jeeagile by jeeagile.
the class SingleRequestBodyResolver method getHttpRequestBody.
/**
* 获取请求体JSON字符串
*/
private String getHttpRequestBody(NativeWebRequest webRequest) {
// 有就直接获取
String jsonBody = (String) webRequest.getAttribute(JSON_REQUEST_BODY, RequestAttributes.SCOPE_REQUEST);
HttpServletRequest servletRequest = webRequest.getNativeRequest(HttpServletRequest.class);
// 没有就从请求中读取
if (jsonBody == null && servletRequest != null) {
try {
jsonBody = IOUtils.toString(servletRequest.getReader());
webRequest.setAttribute(JSON_REQUEST_BODY, jsonBody, RequestAttributes.SCOPE_REQUEST);
} catch (IOException e) {
throw new AgileFrameException(e);
}
}
return jsonBody;
}
use of com.jeeagile.core.exception.AgileFrameException in project jeeagile by jeeagile.
the class SingleRequestBodyResolver method resolveArgument.
@Override
public Object resolveArgument(MethodParameter methodParameter, ModelAndViewContainer modelAndViewContainer, NativeWebRequest nativeWebRequest, WebDataBinderFactory webDataBinderFactory) {
SingleRequestBody singleRequestBody = methodParameter.getParameterAnnotation(SingleRequestBody.class);
Assert.state(singleRequestBody != null, "Unresolvable singleRequestBody");
final String httpRequestBody = getHttpRequestBody(nativeWebRequest);
Assert.state(httpRequestBody != null, "Unresolvable httpRequestBody");
JSONObject jsonObject = getJsonObjectByHttpRequestBody(httpRequestBody);
String parameterName = AgileStringUtil.isEmpty(singleRequestBody.name()) ? methodParameter.getParameterName() : singleRequestBody.name();
Assert.state(parameterName != null, "Unresolvable parameter name");
Class<?> parameterType = methodParameter.getParameterType();
Object object = null;
if (jsonObject == null) {
object = getValueObjectByHttpRequestBody(parameterType, httpRequestBody);
} else {
object = getValueObjectByJsonObject(methodParameter, parameterName, jsonObject);
}
if (singleRequestBody.required()) {
if (object == null) {
throw new AgileFrameException(String.format("required param %s is not present", parameterName));
}
} else {
if (object == null && !singleRequestBody.defaultValue().equals(ValueConstants.DEFAULT_NONE)) {
if (isBasicDataTypes(parameterType)) {
// 基本类型包装类
object = parseBasicTypeWrapper(parameterType, singleRequestBody.defaultValue());
} else if (parameterType == String.class) {
// 字符串类型
object = singleRequestBody.defaultValue();
}
}
}
return object;
}
use of com.jeeagile.core.exception.AgileFrameException in project jeeagile by jeeagile.
the class AgileScheduleUtil method createScheduleJob.
/**
* 创建定时任务
*/
public static void createScheduleJob(AgileQuartzJob agileQuartzJob) {
try {
// 如果任务存在进行移除
if (AgileScheduleUtil.checkJobExists(agileQuartzJob)) {
AgileScheduleUtil.deleteScheduleJob(agileQuartzJob);
}
Class<? extends Job> jobClass = getAgileJobClass(agileQuartzJob);
JobDetail jobDetail = JobBuilder.newJob(jobClass).withIdentity(getJobKey(agileQuartzJob)).build();
// 表达式调度构建器
CronScheduleBuilder cronScheduleBuilder = CronScheduleBuilder.cronSchedule(agileQuartzJob.getJobCron());
cronScheduleBuilder = initCronScheduleMisfirePolicy(agileQuartzJob, cronScheduleBuilder);
// 构建trigger
CronTrigger cronTrigger = TriggerBuilder.newTrigger().withIdentity(getTriggerKey(agileQuartzJob)).withSchedule(cronScheduleBuilder).build();
// 放入运行参数
jobDetail.getJobDataMap().put(AgileScheduleConstants.TASK_JOB_PROPERTIES, agileQuartzJob);
agileScheduler.scheduleJob(jobDetail, cronTrigger);
// 暂停任务
if (agileQuartzJob.getJobStatus().equals(AgileStatusEnum.DISABLE.getCode())) {
AgileScheduleUtil.pauseJob(agileQuartzJob);
}
} catch (SchedulerException ex) {
throw new AgileFrameException("创建任务失败:" + ex.getMessage());
} catch (AgileBaseException ex) {
throw ex;
} catch (Exception ex) {
throw new AgileFrameException("创建任务发生未知异常:" + ex.getMessage());
}
}
Aggregations