Search in sources :

Example 1 with ParameterInfo

use of io.camunda.zeebe.spring.client.bean.ParameterInfo in project spring-zeebe by camunda-community-hub.

the class JobHandlerInvokingSpringBeans method createParameters.

private List<Object> createParameters(JobClient jobClient, ActivatedJob job, List<ParameterInfo> parameters) {
    List<Object> args = new ArrayList<>();
    for (ParameterInfo param : parameters) {
        // parameter default null
        Object arg = null;
        Class<?> clazz = param.getParameterInfo().getType();
        if (JobClient.class.isAssignableFrom(clazz)) {
            arg = jobClient;
        } else if (ActivatedJob.class.isAssignableFrom(clazz)) {
            arg = job;
        } else if (param.getParameterInfo().isAnnotationPresent(ZeebeVariable.class)) {
            try {
                // TODO make this work for complex types as well
                arg = clazz.cast(job.getVariablesAsMap().get(param.getParameterName()));
            } catch (ClassCastException ex) {
                throw new RuntimeException("Cannot assign process variable '" + param.getParameterName() + "' to parameter when executing job '" + job.getType() + "', invalid type found: " + ex.getMessage());
            }
        } else if (param.getParameterInfo().isAnnotationPresent(ZeebeVariablesAsType.class)) {
            try {
                arg = job.getVariablesAsType(clazz);
            } catch (RuntimeException e) {
                throw new RuntimeException("Cannot assign process variables to type '" + clazz.getName() + "' when executing job '" + job.getType() + "', cause is: " + e.getMessage(), e);
            }
        } else if (param.getParameterInfo().isAnnotationPresent(ZeebeCustomHeaders.class)) {
            try {
                arg = job.getCustomHeaders();
            } catch (RuntimeException e) {
                throw new RuntimeException("Cannot assign headers '" + param.getParameterName() + "' to parameter when executing job '" + job.getType() + "', cause is: " + e.getMessage(), e);
            }
        }
        args.add(arg);
    }
    return args;
}
Also used : ActivatedJob(io.camunda.zeebe.client.api.response.ActivatedJob) ZeebeVariablesAsType(io.camunda.zeebe.spring.client.annotation.ZeebeVariablesAsType) ArrayList(java.util.ArrayList) ParameterInfo(io.camunda.zeebe.spring.client.bean.ParameterInfo)

Aggregations

ActivatedJob (io.camunda.zeebe.client.api.response.ActivatedJob)1 ZeebeVariablesAsType (io.camunda.zeebe.spring.client.annotation.ZeebeVariablesAsType)1 ParameterInfo (io.camunda.zeebe.spring.client.bean.ParameterInfo)1 ArrayList (java.util.ArrayList)1