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()));
}
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());
}
Aggregations