1
2
3
4
5
6
7
8
9
10 package eu.etaxonomy.cdm.io.common;
11
12 import java.lang.reflect.Method;
13 import java.util.HashMap;
14 import java.util.List;
15 import java.util.Map;
16 import java.util.UUID;
17
18 import org.apache.log4j.Logger;
19 import org.springframework.stereotype.Component;
20
21 import eu.etaxonomy.cdm.database.DbSchemaValidation;
22 import eu.etaxonomy.cdm.database.ICdmDataSource;
23 import eu.etaxonomy.cdm.io.common.mapping.IInputTransformer;
24 import eu.etaxonomy.cdm.model.agent.Person;
25 import eu.etaxonomy.cdm.model.description.Feature;
26 import eu.etaxonomy.cdm.model.name.NomenclaturalCode;
27 import eu.etaxonomy.cdm.model.reference.ReferenceBase;
28
29
30
31
32
33
34 @Component
35 public abstract class ImportConfiguratorBase<STATE extends ImportStateBase> extends IoConfiguratorBase implements IImportConfigurator{
36 private static final Logger logger = Logger.getLogger(ImportConfiguratorBase.class);
37
38
39 private CHECK check = CHECK.CHECK_AND_IMPORT;
40
41
42 static EDITOR editor = EDITOR.EDITOR_AS_ANNOTATION;
43
44
45
46
47
48 private IInputTransformer transformer;
49
50
51
52 private boolean deleteAll = false;
53
54
55 private boolean ignoreNull = false;
56
57
58 private NomenclaturalCode nomenclaturalCode = null;
59
60 private Map<Integer, Feature> featureMap = new HashMap<Integer, Feature>();
61
62
63
64
65
66 private String taxonomicTreeName = "Taxon tree - no name";
67
68 private UUID taxonomicTreeUuid = UUID.randomUUID();
69
70 private UUID secUuid = UUID.randomUUID();
71
72 private Object sourceSecId = -1;
73
74 private Object source;
75 protected ReferenceBase sourceReference;
76 private ICdmDataSource destination;
77 private Person commentator = Person.NewTitledInstance("automatic CDM importer");
78
79 protected Class<ICdmIO>[] ioClassList;
80
81 protected ICdmIO[] ioList;
82
83 protected String[] ioBeans;
84
85
86
87 public ImportConfiguratorBase(IInputTransformer transformer){
88 super();
89 setDbSchemaValidation(DbSchemaValidation.UPDATE);
90 this.transformer = transformer;
91
92 }
93
94 abstract protected void makeIoClassList();
95
96
97
98
99 public IInputTransformer getTransformer() {
100 return this.transformer;
101 }
102
103
104
105
106 public void setTransformer(IInputTransformer transformer){
107 this.transformer = transformer;
108 }
109
110
111
112
113
114
115
116 public void setSource(Object source) {
117 this.source = source;
118 }
119
120
121
122
123
124 public Object getSource() {
125 return source;
126 }
127
128
129
130
131
132
133 public boolean isValid(){
134 boolean result = true;
135 if (source == null){
136 logger.warn("Connection to source could not be established");
137 result = false;
138 }
139
140
141
142
143
144
145 return result;
146 }
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166 public void setIoClassList(ICdmIO[] ioList){
167 this.ioList = ioList;
168 }
169
170 public Class<ICdmIO>[] getIoClassList(){
171 if (ioClassList == null){
172 makeIoClassList();
173 }
174 return ioClassList;
175 }
176
177
178
179
180 public void setIoClassList(Class<ICdmIO>[] ioClassList){
181 this.ioClassList = ioClassList;
182 }
183
184
185
186
187 public boolean isDeleteAll() {
188 return deleteAll;
189 }
190
191
192
193 public void setDeleteAll(boolean deleteAll) {
194 this.deleteAll = deleteAll;
195 }
196
197
198
199
200
201 public CHECK getCheck() {
202 return this.check;
203 }
204
205
206
207
208 public void setCheck(CHECK check) {
209 this.check = check;
210 }
211
212
213
214
215
216 public EDITOR getEditor() {
217 return editor;
218 }
219
220
221
222
223 public void setEditor(EDITOR editor) {
224 ImportConfiguratorBase.editor = editor;
225 }
226
227
228
229
230
231
232
233 public boolean isIgnoreNull() {
234 return ignoreNull;
235 }
236
237
238
239
240 public void setIgnoreNull(boolean ignoreNull) {
241 this.ignoreNull = ignoreNull;
242 }
243
244
245
246
247 public ICdmDataSource getDestination() {
248 return destination;
249 }
250
251
252
253 public void setDestination(ICdmDataSource destination) {
254 this.destination = destination;
255 }
256
257
258
259
260
261 public abstract ReferenceBase getSourceReference();
262
263
264
265 public void setSourceReference(ReferenceBase sourceReference) {
266 this.sourceReference = sourceReference;
267 }
268
269
270
271 public String getSourceReferenceTitle() {
272 return getSourceReference().getTitleCache();
273 }
274
275
276
277 public void setSourceReferenceTitle(String sourceReferenceTitle) {
278 getSourceReference().setTitleCache(sourceReferenceTitle, true);
279 }
280
281
282
283
284
285 public Person getCommentator() {
286 return commentator;
287 }
288
289
290
291
292 public void setCommentator(Person commentator) {
293 this.commentator = commentator;
294 }
295
296
297
298
299 public NomenclaturalCode getNomenclaturalCode() {
300 return nomenclaturalCode;
301 }
302
303
304
305
306
307 public void setNomenclaturalCode(NomenclaturalCode nomenclaturalCode) {
308 this.nomenclaturalCode = nomenclaturalCode;
309 }
310
311
312
313
314
315 public UUID getTaxonomicTreeUuid() {
316 return taxonomicTreeUuid;
317 }
318
319
320 public void setTaxonomicTreeUuid(UUID treeUuid) {
321 this.taxonomicTreeUuid = treeUuid;
322 }
323
324
325
326
327 public UUID getSecUuid() {
328 return secUuid;
329 }
330 public void setSecUuid(UUID secUuid) {
331 this.secUuid = secUuid;
332 }
333
334
335
336
337 public Object getSourceSecId() {
338 return sourceSecId;
339 }
340
341
342
343
344 public void setSourceSecId(Object sourceSecId) {
345 this.sourceSecId = sourceSecId;
346 }
347
348
349
350
351
352 public Map<Integer, Feature> getFeatureMap() {
353 return featureMap;
354 }
355
356
357
358
359 public void setFeatureMap(Map<Integer, Feature> featureMap) {
360 this.featureMap = featureMap;
361 }
362
363
364 protected static Method getDefaultFunction(Class<?> clazz, String methodName){
365 try {
366 return clazz.getMethod(methodName, List.class) ;
367 } catch (SecurityException e) {
368 logger.error(e.getMessage());
369 e.printStackTrace();
370 } catch (NoSuchMethodException e) {
371 logger.error(e.getMessage());
372 e.printStackTrace();
373 }
374 return null;
375 }
376
377
378
379
380
381 public String getDestinationNameString() {
382 if (this.getDestination() == null) {
383 return null;
384 } else {
385 return (String)this.getDestination().getName();
386 }
387 }
388
389
390
391
392
393
394
395 public void setTaxonomicTreeName(String taxonomicTreeName) {
396 this.taxonomicTreeName = taxonomicTreeName;
397 }
398
399
400
401
402 public String getTaxonomicTreeName() {
403 return taxonomicTreeName;
404 }
405
406
407 }