Search in sources :

Example 1 with AgileFrameException

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("代码生成异常!");
    }
}
Also used : AgileGeneratorTableInfo(com.jeeagile.generator.vo.AgileGeneratorTableInfo) ZipOutputStream(java.util.zip.ZipOutputStream) AgileFrameException(com.jeeagile.core.exception.AgileFrameException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) AgileValidateException(com.jeeagile.core.exception.AgileValidateException) AgileFrameException(com.jeeagile.core.exception.AgileFrameException)

Example 2 with 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);
    }
}
Also used : AgileFrameException(com.jeeagile.core.exception.AgileFrameException) JSONObject(com.alibaba.fastjson.JSONObject) Method(java.lang.reflect.Method)

Example 3 with AgileFrameException

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;
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) AgileFrameException(com.jeeagile.core.exception.AgileFrameException) IOException(java.io.IOException)

Example 4 with AgileFrameException

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;
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject) JSONObject(com.alibaba.fastjson.JSONObject) AgileFrameException(com.jeeagile.core.exception.AgileFrameException) SingleRequestBody(com.jeeagile.frame.support.resolver.annotation.SingleRequestBody)

Example 5 with AgileFrameException

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());
    }
}
Also used : AgileBaseException(com.jeeagile.core.exception.AgileBaseException) AgileFrameException(com.jeeagile.core.exception.AgileFrameException) AgileFrameException(com.jeeagile.core.exception.AgileFrameException) AgileBaseException(com.jeeagile.core.exception.AgileBaseException)

Aggregations

AgileFrameException (com.jeeagile.core.exception.AgileFrameException)11 JSONObject (com.alibaba.fastjson.JSONObject)3 AgileBaseException (com.jeeagile.core.exception.AgileBaseException)3 HttpServletRequest (javax.servlet.http.HttpServletRequest)3 AgileAuthException (com.jeeagile.core.exception.AgileAuthException)2 AgileBaseUser (com.jeeagile.core.security.user.AgileBaseUser)2 UserAgent (eu.bitwalker.useragentutils.UserAgent)2 IOException (java.io.IOException)2 AgileValidateException (com.jeeagile.core.exception.AgileValidateException)1 AgileReference (com.jeeagile.core.protocol.annotation.AgileReference)1 AgileResultCode (com.jeeagile.core.result.AgileResultCode)1 IAgileUserDetailsService (com.jeeagile.core.security.userdetails.IAgileUserDetailsService)1 AgileAgentUtil (com.jeeagile.core.util.AgileAgentUtil)1 AgileStringUtil (com.jeeagile.core.util.AgileStringUtil)1 AgileServletUtil (com.jeeagile.core.util.spring.AgileServletUtil)1 SingleRequestBody (com.jeeagile.frame.support.resolver.annotation.SingleRequestBody)1 AgileGeneratorTableInfo (com.jeeagile.generator.vo.AgileGeneratorTableInfo)1 AgileQuartzJob (com.jeeagile.quartz.entity.AgileQuartzJob)1 BufferedImage (java.awt.image.BufferedImage)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1