Search in sources :

Example 6 with IOProvider

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

the class ReadConfigurationPage method onShowPage.

/**
 * @see HaleWizardPage#onShowPage(boolean)
 */
@Override
protected void onShowPage(boolean firstShow) {
    super.onShowPage(firstShow);
    IOProvider p = getWizard().getProvider();
    String[] separatorSelection = new String[] { "TAB", ",", "|", ".", ";" };
    try {
        BufferedReader streamReader = new BufferedReader(new InputStreamReader(getWizard().getProvider().getSource().getInput(), p.getCharset()));
        String line = streamReader.readLine();
        int tab = 0, comma = 0, pipe = 0, semicolon = 0;
        if (line != null) {
            tab = countChar(line, '\t');
            comma = countChar(line, ',');
            pipe = countChar(line, '|');
            semicolon = countChar(line, ';');
        }
        if (Math.max(tab, comma) == tab && Math.max(tab, pipe) == tab && Math.max(tab, semicolon) == tab) {
            p.setParameter(CSVConstants.PARAM_SEPARATOR, Value.of("TAB"));
        } else if (Math.max(comma, tab) == comma && Math.max(comma, pipe) == comma && Math.max(comma, semicolon) == comma) {
            p.setParameter(CSVConstants.PARAM_SEPARATOR, Value.of(","));
        } else if (Math.max(semicolon, tab) == semicolon && Math.max(semicolon, comma) == semicolon && Math.max(semicolon, pipe) == semicolon) {
            p.setParameter(CSVConstants.PARAM_SEPARATOR, Value.of(";"));
        } else {
            p.setParameter(CSVConstants.PARAM_SEPARATOR, Value.of("|"));
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
    String selection = getWizard().getProvider().getParameter(CSVConstants.PARAM_SEPARATOR).as(String.class);
    for (int i = 0; i < separatorSelection.length; i++) {
        if (separatorSelection[i].equals(selection)) {
            getSeparator().select(i);
            break;
        } else {
            getSeparator().select(0);
        }
    }
    if (p instanceof InstanceReader) {
        QName name = QName.valueOf(p.getParameter(CommonSchemaConstants.PARAM_TYPENAME).as(String.class));
        if (getLast_name() == null || !(getLast_name().equals(name))) {
            TypeDefinition type = ((InstanceReader) p).getSourceSchema().getType(name);
            CSVConfiguration config = type.getConstraint(CSVConfiguration.class);
            String sep = String.valueOf(config.getSeparator());
            if (getBmap().inverse().get(sep) != null) {
                getSeparator().setText(getBmap().inverse().get(sep));
            } else {
                getSeparator().setText(sep);
            }
            String qu = String.valueOf(config.getQuote());
            if (getBmap().inverse().get(qu) != null) {
                getQuote().setText(getBmap().inverse().get(qu));
            } else {
                getQuote().setText(qu);
            }
            String esc = String.valueOf(config.getEscape());
            if (getBmap().inverse().get(esc) != null) {
                getSeparator().setText(getBmap().inverse().get(esc));
            } else {
                getEscape().setText(esc);
            }
            setLast_name(name);
        }
    }
    setPageComplete(true);
}
Also used : InstanceReader(eu.esdihumboldt.hale.common.instance.io.InstanceReader) InputStreamReader(java.io.InputStreamReader) CSVConfiguration(eu.esdihumboldt.hale.io.csv.reader.internal.CSVConfiguration) QName(javax.xml.namespace.QName) BufferedReader(java.io.BufferedReader) IOProvider(eu.esdihumboldt.hale.common.core.io.IOProvider) IOException(java.io.IOException) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition)

Example 7 with IOProvider

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

the class ReadInstanceConfigurationPage method onShowPage.

/**
 * @see HaleWizardPage#onShowPage(boolean)
 */
@Override
protected void onShowPage(boolean firstShow) {
    super.onShowPage(firstShow);
    IOProvider p = getWizard().getProvider();
    QName name = QName.valueOf(p.getParameter(CommonSchemaConstants.PARAM_TYPENAME).as(String.class));
    if (getLast_name() == null || !(getLast_name().equals(name))) {
        TypeDefinition type = ((InstanceReader) p).getSourceSchema().getType(name);
        CSVConfiguration config = type.getConstraint(CSVConfiguration.class);
        String sep = String.valueOf(config.getSeparator());
        if (getBmap().inverse().get(sep) != null) {
            getSeparator().setText(getBmap().inverse().get(sep));
        } else {
            getSeparator().setText(sep);
        }
        String qu = String.valueOf(config.getQuote());
        if (getBmap().inverse().get(qu) != null) {
            getQuote().setText(getBmap().inverse().get(qu));
        } else {
            getQuote().setText(qu);
        }
        String esc = String.valueOf(config.getEscape());
        if (getBmap().inverse().get(esc) != null) {
            getSeparator().setText(getBmap().inverse().get(esc));
        } else {
            getEscape().setText(esc);
        }
        setLast_name(name);
    }
    setPageComplete(true);
}
Also used : CSVConfiguration(eu.esdihumboldt.hale.io.csv.reader.internal.CSVConfiguration) QName(javax.xml.namespace.QName) IOProvider(eu.esdihumboldt.hale.common.core.io.IOProvider) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition)

Example 8 with IOProvider

use of eu.esdihumboldt.hale.common.core.io.IOProvider 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

IOProvider (eu.esdihumboldt.hale.common.core.io.IOProvider)8 IOProviderDescriptor (eu.esdihumboldt.hale.common.core.io.extension.IOProviderDescriptor)4 IOException (java.io.IOException)4 CachingImportProvider (eu.esdihumboldt.hale.common.core.io.CachingImportProvider)2 IOAdvisor (eu.esdihumboldt.hale.common.core.io.IOAdvisor)2 IOAdvisorFactory (eu.esdihumboldt.hale.common.core.io.extension.IOAdvisorFactory)2 InstanceReader (eu.esdihumboldt.hale.common.instance.io.InstanceReader)2 TypeDefinition (eu.esdihumboldt.hale.common.schema.model.TypeDefinition)2 CSVConfiguration (eu.esdihumboldt.hale.io.csv.reader.internal.CSVConfiguration)2 QName (javax.xml.namespace.QName)2 AlignmentReader (eu.esdihumboldt.hale.common.align.io.AlignmentReader)1 JaxbAlignmentReader (eu.esdihumboldt.hale.common.align.io.impl.JaxbAlignmentReader)1 IOProviderConfigurationException (eu.esdihumboldt.hale.common.core.io.IOProviderConfigurationException)1 ImportProvider (eu.esdihumboldt.hale.common.core.io.ImportProvider)1 PathUpdate (eu.esdihumboldt.hale.common.core.io.PathUpdate)1 LogProgressIndicator (eu.esdihumboldt.hale.common.core.io.impl.LogProgressIndicator)1 ArchiveProjectReader (eu.esdihumboldt.hale.common.core.io.project.impl.ArchiveProjectReader)1 IOConfiguration (eu.esdihumboldt.hale.common.core.io.project.model.IOConfiguration)1 ProjectFileInfo (eu.esdihumboldt.hale.common.core.io.project.model.ProjectFileInfo)1 IOReport (eu.esdihumboldt.hale.common.core.io.report.IOReport)1