Search in sources :

Example 6 with ParameterMeta

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));
}
Also used : ParameterMeta(org.talend.sdk.component.runtime.manager.ParameterMeta) ParameterizedType(java.lang.reflect.ParameterizedType) ParameterizedType(java.lang.reflect.ParameterizedType) Type(java.lang.reflect.Type) ArrayList(java.util.ArrayList)

Example 7 with ParameterMeta

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());
}
Also used : Assertions.fail(org.junit.jupiter.api.Assertions.fail) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) ComponentFamilyMeta(org.talend.sdk.component.runtime.manager.ComponentFamilyMeta) HashMap(java.util.HashMap) ClassReader(org.apache.xbean.asm6.ClassReader) Collections.singletonList(java.util.Collections.singletonList) DataStore1(org.talend.test.DataStore1) JarEntry(java.util.jar.JarEntry) Collections.singleton(java.util.Collections.singleton) ClassRemapper(org.apache.xbean.asm6.commons.ClassRemapper) WithTemporaryFolder(org.talend.sdk.component.junit.base.junit5.WithTemporaryFolder) ParameterModelService(org.talend.sdk.component.runtime.manager.reflect.ParameterModelService) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) EXPAND_FRAMES(org.apache.xbean.asm6.ClassReader.EXPAND_FRAMES) JarOutputStream(java.util.jar.JarOutputStream) Remapper(org.apache.xbean.asm6.commons.Remapper) ParameterMeta(org.talend.sdk.component.runtime.manager.ParameterMeta) Collections.emptyMap(java.util.Collections.emptyMap) COMPUTE_FRAMES(org.apache.xbean.asm6.ClassWriter.COMPUTE_FRAMES) Container(org.talend.sdk.component.container.Container) Collections.emptyList(java.util.Collections.emptyList) Optional.ofNullable(java.util.Optional.ofNullable) FileOutputStream(java.io.FileOutputStream) WrappingStore(org.talend.test.WrappingStore) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) IdGenerator(org.talend.sdk.component.runtime.manager.util.IdGenerator) File(java.io.File) TestInfo(org.junit.jupiter.api.TestInfo) RepositoryModel(org.talend.sdk.component.design.extension.RepositoryModel) Test(org.junit.jupiter.api.Test) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) Stream(java.util.stream.Stream) TemporaryFolder(org.talend.sdk.component.junit.base.junit5.TemporaryFolder) JarLocation.jarLocation(org.apache.ziplock.JarLocation.jarLocation) ClassWriter(org.apache.xbean.asm6.ClassWriter) ComponentManager(org.talend.sdk.component.runtime.manager.ComponentManager) MigrationHandlerFactory(org.talend.sdk.component.runtime.manager.reflect.MigrationHandlerFactory) ReflectionService(org.talend.sdk.component.runtime.manager.reflect.ReflectionService) InputStream(java.io.InputStream) PartitionMapper1(org.talend.test.PartitionMapper1) RepositoryModel(org.talend.sdk.component.design.extension.RepositoryModel) ReflectionService(org.talend.sdk.component.runtime.manager.reflect.ReflectionService) PartitionMapper1(org.talend.test.PartitionMapper1) ParameterMeta(org.talend.sdk.component.runtime.manager.ParameterMeta) ComponentManager(org.talend.sdk.component.runtime.manager.ComponentManager) ComponentFamilyMeta(org.talend.sdk.component.runtime.manager.ComponentFamilyMeta) ParameterModelService(org.talend.sdk.component.runtime.manager.reflect.ParameterModelService) MigrationHandlerFactory(org.talend.sdk.component.runtime.manager.reflect.MigrationHandlerFactory) Test(org.junit.jupiter.api.Test)

Aggregations

ParameterMeta (org.talend.sdk.component.runtime.manager.ParameterMeta)7 Stream (java.util.stream.Stream)4 Collection (java.util.Collection)3 Collections.emptyMap (java.util.Collections.emptyMap)3 HashMap (java.util.HashMap)3 List (java.util.List)3 Map (java.util.Map)3 Collectors.toMap (java.util.stream.Collectors.toMap)3 Test (org.junit.jupiter.api.Test)3 ComponentManager (org.talend.sdk.component.runtime.manager.ComponentManager)3 Field (java.lang.reflect.Field)2 ParameterizedType (java.lang.reflect.ParameterizedType)2 Collections (java.util.Collections)2 Collections.emptyList (java.util.Collections.emptyList)2 Objects (java.util.Objects)2 Optional.ofNullable (java.util.Optional.ofNullable)2 Collectors.toList (java.util.stream.Collectors.toList)2 Slf4j (lombok.extern.slf4j.Slf4j)2 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1