use of org.talend.sdk.component.server.front.model.ComponentDetail in project component-runtime by Talend.
the class ComponentResourceTest method getDetailsMeta.
@Test
void getDetailsMeta() {
final ComponentDetailList details = base.path("component/details").queryParam("identifiers", client.getJdbcId()).request(APPLICATION_JSON_TYPE).get(ComponentDetailList.class);
assertEquals(1, details.getDetails().size());
final ComponentDetail detail = details.getDetails().iterator().next();
assertEquals("true", detail.getProperties().stream().filter(p -> p.getPath().equals("configuration.connection.password")).findFirst().orElseThrow(() -> new IllegalArgumentException("No credential found")).getMetadata().get("ui::credential"));
assertEquals("0", detail.getProperties().stream().filter(p -> p.getPath().equals("configuration.timeout")).findFirst().orElseThrow(() -> new IllegalArgumentException("No timeout found")).getDefaultValue());
assertNull(detail.getProperties().stream().filter(p -> p.getPath().equals("configuration.connection.url")).findFirst().orElseThrow(() -> new IllegalArgumentException("No url found")).getDefaultValue());
}
use of org.talend.sdk.component.server.front.model.ComponentDetail 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);
}
use of org.talend.sdk.component.server.front.model.ComponentDetail in project component-runtime by Talend.
the class ComponentResourceTest method getDetails.
@Test
void getDetails() {
final ComponentDetailList details = base.path("component/details").queryParam("identifiers", client.fetchIndex().getComponents().stream().filter(c -> c.getId().getFamily().equals("chain") && c.getId().getName().equals("list")).findFirst().orElseThrow(() -> new IllegalArgumentException("no chain#list component")).getId().getId()).request(APPLICATION_JSON_TYPE).get(ComponentDetailList.class);
assertEquals(1, details.getDetails().size());
final ComponentDetail detail = details.getDetails().iterator().next();
assertEquals("the-test-component", detail.getId().getPlugin());
assertEquals("chain", detail.getId().getFamily());
assertEquals("list", detail.getId().getName());
assertEquals("The List Component", detail.getDisplayName());
final Collection<ActionReference> remoteActions = detail.getActions();
assertEquals(1, remoteActions.size());
final ActionReference action = remoteActions.iterator().next();
assertEquals("default", action.getName());
assertEquals("healthcheck", action.getType());
assertEquals(6, action.getProperties().size());
assertValidation("remote.urls", detail, validation -> validation.getMinItems() == 1);
assertValidation("remote.urls", detail, validation -> validation.getUniqueItems() != null && validation.getUniqueItems());
assertValidation("remote.user.user", detail, validation -> validation.getMinLength() != null && validation.getMinLength() == 2);
assertValidation("remote.user.password", detail, validation -> validation.getMaxLength() != null && validation.getMaxLength() == 8);
assertValidation("remote.user.password", detail, validation -> validation.getRequired() != null && validation.getRequired());
// for now
assertEquals(0, detail.getLinks().size());
/*
* final Link link = detail.getLinks().iterator().next(); assertEquals("Detail", link.getName());
* assertEquals("/component/...", link.getPath());
*/
}
Aggregations