use of org.talend.sdk.component.server.front.model.error.ErrorPayload in project component-runtime by Talend.
the class DocumentationResourceTest method missingDoc.
@Test
void missingDoc() {
final String id = client.getComponentId("chain", "list");
final Response response = base.path("documentation/component/{id}").resolveTemplate("id", id).request(APPLICATION_JSON_TYPE).get();
assertEquals(Response.Status.NOT_FOUND.getStatusCode(), response.getStatus());
final ErrorPayload payload = response.readEntity(ErrorPayload.class);
assertEquals(ErrorDictionary.COMPONENT_MISSING, payload.getCode());
assertEquals("No component '" + id + "'", payload.getDescription());
}
use of org.talend.sdk.component.server.front.model.error.ErrorPayload in project component-runtime by Talend.
the class ConnectionSecurityProvider method filter.
@Override
public void filter(final ContainerRequestContext requestContext) throws IOException {
if (Boolean.TRUE.equals(request.getAttribute(SKIP))) {
return;
}
final OnConnection onConnection = new OnConnection();
onConnectionEvent.fire(onConnection);
if (!onConnection.isValid()) {
requestContext.abortWith(Response.status(Response.Status.UNAUTHORIZED).entity(new ErrorPayload(UNAUTHORIZED, "Invalid connection credentials")).type(APPLICATION_JSON_TYPE).build());
}
}
use of org.talend.sdk.component.server.front.model.error.ErrorPayload 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.error.ErrorPayload in project component-runtime by Talend.
the class ComponentResource method familyIcon.
/**
* Returns a particular family icon in raw bytes.
*
* @param id the family identifier.
* @return the family icon in binary form.
*/
@GET
@Path("icon/family/{id}")
public Response familyIcon(@PathParam("id") final String id) {
// todo: add caching if SvgIconResolver becomes used a lot - not the case ATM
final ComponentFamilyMeta meta = componentFamilyDao.findById(id);
if (meta == null) {
return Response.status(Response.Status.NOT_FOUND).entity(new ErrorPayload(ErrorDictionary.COMPONENT_MISSING, "No family for identifier: " + id)).type(APPLICATION_JSON_TYPE).build();
}
final Optional<Container> plugin = manager.findPlugin(meta.getPlugin());
if (!plugin.isPresent()) {
return Response.status(Response.Status.NOT_FOUND).entity(new ErrorPayload(ErrorDictionary.PLUGIN_MISSING, "No plugin '" + meta.getPlugin() + "' for identifier: " + id)).type(APPLICATION_JSON_TYPE).build();
}
final IconResolver.Icon iconContent = iconResolver.resolve(plugin.get().getLoader(), meta.getIcon());
if (iconContent == null) {
return Response.status(Response.Status.NOT_FOUND).entity(new ErrorPayload(ErrorDictionary.ICON_MISSING, "No icon for family identifier: " + id)).type(APPLICATION_JSON_TYPE).build();
}
return Response.ok(iconContent.getBytes()).type(iconContent.getType()).build();
}
use of org.talend.sdk.component.server.front.model.error.ErrorPayload in project component-runtime by Talend.
the class ComponentResource method getDependency.
/**
* Return a binary of the dependency represented by `id`.
* It can be maven coordinates for dependencies or a component id.
*
* @param id the dependency identifier.
* @return the dependency binary (jar).
*/
@GET
@Path("dependency/{id}")
@Produces(MediaType.APPLICATION_OCTET_STREAM)
public StreamingOutput getDependency(@PathParam("id") final String id) {
final ComponentFamilyMeta.BaseMeta<?> component = componentDao.findById(id);
final File file;
if (component != null) {
// local dep
file = componentManagerService.manager().findPlugin(component.getParent().getPlugin()).orElseThrow(() -> new WebApplicationException(Response.status(Response.Status.NOT_FOUND).type(APPLICATION_JSON_TYPE).entity(new ErrorPayload(PLUGIN_MISSING, "No plugin matching the id: " + id)).build())).getContainerFile().orElseThrow(() -> new WebApplicationException(Response.status(Response.Status.NOT_FOUND).type(APPLICATION_JSON_TYPE).entity(new ErrorPayload(PLUGIN_MISSING, "No dependency matching the id: " + id)).build()));
} else {
// just try to resolve it locally, note we would need to ensure some security here
// .map(Artifact::toPath).map(localDependencyRelativeResolver
final Artifact artifact = Artifact.from(id);
file = componentManagerService.manager().getContainer().resolve(artifact.toPath());
}
if (!file.exists()) {
throw new WebApplicationException(Response.status(Response.Status.NOT_FOUND).type(APPLICATION_JSON_TYPE).entity(new ErrorPayload(PLUGIN_MISSING, "No file found for: " + id)).build());
}
return output -> {
// 5k
final byte[] buffer = new byte[40960];
try (final InputStream stream = new BufferedInputStream(new FileInputStream(file), buffer.length)) {
int count;
while ((count = stream.read(buffer)) >= 0) {
if (count == 0) {
continue;
}
output.write(buffer, 0, count);
}
}
};
}
Aggregations