Search in sources :

Example 16 with IOProviderDescriptor

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

the class ProjectIO method getSupportedExtensions.

/**
 * Get the supported file extensions for projects.
 *
 * @return the set of file extensions (with leading dot)
 */
private static 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 17 with IOProviderDescriptor

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

the class HeadlessIO method loadProvider.

/**
 * Load and configure the I/O provider specified by the given I/O
 * configuration.
 *
 * @param conf the I/O configuration
 * @return the provider or <code>null</code> if it was not found or could
 *         not be created
 */
public static IOProvider loadProvider(IOConfiguration conf) {
    IOProvider provider = null;
    IOProviderDescriptor descriptor = IOProviderExtension.getInstance().getFactory(conf.getProviderId());
    if (descriptor != null) {
        try {
            provider = descriptor.createExtensionObject();
            // configure settings
            provider.loadConfiguration(conf.getProviderConfiguration());
            if (provider instanceof CachingImportProvider) {
                ((CachingImportProvider) provider).setCache(conf.getCache());
            }
        } catch (Exception e) {
            log.error("Could not instantiate I/O provider.", e);
        }
    }
    return provider;
}
Also used : 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) IOException(java.io.IOException)

Example 18 with IOProviderDescriptor

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

the class ProjectParser method load.

private void load(URI source, String actionId, String msgCT, String msgIO, @SuppressWarnings("rawtypes") Class clazz) {
    // create IOConfiguration for source data
    IOConfiguration conf = new IOConfiguration();
    // populate IOConfiguration
    // set action ID
    conf.setActionId(actionId);
    // find provider
    File file;
    try {
        file = new File(source);
    } catch (IllegalArgumentException e) {
        file = null;
    }
    @SuppressWarnings("unchecked") IContentType ct = HaleIO.findContentType(clazz, new DefaultInputSupplier(source), (file == null) ? (null) : (file.getAbsolutePath()));
    if (ct == null) {
        report.error(new IOMessageImpl(msgCT, null, -1, -1, source));
        return;
    }
    @SuppressWarnings("unchecked") IOProviderDescriptor srf = HaleIO.findIOProviderFactory(clazz, ct, null);
    if (srf == null) {
        report.error(new IOMessageImpl(msgIO, null, -1, -1, source));
        return;
    }
    conf.setProviderId(srf.getIdentifier());
    // provider configuration
    // source
    conf.getProviderConfiguration().put(AbstractImportProvider.PARAM_SOURCE, Value.of(source.toString()));
    // content type
    conf.getProviderConfiguration().put(AbstractImportProvider.PARAM_CONTENT_TYPE, Value.of(ct.getId()));
    // no dependencies needed
    // add configuration to project
    project.getResources().add(conf);
}
Also used : DefaultInputSupplier(eu.esdihumboldt.hale.common.core.io.supplier.DefaultInputSupplier) IOProviderDescriptor(eu.esdihumboldt.hale.common.core.io.extension.IOProviderDescriptor) IOConfiguration(eu.esdihumboldt.hale.common.core.io.project.model.IOConfiguration) IOMessageImpl(eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl) IContentType(org.eclipse.core.runtime.content.IContentType) ProjectFile(eu.esdihumboldt.hale.common.core.io.project.model.ProjectFile) File(java.io.File)

Example 19 with IOProviderDescriptor

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

the class AppSchemaFileWriterTest method loadTestProject.

