Search in sources :

Example 1 with TaskInput

use of io.vertigo.dynamo.task.proxy.TaskInput in project vertigo by KleeGroup.

the class TaskProxyMethod method createTaskDefinition.

private static TaskDefinition createTaskDefinition(final Method method) {
    final io.vertigo.dynamo.task.proxy.TaskAnnotation taskAnnotation = method.getAnnotation(io.vertigo.dynamo.task.proxy.TaskAnnotation.class);
    final TaskDefinitionBuilder taskDefinitionBuilder = TaskDefinition.builder(taskAnnotation.name()).withEngine(taskAnnotation.taskEngineClass()).withRequest(taskAnnotation.request()).withDataSpace(taskAnnotation.dataSpace().isEmpty() ? null : taskAnnotation.dataSpace());
    if (hasOut(method)) {
        final Domain outDomain = findOutDomain(method);
        if (isOutOptional(method)) {
            taskDefinitionBuilder.withOutOptional("OUT", outDomain);
        } else {
            taskDefinitionBuilder.withOutRequired("OUT", outDomain);
        }
    }
    for (final Parameter parameter : method.getParameters()) {
        final TaskInput taskAttributeAnnotation = parameter.getAnnotation(TaskInput.class);
        // test if the parameter is an optional type
        final boolean optional = Optional.class.isAssignableFrom(parameter.getType());
        if (optional) {
            taskDefinitionBuilder.addInOptional(taskAttributeAnnotation.name(), resolveDomain(taskAttributeAnnotation.domain()));
        } else {
            taskDefinitionBuilder.addInRequired(taskAttributeAnnotation.name(), resolveDomain(taskAttributeAnnotation.domain()));
        }
    }
    return taskDefinitionBuilder.build();
}
Also used : TaskInput(io.vertigo.dynamo.task.proxy.TaskInput) Parameter(java.lang.reflect.Parameter) TaskDefinitionBuilder(io.vertigo.dynamo.task.metamodel.TaskDefinitionBuilder) Domain(io.vertigo.dynamo.domain.metamodel.Domain)

Example 2 with TaskInput

use of io.vertigo.dynamo.task.proxy.TaskInput in project vertigo by KleeGroup.

the class TaskProxyMethod method createTask.

private static Task createTask(final TaskDefinition taskDefinition, final Method method, final Object[] args) {
    final TaskBuilder taskBuilder = Task.builder(taskDefinition);
    for (int i = 0; i < method.getParameters().length; i++) {
        final Parameter parameter = method.getParameters()[i];
        final boolean optional = Optional.class.isAssignableFrom(parameter.getType());
        final TaskInput taskAttributeAnnotation = parameter.getAnnotation(TaskInput.class);
        final Object arg;
        if (optional) {
            arg = ((Optional) (args[i])).orElse(null);
        } else {
            arg = args[i];
        }
        taskBuilder.addValue(taskAttributeAnnotation.name(), arg);
    }
    return taskBuilder.build();
}
Also used : TaskBuilder(io.vertigo.dynamo.task.model.TaskBuilder) TaskInput(io.vertigo.dynamo.task.proxy.TaskInput) Parameter(java.lang.reflect.Parameter)

Aggregations

TaskInput (io.vertigo.dynamo.task.proxy.TaskInput)2 Parameter (java.lang.reflect.Parameter)2 Domain (io.vertigo.dynamo.domain.metamodel.Domain)1 TaskDefinitionBuilder (io.vertigo.dynamo.task.metamodel.TaskDefinitionBuilder)1 TaskBuilder (io.vertigo.dynamo.task.model.TaskBuilder)1