import org.springframework.transaction.TransactionStatus;\r
\r
import eu.etaxonomy.cdm.api.application.CdmApplicationController;\r
+import eu.etaxonomy.cdm.api.application.ICdmApplicationConfiguration;\r
import eu.etaxonomy.cdm.api.service.ITermService;\r
import eu.etaxonomy.cdm.app.common.CdmDestinations;\r
+import eu.etaxonomy.cdm.common.DefaultProgressMonitor;\r
+import eu.etaxonomy.cdm.common.IProgressMonitor;\r
import eu.etaxonomy.cdm.database.DbSchemaValidation;\r
import eu.etaxonomy.cdm.database.ICdmDataSource;\r
+import eu.etaxonomy.cdm.database.update.CdmUpdater;\r
import eu.etaxonomy.cdm.io.common.CdmDefaultImport;\r
+import eu.etaxonomy.cdm.io.common.CdmImportBase.TermMatchMode;\r
import eu.etaxonomy.cdm.io.common.IImportConfigurator.CHECK;\r
import eu.etaxonomy.cdm.io.common.mapping.IInputTransformer;\r
import eu.etaxonomy.cdm.io.common.mapping.UndefinedTransformerMethodException;\r
import eu.etaxonomy.cdm.io.eflora.EfloraImportConfigurator;\r
import eu.etaxonomy.cdm.io.eflora.centralAfrica.ericaceae.CentralAfricaEricaceaeImportConfigurator;\r
import eu.etaxonomy.cdm.io.eflora.centralAfrica.ericaceae.CentralAfricaEricaceaeTransformer;\r
-import eu.etaxonomy.cdm.model.agent.Person;\r
+import eu.etaxonomy.cdm.io.specimen.excel.in.SpecimenCdmExcelImportConfigurator;\r
import eu.etaxonomy.cdm.model.agent.Team;\r
import eu.etaxonomy.cdm.model.common.Language;\r
+import eu.etaxonomy.cdm.model.common.OrderedTermVocabulary;\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
import eu.etaxonomy.cdm.model.description.PolytomousKey;\r
+import eu.etaxonomy.cdm.model.location.NamedArea;\r
+import eu.etaxonomy.cdm.model.location.NamedAreaLevel;\r
+import eu.etaxonomy.cdm.model.location.NamedAreaType;\r
import eu.etaxonomy.cdm.model.reference.Reference;\r
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;\r
\r
//database validation status (create, update, validate ...)\r
static DbSchemaValidation hbm2dll = DbSchemaValidation.CREATE;\r
static final URI source = EfloraSources.ericacea_local();\r
+ \r
+ static final URI specimenSource = EfloraSources.ericacea_specimen_local();\r
\r
\r
// static final ICdmDataSource cdmDestination = CdmDestinations.cdm_test_andreasM3();\r
static final ICdmDataSource cdmDestination = CdmDestinations.localH2();\r
// static final ICdmDataSource cdmDestination = CdmDestinations.cdm_local_postgres_CdmTest();\r
// static final ICdmDataSource cdmDestination = CdmDestinations.cdm_test_local_mysql();\r
+// static final ICdmDataSource cdmDestination = CdmDestinations.cdm_test_jaxb();\r
\r
//feature tree uuid\r
public static final UUID featureTreeUuid = UUID.fromString("051d35ee-22f1-42d8-be07-9e9bfec5bcf7");\r
static boolean doPrintKeys = false;\r
\r
//taxa\r
+ private boolean includeEricaceae = true;\r
static final boolean doTaxa = true;\r
static final boolean doDeduplicate = false;\r
\r
- private boolean includeEricaceae = true;\r
-\r
+ \r
+ private boolean doNewNamedAreas = false;\r
+ private boolean doFeatureTree = false;\r
+ \r
+ private boolean doSpecimen = false;\r
+ private TermMatchMode specimenAreaMatchMode = TermMatchMode.UUID_ABBREVLABEL;\r
\r
\r
private void doImport(ICdmDataSource cdmDestination){\r
\r
-// CdmUpdater su = CdmUpdater.NewInstance();\r
-// \r
+ CdmUpdater su = CdmUpdater.NewInstance();\r
+ IProgressMonitor monitor = DefaultProgressMonitor.NewInstance();\r
+ \r
// try {\r
-// //su.updateToCurrentVersion(cdmDestination, DefaultProgressMonitor.NewInstance());\r
+// su.updateToCurrentVersion(cdmDestination, monitor);\r
// } catch (Exception e) {\r
// e.printStackTrace();\r
// }\r
-// if (false){\r
+// if (true){\r
// return;\r
// }\r
\r
System.out.println("End import from ("+ source.toString() + ")...");\r
}\r
\r
- FeatureTree tree = makeFeatureNode(myImport.getCdmAppController().getTermService());\r
- myImport.getCdmAppController().getFeatureTreeService().saveOrUpdate(tree);\r
+ if (doFeatureTree){\r
+ FeatureTree tree = makeFeatureNode(myImport.getCdmAppController().getTermService());\r
+ myImport.getCdmAppController().getFeatureTreeService().saveOrUpdate(tree);\r
+ }\r
\r
//check keys\r
if (doPrintKeys){\r
\r
//deduplicate\r
if (doDeduplicate){\r
- CdmApplicationController app = myImport.getCdmAppController();\r
- int count = app.getAgentService().deduplicate(Person.class, null, null);\r
- logger.warn("Deduplicated " + count + " persons.");\r
- count = app.getAgentService().deduplicate(Team.class, null, null);\r
- logger.warn("Deduplicated " + count + " teams.");\r
- count = app.getReferenceService().deduplicate(Reference.class, null, null);\r
- logger.warn("Deduplicated " + count + " references.");\r
+ ICdmApplicationConfiguration app = myImport.getCdmAppController();\r
+ if (app == null){\r
+ app = CdmApplicationController.NewInstance(cdmDestination, hbm2dll, false);\r
+ }\r
+ app.getAgentService().updateTitleCache(Team.class, null, null, null);\r
+ return;\r
+// int count = app.getAgentService().deduplicate(Person.class, null, null);\r
+// \r
+// logger.warn("Deduplicated " + count + " persons.");\r
+//// count = app.getAgentService().deduplicate(Team.class, null, null);\r
+//// logger.warn("Deduplicated " + count + " teams.");\r
+// count = app.getReferenceService().deduplicate(Reference.class, null, null);\r
+// logger.warn("Deduplicated " + count + " references.");\r
+ }\r
+ \r
+ if(doNewNamedAreas){\r
+ newNamedAreas(myImport);\r
+ }\r
+\r
+ if (doSpecimen){\r
+ logger.warn("Start specimen import");\r
+ ICdmApplicationConfiguration app = myImport.getCdmAppController();\r
+ SpecimenCdmExcelImportConfigurator specimenConfig= SpecimenCdmExcelImportConfigurator.NewInstance(specimenSource, cdmDestination);\r
+ specimenConfig.setCdmAppController((CdmApplicationController)app);\r
+ specimenConfig.setAreaMatchMode(specimenAreaMatchMode);\r
+ \r
+ config.setDbSchemaValidation(DbSchemaValidation.VALIDATE);\r
+ specimenConfig.setSourceReference(getSourceReference(specimenConfig.getSourceReferenceTitle()));\r
+ \r
+ CdmDefaultImport<SpecimenCdmExcelImportConfigurator> specimenImport = new CdmDefaultImport<SpecimenCdmExcelImportConfigurator>();\r
+ specimenImport.setCdmAppController(app);\r
+ specimenImport.invoke(specimenConfig);\r
+ \r
+ \r
+ }\r
+ return;\r
+ \r
+\r
+ \r
+ }\r
+\r
+ private void newNamedAreas(CdmDefaultImport<EfloraImportConfigurator> myImport) {\r
+ ICdmApplicationConfiguration app = myImport.getCdmAppController();\r
+ if (app == null){\r
+ app = CdmApplicationController.NewInstance(cdmDestination, hbm2dll, false);\r
}\r
+ TransactionStatus tx = app.startTransaction();\r
+ \r
+ OrderedTermVocabulary<NamedArea> voc = OrderedTermVocabulary.NewInstance("Phytogeographic Regions of Central Africa", "Phytogeographic Regions of Central Africa", "FdAC regions", null);\r
+ app.getVocabularyService().save(voc);\r
+ \r
+ NamedAreaLevel level = NamedAreaLevel.NewInstance("Phytogeographic Regions of Central Africa", "Phytogeographic Regions of Central Africa", "FdAC regions");\r
+ ITermService termService = app.getTermService();\r
+ \r
+ termService.save(level);\r
+ \r
+ NamedArea area = NamedArea.NewInstance("Côtier", "Côtier", "I");\r
+ area.setLevel(level);\r
+ area.setType(NamedAreaType.NATURAL_AREA());\r
+ voc.addTerm(area);\r
+ termService.save(area);\r
+ \r
+\r
+ area = NamedArea.NewInstance("Mayumbe", "Mayumbe", "II");\r
+ area.setLevel(level);\r
+ area.setType(NamedAreaType.NATURAL_AREA());\r
+ voc.addTerm(area);\r
+ termService.save(area);\r
+\r
+ area = NamedArea.NewInstance("Bas-Congo", "Bas-Congo", "III");\r
+ area.setLevel(level);\r
+ area.setType(NamedAreaType.NATURAL_AREA());\r
+ voc.addTerm(area);\r
+ termService.save(area);\r
+\r
+ area = NamedArea.NewInstance("Kasai", "Kasai", "IV");\r
+ area.setLevel(level);\r
+ area.setType(NamedAreaType.NATURAL_AREA());\r
+ voc.addTerm(area);\r
+ termService.save(area);\r
+\r
+ area = NamedArea.NewInstance("Bas-Katanga", "Bas-Katanga", "V");\r
+ area.setLevel(level);\r
+ area.setType(NamedAreaType.NATURAL_AREA());\r
+ voc.addTerm(area);\r
+ termService.save(area);\r
+\r
+ area = NamedArea.NewInstance("Forestier Central", "Forestier Central", "VI");\r
+ area.setLevel(level);\r
+ area.setType(NamedAreaType.NATURAL_AREA());\r
+ voc.addTerm(area);\r
+ termService.save(area);\r
+\r
+ area = NamedArea.NewInstance("Ubangi-Uele", "Ubangi-Uele", "VII");\r
+ area.setLevel(level);\r
+ area.setType(NamedAreaType.NATURAL_AREA());\r
+ voc.addTerm(area);\r
+ termService.save(area);\r
+\r
+ area = NamedArea.NewInstance("Lac Albert", "Lac Albert", "VIII");\r
+ area.setLevel(level);\r
+ area.setType(NamedAreaType.NATURAL_AREA());\r
+ voc.addTerm(area);\r
+ termService.save(area);\r
+\r
+ area = NamedArea.NewInstance("Lacs Édouard et Kivu", "Lacs Édouard et Kivu", "IX");\r
+ area.setLevel(level);\r
+ area.setType(NamedAreaType.NATURAL_AREA());\r
+ voc.addTerm(area);\r
+ termService.save(area);\r
+\r
+ area = NamedArea.NewInstance("Rwanda-Burundi", "Rwanda-Burundi", "X");\r
+ area.setLevel(level);\r
+ area.setType(NamedAreaType.NATURAL_AREA());\r
+ voc.addTerm(area);\r
+ termService.save(area);\r
+\r
+ area = NamedArea.NewInstance("Haut-Katanga", "Haut-Katanga", "XI");\r
+ area.setLevel(level);\r
+ area.setType(NamedAreaType.NATURAL_AREA());\r
+ voc.addTerm(area);\r
+ termService.save(area);\r
\r
+ app.getVocabularyService().save(voc);\r
+ \r
+ app.commitTransaction(tx);\r
+\r
}\r
\r
private Reference getSourceReference(String string) {\r