Search in sources :

Example 26 with IOProviderDescriptor

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

the class HaleIO method createIOProvider.

/**
 * Creates an I/O provider instance
 *
 * @param
 * 			<P>
 *            the provider interface type
 *
 * @param providerType the provider type, usually an interface
 * @param contentType the content type the provider must match, may be
 *            <code>null</code> if providerId is set
 * @param providerId the id of the provider to use, may be <code>null</code>
 *            if contentType is set
 * @return the I/O provider preconfigured with the content type if it was
 *         given or <code>null</code> if no matching I/O provider is found
 */
@SuppressWarnings("unchecked")
public static <P extends IOProvider> P createIOProvider(Class<P> providerType, IContentType contentType, String providerId) {
    IOProviderDescriptor factory = findIOProviderFactory(providerType, contentType, providerId);
    P result;
    try {
        result = (P) ((factory == null) ? (null) : (factory.createExtensionObject()));
    } catch (Exception e) {
        throw new RuntimeException("Could not create I/O provider", e);
    }
    if (result != null && contentType != null) {
        result.setContentType(contentType);
    }
    return result;
}
Also used : IOProviderDescriptor(eu.esdihumboldt.hale.common.core.io.extension.IOProviderDescriptor) IOException(java.io.IOException)

Example 27 with IOProviderDescriptor

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

the class ProjectTransformationEnvironment method init.

/**
 * Initialize the environment based on the loaded project.
 *
 * @param project the project
 */
protected void init(Project project) {
    // export presets
    for (Entry<String, IOConfiguration> preset : project.getExportConfigurations().entrySet()) {
        IOConfiguration conf = preset.getValue();
        if (InstanceIO.ACTION_SAVE_TRANSFORMED_DATA.equals(conf.getActionId())) {
            // configuration for data export
            IOConfiguration c = conf.clone();
            // check provider
            IOProviderDescriptor factory = HaleIO.findIOProviderFactory(InstanceWriter.class, null, c.getProviderId());
            if (factory != null) {
                String name = preset.getKey();
                if (Strings.isNullOrEmpty(name)) {
                    name = factory.getDisplayName();
                }
                exportPresets.put(name, c);
            } else {
                log.error("I/O provider for export preset not found.");
            }
        }
    }
    // export templates
    Collection<IOProviderDescriptor> writerFactories = HaleIO.getProviderFactories(InstanceWriter.class);
    for (IOProviderDescriptor factory : writerFactories) {
        try {
            InstanceWriter writer = (InstanceWriter) factory.createExtensionObject();
            writer.setTargetSchema(getTargetSchema());
            writer.checkCompatibility();
            IOConfiguration conf = new IOConfiguration();
            conf.setActionId(InstanceIO.ACTION_SAVE_TRANSFORMED_DATA);
            conf.setProviderId(factory.getIdentifier());
            exportTemplates.put(factory.getDisplayName(), conf);
        } catch (IOProviderConfigurationException e) {
        // ignore
        } catch (Exception e) {
            log.error("Error initializing instance writer for testing compatibility", e);
        }
    }
}
Also used : IOProviderConfigurationException(eu.esdihumboldt.hale.common.core.io.IOProviderConfigurationException) IOProviderDescriptor(eu.esdihumboldt.hale.common.core.io.extension.IOProviderDescriptor) InstanceWriter(eu.esdihumboldt.hale.common.instance.io.InstanceWriter) IOConfiguration(eu.esdihumboldt.hale.common.core.io.project.model.IOConfiguration) IOProviderConfigurationException(eu.esdihumboldt.hale.common.core.io.IOProviderConfigurationException) IOException(java.io.IOException)

Example 28 with IOProviderDescriptor

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

the class ExecTransformation method setupWriter.

private void setupWriter() {
    String preset = context.getPreset();
    String customProvider = context.getTargetProviderId();
    if (preset == null && customProvider == null) {
        fail("Please specify the name of a data export configuration preset or provide a specific provider ID for the instance writer");
    }
    // create I/O configuration
    IOConfiguration conf = null;
    if (preset != null) {
        conf = env.getExportPresets().get(preset);
    }
    if (conf == null) {
        if (customProvider == null) {
            throw fail("Data export configration preset not found: " + preset + " (please make sure you created it and saved it as part of the project)");
        } else {
            conf = new IOConfiguration();
        }
    }
    if (customProvider != null) {
        conf.setProviderId(customProvider);
    }
    // apply custom settings to configuration
    conf.getProviderConfiguration().putAll(context.getTargetSettings());
    // create I/O provider
    String writerId = conf.getProviderId();
    target = HaleIO.createIOProvider(InstanceWriter.class, null, writerId);
    target.setTarget(createTargetSupplier(context.getTarget()));
    target.setTargetSchema(env.getTargetSchema());
    // determine content type to use based on file extension
    IOProviderDescriptor factory = HaleIO.findIOProviderFactory(InstanceWriter.class, null, writerId);
    if (factory == null) {
        throw fail("Instance writer with ID " + writerId + " not found");
    }
    String path = context.getTarget().getPath();
    List<IContentType> cts;
    if (path != null) {
        cts = HaleIO.findContentTypesFor(factory.getSupportedTypes(), null, path);
    } else {
        cts = new ArrayList<>(factory.getSupportedTypes());
    }
    if (!cts.isEmpty()) {
        target.setContentType(cts.get(0));
    }
    // apply configuration (may override content type)
    target.loadConfiguration(conf.getProviderConfiguration());
}
Also used : InstanceWriter(eu.esdihumboldt.hale.common.instance.io.InstanceWriter) IOProviderDescriptor(eu.esdihumboldt.hale.common.core.io.extension.IOProviderDescriptor) IOConfiguration(eu.esdihumboldt.hale.common.core.io.project.model.IOConfiguration) IContentType(org.eclipse.core.runtime.content.IContentType)

