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;
}
Aggregations