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.io.operation.config;
|
10
|
|
11
|
import java.util.ArrayList;
|
12
|
import java.util.Collection;
|
13
|
import java.util.List;
|
14
|
|
15
|
import org.apache.log4j.Logger;
|
16
|
|
17
|
import eu.etaxonomy.cdm.database.ICdmDataSource;
|
18
|
import eu.etaxonomy.cdm.io.common.DefaultImportState;
|
19
|
import eu.etaxonomy.cdm.io.common.IImportConfigurator;
|
20
|
import eu.etaxonomy.cdm.io.common.ImportConfiguratorBase;
|
21
|
import eu.etaxonomy.cdm.io.common.ImportStateBase;
|
22
|
import eu.etaxonomy.cdm.io.operation.CacheUpdater;
|
23
|
import eu.etaxonomy.cdm.io.operation.CacheUpdaterWithNewCacheStrategy;
|
24
|
import eu.etaxonomy.cdm.model.common.IdentifiableEntity;
|
25
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
26
|
|
27
|
/**
|
28
|
* @author a.mueller
|
29
|
* @since 02-Jul-2010 13:06:43
|
30
|
*
|
31
|
*/
|
32
|
public class CacheUpdaterConfigurator extends ImportConfiguratorBase<DefaultImportState<CacheUpdaterConfigurator>, Object> implements IImportConfigurator{
|
33
|
@SuppressWarnings("unused")
|
34
|
private static final Logger logger = Logger.getLogger(CacheUpdaterConfigurator.class);
|
35
|
|
36
|
|
37
|
private boolean updateCacheStrategies = false;
|
38
|
|
39
|
public static CacheUpdaterConfigurator NewInstance(ICdmDataSource destination){
|
40
|
return new CacheUpdaterConfigurator(destination, false);
|
41
|
}
|
42
|
|
43
|
/**
|
44
|
* Returns a new Configurator with all boolean values set to false
|
45
|
* @param allFalse
|
46
|
* @return
|
47
|
*/
|
48
|
public static CacheUpdaterConfigurator NewInstance(ICdmDataSource destination, boolean allTrue){
|
49
|
return new CacheUpdaterConfigurator(destination, allTrue);
|
50
|
}
|
51
|
|
52
|
public static CacheUpdaterConfigurator NewInstance(ICdmDataSource destination, List<Class<? extends IdentifiableEntity>> classList){
|
53
|
CacheUpdaterConfigurator result = new CacheUpdaterConfigurator(destination, true);
|
54
|
result.setClassList(classList);
|
55
|
return result;
|
56
|
}
|
57
|
|
58
|
public static CacheUpdaterConfigurator NewInstance(ICdmDataSource destination, Collection<String> classListNames) throws ClassNotFoundException{
|
59
|
CacheUpdaterConfigurator result = new CacheUpdaterConfigurator(destination, true);
|
60
|
List<Class<? extends IdentifiableEntity>> classList = new ArrayList<Class<? extends IdentifiableEntity>>();
|
61
|
for (String className : classListNames){
|
62
|
Class clazz = Class.forName(className);
|
63
|
classList.add(clazz);
|
64
|
}
|
65
|
result.setClassList(classList);
|
66
|
return result;
|
67
|
}
|
68
|
|
69
|
public static CacheUpdaterConfigurator NewInstance(ICdmDataSource destination, Collection<String> classListNames, boolean doUpdateCacheStrategies) throws ClassNotFoundException{
|
70
|
CacheUpdaterConfigurator result = new CacheUpdaterConfigurator(destination, false);
|
71
|
List<Class<? extends IdentifiableEntity>> classList = new ArrayList<Class<? extends IdentifiableEntity>>();
|
72
|
for (String className : classListNames){
|
73
|
Class clazz = Class.forName(className);
|
74
|
classList.add(clazz);
|
75
|
}
|
76
|
result.setClassList(classList);
|
77
|
result.setUpdateCacheStrategy(doUpdateCacheStrategies);
|
78
|
return result;
|
79
|
}
|
80
|
|
81
|
|
82
|
|
83
|
// //DescriptionBase
|
84
|
// private boolean doTaxonDescription = true;
|
85
|
// private boolean doSpecimenDescription = true;
|
86
|
// private boolean doNameDescription = true;
|
87
|
//
|
88
|
// //AgentBase
|
89
|
// private boolean doPerson = true;
|
90
|
// private boolean doTeam = true;
|
91
|
// private boolean doInstitution = true;
|
92
|
//
|
93
|
// //MediaEntities
|
94
|
// private boolean doCollection = true;
|
95
|
// private boolean doReferenceBase = true;
|
96
|
//
|
97
|
// //SpecimenOrObservationBase
|
98
|
// private boolean doFieldUnit = true;
|
99
|
// private boolean doDeriveUnit = true;
|
100
|
// private boolean doDnaSample = true;
|
101
|
//
|
102
|
// //Media
|
103
|
// private boolean doMedia = true;
|
104
|
// private boolean doMediaKey = true;
|
105
|
// private boolean doPhylogenticTree = true;
|
106
|
//
|
107
|
//
|
108
|
// //TaxonBase
|
109
|
// private boolean doTaxon = true;
|
110
|
// private boolean doSynonym = true;
|
111
|
//
|
112
|
// private boolean doSequence = true;
|
113
|
//
|
114
|
// //Names
|
115
|
// private boolean doTaxonName = true;
|
116
|
//
|
117
|
// private boolean doClassification = true;
|
118
|
//
|
119
|
// //TermBase
|
120
|
// private boolean doFeatureTree = true;
|
121
|
// private boolean doPolytomousKey = true;
|
122
|
//
|
123
|
// private boolean doTermVocabulary = true;
|
124
|
// private boolean doDefinedTermBase = true;
|
125
|
private List<Class<? extends IdentifiableEntity>> classList;
|
126
|
|
127
|
private CacheUpdaterConfigurator(ICdmDataSource destination, boolean allFalse){
|
128
|
super(null);
|
129
|
this.setDestination(destination);
|
130
|
this.classList = new ArrayList<Class<? extends IdentifiableEntity>>();
|
131
|
if (allFalse){
|
132
|
//DescriptionBase
|
133
|
// doTaxonDescription = false;
|
134
|
// doSpecimenDescription = false;
|
135
|
// doNameDescription = false;
|
136
|
//
|
137
|
// //AgentBase
|
138
|
// doPerson = false;
|
139
|
// doTeam = false;
|
140
|
// doInstitution = false;
|
141
|
//
|
142
|
// //MediaEntities
|
143
|
// doCollection = false;
|
144
|
// doReferenceBase = false;
|
145
|
//
|
146
|
// //SpecimenOrObservationBase
|
147
|
// doFieldUnit = false;
|
148
|
// doDeriveUnit = false;
|
149
|
// doDnaSample = false;
|
150
|
//
|
151
|
// //Media
|
152
|
// doMedia = false;
|
153
|
// doMediaKey = false;
|
154
|
// doPhylogenticTree = false;
|
155
|
//
|
156
|
//
|
157
|
// //TaxonBase
|
158
|
// doTaxon = false;
|
159
|
// doSynonym = false;
|
160
|
//
|
161
|
// doSequence = false;
|
162
|
//
|
163
|
// //Names
|
164
|
// doTaxonName = false;
|
165
|
//
|
166
|
// doClassification = false;
|
167
|
//
|
168
|
// //TermBase
|
169
|
// doFeatureTree = false;
|
170
|
// doPolytomousKey = false;
|
171
|
//
|
172
|
// doTermVocabulary = false;
|
173
|
// doDefinedTermBase = false;
|
174
|
}
|
175
|
}
|
176
|
|
177
|
|
178
|
|
179
|
// **************** GETTER / SETTER ************************************
|
180
|
|
181
|
|
182
|
public List<Class<? extends IdentifiableEntity>> getClassList(){
|
183
|
// classList.sort(new ClassComparator());
|
184
|
return classList;
|
185
|
}
|
186
|
private void setClassList(List<Class<? extends IdentifiableEntity>> classList) {
|
187
|
this.classList = classList;
|
188
|
}
|
189
|
|
190
|
|
191
|
// public void setDoTaxonDescription(boolean doTaxonDescription) {
|
192
|
// this.doTaxonDescription = doTaxonDescription;
|
193
|
// }
|
194
|
// public boolean isDoTaxonDescription() {
|
195
|
// return doTaxonDescription;
|
196
|
// }
|
197
|
// public void setDoSpecimenDescription(boolean doSpecimenDescription) {
|
198
|
// this.doSpecimenDescription = doSpecimenDescription;
|
199
|
// }
|
200
|
// public boolean isDoSpecimenDescription() {
|
201
|
// return doSpecimenDescription;
|
202
|
// }
|
203
|
// public void setDoNameDescription(boolean doNameDescription) {
|
204
|
// this.doNameDescription = doNameDescription;
|
205
|
// }
|
206
|
// public boolean isDoNameDescription() {
|
207
|
// return doNameDescription;
|
208
|
// }
|
209
|
// public void setDoPerson(boolean doPerson) {
|
210
|
// this.doPerson = doPerson;
|
211
|
// }
|
212
|
// public boolean isDoPerson() {
|
213
|
// return doPerson;
|
214
|
// }
|
215
|
// public void setDoTeam(boolean doTeam) {
|
216
|
// this.doTeam = doTeam;
|
217
|
// }
|
218
|
// public boolean isDoTeam() {
|
219
|
// return doTeam;
|
220
|
// }
|
221
|
// public void setDoInstitution(boolean doInstitution) {
|
222
|
// this.doInstitution = doInstitution;
|
223
|
// }
|
224
|
// public boolean isDoInstitution() {
|
225
|
// return doInstitution;
|
226
|
// }
|
227
|
// public void setDoCollection(boolean doCollection) {
|
228
|
// this.doCollection = doCollection;
|
229
|
// }
|
230
|
// public boolean isDoCollection() {
|
231
|
// return doCollection;
|
232
|
// }
|
233
|
// public void setDoReferenceBase(boolean doReferenceBase) {
|
234
|
// this.doReferenceBase = doReferenceBase;
|
235
|
// }
|
236
|
// public boolean isDoReferenceBase() {
|
237
|
// return doReferenceBase;
|
238
|
// }
|
239
|
// public void setDoFieldUnit(boolean doFieldUnit) {
|
240
|
// this.doFieldUnit = doFieldUnit;
|
241
|
// }
|
242
|
// public boolean isDoFieldUnit() {
|
243
|
// return doFieldUnit;
|
244
|
// }
|
245
|
// public void setDoDeriveUnit(boolean doDeriveUnit) {
|
246
|
// this.doDeriveUnit = doDeriveUnit;
|
247
|
// }
|
248
|
// public boolean isDoDeriveUnit() {
|
249
|
// return doDeriveUnit;
|
250
|
// }
|
251
|
// public void setDoDnaSample(boolean doDnaSample) {
|
252
|
// this.doDnaSample = doDnaSample;
|
253
|
// }
|
254
|
// public boolean isDoDnaSample() {
|
255
|
// return doDnaSample;
|
256
|
// }
|
257
|
// public void setDoMedia(boolean doMedia) {
|
258
|
// this.doMedia = doMedia;
|
259
|
// }
|
260
|
// public boolean isDoMedia() {
|
261
|
// return doMedia;
|
262
|
// }
|
263
|
// public void setDoMediaKey(boolean doMediaKey) {
|
264
|
// this.doMediaKey = doMediaKey;
|
265
|
// }
|
266
|
// public boolean isDoMediaKey() {
|
267
|
// return doMediaKey;
|
268
|
// }
|
269
|
// public void setDoPhylogenticTree(boolean doPhylogenticTree) {
|
270
|
// this.doPhylogenticTree = doPhylogenticTree;
|
271
|
// }
|
272
|
// public boolean isDoPhylogenticTree() {
|
273
|
// return doPhylogenticTree;
|
274
|
// }
|
275
|
// public void setDoTaxon(boolean doTaxon) {
|
276
|
// this.doTaxon = doTaxon;
|
277
|
// }
|
278
|
// public boolean isDoTaxon() {
|
279
|
// return doTaxon;
|
280
|
// }
|
281
|
// public void setDoSynonym(boolean doSynonym) {
|
282
|
// this.doSynonym = doSynonym;
|
283
|
// }
|
284
|
// public boolean isDoSynonym() {
|
285
|
// return doSynonym;
|
286
|
// }
|
287
|
// public void setDoSequence(boolean doSequence) {
|
288
|
// this.doSequence = doSequence;
|
289
|
// }
|
290
|
// public boolean isDoSequence() {
|
291
|
// return doSequence;
|
292
|
// }
|
293
|
// public void setDoClassification(boolean doClassification) {
|
294
|
// this.doClassification = doClassification;
|
295
|
// }
|
296
|
// public boolean isDoClassification() {
|
297
|
// return doClassification;
|
298
|
// }
|
299
|
// public void setDoFeatureTree(boolean doFeatureTree) {
|
300
|
// this.doFeatureTree = doFeatureTree;
|
301
|
// }
|
302
|
// public boolean isDoFeatureTree() {
|
303
|
// return doFeatureTree;
|
304
|
// }
|
305
|
// public void setDoPolytomousKey(boolean doPolytomousKey) {
|
306
|
// this.doPolytomousKey = doPolytomousKey;
|
307
|
// }
|
308
|
// public boolean isDoPolytomousKey() {
|
309
|
// return doPolytomousKey;
|
310
|
// }
|
311
|
// public void setDoTermVocabulary(boolean doTermVocabulary) {
|
312
|
// this.doTermVocabulary = doTermVocabulary;
|
313
|
// }
|
314
|
// public boolean isDoTermVocabulary() {
|
315
|
// return doTermVocabulary;
|
316
|
// }
|
317
|
// public void setDoDefinedTermBase(boolean doDefinedTermBase) {
|
318
|
// this.doDefinedTermBase = doDefinedTermBase;
|
319
|
// }
|
320
|
// public boolean isDoDefinedTermBase() {
|
321
|
// return doDefinedTermBase;
|
322
|
// }
|
323
|
|
324
|
@Override
|
325
|
public Reference getSourceReference() {
|
326
|
//not needed here
|
327
|
return null;
|
328
|
}
|
329
|
|
330
|
@Override
|
331
|
protected void makeIoClassList() {
|
332
|
if (this.doUpdateCacheStrategy()){
|
333
|
ioClassList = new Class[]{
|
334
|
CacheUpdaterWithNewCacheStrategy.class
|
335
|
};
|
336
|
}else{
|
337
|
ioClassList = new Class[]{
|
338
|
CacheUpdater.class
|
339
|
};
|
340
|
}
|
341
|
}
|
342
|
|
343
|
@Override
|
344
|
public <STATE extends ImportStateBase> STATE getNewState() {
|
345
|
return (STATE) new DefaultImportState(this);
|
346
|
}
|
347
|
|
348
|
@Override
|
349
|
public boolean isValid() {
|
350
|
//as no source needs to exist
|
351
|
return true;
|
352
|
}
|
353
|
|
354
|
@Override
|
355
|
public String getSourceNameString() {
|
356
|
//not needed here
|
357
|
return null;
|
358
|
}
|
359
|
|
360
|
public boolean doUpdateCacheStrategy() {
|
361
|
return updateCacheStrategies;
|
362
|
}
|
363
|
|
364
|
public void setUpdateCacheStrategy(boolean doUpdateCacheStrategies){
|
365
|
this.updateCacheStrategies = doUpdateCacheStrategies;
|
366
|
}
|
367
|
|
368
|
// private class ClassComparator implements Comparator<Class>{
|
369
|
//
|
370
|
// /**
|
371
|
// * {@inheritDoc}
|
372
|
// */
|
373
|
// @Override
|
374
|
// public int compare(Class o1, Class o2) {
|
375
|
// if (o1.equals(o2)){
|
376
|
// return 0;
|
377
|
// }
|
378
|
// if (o1 == null){
|
379
|
// return -1;
|
380
|
// }
|
381
|
// if (o2 == null){
|
382
|
// return 1;
|
383
|
// }
|
384
|
// if (o1.equals(AgentBase.class)){
|
385
|
// return -1;
|
386
|
// }
|
387
|
// if (o1.equals(Reference.class)){
|
388
|
// if (o2.equals(AgentBase.class)){
|
389
|
// return 1;
|
390
|
// }else{
|
391
|
// return -1;
|
392
|
// }
|
393
|
// }
|
394
|
// if (o1.equals(TaxonName.class)){
|
395
|
// if (o2.equals(AgentBase.class) || o2.equals(Reference.class)){
|
396
|
// return 1;
|
397
|
// }else{
|
398
|
// return -1;
|
399
|
// }
|
400
|
// }
|
401
|
// if (o1.equals(TaxonBase.class)){
|
402
|
// if (o2.equals(AgentBase.class) || o2.equals(Reference.class) || o2.equals(TaxonName.class)){
|
403
|
// return 1;
|
404
|
// }else{
|
405
|
// return -1;
|
406
|
// }
|
407
|
// }
|
408
|
// if (o1.equals(SpecimenOrObservationBase.class)){
|
409
|
// if (o2.equals(AgentBase.class) || o2.equals(Reference.class) || o2.equals(TaxonName.class) || o2.equals(TaxonBase.class)){
|
410
|
// return 1;
|
411
|
// }else{
|
412
|
// return -1;
|
413
|
// }
|
414
|
// }
|
415
|
// return 0;
|
416
|
//
|
417
|
// }
|
418
|
//
|
419
|
// }
|
420
|
|
421
|
}
|