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;
}
Aggregations