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.wp6.cichorieae;
|
11
|
|
12
|
import java.util.Arrays;
|
13
|
import java.util.List;
|
14
|
import java.util.UUID;
|
15
|
|
16
|
import org.apache.log4j.Logger;
|
17
|
|
18
|
import eu.etaxonomy.cdm.api.application.CdmApplicationController;
|
19
|
import eu.etaxonomy.cdm.api.service.config.CacheUpdaterConfigurator;
|
20
|
import eu.etaxonomy.cdm.app.common.CdmDestinations;
|
21
|
import eu.etaxonomy.cdm.common.monitor.IRemotingProgressMonitor;
|
22
|
import eu.etaxonomy.cdm.database.DbSchemaValidation;
|
23
|
import eu.etaxonomy.cdm.database.ICdmDataSource;
|
24
|
import eu.etaxonomy.cdm.io.api.application.CdmIoApplicationController;
|
25
|
import eu.etaxonomy.cdm.io.common.CdmDefaultImport;
|
26
|
import eu.etaxonomy.cdm.io.common.ImportResult;
|
27
|
import eu.etaxonomy.cdm.model.name.TaxonName;
|
28
|
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
|
29
|
|
30
|
|
31
|
/**
|
32
|
* TODO add the following to a wiki page:
|
33
|
* HINT: If you are about to import into a mysql data base running under windows and if you wish to dump and restore the resulting data bas under another operation systen
|
34
|
* you must set the mysql system variable lower_case_table_names = 0 in order to create data base with table compatible names.
|
35
|
*
|
36
|
*
|
37
|
* @author a.mueller
|
38
|
*
|
39
|
*/
|
40
|
public class CichorieaeCacheUpdater {
|
41
|
private static final Logger logger = Logger.getLogger(CichorieaeCacheUpdater.class);
|
42
|
|
43
|
//database validation status (create, update, validate ...)
|
44
|
static DbSchemaValidation hbm2dll = DbSchemaValidation.VALIDATE;
|
45
|
static final ICdmDataSource cdmDestination = CdmDestinations.cdm_production_cichorieae();
|
46
|
|
47
|
static final List<String> classListStrings = Arrays.asList(new String[]{
|
48
|
//IdentifiableEntity.class.getName(),
|
49
|
// IdentifiableEntity.class.getName(),
|
50
|
TaxonName.class.getName(),
|
51
|
TaxonBase.class.getName()
|
52
|
});
|
53
|
//new ArrayList<Class<? extends IdentifiableEntity>>();
|
54
|
|
55
|
// **************** ALL *********************
|
56
|
|
57
|
// //DescriptionBase
|
58
|
// static final boolean doTaxonDescription = true;
|
59
|
// static final boolean doSpecimenDescription = true;
|
60
|
// static final boolean doNameDescription = true;
|
61
|
//
|
62
|
// //AgentBase
|
63
|
// static final boolean doPerson = true;
|
64
|
// static final boolean doTeam = true;
|
65
|
// static final boolean doInstitution = true;
|
66
|
//
|
67
|
// //MediaEntities
|
68
|
// static final boolean doCollection = true;
|
69
|
// static final boolean doReferenceBase = true;
|
70
|
//
|
71
|
// //SpecimenOrObservationBase
|
72
|
// static final boolean doFieldObservation = true;
|
73
|
// static final boolean doDeriveUnit = true;
|
74
|
// static final boolean doLivingBeing = true;
|
75
|
// static final boolean doObservation = true;
|
76
|
// static final boolean doSpecimen = true;
|
77
|
//
|
78
|
// //Media
|
79
|
// static final boolean doMedia = true;
|
80
|
// static final boolean doMediaKey = true;
|
81
|
// static final boolean doFigure = true;
|
82
|
// static final boolean doPhylogenticTree = true;
|
83
|
//
|
84
|
//
|
85
|
// //TaxonBase
|
86
|
// static final boolean doTaxon = true;
|
87
|
// static final boolean doSynonym = true;
|
88
|
//
|
89
|
// static final boolean doSequence = true;
|
90
|
//
|
91
|
// //Names
|
92
|
// static final boolean doViralName = true;
|
93
|
// static final boolean doNonViralName = true;
|
94
|
// static final boolean doBotanicalName = true;
|
95
|
// static final boolean doZoologicalName = true;
|
96
|
// static final boolean doCultivarPlantName = true;
|
97
|
//
|
98
|
// static final boolean doClassification = true;
|
99
|
//
|
100
|
// //TermBase
|
101
|
// static final boolean doFeatureTree = true;
|
102
|
// static final boolean doPolytomousKey = true;
|
103
|
//
|
104
|
// static final boolean doTermVocabulary = true;
|
105
|
// static final boolean doDefinedTermBase = true;
|
106
|
//
|
107
|
|
108
|
|
109
|
private ImportResult doInvoke(ICdmDataSource destination){
|
110
|
ImportResult success = null;
|
111
|
|
112
|
CacheUpdaterConfigurator config;
|
113
|
try {
|
114
|
config = CacheUpdaterConfigurator.NewInstance(classListStrings);
|
115
|
|
116
|
// invoke import
|
117
|
CdmApplicationController appCtrInit = CdmIoApplicationController.NewInstance(destination, DbSchemaValidation.VALIDATE, false);
|
118
|
appCtrInit.authenticate("admin", "kups366+RU");
|
119
|
UUID monitUuid = appCtrInit.getLongRunningTasksService().monitLongRunningTask(config);
|
120
|
IRemotingProgressMonitor monitor = appCtrInit.getProgressMonitorService().getRemotingMonitor(monitUuid);
|
121
|
while(monitor != null && (!monitor.isCanceled() || !monitor.isDone() || !monitor.isFailed())) {
|
122
|
try {
|
123
|
Thread.sleep(10);
|
124
|
} catch (InterruptedException e) {
|
125
|
// TODO Auto-generated catch block
|
126
|
e.printStackTrace();
|
127
|
}
|
128
|
logger.info("Waiting for monitered work to start ..");
|
129
|
monitor = appCtrInit.getProgressMonitorService().getRemotingMonitor(monitUuid);
|
130
|
}
|
131
|
|
132
|
|
133
|
String successString = monitor == null || monitor.isDone() ? "successful" : " with errors ";
|
134
|
System.out.println("End updating caches for "+ destination.getDatabase() + "..." + successString);
|
135
|
return success;
|
136
|
} catch (ClassNotFoundException e) {
|
137
|
logger.error(e);
|
138
|
success = new ImportResult();
|
139
|
success.addException(e);
|
140
|
return success;
|
141
|
}
|
142
|
}
|
143
|
|
144
|
/**
|
145
|
* @param args
|
146
|
*/
|
147
|
public static void main(String[] args) {
|
148
|
ICdmDataSource destination = CdmDestinations.chooseDestination(args) != null ? CdmDestinations.chooseDestination(args) : cdmDestination;
|
149
|
|
150
|
System.out.println("Start updating caches for "+ destination.getDatabase() + "...");
|
151
|
CichorieaeCacheUpdater me = new CichorieaeCacheUpdater();
|
152
|
me.doInvoke(destination);
|
153
|
|
154
|
}
|
155
|
|
156
|
}
|