Search in sources :

Example 1 with NormalExplicitImportConfigurator

use of eu.etaxonomy.cdm.io.excel.taxa.NormalExplicitImportConfigurator in project cdmlib by cybertaxonomy.

the class ExcelImportBase method doInvoke.

/**
 * Reads data from an Excel file and stores them into a CDM DB.
 *
 * @param config
 * @param stores (not used)
 */
@Override
protected void doInvoke(STATE state) {
    logger.debug("Importing excel data");
    // cleanup state from prior session
    state.setSourceReference(null);
    configurator = state.getConfig();
    NomenclaturalCode nc = getConfigurator().getNomenclaturalCode();
    if (nc == null && requiresNomenclaturalCode()) {
        logger.error("Nomenclatural code could not be determined. Skip invoke.");
        state.setUnsuccessfull();
        return;
    }
    URI source = null;
    byte[] data = null;
    // read and save all rows of the excel worksheet
    if ((state.getConfig() instanceof NormalExplicitImportConfigurator || state.getConfig() instanceof ExcelDistributionUpdateConfigurator || state.getConfig() instanceof TaxonListImportConfigurator) && (state.getConfig().getStream() != null)) {
        data = state.getConfig().getStream();
    } else {
        source = state.getConfig().getSource();
    }
    String sheetName = getWorksheetName(state.getConfig());
    if (data != null) {
        try {
            ByteArrayInputStream stream = new ByteArrayInputStream(data);
            recordList = ExcelUtils.parseXLS(stream, sheetName);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    } else {
        try {
            recordList = ExcelUtils.parseXLS(source, sheetName);
        } catch (FileNotFoundException e) {
            String message = "File not found: " + source;
            warnProgress(state, message, e);
            logger.error(message);
            state.setUnsuccessfull();
            return;
        }
    }
    handleRecordList(state, source);
    logger.debug("End excel data import");
    return;
}
Also used : NomenclaturalCode(eu.etaxonomy.cdm.model.name.NomenclaturalCode) TaxonListImportConfigurator(eu.etaxonomy.cdm.io.excel.taxa.TaxonListImportConfigurator) NormalExplicitImportConfigurator(eu.etaxonomy.cdm.io.excel.taxa.NormalExplicitImportConfigurator) ByteArrayInputStream(java.io.ByteArrayInputStream) FileNotFoundException(java.io.FileNotFoundException) URI(eu.etaxonomy.cdm.common.URI) ExcelDistributionUpdateConfigurator(eu.etaxonomy.cdm.io.distribution.excelupdate.ExcelDistributionUpdateConfigurator) FileNotFoundException(java.io.FileNotFoundException)

Aggregations

URI (eu.etaxonomy.cdm.common.URI)1 ExcelDistributionUpdateConfigurator (eu.etaxonomy.cdm.io.distribution.excelupdate.ExcelDistributionUpdateConfigurator)1 NormalExplicitImportConfigurator (eu.etaxonomy.cdm.io.excel.taxa.NormalExplicitImportConfigurator)1 TaxonListImportConfigurator (eu.etaxonomy.cdm.io.excel.taxa.TaxonListImportConfigurator)1 NomenclaturalCode (eu.etaxonomy.cdm.model.name.NomenclaturalCode)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1