Search in sources :

Example 1 with FetcherPlugin

use of io.gravitee.plugin.fetcher.FetcherPlugin in project gravitee-management-rest-api by gravitee-io.

the class FetcherServiceImpl method findById.

@Override
public FetcherEntity findById(String fetcher) {
    LOGGER.debug("Find fetcher by ID: {}", fetcher);
    FetcherPlugin fetcherDefinition = fetcherPluginManager.get(fetcher);
    if (fetcherDefinition == null) {
        throw new FetcherNotFoundException(fetcher);
    }
    return convert(fetcherDefinition, true);
}
Also used : FetcherPlugin(io.gravitee.plugin.fetcher.FetcherPlugin) FetcherNotFoundException(io.gravitee.management.service.exceptions.FetcherNotFoundException)

Example 2 with FetcherPlugin

use of io.gravitee.plugin.fetcher.FetcherPlugin in project gravitee-management-rest-api by gravitee-io.

the class FetcherServiceImpl method convert.

private FetcherEntity convert(FetcherPlugin fetcherPlugin, boolean withPlugin) {
    FetcherEntity entity = new FetcherEntity();
    entity.setId(fetcherPlugin.id());
    entity.setDescription(fetcherPlugin.manifest().description());
    entity.setName(fetcherPlugin.manifest().name());
    entity.setVersion(fetcherPlugin.manifest().version());
    if (withPlugin) {
        // Plugin information
        Plugin plugin = fetcherPlugin;
        PluginEntity pluginEntity = new PluginEntity();
        pluginEntity.setPlugin(plugin.clazz());
        pluginEntity.setPath(plugin.path().toString());
        pluginEntity.setType(plugin.type().toString().toLowerCase());
        pluginEntity.setDependencies(plugin.dependencies());
        entity.setPlugin(pluginEntity);
    }
    return entity;
}
Also used : PluginEntity(io.gravitee.management.model.PluginEntity) FetcherEntity(io.gravitee.management.model.FetcherEntity) FetcherPlugin(io.gravitee.plugin.fetcher.FetcherPlugin) Plugin(io.gravitee.plugin.core.api.Plugin)

Example 3 with FetcherPlugin

use of io.gravitee.plugin.fetcher.FetcherPlugin in project gravitee-management-rest-api by gravitee-io.

the class PageServiceImpl method getContentFromFetcher.

private String getContentFromFetcher(PageSource ps) throws FetcherException {
    if (ps.getConfiguration().isEmpty()) {
        return null;
    }
    try {
        FetcherPlugin fetcherPlugin = fetcherPluginManager.get(ps.getType());
        ClassLoader fetcherCL = fetcherPlugin.fetcher().getClassLoader();
        Class<? extends FetcherConfiguration> fetcherConfigurationClass = (Class<? extends FetcherConfiguration>) fetcherCL.loadClass(fetcherPlugin.configuration().getName());
        Class<? extends Fetcher> fetcherClass = (Class<? extends Fetcher>) fetcherCL.loadClass(fetcherPlugin.clazz());
        FetcherConfiguration fetcherConfigurationInstance = fetcherConfigurationFactory.create(fetcherConfigurationClass, ps.getConfiguration());
        Fetcher fetcher = fetcherClass.getConstructor(fetcherConfigurationClass).newInstance(fetcherConfigurationInstance);
        // Autowire fetcher
        applicationContext.getAutowireCapableBeanFactory().autowireBean(fetcher);
        StringBuilder sb = new StringBuilder();
        try (BufferedReader br = new BufferedReader(new InputStreamReader(fetcher.fetch()))) {
            String line;
            while ((line = br.readLine()) != null) {
                sb.append(line);
                sb.append("\n");
            }
        }
        return sb.toString();
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
        throw new FetcherException(e.getMessage(), e);
    }
}
Also used : FetcherConfiguration(io.gravitee.fetcher.api.FetcherConfiguration) InputStreamReader(java.io.InputStreamReader) TemplateException(freemarker.template.TemplateException) TechnicalException(io.gravitee.repository.exceptions.TechnicalException) PageAlreadyExistsException(io.gravitee.management.service.exceptions.PageAlreadyExistsException) PageNotFoundException(io.gravitee.management.service.exceptions.PageNotFoundException) FetcherException(io.gravitee.fetcher.api.FetcherException) TechnicalManagementException(io.gravitee.management.service.exceptions.TechnicalManagementException) BeansException(org.springframework.beans.BeansException) IOException(java.io.IOException) FetcherPlugin(io.gravitee.plugin.fetcher.FetcherPlugin) FetcherException(io.gravitee.fetcher.api.FetcherException) BufferedReader(java.io.BufferedReader) Fetcher(io.gravitee.fetcher.api.Fetcher)

