Search in sources :

Example 1 with IOAdvisorFactory

use of eu.esdihumboldt.hale.common.core.io.extension.IOAdvisorFactory in project hale by halestudio.

the class HeadlessIO method executeConfiguration.

/**
 * Execute a single I/O configuration. If no matching advisor is given for
 * the configuration, first the extension point is queried for an advisor,
 * if not found it is ignored.
 *
 * @param conf the I/O configuration
 * @param advisors map of advisors, action ID mapped to responsible advisor
 * @param reportHandler the report handler, may be <code>null</code>
 * @param serviceProvider the service provider
 * @throws IOException if an error occurs executing a configuration
 */
public static void executeConfiguration(IOConfiguration conf, Map<String, IOAdvisor<?>> advisors, ReportHandler reportHandler, ServiceProvider serviceProvider) throws IOException {
    // get advisor ...
    final String actionId = conf.getActionId();
    IOAdvisor<?> advisor = advisors.get(actionId);
    if (advisor == null) {
        // try to find registered advisor for action (e.g. lookup)
        List<IOAdvisorFactory> regAdvisors = IOAdvisorExtension.getInstance().getFactories(new FactoryFilter<IOAdvisor<?>, IOAdvisorFactory>() {

            @Override
            public boolean acceptFactory(IOAdvisorFactory factory) {
                return factory.getActionID().equals(actionId);
            }

            @Override
            public boolean acceptCollection(ExtensionObjectFactoryCollection<IOAdvisor<?>, IOAdvisorFactory> collection) {
                return true;
            }
        });
        if (regAdvisors != null && !regAdvisors.isEmpty()) {
            try {
                advisor = regAdvisors.get(0).createAdvisor(actionId, serviceProvider);
                log.info(MessageFormat.format("No advisor for action {0} given, using advisor registered through extension point.", actionId));
            } catch (Exception e) {
                log.error(MessageFormat.format("Failed to load registered advisor for action {0}.", actionId));
                if (advisor != null) {
                    // shouldn't happen, but seems to happen anyway
                    log.error("Advisor is set in spite of error", e);
                }
            }
        }
    }
    if (advisor == null) {
        log.info(MessageFormat.format("No advisor for action {0} given, I/O configuration is ignored.", actionId));
        // ignore this configuration
        return;
    }
    // ... and provider
    IOProvider provider = loadProvider(conf);
    if (provider != null) {
        if (serviceProvider != null) {
            // set service provider, just in case the advisor does not do it
            provider.setServiceProvider(serviceProvider);
        }
        // execute provider
        executeProvider(provider, advisor, null, reportHandler);
    // XXX progress?!!
    } else {
        throw new IOException(MessageFormat.format("Could not execute I/O configuration, provider with ID {0} not found.", conf.getProviderId()));
    }
}
Also used : IOAdvisorFactory(eu.esdihumboldt.hale.common.core.io.extension.IOAdvisorFactory) IOAdvisor(eu.esdihumboldt.hale.common.core.io.IOAdvisor) IOProvider(eu.esdihumboldt.hale.common.core.io.IOProvider) IOException(java.io.IOException) IOException(java.io.IOException)

Example 2 with IOAdvisorFactory

use of eu.esdihumboldt.hale.common.core.io.extension.IOAdvisorFactory in project hale by halestudio.

the class ProjectResourcesUtil method executeConfiguration.

/**
 * Execute a single I/O configuration with a custom advisor.
 *
 * @param conf the I/O configuration
 * @param customAdvisor the custom advisor to use or <code>null</code>
 * @param publishReport if the report should be published
 * @param cacheCallback call back that is notified on cache changes for the
 *            I/O configuration, may be <code>null</code>
 */
public static void executeConfiguration(IOConfiguration conf, IOAdvisor<?> customAdvisor, boolean publishReport, CacheCallback cacheCallback) {
    // get provider ...
    IOProvider provider = null;
    IOProviderDescriptor descriptor = IOProviderExtension.getInstance().getFactory(conf.getProviderId());
    if (descriptor != null) {
        try {
            provider = descriptor.createExtensionObject();
        } catch (Exception e) {
            log.error(MessageFormat.format("Could not execute I/O configuration, provider with ID {0} could not be created.", conf.getProviderId()), e);
            return;
        }
        // ... and advisor
        final String actionId = conf.getActionId();
        IOAdvisor<?> advisor = customAdvisor;
        if (advisor == null) {
            List<IOAdvisorFactory> advisors = IOAdvisorExtension.getInstance().getFactories(new FactoryFilter<IOAdvisor<?>, IOAdvisorFactory>() {

                @Override
                public boolean acceptFactory(IOAdvisorFactory factory) {
                    return factory.getActionID().equals(actionId);
                }

                @Override
                public boolean acceptCollection(ExtensionObjectFactoryCollection<IOAdvisor<?>, IOAdvisorFactory> collection) {
                    return true;
                }
            });
            if (advisors != null && !advisors.isEmpty()) {
                try {
                    advisor = advisors.get(0).createAdvisor(actionId, HaleUI.getServiceProvider());
                } catch (Exception e) {
                    log.error(MessageFormat.format("Could not execute I/O configuration, advisor with ID {0} could not be created.", advisors.get(0).getIdentifier()), e);
                    return;
                }
            }
        }
        if (advisor != null) {
            // configure settings
            provider.loadConfiguration(conf.getProviderConfiguration());
            if (provider instanceof CachingImportProvider) {
                ((CachingImportProvider) provider).setCache(conf.getCache());
            }
            // execute provider
            executeProvider(provider, advisor, publishReport, cacheCallback);
        } else {
            log.error(MessageFormat.format("Could not execute I/O configuration, no advisor for action {0} found.", actionId));
        }
    } else {
        log.error(MessageFormat.format("Could not execute I/O configuration, provider with ID {0} not found.", conf.getProviderId()));
    }
}
Also used : IOAdvisorFactory(eu.esdihumboldt.hale.common.core.io.extension.IOAdvisorFactory) IOAdvisor(eu.esdihumboldt.hale.common.core.io.IOAdvisor) IOProviderDescriptor(eu.esdihumboldt.hale.common.core.io.extension.IOProviderDescriptor) CachingImportProvider(eu.esdihumboldt.hale.common.core.io.CachingImportProvider) IOProvider(eu.esdihumboldt.hale.common.core.io.IOProvider) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Aggregations

IOAdvisor (eu.esdihumboldt.hale.common.core.io.IOAdvisor)2 IOProvider (eu.esdihumboldt.hale.common.core.io.IOProvider)2 IOAdvisorFactory (eu.esdihumboldt.hale.common.core.io.extension.IOAdvisorFactory)2 CachingImportProvider (eu.esdihumboldt.hale.common.core.io.CachingImportProvider)1 IOProviderDescriptor (eu.esdihumboldt.hale.common.core.io.extension.IOProviderDescriptor)1 IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1