1
|
/**
|
2
|
* Copyright (C) 2007 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*
|
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.
|
8
|
*/
|
9
|
|
10
|
package eu.etaxonomy.cdm.app.eflora;
|
11
|
|
12
|
import java.util.UUID;
|
13
|
|
14
|
import org.apache.log4j.Logger;
|
15
|
|
16
|
import eu.etaxonomy.cdm.api.service.ITermService;
|
17
|
import eu.etaxonomy.cdm.database.DbSchemaValidation;
|
18
|
import eu.etaxonomy.cdm.database.ICdmDataSource;
|
19
|
import eu.etaxonomy.cdm.io.common.CdmDefaultImport;
|
20
|
import eu.etaxonomy.cdm.io.common.IImportConfigurator.CHECK;
|
21
|
import eu.etaxonomy.cdm.io.common.Source;
|
22
|
import eu.etaxonomy.cdm.io.eflora.centralAfrica.ferns.CentralAfricaFernsImportConfigurator;
|
23
|
import eu.etaxonomy.cdm.model.description.Feature;
|
24
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
25
|
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
|
26
|
import eu.etaxonomy.cdm.model.term.TermNode;
|
27
|
import eu.etaxonomy.cdm.model.term.TermTree;
|
28
|
|
29
|
/**
|
30
|
* @author a.mueller
|
31
|
* @since 20.06.2008
|
32
|
* @version 1.0
|
33
|
*/
|
34
|
public class CentralAfricaFernsActivator {
|
35
|
@SuppressWarnings("unused")
|
36
|
private static final Logger logger = Logger.getLogger(CentralAfricaFernsActivator.class);
|
37
|
|
38
|
//database validation status (create, update, validate ...)
|
39
|
static DbSchemaValidation hbm2dll = DbSchemaValidation.CREATE;
|
40
|
static final Source mySource = CdmImportSources.AFRICA_FERNS_ACCESS();
|
41
|
|
42
|
// static final ICdmDataSource cdmDestination = CdmDestinations.cdm_test_andreasM2();
|
43
|
// static final ICdmDataSource cdmDestination = CdmDestinations.cdm_flora_central_africa_preview();
|
44
|
// static final ICdmDataSource cdmDestination = CdmDestinations.cdm_flora_central_africa_production();
|
45
|
static final ICdmDataSource cdmDestination = CdmDestinations.localH2();
|
46
|
// static final ICdmDataSource cdmDestination = CdmDestinations.cdm_local_postgres_CdmTest();
|
47
|
// static final ICdmDataSource cdmDestination = CdmDestinations.cdm_test_local_mysql();
|
48
|
|
49
|
//feature tree uuid
|
50
|
public static final UUID featureTreeUuid = UUID.fromString("62d930cb-aabb-461c-ad16-0fdbd2bae592");
|
51
|
|
52
|
public static final String sourceReference = "Flora of Central Africa";
|
53
|
|
54
|
public static final String classificationName = "Flora of Central Africa - Ferns";
|
55
|
|
56
|
//classification
|
57
|
static final UUID classificationUuid = UUID.fromString("a90fa160-8f33-4a19-9c5a-ab05a1553017");
|
58
|
|
59
|
//check - import
|
60
|
static final CHECK check = CHECK.IMPORT_WITHOUT_CHECK;
|
61
|
|
62
|
// static boolean doPrintKeys = false;
|
63
|
|
64
|
//taxa
|
65
|
static final boolean doTaxa = true;
|
66
|
|
67
|
// private boolean includeSapindaceae1 = true;
|
68
|
|
69
|
|
70
|
|
71
|
private void doImport(ICdmDataSource cdmDestination){
|
72
|
|
73
|
|
74
|
//make Source
|
75
|
Source source = mySource;
|
76
|
|
77
|
// mySource.getResultSet("SELECT * FROM tmp");
|
78
|
CentralAfricaFernsImportConfigurator config= CentralAfricaFernsImportConfigurator.NewInstance(source, cdmDestination);
|
79
|
config.setClassificationUuid(classificationUuid);
|
80
|
config.setClassificationName(classificationName);
|
81
|
config.setDoTaxa(doTaxa);
|
82
|
config.setCheck(check);
|
83
|
// configsetDoPrintKeys(doPrintKeys);
|
84
|
config.setDbSchemaValidation(hbm2dll);
|
85
|
|
86
|
CdmDefaultImport<CentralAfricaFernsImportConfigurator> myImport = new CdmDefaultImport<CentralAfricaFernsImportConfigurator>();
|
87
|
|
88
|
|
89
|
// if (includeSapindaceae1){
|
90
|
System.out.println("Start import from ("+ source.toString() + ") ...");
|
91
|
config.setSourceReference(getSourceReference(sourceReference));
|
92
|
myImport.invoke(config);
|
93
|
System.out.println("End import from ("+ source.toString() + ")...");
|
94
|
// }
|
95
|
|
96
|
TermTree<Feature> tree = makeFeatureNode(myImport.getCdmAppController().getTermService());
|
97
|
myImport.getCdmAppController().getTermTreeService().saveOrUpdate(tree);
|
98
|
|
99
|
//check keys
|
100
|
// if (doPrintKeys){
|
101
|
// TransactionStatus tx = myImport.getCdmAppController().startTransaction();
|
102
|
// List<FeatureTree> keys = myImport.getCdmAppController().getTermTreeService().list(PolytomousKey.class, null, null, null, null);
|
103
|
// for(FeatureTree key : keys){
|
104
|
// ((PolytomousKey)key).print(System.out);
|
105
|
// System.out.println();
|
106
|
// }
|
107
|
// myImport.getCdmAppController().commitTransaction(tx);
|
108
|
// }
|
109
|
|
110
|
}
|
111
|
|
112
|
private Reference getSourceReference(String string) {
|
113
|
Reference result = ReferenceFactory.newGeneric();
|
114
|
result.setTitleCache(string, true);
|
115
|
return result;
|
116
|
}
|
117
|
|
118
|
private TermTree<Feature> makeFeatureNode(ITermService service){
|
119
|
|
120
|
TermTree<Feature> result = TermTree.NewFeatureInstance(featureTreeUuid);
|
121
|
result.setTitleCache("Flora Malesiana Presentation Feature Tree", true);
|
122
|
TermNode<Feature> root = result.getRoot();
|
123
|
TermNode<Feature> newNode = root.addChild(Feature.CITATION());
|
124
|
|
125
|
root.addChild(Feature.DESCRIPTION());
|
126
|
|
127
|
return result;
|
128
|
}
|
129
|
|
130
|
public static void main(String[] args) {
|
131
|
CentralAfricaFernsActivator me = new CentralAfricaFernsActivator();
|
132
|
me.doImport(cdmDestination);
|
133
|
}
|
134
|
|
135
|
}
|