package eu.etaxonomy.cdm.io.excel.distribution;\r
\r
+import java.io.FileNotFoundException;\r
import java.util.ArrayList;\r
import java.util.HashMap;\r
import java.util.List;\r
import java.util.Set;\r
\r
import org.apache.log4j.Logger;\r
+import org.springframework.stereotype.Component;\r
import org.springframework.transaction.TransactionStatus;\r
\r
import eu.etaxonomy.cdm.api.application.CdmApplicationController;\r
import eu.etaxonomy.cdm.model.name.TaxonNameBase;\r
import eu.etaxonomy.cdm.model.taxon.Taxon;\r
\r
+@Component\r
public class DistributionImporter extends CdmIoBase<IImportConfigurator> implements ICdmIO<IImportConfigurator> {\r
\r
/* used */\r
\r
private static final Logger logger = Logger.getLogger(DistributionImporter.class);\r
\r
- private CdmApplicationController appCtr = null;\r
// Stores already processed descriptions\r
Map<Taxon, TaxonDescription> myDescriptions = new HashMap<Taxon, TaxonDescription>();\r
\r
protected boolean doInvoke(IImportConfigurator config,\r
Map<String, MapWrapper<? extends CdmBase>> stores) {\r
\r
- logger.debug("Importing distribution data");\r
+ if (logger.isDebugEnabled()) { logger.debug("Importing distribution data"); }\r
\r
// read and save all rows of the excel worksheet\r
- ArrayList<HashMap<String, String>> recordList = ExcelUtils.parseXLS(config.getSourceNameString());\r
+ ArrayList<HashMap<String, String>> recordList;\r
+ try{\r
+ recordList = ExcelUtils.parseXLS(config.getSourceNameString());\r
+ } catch (FileNotFoundException e1) {\r
+ logger.error("File not found: " + (String)config.getSource());\r
+ return false;\r
+ }\r
if (recordList != null) {\r
HashMap<String,String> record = null;\r
TransactionStatus txStatus = startTransaction();\r
}\r
\r
try {\r
- logger.debug("End distribution data import"); \r
+ if (logger.isDebugEnabled()) { logger.debug("End distribution data import"); }\r
\r
} catch (Exception e) {\r
logger.error("Error closing the application context");\r
\r
String value = (String) record.get(key);\r
if (!value.equals("")) {\r
- logger.debug(key + ": '" + value + "'");\r
+ if (logger.isDebugEnabled()) { logger.debug(key + ": '" + value + "'"); }\r
}\r
\r
if (key.contains(EDIT_NAME_COLUMN)) {\r
\r
try {\r
// get the matching names from the DB\r
- List<TaxonNameBase<?,?>> taxonNameBases = appCtr.getNameService().findNamesByTitle(taxonName);\r
+ List<TaxonNameBase<?,?>> taxonNameBases = getNameService().findNamesByTitle(taxonName);\r
if (taxonNameBases.isEmpty()) {\r
logger.error("Taxon name '" + taxonName + "' not found in DB");\r
} else {\r
- logger.debug("Taxon found");\r
+ if (logger.isDebugEnabled()) { logger.debug("Taxon found"); }\r
}\r
\r
// get the taxa for the matching names\r
- for(TaxonNameBase dbTaxonName: taxonNameBases) {\r
+ for(TaxonNameBase<?,?> dbTaxonName: taxonNameBases) {\r
\r
Set<Taxon> taxa = dbTaxonName.getTaxa();\r
if (taxa.isEmpty()) {\r
if (descriptionElement instanceof Distribution) {\r
if (namedArea == ((Distribution)descriptionElement).getArea()) {\r
ignore = true;\r
- logger.debug("Distribution ignored: " + distribution);\r
+ if (logger.isDebugEnabled()) { \r
+ logger.debug("Distribution ignored: " + distribution); \r
+ }\r
break;\r
}\r
}\r
save = true;\r
Distribution newDistribution = Distribution.NewInstance(namedArea, presenceAbsenceStatus);\r
myDescription.addElement(newDistribution);\r
- logger.debug("Distribution created: " + newDistribution.toString());\r
+ if (logger.isDebugEnabled()) { \r
+ logger.debug("Distribution created: " + newDistribution.toString());\r
+ }\r
}\r
}\r
}\r
}\r
if (save == true) {\r
- appCtr.getTaxonService().saveTaxon(taxon);\r
- logger.debug("Taxon saved");\r
+ getTaxonService().saveTaxon(taxon);\r
+ if (logger.isDebugEnabled()) { logger.debug("Taxon saved"); }\r
}\r
}\r
} \r