use of org.talend.sdk.component.api.configuration.condition.meta.Condition in project component-runtime by Talend.
the class ConditionParameterEnricher method onParameterAnnotation.
@Override
public Map<String, String> onParameterAnnotation(final String parameterName, final Type parameterType, final Annotation annotation) {
final Condition condition = annotation.annotationType().getAnnotation(Condition.class);
if (condition != null) {
final String type = condition.value();
if (ActiveIfs.class.isInstance(annotation)) {
return Stream.of(ActiveIfs.class.cast(annotation).value()).map(ai -> onParameterAnnotation(parameterName, parameterType, ai)).collect(HashMap::new, (map, entry) -> {
final String suffix = "::" + (map.size() / 2);
map.putAll(entry.entrySet().stream().collect(toMap(e -> e.getKey() + suffix, Map.Entry::getValue)));
}, HashMap::putAll);
}
return Stream.of(annotation.annotationType().getMethods()).filter(m -> m.getDeclaringClass() == annotation.annotationType()).collect(toMap(m -> META_PREFIX + type + "::" + m.getName(), m -> {
try {
final Object invoke = m.invoke(annotation);
if (String[].class.isInstance(invoke)) {
return Stream.of(String[].class.cast(invoke)).collect(joining(","));
}
return String.valueOf(invoke);
} catch (final InvocationTargetException | IllegalAccessException e) {
throw new IllegalStateException(e);
}
}));
}
return emptyMap();
}
Aggregations