static final String tcsSource = TcsSources.arecaceae_local();\r
static final ICdmDataSource cdmDestination = CdmDestinations.localH2Palmae();\r
\r
- static final UUID featureTreeUuid = UUID.fromString("72ccce05-7cc8-4dab-8e47-bf3f5fd848a0");\r
+ public static final UUID featureTreeUuid = UUID.fromString("72ccce05-7cc8-4dab-8e47-bf3f5fd848a0");\r
\r
static final UUID treeUuid = UUID.fromString("1adb71d4-cce6-45e1-b578-e668778d9ec6");\r
static final UUID secUuid = UUID.fromString("5f32b8af-0c97-48ac-8d33-6099ed68c625");\r
static final boolean includeImages = true;\r
static final boolean includeExcelProtologue = true;\r
static final boolean includeMediaProtologue = true;\r
+ static final boolean updateFeatureTree = true;\r
\r
//check - import\r
static final CHECK check = CHECK.CHECK_AND_IMPORT;\r
System.out.println("End importing taxonX ...");\r
}\r
\r
+ PalmaeFeatureTreeUpdater updater = new PalmaeFeatureTreeUpdater();\r
+ if (updateFeatureTree){\r
+ updater.updateMissingFeatures(cdmDestination);\r
+ }\r
+ \r
String strSuccess = "";\r
if (success == false){\r
strSuccess = "not ";\r
--- /dev/null
+// $Id$\r
+/**\r
+* Copyright (C) 2007 EDIT\r
+* European Distributed Institute of Taxonomy \r
+* http://www.e-taxonomy.eu\r
+* \r
+* The contents of this file are subject to the Mozilla Public License Version 1.1\r
+* See LICENSE.TXT at the top of this package for the full license terms.\r
+*/\r
+\r
+package eu.etaxonomy.cdm.app.wp6.palmae;\r
+\r
+import java.util.List;\r
+import java.util.UUID;\r
+\r
+import org.apache.log4j.Logger;\r
+import org.springframework.transaction.TransactionStatus;\r
+\r
+import eu.etaxonomy.cdm.api.application.CdmApplicationController;\r
+import eu.etaxonomy.cdm.app.common.CdmDestinations;\r
+import eu.etaxonomy.cdm.database.DbSchemaValidation;\r
+import eu.etaxonomy.cdm.database.ICdmDataSource;\r
+import eu.etaxonomy.cdm.model.description.Feature;\r
+import eu.etaxonomy.cdm.model.description.FeatureNode;\r
+import eu.etaxonomy.cdm.model.description.FeatureTree;\r
+\r
+/**\r
+ * @author a.mueller\r
+ * @created 01.10.2009\r
+ * @version 1.0\r
+ */\r
+public class PalmaeFeatureTreeUpdater {\r
+ private static final Logger logger = Logger.getLogger(PalmaeFeatureTreeUpdater.class);\r
+\r
+ static final ICdmDataSource cdmDestination = CdmDestinations.localH2Palmae();\r
+ \r
+ \r
+ private String relationships = "relationships";\r
+ private String taxonomicAccounts = "taxonomic accounts";\r
+ private String fossilRecord = "fossil record";\r
+ \r
+ public boolean updateMissingFeatures(ICdmDataSource dataSource) {\r
+ try{\r
+ int count = 0;\r
+ UUID featureTreeUuid = PalmaeActivator.featureTreeUuid;\r
+ CdmApplicationController cdmApp = CdmApplicationController.NewInstance(dataSource, DbSchemaValidation.VALIDATE);\r
+ \r
+ TransactionStatus tx = cdmApp.startTransaction();\r
+ \r
+ FeatureTree tree = cdmApp.getDescriptionService().getFeatureTreeByUuid(featureTreeUuid);\r
+ FeatureNode root = tree.getRoot();\r
+ \r
+ List<Feature> featureList = cdmApp.getDescriptionService().getFeaturesAll();\r
+ for (Feature feature : featureList){\r
+ String label = feature.getLabel();\r
+ if (relationships.equals(label)){\r
+ FeatureNode newNode = FeatureNode.NewInstance(feature);\r
+ root.addChild(newNode);\r
+ count++;\r
+ }else if(taxonomicAccounts.equals(label)){\r
+ FeatureNode newNode = FeatureNode.NewInstance(feature);\r
+ root.addChild(newNode);\r
+ count++;\r
+ }else if(fossilRecord.equals(label)){\r
+ FeatureNode newNode = FeatureNode.NewInstance(feature);\r
+ root.addChild(newNode);\r
+ count++;\r
+ }\r
+ }\r
+ cdmApp.commitTransaction(tx);\r
+ if (count != 3){\r
+ logger.warn("Did not find 3 additional features but " + count);\r
+ return false;\r
+ }\r
+ logger.info("Feature tree updated!");\r
+ return true;\r
+ } catch (Exception e) {\r
+ e.printStackTrace();\r
+ logger.error("ERROR in feature tree update");\r
+ return false;\r
+ }\r
+ \r
+ }\r
+ \r
+ \r
+ /**\r
+ * @param args\r
+ */\r
+ public static void main(String[] args) {\r
+ PalmaeFeatureTreeUpdater updater = new PalmaeFeatureTreeUpdater();\r
+ try {\r
+ updater.updateMissingFeatures(cdmDestination);\r
+ } catch (Exception e) {\r
+ e.printStackTrace();\r
+ logger.error("ERROR in feature tree update");\r
+ }\r
+ }\r
+}\r
\r
private boolean makeDirectory(CdmDefaultImport<IImportConfigurator> cdmImport, TaxonXImportConfigurator taxonXImportConfigurator, File source){\r
boolean success = true;\r
+ int count = 0;\r
for (File file : source.listFiles() ){\r
if (file.isFile()){\r
+ doCount(count++, 300, "Files");\r
success &= importFile(cdmImport, taxonXImportConfigurator, file);\r
}else{\r
if (! file.getName().startsWith(".")){\r
config.setSource(url.toString());\r
String originalSourceId = file.getName();\r
originalSourceId =originalSourceId.replace(".xml", "");\r
- logger.info(originalSourceId);\r
+ logger.debug(originalSourceId);\r
config.setOriginalSourceId(originalSourceId);\r
TransactionStatus tx = cdmImport.getCdmAppController().startTransaction();\r
success &= cdmImport.invoke(config);\r
}\r
}\r
\r
+ protected void doCount(int count, int modCount, String pluralString){\r
+ if ((count % modCount ) == 0 && count!= 0 ){ logger.info(pluralString + " handled: " + (count));}\r
+ }\r
\r
/**\r
* @param args\r