Search in sources :

Example 1 with ComponentExtension

use of org.talend.sdk.component.spi.component.ComponentExtension in project component-runtime by Talend.

the class DesignContainerListener method onCreate.

/**
 * Enriches {@link Container} with {@link DesignModel} and
 * {@link RepositoryModel} It depends on Updater listener which adds
 * {@link ContainerComponentRegistry} class to {@link Container}
 */
@Override
public void onCreate(final Container container) {
    final ContainerComponentRegistry componentRegistry = container.get(ContainerComponentRegistry.class);
    if (componentRegistry == null) {
        throw new IllegalArgumentException("container doesn't contain ContainerComponentRegistry");
    }
    final Collection<ComponentFamilyMeta> componentFamilyMetas = componentRegistry.getComponents().values();
    // Create Design Model
    componentFamilyMetas.stream().flatMap(family -> Stream.concat(family.getPartitionMappers().values().stream(), family.getProcessors().values().stream())).forEach(meta -> {
        final ComponentExtension.ComponentContext context = container.get(ComponentContexts.class).getContexts().get(meta.getType());
        final ComponentExtension owningExtension = context.owningExtension();
        meta.set(DesignModel.class, ofNullable(owningExtension).map(e -> e.unwrap(FlowsFactory.class, meta)).map(e -> new DesignModel(meta.getId(), e.getInputFlows(), e.getOutputFlows())).orElseGet(() -> {
            final FlowsFactory factory = FlowsFactory.get(meta);
            return new DesignModel(meta.getId(), factory.getInputFlows(), factory.getOutputFlows());
        }));
    });
    // Create Repository Model
    container.set(RepositoryModel.class, repositoryModelBuilder.create(container.get(ComponentManager.AllServices.class), componentFamilyMetas, migrationHandlerFactory));
}
Also used : ContainerComponentRegistry(org.talend.sdk.component.runtime.manager.ContainerComponentRegistry) Container(org.talend.sdk.component.container.Container) ComponentContexts(org.talend.sdk.component.runtime.manager.extension.ComponentContexts) Optional.ofNullable(java.util.Optional.ofNullable) Collection(java.util.Collection) ComponentFamilyMeta(org.talend.sdk.component.runtime.manager.ComponentFamilyMeta) Stream(java.util.stream.Stream) FlowsFactory(org.talend.sdk.component.design.extension.flows.FlowsFactory) RepositoryModelBuilder(org.talend.sdk.component.design.extension.repository.RepositoryModelBuilder) ComponentManager(org.talend.sdk.component.runtime.manager.ComponentManager) MigrationHandlerFactory(org.talend.sdk.component.runtime.manager.reflect.MigrationHandlerFactory) ContainerListenerExtension(org.talend.sdk.component.runtime.manager.spi.ContainerListenerExtension) ComponentExtension(org.talend.sdk.component.spi.component.ComponentExtension) ContainerComponentRegistry(org.talend.sdk.component.runtime.manager.ContainerComponentRegistry) FlowsFactory(org.talend.sdk.component.design.extension.flows.FlowsFactory) ComponentFamilyMeta(org.talend.sdk.component.runtime.manager.ComponentFamilyMeta) ComponentManager(org.talend.sdk.component.runtime.manager.ComponentManager) ComponentExtension(org.talend.sdk.component.spi.component.ComponentExtension)

Aggregations

Collection (java.util.Collection)1 Optional.ofNullable (java.util.Optional.ofNullable)1 Stream (java.util.stream.Stream)1 Container (org.talend.sdk.component.container.Container)1 FlowsFactory (org.talend.sdk.component.design.extension.flows.FlowsFactory)1 RepositoryModelBuilder (org.talend.sdk.component.design.extension.repository.RepositoryModelBuilder)1 ComponentFamilyMeta (org.talend.sdk.component.runtime.manager.ComponentFamilyMeta)1 ComponentManager (org.talend.sdk.component.runtime.manager.ComponentManager)1 ContainerComponentRegistry (org.talend.sdk.component.runtime.manager.ContainerComponentRegistry)1 ComponentContexts (org.talend.sdk.component.runtime.manager.extension.ComponentContexts)1 MigrationHandlerFactory (org.talend.sdk.component.runtime.manager.reflect.MigrationHandlerFactory)1 ContainerListenerExtension (org.talend.sdk.component.runtime.manager.spi.ContainerListenerExtension)1 ComponentExtension (org.talend.sdk.component.spi.component.ComponentExtension)1