use of org.talend.sdk.component.runtime.manager.ParameterMeta in project component-runtime by Talend.
the class ParameterModelService method buildParameter.
protected ParameterMeta buildParameter(final String name, final String prefix, final ParameterMeta.Source source, final Type genericType, final Annotation[] annotations, final Collection<String> i18nPackages) {
final ParameterMeta.Type type = findType(genericType);
final String normalizedPrefix = prefix.endsWith(".") ? prefix.substring(0, prefix.length() - 1) : prefix;
final List<ParameterMeta> nested = new ArrayList<>();
final List<String> proposals = new ArrayList<>();
switch(type) {
case OBJECT:
addI18nPackageIfPossible(i18nPackages, genericType);
final List<ParameterMeta> meta = buildParametersMetas(name, normalizedPrefix + ".", genericType, annotations, i18nPackages);
meta.sort(Comparator.comparing(ParameterMeta::getName));
nested.addAll(meta);
break;
case ARRAY:
final Type nestedType = Class.class.isInstance(genericType) && Class.class.cast(genericType).isArray() ? Class.class.cast(genericType).getComponentType() : ParameterizedType.class.cast(genericType).getActualTypeArguments()[0];
addI18nPackageIfPossible(i18nPackages, nestedType);
nested.addAll(buildParametersMetas(name + "[${index}]", normalizedPrefix + "[${index}].", nestedType, Class.class.isInstance(nestedType) ? Class.class.cast(nestedType).getAnnotations() : NO_ANNOTATIONS, i18nPackages));
break;
case ENUM:
addI18nPackageIfPossible(i18nPackages, genericType);
proposals.addAll(Stream.of(((Class<? extends Enum<?>>) genericType).getEnumConstants()).map(Enum::name).sorted().collect(toList()));
break;
default:
}
// don't sort here to ensure we don't mess up parameter method ordering
return new ParameterMeta(source, genericType, type, normalizedPrefix, name, i18nPackages.toArray(new String[i18nPackages.size()]), nested, proposals, buildExtensions(name, genericType, annotations));
}
use of org.talend.sdk.component.runtime.manager.ParameterMeta in project component-runtime by Talend.
the class RepositoryModelBuilderTest method notRootConfig.
@Test
void notRootConfig() {
final RepositoryModel model = new RepositoryModelBuilder().create(new ComponentManager.AllServices(emptyMap()), singleton(new ComponentFamilyMeta("test", emptyList(), "noicon", "test", "test") {
{
final ParameterMeta store = new ParameterMeta(null, DataStore1.class, ParameterMeta.Type.OBJECT, "config.store", "store", new String[0], emptyList(), emptyList(), new HashMap<String, String>() {
{
put("tcomp::configurationtype::type", "datastore");
put("tcomp::configurationtype::name", "testDatastore");
}
});
final ParameterMeta wrapper = new ParameterMeta(null, WrappingStore.class, ParameterMeta.Type.OBJECT, "config", "config", new String[0], singletonList(store), emptyList(), emptyMap());
getPartitionMappers().put("test", new PartitionMapperMeta(this, "mapper", "noicon", 1, PartitionMapper1.class, singletonList(wrapper), m -> null, (a, b) -> null, true) {
});
}
}), new MigrationHandlerFactory(new ReflectionService(new ParameterModelService())));
final List<Config> configs = model.getFamilies().stream().flatMap(f -> f.getConfigs().stream()).collect(toList());
assertEquals(1, configs.size());
}
Aggregations