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