/**\r
* Copyright (C) 2007 EDIT\r
-* European Distributed Institute of Taxonomy \r
+* European Distributed Institute of Taxonomy\r
* http://www.e-taxonomy.eu\r
-* \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
import org.apache.log4j.Logger;\r
\r
-import eu.etaxonomy.cdm.api.application.ICdmApplicationDefaultConfiguration;\r
+import eu.etaxonomy.cdm.api.application.ICdmRepository;\r
import eu.etaxonomy.cdm.app.berlinModelImport.BerlinModelSources;\r
-import eu.etaxonomy.cdm.app.common.CdmDestinations;\r
import eu.etaxonomy.cdm.app.berlinModelImport.TreeCreator;\r
+import eu.etaxonomy.cdm.app.common.CdmDestinations;\r
import eu.etaxonomy.cdm.app.images.ImageImportConfigurator;\r
import eu.etaxonomy.cdm.database.DbSchemaValidation;\r
import eu.etaxonomy.cdm.database.ICdmDataSource;\r
import eu.etaxonomy.cdm.io.common.IImportConfigurator.CHECK;\r
import eu.etaxonomy.cdm.io.common.IImportConfigurator.DO_REFERENCES;\r
import eu.etaxonomy.cdm.io.common.IImportConfigurator.EDITOR;\r
+import eu.etaxonomy.cdm.io.common.ImportResult;\r
import eu.etaxonomy.cdm.io.common.Source;\r
import eu.etaxonomy.cdm.io.wp6.CichorieaeImageImport;\r
import eu.etaxonomy.cdm.model.common.ISourceable;\r
\r
/**\r
* TODO add the following to a wiki page:\r
- * HINT: If you are about to import into a mysql data base running under windows and if you wish to dump and restore the resulting data bas under another operation systen \r
+ * HINT: If you are about to import into a mysql data base running under windows and if you wish to dump and restore the resulting data bas under another operation systen\r
* you must set the mysql system variable lower_case_table_names = 0 in order to create data base with table compatible names.\r
- * \r
- * \r
+ *\r
+ *\r
* @author a.mueller\r
*\r
*/\r
//database validation status (create, update, validate ...)\r
static DbSchemaValidation hbm2dll = DbSchemaValidation.CREATE;\r
static final Source berlinModelSource = BerlinModelSources.EDIT_CICHORIEAE();\r
- static final ICdmDataSource cdmDestination = CdmDestinations.localH2Cichorieae();\r
+ static final ICdmDataSource cdmDestination = CdmDestinations.cdm_test_local_mysql_test();\r
\r
static final UUID secUuid = UUID.fromString("6924c75d-e0d0-4a6d-afb7-3dd8c71195ca");\r
static final UUID classificationUuid = UUID.fromString("534e190f-3339-49ba-95d9-fa27d5493e3e");\r
// static final UUID treeUuid = UUID.fromString("00db28a7-50e1-4abc-86ec-b2a8ce870de9");\r
static final int sourceSecId = 7800000;\r
- \r
+\r
static final UUID featureTreeUuid = UUID.fromString("ae9615b8-bc60-4ed0-ad96-897f9226d568");\r
- static final Object[] featureKeyList = new Integer[]{1, 43, 31, 4, 12, 98, 41}; \r
- \r
+ static final Object[] featureKeyList = new Integer[]{1, 43, 31, 4, 12, 98, 41};\r
+\r
/* --------- MEDIA recources ------------ */\r
- static final boolean stopOnMediaErrors = true;\r
+ static final boolean stopOnMediaErrors = false;\r
static final String protologueUrlString = "http://wp5.e-taxonomy.eu/dataportal/cichorieae/media/protolog/";\r
//Mac\r
//static final File protologuePath = new File("/Volumes/protolog/protolog/");\r
// public static final File imageFolder = new File("/media/photos");\r
// static final File protologuePath = new File("/media/protolog");\r
/* -------------------------------------- */\r
- \r
+\r
// set to zero for unlimited nameFacts\r
static final int maximumNumberOfNameFacts = 0;\r
static final int recordsPerTransaction = 2000;\r
- \r
+\r
//should the other imports run as well?\r
- static final boolean includeTaraxacum = true; \r
- static final boolean includeImages = true;\r
- \r
- \r
+ static final boolean includeTaraxacum = true;\r
+ static final boolean includeImages = false;\r
+\r
+\r
//check - import\r
static final CHECK check = CHECK.CHECK_AND_IMPORT;\r
\r
//editor - import\r
static final EDITOR editor = EDITOR.EDITOR_AS_EDITOR;\r
- \r
- //NomeclaturalCode\r
+\r
+ //NomenclaturalCode\r
static final NomenclaturalCode nomenclaturalCode = NomenclaturalCode.ICNAFP;\r
\r
//ignore null\r
static final boolean ignoreNull = true;\r
- \r
+\r
static boolean useClassification = true;\r
\r
\r
-// **************** ALL ********************* \r
+// **************** ALL *********************\r
\r
static final boolean doUser = true;\r
//authors\r
static final boolean doNameStatus = true;\r
static final boolean doTypes = true;\r
static final boolean doNameFacts = true;\r
- \r
+\r
//taxa\r
static final boolean doTaxa = true;\r
static final boolean doRelTaxa = true;\r
- static final boolean doFacts = true;\r
- static final boolean doOccurences = true;\r
+ static final boolean doFacts = false;\r
+ static final boolean doOccurences = false;\r
static final boolean doCommonNames = true;\r
\r
//etc.\r
- static final boolean doMarker = true;\r
+ static final boolean doMarker = false;\r
+\r
\r
- \r
// **************** SELECTED *********************\r
//\r
// static final boolean doUser = false;\r
// static final boolean doNameStatus = false;\r
// static final boolean doTypes = false;\r
// static final boolean doNameFacts = false;\r
-// \r
-// //taxa \r
+//\r
+// //taxa\r
// static final boolean doTaxa = false;\r
// static final boolean doRelTaxa = false;\r
// static final boolean doCommonNames = false;\r
// static final boolean doFacts = false;\r
// static final boolean doOccurences = false;\r
-// \r
+//\r
// //etc.\r
// static final boolean doMarker = false;\r
- \r
- \r
- private boolean doInvoke(ICdmDataSource destination){\r
- boolean success = true;\r
+\r
+\r
+ private ImportResult doInvoke(ICdmDataSource destination){\r
+ ImportResult success = new ImportResult();\r
Source source = berlinModelSource;\r
- \r
+\r
BerlinModelImportConfigurator bmImportConfigurator = BerlinModelImportConfigurator.NewInstance(source, destination);\r
- \r
+\r
bmImportConfigurator.setClassificationUuid(classificationUuid);\r
bmImportConfigurator.setSourceSecId(sourceSecId);\r
- \r
+\r
bmImportConfigurator.setNomenclaturalCode(nomenclaturalCode);\r
\r
bmImportConfigurator.setIgnoreNull(ignoreNull);\r
bmImportConfigurator.setDoTypes(doTypes);\r
bmImportConfigurator.setDoNameFacts(doNameFacts);\r
bmImportConfigurator.setUseClassification(useClassification);\r
- \r
+\r
bmImportConfigurator.setDoTaxa(doTaxa);\r
bmImportConfigurator.setDoRelTaxa(doRelTaxa);\r
bmImportConfigurator.setDoFacts(doFacts);\r
bmImportConfigurator.setDoOccurrence(doOccurences);\r
bmImportConfigurator.setDoCommonNames(doCommonNames);\r
- \r
+\r
bmImportConfigurator.setDoMarker(doMarker);\r
bmImportConfigurator.setDoUser(doUser);\r
bmImportConfigurator.setEditor(editor);\r
bmImportConfigurator.setDbSchemaValidation(hbm2dll);\r
bmImportConfigurator.setRecordsPerTransaction(recordsPerTransaction);\r
- \r
+\r
\r
// protologueResourceLocations\r
if ( protologuePath.exists() && protologuePath.isDirectory()){\r
}\r
logger.error("Could not configure protologue ResourceLocations");\r
}\r
- \r
+\r
File imageFolder = new File(imageFolderString);\r
// also check the image source folder\r
if ( !imageFolder.exists() || !imageFolder.isDirectory()){\r
}\r
logger.error("Could not configure imageFolder");\r
}\r
- \r
+\r
// maximum number of name facts to import\r
bmImportConfigurator.setMaximumNumberOfNameFacts(maximumNumberOfNameFacts);\r
- \r
- \r
+\r
+\r
bmImportConfigurator.setCheck(check);\r
bmImportConfigurator.setEditor(editor);\r
- \r
+\r
// invoke import\r
CdmDefaultImport<BerlinModelImportConfigurator> bmImport = new CdmDefaultImport<BerlinModelImportConfigurator>();\r
- success &= bmImport.invoke(bmImportConfigurator);\r
- \r
+ success = bmImport.invoke(bmImportConfigurator);\r
+\r
if (doFacts && (bmImportConfigurator.getCheck().equals(CHECK.CHECK_AND_IMPORT) || bmImportConfigurator.getCheck().equals(CHECK.IMPORT_WITHOUT_CHECK) ) ){\r
- ICdmApplicationDefaultConfiguration app = bmImport.getCdmAppController();\r
+ ICdmRepository app = bmImport.getCdmAppController();\r
ISourceable obj = app.getCommonService().getSourcedObjectByIdInSource(ZoologicalName.class, "1000027", null);\r
logger.info(obj);\r
- \r
+\r
//make feature tree\r
FeatureTree tree = TreeCreator.flatTree(featureTreeUuid, bmImportConfigurator.getFeatureMap(), featureKeyList);\r
FeatureNode imageNode = FeatureNode.NewInstance(Feature.IMAGE());\r
tree.getRoot().addChild(imageNode);\r
FeatureNode distributionNode = FeatureNode.NewInstance(Feature.DISTRIBUTION());\r
- tree.getRoot().addChild(distributionNode, 2); \r
+ tree.getRoot().addChild(distributionNode, 2);\r
app.getFeatureTreeService().saveOrUpdate(tree);\r
}\r
- \r
+\r
System.out.println("End import from BerlinModel ("+ source.getDatabase() + ")...");\r
\r
\r
if (includeTaraxacum) {\r
System.out.println("Start Taraxacum import from BerlinModel ...");\r
TaraxacumActivator taraxacumActivator = new TaraxacumActivator();\r
- success &= taraxacumActivator.doImport(destination, DbSchemaValidation.UPDATE);\r
+ ImportResult successTaraxacum = taraxacumActivator.doImport(destination, DbSchemaValidation.UPDATE);\r
+ success.setSuccess(success.isSuccess() & successTaraxacum.isSuccess());\r
+ for (byte [] report : successTaraxacum.getReports()){\r
+ success.addReport(report);\r
+ }\r
logger.warn("Taraxacum import still needs to be tested");\r
System.out.println("End Taraxacum import from BerlinModel ...");\r
}\r
} catch (Exception e) {\r
- success = false;\r
+ success.setSuccess(false);\r
+ String report = "Exception occurred during Taraxacum import.";\r
+ success.addReport(report.getBytes());\r
logger.error("Exception occurred during Taraxacum import.");\r
- e.printStackTrace(); \r
+ e.printStackTrace();\r
}\r
\r
\r
- \r
+\r
if (includeImages) {\r
System.out.println("Start importing images ...");\r
CdmDefaultImport<IImportConfigurator> imageImporter = new CdmDefaultImport<IImportConfigurator>();\r
imageFolderCichorieae, destination, CichorieaeImageImport.class);\r
imageConfigurator.setSecUuid(secUuid);\r
imageConfigurator.setClassificationUuid(classificationUuid);\r
- success &= imageImporter.invoke(imageConfigurator);\r
+ ImportResult resultImageImport = imageImporter.invoke(imageConfigurator);\r
+ success.setSuccess(resultImageImport.isSuccess() & success.isSuccess());\r
+ for (byte[] report : resultImageImport.getReports()){\r
+ success.addReport(report);\r
+ }\r
} catch (URISyntaxException e) {\r
e.printStackTrace();\r
}\r
System.out.println("End importing images ...");\r
}\r
logger.warn("!!!! NOTE: RefDetail notes and RelPTaxon notes are not imported automatically. Please check for these notes and import them manually.");\r
- \r
+\r
return success;\r
- \r
+\r
}\r
- \r
+\r
/**\r
* @param args\r
*/\r
public static void main(String[] args) {\r
ICdmDataSource destination = CdmDestinations.chooseDestination(args) != null ? CdmDestinations.chooseDestination(args) : cdmDestination;\r
- \r
+\r
System.out.println("Start import from BerlinModel("+ berlinModelSource.getDatabase() + ") to " + destination.getDatabase() + " ...");\r
CichorieaeActivator me = new CichorieaeActivator();\r
me.doInvoke(destination);\r
- \r
+\r
}\r
\r
}\r