Example 29 with IOProviderDescriptor

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

the class ProjectReference method getSupportedExtensions.

/**
 * Get the supported file extensions for projects.
 *
 * @return the set of file extensions (with leading dot)
 */
protected Set<String> getSupportedExtensions() {
    Collection<IOProviderDescriptor> providers = HaleIO.getProviderFactories(ProjectReader.class);
    // collect supported content types
    Set<String> supportedExtensions = new HashSet<String>();
    for (IOProviderDescriptor factory : providers) {
        for (IContentType type : factory.getSupportedTypes()) {
            String[] extensions = type.getFileSpecs(IContentType.FILE_EXTENSION_SPEC);
            if (extensions != null) {
                for (String ext : extensions) {
                    supportedExtensions.add('.' + ext);
                }
            }
        }
    }
    return supportedExtensions;
}
Also used : IOProviderDescriptor(eu.esdihumboldt.hale.common.core.io.extension.IOProviderDescriptor) IContentType(org.eclipse.core.runtime.content.IContentType) HashSet(java.util.HashSet)

Example 30 with IOProviderDescriptor

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

the class ExportSelectProviderPage method createContent.

/**
 * @see HaleWizardPage#createContent(Composite)
 */
@Override
protected void createContent(Composite page) {
    page.setLayout(new GridLayout(1, false));
    // create provider list viewer
    providers = new ListViewer(page, SWT.BORDER);
    providers.getControl().setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false));
    providers.setContentProvider(ArrayContentProvider.getInstance());
    providers.setLabelProvider(new LabelProvider() {

        @Override
        public String getText(Object element) {
            if (element instanceof IOProviderDescriptor) {
                return ((IOProviderDescriptor) element).getDisplayName();
            }
            return "Custom configuration: " + super.getText(element);
        }
    });
    factories = getWizard().getFactories();
    List<Object> input = new ArrayList<>();
    // check for presets
    Collection<String> presets = getWizard().getPresets();
    if (presets != null && !presets.isEmpty()) {
        input.addAll(presets);
    }
    input.addAll(factories);
    providers.setInput(input);
    providers.addDoubleClickListener(new IDoubleClickListener() {

        @Override
        public void doubleClick(DoubleClickEvent event) {
            if (canFlipToNextPage()) {
                getContainer().showPage(getNextPage());
                return;
            }
        }
    });
    // set initial selection
    // if (!factories.isEmpty()) {
    // providers.setSelection(new StructuredSelection(factories.iterator().next()), true);
    // }
    // process current selection
    ISelection selection = providers.getSelection();
    setPageComplete(!selection.isEmpty());
    updateWizard(selection);
    // process selection changes
    providers.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            ISelection selection = event.getSelection();
            setPageComplete(!selection.isEmpty());
            updateWizard(selection);
        }
    });
}
Also used : ListViewer(org.eclipse.jface.viewers.ListViewer) IOProviderDescriptor(eu.esdihumboldt.hale.common.core.io.extension.IOProviderDescriptor) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) ArrayList(java.util.ArrayList) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) GridLayout(org.eclipse.swt.layout.GridLayout) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) GridData(org.eclipse.swt.layout.GridData) ISelection(org.eclipse.jface.viewers.ISelection) LabelProvider(org.eclipse.jface.viewers.LabelProvider)

Aggregations

IOProviderDescriptor (eu.esdihumboldt.hale.common.core.io.extension.IOProviderDescriptor)40 IContentType (org.eclipse.core.runtime.content.IContentType)17 IOConfiguration (eu.esdihumboldt.hale.common.core.io.project.model.IOConfiguration)8 IOReport (eu.esdihumboldt.hale.common.core.io.report.IOReport)8 Label (org.eclipse.swt.widgets.Label)7 IOException (java.io.IOException)6 HashSet (java.util.HashSet)6 ComboViewer (org.eclipse.jface.viewers.ComboViewer)6 SelectionEvent (org.eclipse.swt.events.SelectionEvent)6 GridData (org.eclipse.swt.layout.GridData)6 Composite (org.eclipse.swt.widgets.Composite)6 IOProviderConfigurationException (eu.esdihumboldt.hale.common.core.io.IOProviderConfigurationException)5 ArrayList (java.util.ArrayList)5 IPropertyChangeListener (org.eclipse.jface.util.IPropertyChangeListener)5 PropertyChangeEvent (org.eclipse.jface.util.PropertyChangeEvent)5 GridLayout (org.eclipse.swt.layout.GridLayout)5 IOProvider (eu.esdihumboldt.hale.common.core.io.IOProvider)4 FileIOSupplier (eu.esdihumboldt.hale.common.core.io.supplier.FileIOSupplier)4 InstanceWriter (eu.esdihumboldt.hale.common.instance.io.InstanceWriter)4 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)4