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
|
package eu.etaxonomy.cdm.app.testUpdate;
|
10
|
|
11
|
import java.util.List;
|
12
|
import java.util.UUID;
|
13
|
|
14
|
import org.apache.log4j.Logger;
|
15
|
import org.springframework.transaction.TransactionStatus;
|
16
|
|
17
|
import eu.etaxonomy.cdm.api.application.ICdmRepository;
|
18
|
import eu.etaxonomy.cdm.app.eflora.CdmDestinations;
|
19
|
import eu.etaxonomy.cdm.app.eflora.EfloraSources;
|
20
|
import eu.etaxonomy.cdm.common.URI;
|
21
|
import eu.etaxonomy.cdm.common.monitor.DefaultProgressMonitor;
|
22
|
import eu.etaxonomy.cdm.database.DbSchemaValidation;
|
23
|
import eu.etaxonomy.cdm.database.ICdmDataSource;
|
24
|
import eu.etaxonomy.cdm.database.update.CdmUpdater;
|
25
|
import eu.etaxonomy.cdm.io.common.CdmDefaultImport;
|
26
|
import eu.etaxonomy.cdm.io.common.IImportConfigurator.CHECK;
|
27
|
import eu.etaxonomy.cdm.io.eflora.EfloraImportConfigurator;
|
28
|
import eu.etaxonomy.cdm.io.eflora.centralAfrica.ericaceae.CentralAfricaEricaceaeImportConfigurator;
|
29
|
import eu.etaxonomy.cdm.model.common.Language;
|
30
|
import eu.etaxonomy.cdm.model.description.Feature;
|
31
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
32
|
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
|
33
|
import eu.etaxonomy.cdm.model.term.TermNode;
|
34
|
import eu.etaxonomy.cdm.model.term.TermTree;
|
35
|
import eu.etaxonomy.cdm.model.term.TermType;
|
36
|
|
37
|
/**
|
38
|
* @author a.mueller
|
39
|
* @since 20.06.2008
|
40
|
*/
|
41
|
public class EricaceaeTestUpdateActivator {
|
42
|
|
43
|
@SuppressWarnings("unused")
|
44
|
private static final Logger logger = Logger.getLogger(EricaceaeTestUpdateActivator.class);
|
45
|
|
46
|
//database validation status (create, update, validate ...)
|
47
|
static DbSchemaValidation hbm2dll = DbSchemaValidation.VALIDATE;
|
48
|
static final URI source = EfloraSources.ericacea_local();
|
49
|
|
50
|
|
51
|
// static final ICdmDataSource cdmDestination = CdmDestinations.cdm_test_andreasM2();
|
52
|
// static final ICdmDataSource cdmDestination = CdmDestinations.cdm_flora_central_africa_preview();
|
53
|
// static final ICdmDataSource cdmDestination = CdmDestinations.cdm_flora_central_africa_production();
|
54
|
static final ICdmDataSource cdmDestination = CdmDestinations.localH2();
|
55
|
// static final ICdmDataSource cdmDestination = CdmDestinations.cdm_local_postgres_CdmTest();
|
56
|
|
57
|
|
58
|
//feature tree uuid
|
59
|
public static final UUID featureTreeUuid = UUID.fromString("051d35ee-22f1-42d8-be07-9e9bfec5bcf7");
|
60
|
|
61
|
public static UUID defaultLanguageUuid = Language.uuidEnglish;
|
62
|
|
63
|
//classification
|
64
|
static final UUID classificationUuid = UUID.fromString("10e5efcc-6e13-4abc-ad42-e0b46e50cbe7");
|
65
|
|
66
|
//check - import
|
67
|
static final CHECK check = CHECK.IMPORT_WITHOUT_CHECK;
|
68
|
|
69
|
static boolean doPrintKeys = false;
|
70
|
|
71
|
//taxa
|
72
|
static final boolean doTaxa = false;
|
73
|
|
74
|
private boolean includeEricaceae = true;
|
75
|
|
76
|
|
77
|
|
78
|
private void doImport(ICdmDataSource cdmDestination){
|
79
|
|
80
|
CdmUpdater updater = new CdmUpdater();
|
81
|
updater.updateToCurrentVersion(cdmDestination, DefaultProgressMonitor.NewInstance());
|
82
|
|
83
|
//make Source
|
84
|
CentralAfricaEricaceaeImportConfigurator config= CentralAfricaEricaceaeImportConfigurator.NewInstance(source, cdmDestination);
|
85
|
config.setClassificationUuid(classificationUuid);
|
86
|
config.setDoTaxa(doTaxa);
|
87
|
config.setCheck(check);
|
88
|
config.setDefaultLanguageUuid(defaultLanguageUuid);
|
89
|
config.setDoPrintKeys(doPrintKeys);
|
90
|
config.setDbSchemaValidation(hbm2dll);
|
91
|
|
92
|
CdmDefaultImport<EfloraImportConfigurator> myImport = new CdmDefaultImport<EfloraImportConfigurator>();
|
93
|
|
94
|
ICdmRepository app = myImport.getCdmAppController();
|
95
|
|
96
|
//
|
97
|
if (includeEricaceae){
|
98
|
System.out.println("Start import from ("+ source.toString() + ") ...");
|
99
|
config.setSourceReference(getSourceReference(config.getSourceReferenceTitle()));
|
100
|
myImport.invoke(config);
|
101
|
System.out.println("End import from ("+ source.toString() + ")...");
|
102
|
}
|
103
|
|
104
|
app = myImport.getCdmAppController();
|
105
|
|
106
|
TransactionStatus tx = app.startTransaction();
|
107
|
List<TermTree> featureTrees = app.getTermTreeService().list(TermType.Feature, null, null, null, null);
|
108
|
for (TermTree<Feature> tree :featureTrees){
|
109
|
if (tree.getClass().getSimpleName().equalsIgnoreCase("FeatureTree")){
|
110
|
moveChild(app, tree);
|
111
|
}
|
112
|
}
|
113
|
app.commitTransaction(tx);
|
114
|
}
|
115
|
|
116
|
private void moveChild(ICdmRepository app, TermTree<Feature> tree) {
|
117
|
TermNode<Feature> root = tree.getRoot();
|
118
|
int count = root.getChildCount();
|
119
|
TermNode<Feature> lastChild = root.getChildAt(count - 1);
|
120
|
root.removeChild(lastChild);
|
121
|
root.addChild(lastChild, 1);
|
122
|
app.getTermTreeService().saveOrUpdate(tree);
|
123
|
}
|
124
|
|
125
|
private Reference getSourceReference(String string) {
|
126
|
Reference result = ReferenceFactory.newGeneric();
|
127
|
result.setTitleCache(string, true);
|
128
|
return result;
|
129
|
}
|
130
|
|
131
|
public static void main(String[] args) {
|
132
|
EricaceaeTestUpdateActivator me = new EricaceaeTestUpdateActivator();
|
133
|
me.doImport(cdmDestination);
|
134
|
}
|
135
|
}
|