use of org.talend.sdk.component.design.extension.DesignModel in project component-runtime by Talend.
the class ComponentResource method getDetail.
/**
* Returns the set of metadata about a few components identified by their 'id'.
*
* @param language the language for display names/placeholders/....
* @param ids the component identifiers to request.
* @return the list of details for the requested components.
*/
// TODO: max ids.length
@GET
// bulk mode to avoid to fetch components one by one when reloading a pipeline/job
@Path("details")
public ComponentDetailList getDetail(@QueryParam("language") @DefaultValue("en") final String language, @QueryParam("identifiers") final String[] ids) {
if (ids == null || ids.length == 0) {
return new ComponentDetailList(emptyList());
}
final Map<String, ErrorPayload> errors = new HashMap<>();
final List<ComponentDetail> details = Stream.of(ids).map(id -> ofNullable(componentDao.findById(id)).orElseGet(() -> {
errors.put(id, new ErrorPayload(COMPONENT_MISSING, "No component '" + id + "'"));
return null;
})).filter(Objects::nonNull).map(meta -> {
final Optional<Container> plugin = manager.findPlugin(meta.getParent().getPlugin());
if (!plugin.isPresent()) {
errors.put(meta.getId(), new ErrorPayload(PLUGIN_MISSING, "No plugin '" + meta.getParent().getPlugin() + "'"));
return null;
}
final Container container = plugin.get();
final Optional<DesignModel> model = ofNullable(meta.get(DesignModel.class));
if (!model.isPresent()) {
errors.put(meta.getId(), new ErrorPayload(DESIGN_MODEL_MISSING, "No design model '" + meta.getId() + "'"));
return null;
}
final Locale locale = localeMapper.mapLocale(language);
final ComponentDetail componentDetail = new ComponentDetail();
componentDetail.setLinks(emptyList());
componentDetail.setId(createMetaId(container, meta));
componentDetail.setVersion(meta.getVersion());
componentDetail.setIcon(meta.getIcon());
componentDetail.setInputFlows(model.get().getInputFlows());
componentDetail.setOutputFlows(model.get().getOutputFlows());
componentDetail.setType(ComponentFamilyMeta.ProcessorMeta.class.isInstance(meta) ? "processor" : "input");
componentDetail.setDisplayName(meta.findBundle(container.getLoader(), locale).displayName().orElse(meta.getName()));
componentDetail.setProperties(propertiesService.buildProperties(meta.getParameterMetas(), container.getLoader(), locale, null).collect(toList()));
componentDetail.setActions(actionsService.findActions(meta.getParent().getName(), container, locale, meta));
return componentDetail;
}).filter(Objects::nonNull).collect(toList());
if (!errors.isEmpty()) {
throw new WebApplicationException(Response.status(Response.Status.BAD_REQUEST).entity(errors).build());
}
return new ComponentDetailList(details);
}
Aggregations