Search in sources :

Example 1 with ActionItem

use of org.talend.sdk.component.server.front.model.ActionItem in project component-runtime by Talend.

the class ActionResource method getIndex.

/**
 * This endpoint returns the list of available actions for a certain family and potentially filters the "
 * output limiting it to some families and types of actions.
 *
 * @param types the types of actions (optional).
 * @param families the families (optional).
 * @param language the language to use (optional).
 * @return the list of actions matching the requested filters or all if none are set.
 */
@GET
// add an index if needed or too slow
@Path("index")
public ActionList getIndex(@QueryParam("type") final String[] types, @QueryParam("family") final String[] families, @QueryParam("language") @DefaultValue("en") final String language) {
    final Predicate<ServiceMeta.ActionMeta> typeMatcher = new Predicate<ServiceMeta.ActionMeta>() {

        private final Collection<String> accepted = new HashSet<>(asList(types));

        @Override
        public boolean test(final ServiceMeta.ActionMeta actionMeta) {
            return accepted.isEmpty() || accepted.contains(actionMeta.getType());
        }
    };
    final Predicate<ServiceMeta.ActionMeta> componentMatcher = new Predicate<ServiceMeta.ActionMeta>() {

        private final Collection<String> accepted = new HashSet<>(asList(families));

        @Override
        public boolean test(final ServiceMeta.ActionMeta actionMeta) {
            return accepted.isEmpty() || accepted.contains(actionMeta.getFamily());
        }
    };
    final Locale locale = localeMapper.mapLocale(language);
    return new ActionList(manager.find(c -> c.get(ContainerComponentRegistry.class).getServices().stream().map(s -> s.getActions().stream()).flatMap(identity()).filter(typeMatcher.and(componentMatcher)).map(s -> new ActionItem(s.getFamily(), s.getType(), s.getAction(), propertiesService.buildProperties(s.getParameters(), c.getLoader(), locale, null).collect(toList())))).collect(toList()));
}
Also used : Locale(java.util.Locale) Produces(javax.ws.rs.Produces) PropertiesService(org.talend.sdk.component.server.service.PropertiesService) GET(javax.ws.rs.GET) Path(javax.ws.rs.Path) HashSet(java.util.HashSet) Inject(javax.inject.Inject) LocaleMapper(org.talend.sdk.component.server.service.LocaleMapper) QueryParam(javax.ws.rs.QueryParam) Consumes(javax.ws.rs.Consumes) Arrays.asList(java.util.Arrays.asList) Locale(java.util.Locale) Map(java.util.Map) DefaultValue(javax.ws.rs.DefaultValue) APPLICATION_JSON(javax.ws.rs.core.MediaType.APPLICATION_JSON) IgnoreNetAuthenticator(org.talend.sdk.component.server.service.httpurlconnection.IgnoreNetAuthenticator) ActionItem(org.talend.sdk.component.server.front.model.ActionItem) POST(javax.ws.rs.POST) ContainerComponentRegistry(org.talend.sdk.component.runtime.manager.ContainerComponentRegistry) Optional.ofNullable(java.util.Optional.ofNullable) Predicate(java.util.function.Predicate) Collection(java.util.Collection) ActionList(org.talend.sdk.component.server.front.model.ActionList) ErrorDictionary(org.talend.sdk.component.server.front.model.ErrorDictionary) ErrorPayload(org.talend.sdk.component.server.front.model.error.ErrorPayload) ComponentActionDao(org.talend.sdk.component.server.dao.ComponentActionDao) Collectors.toList(java.util.stream.Collectors.toList) Slf4j(lombok.extern.slf4j.Slf4j) Response(javax.ws.rs.core.Response) Function.identity(java.util.function.Function.identity) APPLICATION_JSON_TYPE(javax.ws.rs.core.MediaType.APPLICATION_JSON_TYPE) WebApplicationException(javax.ws.rs.WebApplicationException) ApplicationScoped(javax.enterprise.context.ApplicationScoped) ComponentManager(org.talend.sdk.component.runtime.manager.ComponentManager) ServiceMeta(org.talend.sdk.component.runtime.manager.ServiceMeta) ContainerComponentRegistry(org.talend.sdk.component.runtime.manager.ContainerComponentRegistry) ActionItem(org.talend.sdk.component.server.front.model.ActionItem) Collection(java.util.Collection) ActionList(org.talend.sdk.component.server.front.model.ActionList) Predicate(java.util.function.Predicate) ServiceMeta(org.talend.sdk.component.runtime.manager.ServiceMeta) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 2 with ActionItem

use of org.talend.sdk.component.server.front.model.ActionItem in project component-runtime by Talend.

the class ActionResourceTest method index.

@Test
void index() {
    final ActionList index = base.path("action/index").request(APPLICATION_JSON_TYPE).get(ActionList.class);
    assertEquals(2, index.getItems().size());
    final List<ActionItem> items = new ArrayList<>(index.getItems());
    items.sort(Comparator.comparing(ActionItem::getName));
    final Iterator<ActionItem> it = items.iterator();
    assertAction("proc", "user", "another-test-component-14.11.1986.jarAction", 1, it.next());
    assertAction("chain", "healthcheck", "default", 6, it.next());
}
Also used : ActionItem(org.talend.sdk.component.server.front.model.ActionItem) ArrayList(java.util.ArrayList) ActionList(org.talend.sdk.component.server.front.model.ActionList) Test(org.junit.jupiter.api.Test)

Aggregations

ActionItem (org.talend.sdk.component.server.front.model.ActionItem)2 ActionList (org.talend.sdk.component.server.front.model.ActionList)2 ArrayList (java.util.ArrayList)1 Arrays.asList (java.util.Arrays.asList)1 Collection (java.util.Collection)1 HashSet (java.util.HashSet)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 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 Produces (javax.ws.rs.Produces)1