private <C, T, A> A create(final Class<A> api, final Class<T> componentType, final C configuration) { final ComponentFamilyMeta.BaseMeta<? extends Lifecycle> meta = findMeta(componentType); return api .cast(meta .getInstantiator() .apply(configuration == null || meta.getParameterMetas().isEmpty() ? emptyMap() : configurationByExample(configuration, meta .getParameterMetas() .stream() .filter(p -> p.getName().equals(p.getPath())) .findFirst() .map(p -> p.getName() + '.') .orElseThrow(() -> new IllegalArgumentException( "Didn't find any option and therefore " + "can't convert the configuration instance to a configuration"))))); }
/** * Creates appropriate factory according {@link BaseMeta} type (either * {@link ProcessorMeta} or {@link PartitionMapperMeta}) * * @param meta the meta instance to use as reference to find the right factory. * @return the factory to use to create a flow for this meta. */ static FlowsFactory get(final BaseMeta<?> meta) { if (meta == null) { throw new IllegalArgumentException("meta should not be null"); } if (PartitionMapperMeta.class.isInstance(meta)) { return new PartitionMapperFlowsFactory(); } if (ProcessorMeta.class.isInstance(meta)) { return new ProcessorFlowsFactory(meta.getType()); } throw new IllegalArgumentException("unknown meta type " + meta.getClass().getName()); }
public Optional<Object> createComponent(final String plugin, final String name, final ComponentType componentType, final int version, final Map<String, String> configuration) { final String familyName = container.buildAutoIdFromName(plugin); return find(pluginContainer -> Stream.of(pluginContainer.get(ContainerComponentRegistry.class))) .filter(Objects::nonNull) .map(r -> r.getComponents().get(familyName)) .filter(Objects::nonNull) .map(component -> ofNullable(componentType.findMeta(component).get(name)) .map(comp -> comp .getInstantiator() .apply(configuration == null ? null : comp.getMigrationHandler().migrate(version, configuration)))) .findFirst() .flatMap(identity()) // unwrap to access the actual instance which is the desired one .map(i -> Delegated.class.isInstance(i) ? Delegated.class.cast(i).getDelegate() : i); }
final Container container = ofNullable(componentDao.findById(id)) .map(meta -> manager .findPlugin(meta.getParent().getPlugin()) .orElseThrow(() -> new WebApplicationException(Response .status(NOT_FOUND) .entity(new ErrorPayload(ErrorDictionary.PLUGIN_MISSING, "No plugin '" + meta.getParent().getPlugin() + "'")) .build()))) .orElseThrow(() -> new WebApplicationException(Response .concat(f.getPartitionMappers().values().stream(), f.getProcessors().values().stream())) .filter(c -> c.getId().equals(id)) .findFirst() .map(c -> selectById(c.getName(), value, segment))) .orElse(value)) .orElseThrow(() -> new WebApplicationException(Response
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 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; componentDetail.setVersion(meta.getVersion()); componentDetail.setIcon(meta.getIcon()); componentDetail.setInputFlows(model.get().getInputFlows()); componentDetail.setOutputFlows(model.get().getOutputFlows()); componentDetail .setDisplayName(meta .findBundle(container.getLoader(), locale) .displayName() .orElse(meta.getName())); componentDetail .setProperties(propertiesService .buildProperties(meta.getParameterMetas(), container.getLoader(), locale, null)
.map(id -> componentDao.findById(id)) .collect(toMap(ComponentFamilyMeta.BaseMeta::getId, meta -> componentManagerService.manager().findPlugin(meta.getParent().getPlugin()).map(c -> { ComponentExtension.ComponentContext context = c.get(ComponentContexts.class).getContexts().get(meta.getType()); ComponentExtension extension = context.owningExtension(); final Stream<Artifact> deps = c.findDependencies();
.concat(familyMeta.getPartitionMappers().values().stream(), familyMeta.getProcessors().values().stream()) .flatMap(b -> b.getParameterMetas().stream()) .flatMap(this::flatten) .filter(RepositoryModelBuilder::isConfiguration)
.forEach(meta -> { final ComponentExtension.ComponentContext context = container.get(ComponentContexts.class).getContexts().get(meta.getType()); final ComponentExtension owningExtension = context.owningExtension(); meta .set(DesignModel.class, ofNullable(owningExtension) .map(e -> e.unwrap(FlowsFactory.class, meta)) .map(e -> new DesignModel(meta.getId(), e.getInputFlows(), e.getOutputFlows())) .orElseGet(() -> { final FlowsFactory factory = FlowsFactory.get(meta); return new DesignModel(meta.getId(), factory.getInputFlows(), factory.getOutputFlows()); }));
final Optional<Container> plugin = manager.findPlugin(meta.getParent().getPlugin()); if (!plugin.isPresent()) { return Response .status(Response.Status.NOT_FOUND) .entity(new ErrorPayload(ErrorDictionary.PLUGIN_MISSING, "No plugin '" + meta.getParent().getPlugin() + "' for identifier: " + id)) .type(APPLICATION_JSON_TYPE) .build(); final IconResolver.Icon iconContent = iconResolver.resolve(plugin.get(), meta.getIcon()); if (iconContent == null) { return Response
final boolean includeIcon) { final ClassLoader loader = container.getLoader(); final String icon = meta.getIcon(); final String familyIcon = meta.getParent().getIcon(); final IconResolver.Icon iconContent = iconResolver.resolve(container, icon); final IconResolver.Icon iconFamilyContent = iconResolver.resolve(container, familyIcon); final String familyDisplayName = meta.getParent().findBundle(loader, locale).displayName().orElse(meta.getParent().getName()); final List<String> categories = ofNullable(meta.getParent().getCategories()) .map(vals -> vals .stream() .map(this::normalizeCategory) .map(category -> category.replace("${family}", meta.getParent().getName())) // not .getParent() .findBundle(loader, locale) .category(category) .orElseGet(() -> category .replace("/" + meta.getParent().getName() + "/", "/" + familyDisplayName + "/"))) .collect(toList())) .orElseGet(Collections::emptyList); return new ComponentIndex( new ComponentId(meta.getId(), meta.getParent().getId(), plugin, ofNullable(originalId).map(ComponentManager.OriginalId::getValue).orElse(plugin), meta.getParent().getName(), meta.getName()), meta.findBundle(loader, locale).displayName().orElse(meta.getName()), familyDisplayName, new Icon(icon, iconContent == null ? null : iconContent.getType(), !includeIcon ? null : (iconContent == null ? null : iconContent.getBytes())),
@POST @Path("migrate/{id}/{configurationVersion}") @Operation(description = "Allows to migrate a component configuration without calling any component execution.") @APIResponse(responseCode = "200", description = "the new configuration for that component (or the same if no migration was needed).", content = @Content(mediaType = APPLICATION_JSON)) @APIResponse(responseCode = "404", description = "The component is not found", content = @Content(mediaType = APPLICATION_JSON, schema = @Schema(type = OBJECT, implementation = ErrorPayload.class))) public Map<String, String> migrate(@PathParam("id") @Parameter(name = "id", description = "the component identifier", in = PATH) final String id, @PathParam("configurationVersion") @Parameter(name = "configurationVersion", description = "the configuration version you send", in = PATH) final int version, @RequestBody(description = "the actual configuration in key/value form.", required = true, content = @Content(mediaType = APPLICATION_JSON, schema = @Schema(type = OBJECT))) final Map<String, String> config) { return ofNullable(componentDao.findById(id)) .orElseThrow(() -> new WebApplicationException(Response .status(Response.Status.NOT_FOUND) .entity(new ErrorPayload(ErrorDictionary.COMPONENT_MISSING, "Didn't find component " + id)) .build())) .getMigrationHandler() .migrate(version, config); }
public Set<ActionReference> getActionReference(final ComponentFamilyMeta.BaseMeta<Object> meta, final FamilyBundle familyBundle) { return getActionReference(toStream(meta.getParameterMetas()), meta.getParent().getName(), familyBundle); }
private <T> ComponentFamilyMeta.BaseMeta<? extends Lifecycle> findMeta(final Class<T> componentType) { return asManager() .find(c -> c.get(ContainerComponentRegistry.class).getComponents().values().stream()) .flatMap(f -> Stream .concat(f.getProcessors().values().stream(), f.getPartitionMappers().values().stream())) .filter(m -> m.getType().getName().equals(componentType.getName())) .findFirst() .orElseThrow(() -> new IllegalArgumentException("No component " + componentType)); }
private ComponentId createMetaId(final Container container, final ComponentFamilyMeta.BaseMeta<Object> meta) { return new ComponentId(meta.getId(), meta.getParent().getId(), meta.getParent().getPlugin(), ofNullable(container.get(ComponentManager.OriginalId.class)) .map(ComponentManager.OriginalId::getValue) .orElse(container.getId()), meta.getParent().getName(), meta.getName()); }