2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
10 package eu
.etaxonomy
.cdm
.app
.pesi
;
12 import java
.util
.UUID
;
14 import org
.apache
.log4j
.Logger
;
16 import eu
.etaxonomy
.cdm
.api
.application
.ICdmRepository
;
17 import eu
.etaxonomy
.cdm
.app
.common
.CdmDestinations
;
18 import eu
.etaxonomy
.cdm
.database
.DbSchemaValidation
;
19 import eu
.etaxonomy
.cdm
.database
.ICdmDataSource
;
20 import eu
.etaxonomy
.cdm
.io
.common
.CdmDefaultImport
;
21 import eu
.etaxonomy
.cdm
.io
.common
.IImportConfigurator
.CHECK
;
22 import eu
.etaxonomy
.cdm
.io
.common
.IImportConfigurator
.DO_REFERENCES
;
23 import eu
.etaxonomy
.cdm
.io
.common
.Source
;
24 import eu
.etaxonomy
.cdm
.io
.pesi
.erms
.ErmsImportConfigurator
;
25 import eu
.etaxonomy
.cdm
.io
.pesi
.out
.PesiTransformer
;
26 import eu
.etaxonomy
.cdm
.model
.name
.TaxonName
;
27 import eu
.etaxonomy
.cdm
.model
.reference
.ISourceable
;
32 public class ErmsImportActivator
{
34 private static final Logger logger
= Logger
.getLogger(ErmsImportActivator
.class);
36 // static final Source ermsSource = PesiSources.PESI3_ERMS();
37 static final Source ermsSource
= PesiSources
.PESI2019_ERMS();
39 // static final ICdmDataSource cdmDestination = CdmDestinations.test_cdm_pesi_erms();
40 static final ICdmDataSource cdmDestination
= CdmDestinations
.cdm_test_local_mysql_erms();
41 // static final ICdmDataSource cdmDestination = CdmDestinations.cdm_test_local_mysql_erms2();
43 static final Source pesiDestination
=
44 cdmDestination
== CdmDestinations
.cdm_test_local_mysql_erms()?
45 PesiDestinations
.pesi_test_local_CDM_ERMS2PESI():
46 PesiDestinations
.pesi_test_local_CDM_ERMS2PESI_2() ;
48 static final boolean includeExport2PESI
= false;
50 static final UUID classificationUuid
= UUID
.fromString("6fa988a9-10b7-48b0-a370-2586fbc066eb");
51 static final String classificationName
= "ERMS 2019";
52 static final String sourceRefTitle
= "ERMS export for PESI";
55 static final CHECK check
= CHECK
.IMPORT_WITHOUT_CHECK
;
56 static final int partitionSize
= 5000;
58 static final boolean ignoreNull
= true;
60 // ***************** ALL ************************************************//
62 // static final DO_REFERENCES doReferences = DO_REFERENCES.ALL;
63 // static final boolean doTaxa = true;
64 // static final boolean doRelTaxa = doTaxa; //should always run with doTaxa because dependent on state from doTaxa
65 // static final boolean doSourceUse = false;
66 // static final boolean doCommonNames = false;
67 // static final boolean doNotes = false;
68 // static final boolean doDistributions = false;
69 // static final boolean doLinks = false;
70 // static final boolean doImages = false;
72 //******************** NONE ***************************************//
74 static final DO_REFERENCES doReferences
= DO_REFERENCES
.NONE
;
75 static final boolean doTaxa
= false;
76 static final boolean doRelTaxa
= doTaxa
; //should always run with doTaxa because depends on state from doTaxa
77 static final boolean doSourceUse
= true;
78 static final boolean doCommonNames
= true;
79 static final boolean doNotes
= true;
80 static final boolean doDistributions
= true;
81 static final boolean doLinks
= true;
82 static final boolean doImages
= true;
84 private static DbSchemaValidation hbm2dll
= (doReferences
== DO_REFERENCES
.ALL
)? DbSchemaValidation
.CREATE
:DbSchemaValidation
.VALIDATE
;
86 private void doImport(Source source
, ICdmDataSource destination
, DbSchemaValidation hbm2dll
){
87 System
.out
.println("Start import from ("+ ermsSource
.getDatabase() + ") to " + cdmDestination
.getDatabase() + " ..." );
91 ErmsImportConfigurator config
= ErmsImportConfigurator
.NewInstance(source
, destination
);
93 config
.setClassificationUuid(classificationUuid
);
95 config
.setIgnoreNull(ignoreNull
);
96 config
.setDoReferences(doReferences
);
98 config
.setDoTaxa(doTaxa
);
99 config
.setDoRelTaxa(doRelTaxa
);
100 config
.setDoSourceUse(doSourceUse
);
101 config
.setDoLinks(doLinks
);
102 config
.setDoDistributions(doDistributions
);
103 config
.setDoVernaculars(doCommonNames
);
104 config
.setDoNotes(doNotes
);
105 config
.setDoImages(doImages
);
107 config
.setDbSchemaValidation(hbm2dll
);
109 config
.setCheck(check
);
110 config
.setRecordsPerTransaction(partitionSize
);
111 config
.setSourceRefUuid(PesiTransformer
.uuidSourceRefErms
);
112 config
.setClassificationName(classificationName
);
113 config
.setSourceReferenceTitle(sourceRefTitle
);
116 CdmDefaultImport
<ErmsImportConfigurator
> ermsImport
= new CdmDefaultImport
<>();
117 ermsImport
.invoke(config
);
119 if (config
.getCheck().equals(CHECK
.CHECK_AND_IMPORT
) || config
.getCheck().equals(CHECK
.IMPORT_WITHOUT_CHECK
) ){
120 ICdmRepository app
= ermsImport
.getCdmAppController();
121 ISourceable
<?
> obj
= app
.getCommonService().getSourcedObjectByIdInSource(TaxonName
.class, "1000027", null);
124 // //make feature tree
125 // FeatureTree tree = TreeCreator.flatTree(featureTreeUuid, ermsImportConfigurator.getFeatureMap(), featureKeyList);
126 // app = ermsImport.getCdmAppController();
127 // app.getFeatureTreeService().saveOrUpdate(tree);
129 System
.out
.println("End import from ("+ source
.getDatabase() + ") to "+cdmDestination
.getDatabase() + "...");
132 public static void main(String
[] args
) {
133 ICdmDataSource cdmDB
= CdmDestinations
.chooseDestination(args
) != null ? CdmDestinations
.chooseDestination(args
) : cdmDestination
;
134 ErmsImportActivator ermsImport
= new ErmsImportActivator();
135 ermsImport
.doImport(ermsSource
, cdmDB
, hbm2dll
);
137 if (includeExport2PESI
){
138 PesiExportActivatorERMS ermsExport
= new PesiExportActivatorERMS();
139 ermsExport
.doTaxa
= doTaxa
;
140 ermsExport
.doTreeIndex
= doTaxa
;
141 ermsExport
.doRelTaxa
= doRelTaxa
;
142 // ermsExport.doInferredSynonyms = doRelTaxa;
143 ermsExport
.doDescriptions
= doImages
;
145 ermsExport
.doExport(cdmDB
, pesiDestination
);