@BeforeClass
public static void loadTestProject() {
    try {
        URL archiveLocation = AppSchemaFileWriterTest.class.getResource(PROJECT_LOCATION);
        ArchiveProjectReader projectReader = new ArchiveProjectReader();
        projectReader.setSource(new DefaultInputSupplier(archiveLocation.toURI()));
        IOReport report = projectReader.execute(new LogProgressIndicator());
        if (!report.isSuccess()) {
            throw new RuntimeException("project reader execution failed");
        }
        tempDir = projectReader.getTemporaryFiles().iterator().next();
        project = projectReader.getProject();
        assertNotNull(project);
        sourceSchemaSpace = new DefaultSchemaSpace();
        targetSchemaSpace = new DefaultSchemaSpace();
        // load schemas
        List<IOConfiguration> resources = project.getResources();
        for (IOConfiguration resource : resources) {
            String actionId = resource.getActionId();
            String providerId = resource.getProviderId();
            // get provider
            IOProvider provider = null;
            IOProviderDescriptor descriptor = IOProviderExtension.getInstance().getFactory(providerId);
            if (descriptor == null) {
                throw new RuntimeException("Could not load I/O provider with ID: " + resource.getProviderId());
            }
            provider = descriptor.createExtensionObject();
            provider.loadConfiguration(resource.getProviderConfiguration());
            prepareProvider(provider, project, tempDir.toURI());
            IOReport providerReport = provider.execute(new LogProgressIndicator());
            if (!providerReport.isSuccess()) {
                throw new RuntimeException("I/O provider execution failed");
            }
            // TODO: could (should?) be done by an advisor
            if (provider instanceof SchemaReader) {
                Schema schema = ((SchemaReader) provider).getSchema();
                if (actionId.equals(SchemaIO.ACTION_LOAD_SOURCE_SCHEMA)) {
                    sourceSchemaSpace.addSchema(schema);
                } else if (actionId.equals(SchemaIO.ACTION_LOAD_TARGET_SCHEMA)) {
                    targetSchemaSpace.addSchema(schema);
                }
            }
        }
        // load alignment
        List<ProjectFileInfo> projectFiles = project.getProjectFiles();
        for (ProjectFileInfo projectFile : projectFiles) {
            if (projectFile.getName().equals(AlignmentIO.PROJECT_FILE_ALIGNMENT)) {
                AlignmentReader alignReader = new JaxbAlignmentReader();
                alignReader.setSource(new DefaultInputSupplier(projectFile.getLocation()));
                alignReader.setSourceSchema(sourceSchemaSpace);
                alignReader.setTargetSchema(targetSchemaSpace);
                alignReader.setPathUpdater(new PathUpdate(null, null));
                IOReport alignReport = alignReader.execute(new LogProgressIndicator());
                if (!alignReport.isSuccess()) {
                    throw new RuntimeException("alignment reader execution failed");
                }
                alignment = alignReader.getAlignment();
                assertNotNull(alignment);
                break;
            }
        }
    } catch (Exception e) {
        log.error("Exception occurred", e);
        fail("Test project could not be loaded: " + e.getMessage());
    }
}
Also used : JaxbAlignmentReader(eu.esdihumboldt.hale.common.align.io.impl.JaxbAlignmentReader) AlignmentReader(eu.esdihumboldt.hale.common.align.io.AlignmentReader) JaxbAlignmentReader(eu.esdihumboldt.hale.common.align.io.impl.JaxbAlignmentReader) SchemaReader(eu.esdihumboldt.hale.common.schema.io.SchemaReader) DefaultInputSupplier(eu.esdihumboldt.hale.common.core.io.supplier.DefaultInputSupplier) IOProviderDescriptor(eu.esdihumboldt.hale.common.core.io.extension.IOProviderDescriptor) IOConfiguration(eu.esdihumboldt.hale.common.core.io.project.model.IOConfiguration) Schema(eu.esdihumboldt.hale.common.schema.model.Schema) DefaultSchemaSpace(eu.esdihumboldt.hale.common.schema.model.impl.DefaultSchemaSpace) IOReport(eu.esdihumboldt.hale.common.core.io.report.IOReport) LogProgressIndicator(eu.esdihumboldt.hale.common.core.io.impl.LogProgressIndicator) URL(java.net.URL) IOProviderConfigurationException(eu.esdihumboldt.hale.common.core.io.IOProviderConfigurationException) ZipException(java.util.zip.ZipException) SAXException(org.xml.sax.SAXException) IOException(java.io.IOException) ArchiveProjectReader(eu.esdihumboldt.hale.common.core.io.project.impl.ArchiveProjectReader) ProjectFileInfo(eu.esdihumboldt.hale.common.core.io.project.model.ProjectFileInfo) PathUpdate(eu.esdihumboldt.hale.common.core.io.PathUpdate) IOProvider(eu.esdihumboldt.hale.common.core.io.IOProvider) BeforeClass(org.junit.BeforeClass)

Example 20 with IOProviderDescriptor

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

the class ExamplesContent method executeProvider.

/**
 * Execute the I/O provider given or specified by the given provider ID.
 *
 * @param advisor the advisor to use for configuration of the provider and
 *            handling the results
 * @param providerId the ID of the provider to execute, may be
 *            <code>null</code> if provider is set
 * @param provider the provider to execute
 * @throws Exception if executing the provider fails or if a provider with
 *             the given ID is not found
 */
@SuppressWarnings("unchecked")
private void executeProvider(@SuppressWarnings("rawtypes") IOAdvisor advisor, String providerId, IOProvider provider) throws Exception {
    if (provider == null) {
        // find and create the provider
        IOProviderDescriptor descriptor = IOProviderExtension.getInstance().getFactory(providerId);
        if (descriptor != null) {
            provider = descriptor.createExtensionObject();
        } else {
            throw new IllegalStateException("I/O provider with ID " + providerId + " not found");
        }
    }
    // use advisor to configure provider
    advisor.prepareProvider(provider);
    advisor.updateConfiguration(provider);
    // execute
    IOReport report = provider.execute(null);
    // handle results
    if (report.isSuccess()) {
        advisor.handleResults(provider);
    }
}
Also used : IOProviderDescriptor(eu.esdihumboldt.hale.common.core.io.extension.IOProviderDescriptor) IOReport(eu.esdihumboldt.hale.common.core.io.report.IOReport)

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