Example 4 with FetcherPlugin

use of io.gravitee.plugin.fetcher.FetcherPlugin in project gravitee-management-rest-api by gravitee-io.

the class FetcherServiceImpl method findAll.

@Override
public Set<FetcherEntity> findAll() {
    try {
        LOGGER.debug("List all fetchers");
        final Collection<FetcherPlugin> fetcherDefinitions = fetcherPluginManager.findAll();
        return fetcherDefinitions.stream().map(fetcherDefinition -> convert(fetcherDefinition, false)).collect(Collectors.toSet());
    } catch (Exception ex) {
        LOGGER.error("An error occurs while trying to list all fetchers", ex);
        throw new TechnicalManagementException("An error occurs while trying to list all fetchers", ex);
    }
}
Also used : Logger(org.slf4j.Logger) PluginEntity(io.gravitee.management.model.PluginEntity) Collection(java.util.Collection) LoggerFactory(org.slf4j.LoggerFactory) TechnicalManagementException(io.gravitee.management.service.exceptions.TechnicalManagementException) Autowired(org.springframework.beans.factory.annotation.Autowired) Set(java.util.Set) IOException(java.io.IOException) FetcherService(io.gravitee.management.service.FetcherService) FetcherPluginManager(io.gravitee.plugin.fetcher.FetcherPluginManager) Collectors(java.util.stream.Collectors) FetcherPlugin(io.gravitee.plugin.fetcher.FetcherPlugin) Component(org.springframework.stereotype.Component) Plugin(io.gravitee.plugin.core.api.Plugin) FetcherNotFoundException(io.gravitee.management.service.exceptions.FetcherNotFoundException) FetcherEntity(io.gravitee.management.model.FetcherEntity) FetcherPlugin(io.gravitee.plugin.fetcher.FetcherPlugin) TechnicalManagementException(io.gravitee.management.service.exceptions.TechnicalManagementException) IOException(java.io.IOException) FetcherNotFoundException(io.gravitee.management.service.exceptions.FetcherNotFoundException) TechnicalManagementException(io.gravitee.management.service.exceptions.TechnicalManagementException)

Aggregations

FetcherPlugin (io.gravitee.plugin.fetcher.FetcherPlugin)4 FetcherEntity (io.gravitee.management.model.FetcherEntity)2 PluginEntity (io.gravitee.management.model.PluginEntity)2 FetcherNotFoundException (io.gravitee.management.service.exceptions.FetcherNotFoundException)2 TechnicalManagementException (io.gravitee.management.service.exceptions.TechnicalManagementException)2 Plugin (io.gravitee.plugin.core.api.Plugin)2 IOException (java.io.IOException)2 TemplateException (freemarker.template.TemplateException)1 Fetcher (io.gravitee.fetcher.api.Fetcher)1 FetcherConfiguration (io.gravitee.fetcher.api.FetcherConfiguration)1 FetcherException (io.gravitee.fetcher.api.FetcherException)1 FetcherService (io.gravitee.management.service.FetcherService)1 PageAlreadyExistsException (io.gravitee.management.service.exceptions.PageAlreadyExistsException)1 PageNotFoundException (io.gravitee.management.service.exceptions.PageNotFoundException)1 FetcherPluginManager (io.gravitee.plugin.fetcher.FetcherPluginManager)1 TechnicalException (io.gravitee.repository.exceptions.TechnicalException)1 BufferedReader (java.io.BufferedReader)1 InputStreamReader (java.io.InputStreamReader)1 Collection (java.util.Collection)1 Set (java.util.Set)1