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
.app
.common
.PesiDestinations
;
19 import eu
.etaxonomy
.cdm
.app
.common
.PesiSources
;
20 import eu
.etaxonomy
.cdm
.database
.DbSchemaValidation
;
21 import eu
.etaxonomy
.cdm
.database
.ICdmDataSource
;
22 import eu
.etaxonomy
.cdm
.io
.common
.CdmDefaultImport
;
23 import eu
.etaxonomy
.cdm
.io
.common
.IImportConfigurator
.CHECK
;
24 import eu
.etaxonomy
.cdm
.io
.common
.IImportConfigurator
.DO_REFERENCES
;
25 import eu
.etaxonomy
.cdm
.io
.common
.Source
;
26 import eu
.etaxonomy
.cdm
.io
.pesi
.erms
.ErmsImportConfigurator
;
27 import eu
.etaxonomy
.cdm
.io
.pesi
.out
.PesiTransformer
;
28 import eu
.etaxonomy
.cdm
.model
.name
.TaxonName
;
33 public class ErmsImportActivator
{
35 private static final Logger logger
= Logger
.getLogger(ErmsImportActivator
.class);
37 // static final Source ermsSource = PesiSources.PESI3_ERMS();
38 static final Source ermsSource
= PesiSources
.PESI2019_ERMS();
40 // static final ICdmDataSource cdmDestination = CdmDestinations.test_cdm_pesi_erms();
42 static final ICdmDataSource cdmDestination
= CdmDestinations
.cdm_test_local_mysql_erms();
43 // static final ICdmDataSource cdmDestination = CdmDestinations.cdm_test_local_mysql_erms2();
46 static final boolean includeExport2PESI
= false;
47 static final Source pesiDestination
= !includeExport2PESI ?
null :
48 cdmDestination
== CdmDestinations
.cdm_test_local_mysql_erms()?
49 PesiDestinations
.pesi_test_local_CDM_ERMS2PESI():
50 PesiDestinations
.pesi_test_local_CDM_ERMS2PESI_2() ;
52 static final UUID classificationUuid
= UUID
.fromString("6fa988a9-10b7-48b0-a370-2586fbc066eb");
53 static final String classificationName
= "ERMS 2019";
54 static final String sourceRefTitle
= "ERMS export for PESI";
57 static final CHECK check
= CHECK
.IMPORT_WITHOUT_CHECK
;
58 static final int partitionSize
= 5000;
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
= true;
66 static final boolean doCommonNames
= true;
67 static final boolean doNotes
= true;
68 static final boolean doDistributions
= true;
69 static final boolean doLinks
= true;
70 static final boolean doImages
= true;
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
78 // static final boolean doSourceUse = false;
79 // static final boolean doCommonNames = false;
80 // static final boolean doNotes = false;
81 // static final boolean doDistributions = false;
82 // static final boolean doLinks = false;
83 // static final boolean doImages = false;
85 //private static DbSchemaValidation hbm2dll = (doReferences == DO_REFERENCES.ALL)? DbSchemaValidation.CREATE:DbSchemaValidation.VALIDATE;
86 private static DbSchemaValidation hbm2dll
= DbSchemaValidation
.VALIDATE
;
88 private void doImport(Source source
, ICdmDataSource destination
, DbSchemaValidation hbm2dll
){
89 System
.out
.println("Start import from ("+ ermsSource
.getDatabase() + ") to " + destination
.getDatabase() + " ..." );
93 ErmsImportConfigurator config
= ErmsImportConfigurator
.NewInstance(source
, destination
);
95 config
.setClassificationUuid(classificationUuid
);
97 config
.setDoReferences(doReferences
);
99 config
.setDoTaxa(doTaxa
);
100 config
.setDoRelTaxa(doRelTaxa
);
101 config
.setDoSourceUse(doSourceUse
);
102 config
.setDoLinks(doLinks
);
103 config
.setDoDistributions(doDistributions
);
104 config
.setDoVernaculars(doCommonNames
);
105 config
.setDoNotes(doNotes
);
106 config
.setDoImages(doImages
);
108 config
.setDbSchemaValidation(hbm2dll
);
110 config
.setCheck(check
);
111 config
.setRecordsPerTransaction(partitionSize
);
112 config
.setSourceRefUuid(PesiTransformer
.uuidSourceRefErms
);
113 config
.setClassificationName(classificationName
);
114 config
.setSourceReferenceTitle(sourceRefTitle
);
117 CdmDefaultImport
<ErmsImportConfigurator
> ermsImport
= new CdmDefaultImport
<>();
118 ermsImport
.invoke(config
);
120 if (config
.getCheck().equals(CHECK
.CHECK_AND_IMPORT
) || config
.getCheck().equals(CHECK
.IMPORT_WITHOUT_CHECK
) ){
121 ICdmRepository app
= ermsImport
.getCdmAppController();
122 TaxonName obj
= app
.getCommonService().getSourcedObjectByIdInSource(TaxonName
.class, "1000027", null);
125 System
.out
.println("End import from ("+ source
.getDatabase() + ") to " + destination
.getDatabase() + "...");
128 public static void main(String
[] args
) {
129 ICdmDataSource cdmDB
= CdmDestinations
.chooseDestination(args
) != null ? CdmDestinations
.chooseDestination(args
) : cdmDestination
;
130 ErmsImportActivator ermsImport
= new ErmsImportActivator();
131 ermsImport
.doImport(ermsSource
, cdmDB
, hbm2dll
);
133 if (includeExport2PESI
){
134 PesiExportActivatorERMS ermsExport
= new PesiExportActivatorERMS();
135 ermsExport
.doTaxa
= doTaxa
;
136 ermsExport
.doTreeIndex
= doTaxa
;
137 ermsExport
.doRelTaxa
= doRelTaxa
;
138 ermsExport
.doDescriptions
= doImages
;
140 ermsExport
.doExport(cdmDB
, pesiDestination
);