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.common;
|
10
|
|
11
|
import java.lang.reflect.Method;
|
12
|
import java.util.HashMap;
|
13
|
import java.util.List;
|
14
|
import java.util.Map;
|
15
|
import java.util.UUID;
|
16
|
|
17
|
import org.joda.time.DateTime;
|
18
|
import org.joda.time.format.DateTimeFormat;
|
19
|
import org.joda.time.format.DateTimeFormatter;
|
20
|
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
21
|
import org.springframework.stereotype.Component;
|
22
|
|
23
|
import eu.etaxonomy.cdm.database.DbSchemaValidation;
|
24
|
import eu.etaxonomy.cdm.database.ICdmDataSource;
|
25
|
import eu.etaxonomy.cdm.io.common.mapping.IInputTransformer;
|
26
|
import eu.etaxonomy.cdm.model.agent.Person;
|
27
|
import eu.etaxonomy.cdm.model.description.Feature;
|
28
|
import eu.etaxonomy.cdm.model.name.NomenclaturalCode;
|
29
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
30
|
|
31
|
/**
|
32
|
* @author a.mueller
|
33
|
* @since 20.06.2008
|
34
|
* @param <STATE> the import state
|
35
|
*/
|
36
|
@Component
|
37
|
public abstract class ImportConfiguratorBase<STATE extends ImportStateBase, SOURCE>
|
38
|
extends IoConfiguratorBase
|
39
|
implements IImportConfigurator{
|
40
|
|
41
|
private static final long serialVersionUID = 7223140465020160905L;
|
42
|
|
43
|
//check
|
44
|
private CHECK check = CHECK.CHECK_AND_IMPORT;
|
45
|
|
46
|
//editor
|
47
|
static EDITOR editor = EDITOR.EDITOR_AS_ANNOTATION;
|
48
|
|
49
|
/**
|
50
|
* The transformer class to be used for Input
|
51
|
*/
|
52
|
private IInputTransformer transformer;
|
53
|
|
54
|
private UUID uuidFeatureTree;
|
55
|
|
56
|
private String featureTreeTitle;
|
57
|
|
58
|
//Nomenclatural Code
|
59
|
private NomenclaturalCode nomenclaturalCode = null;
|
60
|
|
61
|
private Map<Integer, Feature> featureMap = new HashMap<>();
|
62
|
|
63
|
/* The classification name for the first classification.
|
64
|
* Needs only to be defined if the import does not handle the naming
|
65
|
* itself (e.g. by using the taxon sec. reference title cache)
|
66
|
*/
|
67
|
private String classificationName = "Classification - no name";
|
68
|
|
69
|
private UUID classificationUuid = UUID.randomUUID();
|
70
|
//uuid of concept reference
|
71
|
private UUID secUuid = UUID.randomUUID();
|
72
|
|
73
|
private Object sourceSecId = -1;
|
74
|
|
75
|
private SOURCE source;
|
76
|
protected Reference sourceReference;
|
77
|
private UUID sourceRefUuid;
|
78
|
private ICdmDataSource destination;
|
79
|
private Person commentator = Person.NewTitledInstance("automatic CDM importer");
|
80
|
|
81
|
@SuppressWarnings("rawtypes")
|
82
|
protected Class<ICdmImport>[] ioClassList;
|
83
|
|
84
|
@SuppressWarnings("rawtypes")
|
85
|
protected ICdmIO[] ioList;
|
86
|
|
87
|
protected String[] ioBeans;
|
88
|
|
89
|
/*user interaction*/
|
90
|
private boolean askUserForHelp =false;
|
91
|
|
92
|
/* *****************CONSTRUCTOR *****************************/
|
93
|
|
94
|
protected ImportConfiguratorBase(IInputTransformer transformer){
|
95
|
setDbSchemaValidation(DbSchemaValidation.VALIDATE);
|
96
|
this.transformer = transformer;
|
97
|
}
|
98
|
|
99
|
abstract protected void makeIoClassList();
|
100
|
|
101
|
@Override
|
102
|
public IInputTransformer getTransformer() {
|
103
|
return this.transformer;
|
104
|
}
|
105
|
@Override
|
106
|
public void setTransformer(IInputTransformer transformer){
|
107
|
this.transformer = transformer;
|
108
|
}
|
109
|
|
110
|
@Override
|
111
|
public SOURCE getSource() {
|
112
|
return source;
|
113
|
}
|
114
|
public void setSource(SOURCE source) {
|
115
|
this.source = source;
|
116
|
}
|
117
|
|
118
|
@Override
|
119
|
public boolean isValid(){
|
120
|
boolean result = true;
|
121
|
if (getSource() == null){
|
122
|
//logger.warn("Connection to source could not be established");
|
123
|
result = false;
|
124
|
}
|
125
|
//Not valid any more as the importer may already have a destination
|
126
|
// if (destination == null ){
|
127
|
// logger.warn("Connection to Cdm could not be established");
|
128
|
// result = false;
|
129
|
// }
|
130
|
|
131
|
return result;
|
132
|
}
|
133
|
|
134
|
/* ****************** GETTER/SETTER **************************/
|
135
|
|
136
|
|
137
|
public void setIoClassList(ICdmImport[] ioList){
|
138
|
this.ioList = ioList;
|
139
|
}
|
140
|
|
141
|
@Override
|
142
|
public Class<ICdmImport>[] getIoClassList(){
|
143
|
if (ioClassList == null){
|
144
|
makeIoClassList();
|
145
|
}
|
146
|
return ioClassList;
|
147
|
}
|
148
|
public void setIoClassList(Class<ICdmImport>[] ioClassList){
|
149
|
this.ioClassList = ioClassList;
|
150
|
}
|
151
|
|
152
|
@Override
|
153
|
public CHECK getCheck() {
|
154
|
return this.check;
|
155
|
}
|
156
|
@Override
|
157
|
public void setCheck(CHECK check) {
|
158
|
this.check = check;
|
159
|
}
|
160
|
|
161
|
@Override
|
162
|
public EDITOR getEditor() {
|
163
|
return editor;
|
164
|
}
|
165
|
@Override
|
166
|
public void setEditor(EDITOR editor) {
|
167
|
ImportConfiguratorBase.editor = editor;
|
168
|
}
|
169
|
|
170
|
@Override
|
171
|
public ICdmDataSource getDestination() {
|
172
|
return destination;
|
173
|
}
|
174
|
@Override
|
175
|
public void setDestination(ICdmDataSource destination) {
|
176
|
this.destination = destination;
|
177
|
}
|
178
|
|
179
|
@Override
|
180
|
public abstract Reference getSourceReference();
|
181
|
@Override
|
182
|
public void setSourceReference(Reference sourceReference) {
|
183
|
this.sourceReference = sourceReference;
|
184
|
}
|
185
|
|
186
|
@Override
|
187
|
public String getSourceReferenceTitle() {
|
188
|
return getSourceReference().getTitleCache();
|
189
|
}
|
190
|
@Override
|
191
|
public void setSourceReferenceTitle(String sourceReferenceTitle) {
|
192
|
getSourceReference().setTitleCache(sourceReferenceTitle, true);
|
193
|
}
|
194
|
|
195
|
@Override
|
196
|
public Person getCommentator() {
|
197
|
return commentator;
|
198
|
}
|
199
|
@Override
|
200
|
public void setCommentator(Person commentator) {
|
201
|
this.commentator = commentator;
|
202
|
}
|
203
|
|
204
|
@Override
|
205
|
public NomenclaturalCode getNomenclaturalCode() {
|
206
|
return nomenclaturalCode;
|
207
|
}
|
208
|
@Override
|
209
|
public void setNomenclaturalCode(NomenclaturalCode nomenclaturalCode) {
|
210
|
this.nomenclaturalCode = nomenclaturalCode;
|
211
|
}
|
212
|
|
213
|
@Override
|
214
|
public UUID getClassificationUuid() {
|
215
|
return classificationUuid;
|
216
|
}
|
217
|
@Override
|
218
|
public void setClassificationUuid(UUID classificationUuid) {
|
219
|
this.classificationUuid = classificationUuid;
|
220
|
}
|
221
|
|
222
|
@Override
|
223
|
public UUID getSecUuid() {
|
224
|
return secUuid;
|
225
|
}
|
226
|
@Override
|
227
|
public void setSecUuid(UUID secUuid) {
|
228
|
this.secUuid = secUuid;
|
229
|
}
|
230
|
|
231
|
@Override
|
232
|
public Object getSourceSecId() {
|
233
|
return sourceSecId;
|
234
|
}
|
235
|
public void setSourceSecId(Object sourceSecId) {
|
236
|
this.sourceSecId = sourceSecId;
|
237
|
}
|
238
|
|
239
|
public Map<Integer, Feature> getFeatureMap() {
|
240
|
return featureMap;
|
241
|
}
|
242
|
public void setFeatureMap(Map<Integer, Feature> featureMap) {
|
243
|
this.featureMap = featureMap;
|
244
|
}
|
245
|
|
246
|
protected static Method getDefaultFunction(Class<?> clazz, String methodName){
|
247
|
try {
|
248
|
return clazz.getMethod(methodName, List.class) ;
|
249
|
} catch (SecurityException e) {
|
250
|
e.printStackTrace();
|
251
|
} catch (NoSuchMethodException e) {
|
252
|
e.printStackTrace();
|
253
|
}
|
254
|
return null;
|
255
|
}
|
256
|
|
257
|
@Override
|
258
|
public String getDestinationNameString() {
|
259
|
if (this.getDestination() == null) {
|
260
|
return null;
|
261
|
} else {
|
262
|
return this.getDestination().getName().toString();
|
263
|
}
|
264
|
}
|
265
|
|
266
|
@Override
|
267
|
public String getSourceNameString() {
|
268
|
if (this.getSource() == null){
|
269
|
return null;
|
270
|
}else{
|
271
|
return this.getSource().toString();
|
272
|
}
|
273
|
}
|
274
|
|
275
|
/**
|
276
|
* The classification name for the first classification.
|
277
|
* Needs only to be defined if the import does not handle the naming
|
278
|
* itself (e.g. by using the taxon sec. reference title cache)
|
279
|
* @param classificationName the classificationName to set
|
280
|
*/
|
281
|
public void setClassificationName(String classificationName) {
|
282
|
this.classificationName = classificationName;
|
283
|
}
|
284
|
public String getClassificationName() {
|
285
|
return classificationName;
|
286
|
}
|
287
|
|
288
|
public UUID getSourceRefUuid() {
|
289
|
return sourceRefUuid;
|
290
|
}
|
291
|
public void setSourceRefUuid(UUID sourceRefUuid) {
|
292
|
this.sourceRefUuid = sourceRefUuid;
|
293
|
}
|
294
|
|
295
|
@Override
|
296
|
public boolean isOmitTermLoading() {
|
297
|
return false;
|
298
|
}
|
299
|
|
300
|
@Override
|
301
|
public boolean isCreateNew(){
|
302
|
return false;
|
303
|
}
|
304
|
|
305
|
@Override
|
306
|
public UsernamePasswordAuthenticationToken getAuthenticationToken(){
|
307
|
return this.authenticationToken;
|
308
|
}
|
309
|
|
310
|
/*user interaction*/
|
311
|
public boolean isInteractWithUser() {
|
312
|
return askUserForHelp;
|
313
|
}
|
314
|
public void setInteractWithUser (boolean interaction){
|
315
|
askUserForHelp=interaction;
|
316
|
}
|
317
|
|
318
|
public UUID getUuidFeatureTree() {
|
319
|
return uuidFeatureTree;
|
320
|
}
|
321
|
public void setUuidFeatureTree(UUID uuidFeatureTree) {
|
322
|
this.uuidFeatureTree = uuidFeatureTree;
|
323
|
}
|
324
|
|
325
|
public String getFeatureTreeTitle() {
|
326
|
return featureTreeTitle;
|
327
|
}
|
328
|
public void setFeatureTreeTitle(String featureTreeTitle) {
|
329
|
this.featureTreeTitle = featureTreeTitle;
|
330
|
}
|
331
|
|
332
|
private static final DateTimeFormatter formatter = DateTimeFormat.forPattern("YYYY-MM-dd");
|
333
|
|
334
|
protected String getDateString(){
|
335
|
return formatter.print(new DateTime());
|
336
|
}
|
337
|
|
338
|
/**
|
339
|
* If <code>false</code> auditing is switched off during import.
|
340
|
* This is only applicable if an own application context is started
|
341
|
* for the import/export. For imports into/from running application contexts
|
342
|
* it has no affect.
|
343
|
*/
|
344
|
public boolean isRegisterAuditing() {
|
345
|
return hibernateConfig.getRegisterEnvers();
|
346
|
}
|
347
|
/**
|
348
|
* @see #isRegisterAuditing()
|
349
|
*/
|
350
|
public void setRegisterAuditing(boolean registerAuditing) {
|
351
|
this.hibernateConfig.setRegisterEnvers(registerAuditing);
|
352
|
}
|
353
|
|
354
|
}
|