Search in sources :

Example 1 with DesignModel

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);
}
Also used : Locale(java.util.Locale) WebApplicationException(javax.ws.rs.WebApplicationException) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) DesignModel(org.talend.sdk.component.design.extension.DesignModel) ComponentDetailList(org.talend.sdk.component.server.front.model.ComponentDetailList) ErrorPayload(org.talend.sdk.component.server.front.model.error.ErrorPayload) Container(org.talend.sdk.component.container.Container) ComponentFamilyMeta(org.talend.sdk.component.runtime.manager.ComponentFamilyMeta) ComponentDetail(org.talend.sdk.component.server.front.model.ComponentDetail) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Aggregations

HashMap (java.util.HashMap)1 Locale (java.util.Locale)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 Container (org.talend.sdk.component.container.Container)1 DesignModel (org.talend.sdk.component.design.extension.DesignModel)1 ComponentFamilyMeta (org.talend.sdk.component.runtime.manager.ComponentFamilyMeta)1 ComponentDetail (org.talend.sdk.component.server.front.model.ComponentDetail)1 ComponentDetailList (org.talend.sdk.component.server.front.model.ComponentDetailList)1 ErrorPayload (org.talend.sdk.component.server.front.model.error.ErrorPayload)1