Search in sources :

Example 1 with FamilyBundle

use of org.talend.sdk.component.runtime.internationalization.FamilyBundle in project component-runtime by Talend.

the class ConfigurationTypeResource method toNodes.

private ConfigTypeNodes toNodes(final String language, final Predicate<String> filter, final boolean lightPayload) {
    final Locale locale = localeMapper.mapLocale(language);
    return manager.find(Stream::of).filter(c -> c.get(RepositoryModel.class) != null).map(c -> c.get(RepositoryModel.class).getFamilies().stream().filter(f -> !f.getConfigs().isEmpty()).flatMap(family -> {
        final FamilyBundle resourcesBundle = family.getMeta().findBundle(c.getLoader(), locale);
        final Stream<ConfigTypeNode> familyNode;
        if (filter.test(family.getId())) {
            final ConfigTypeNode node = new ConfigTypeNode();
            node.setId(family.getId());
            node.setName(family.getMeta().getName());
            node.setDisplayName(resourcesBundle.displayName().orElse(family.getMeta().getName()));
            node.setEdges(family.getConfigs().stream().map(Config::getId).collect(toSet()));
            familyNode = Stream.of(node);
        } else {
            familyNode = Stream.empty();
        }
        return Stream.concat(familyNode, createNode(family.getId(), family.getMeta().getName(), family.getConfigs().stream(), resourcesBundle, c, locale, filter, lightPayload));
    })).collect(() -> {
        final ConfigTypeNodes nodes = new ConfigTypeNodes();
        nodes.setNodes(new HashMap<>());
        return nodes;
    }, (root, children) -> root.getNodes().putAll(children.collect(toMap(ConfigTypeNode::getId, identity()))), (first, second) -> first.getNodes().putAll(second.getNodes()));
}
Also used : Locale(java.util.Locale) PathParam(javax.ws.rs.PathParam) Produces(javax.ws.rs.Produces) PropertiesService(org.talend.sdk.component.server.service.PropertiesService) GET(javax.ws.rs.GET) Path(javax.ws.rs.Path) HashMap(java.util.HashMap) FamilyBundle(org.talend.sdk.component.runtime.internationalization.FamilyBundle) Inject(javax.inject.Inject) ConfigTypeNodes(org.talend.sdk.component.server.front.model.ConfigTypeNodes) LocaleMapper(org.talend.sdk.component.server.service.LocaleMapper) QueryParam(javax.ws.rs.QueryParam) Collections.singleton(java.util.Collections.singleton) Collectors.toMap(java.util.stream.Collectors.toMap) Consumes(javax.ws.rs.Consumes) ConfigurationDao(org.talend.sdk.component.server.dao.ConfigurationDao) Locale(java.util.Locale) Map(java.util.Map) DefaultValue(javax.ws.rs.DefaultValue) Config(org.talend.sdk.component.design.extension.repository.Config) APPLICATION_JSON(javax.ws.rs.core.MediaType.APPLICATION_JSON) ActionsService(org.talend.sdk.component.server.service.ActionsService) Collectors.toSet(java.util.stream.Collectors.toSet) POST(javax.ws.rs.POST) Container(org.talend.sdk.component.container.Container) Optional.ofNullable(java.util.Optional.ofNullable) Predicate(java.util.function.Predicate) Collection(java.util.Collection) ErrorDictionary(org.talend.sdk.component.server.front.model.ErrorDictionary) ErrorPayload(org.talend.sdk.component.server.front.model.error.ErrorPayload) RepositoryModel(org.talend.sdk.component.design.extension.RepositoryModel) Collectors.toList(java.util.stream.Collectors.toList) Slf4j(lombok.extern.slf4j.Slf4j) Stream(java.util.stream.Stream) Response(javax.ws.rs.core.Response) SimplePropertyDefinition(org.talend.sdk.component.server.front.model.SimplePropertyDefinition) Function.identity(java.util.function.Function.identity) WebApplicationException(javax.ws.rs.WebApplicationException) ApplicationScoped(javax.enterprise.context.ApplicationScoped) ComponentManager(org.talend.sdk.component.runtime.manager.ComponentManager) ConfigTypeNode(org.talend.sdk.component.server.front.model.ConfigTypeNode) FamilyBundle(org.talend.sdk.component.runtime.internationalization.FamilyBundle) ConfigTypeNode(org.talend.sdk.component.server.front.model.ConfigTypeNode) Config(org.talend.sdk.component.design.extension.repository.Config) ConfigTypeNodes(org.talend.sdk.component.server.front.model.ConfigTypeNodes)

Aggregations

Collection (java.util.Collection)1 Collections.singleton (java.util.Collections.singleton)1 HashMap (java.util.HashMap)1 Locale (java.util.Locale)1 Map (java.util.Map)1 Optional.ofNullable (java.util.Optional.ofNullable)1 Function.identity (java.util.function.Function.identity)1 Predicate (java.util.function.Predicate)1 Collectors.toList (java.util.stream.Collectors.toList)1 Collectors.toMap (java.util.stream.Collectors.toMap)1 Collectors.toSet (java.util.stream.Collectors.toSet)1 Stream (java.util.stream.Stream)1 ApplicationScoped (javax.enterprise.context.ApplicationScoped)1 Inject (javax.inject.Inject)1 Consumes (javax.ws.rs.Consumes)1 DefaultValue (javax.ws.rs.DefaultValue)1 GET (javax.ws.rs.GET)1 POST (javax.ws.rs.POST)1 Path (javax.ws.rs.Path)1 PathParam (javax.ws.rs.PathParam)1