Project

General

Profile

Download (9.73 KB) Statistics
| Branch: | Tag: | Revision:
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.io.common;
11

    
12
import java.lang.reflect.Method;
13
import java.time.ZonedDateTime;
14
import java.time.format.DateTimeFormatter;
15
import java.util.HashMap;
16
import java.util.List;
17
import java.util.Map;
18
import java.util.UUID;
19

    
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
 * @created 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
//
55
//	//TODO
56
//	private boolean deleteAll = false;
57

    
58
	//nullValues
59
	private boolean ignoreNull = false;
60

    
61
	private UUID uuidFeatureTree;
62

    
63
	private String featureTreeTitle;
64

    
65
	//Nomenclatural Code
66
	private NomenclaturalCode nomenclaturalCode = null;
67

    
68
	private Map<Integer, Feature>  featureMap = new HashMap<>();
69

    
70
	 /* The classification name for the first classification.
71
	  * Needs only to be defined if the import does not handle the naming
72
	  * itself (e.g. by using the taxon sec. reference title cache)
73
	  */
74
	private String classificationName = "Classification - no name";
75

    
76
	private UUID  classificationUuid = UUID.randomUUID();
77
	//uuid of concept reference
78
	private UUID  secUuid = UUID.randomUUID();
79

    
80
	private Object sourceSecId = -1;
81

    
82
	private SOURCE source;
83
	protected Reference sourceReference;
84
	private UUID sourceRefUuid;
85
	private ICdmDataSource destination;
86
	private Person commentator =  Person.NewTitledInstance("automatic CDM importer");
87

    
88
	protected Class<ICdmImport>[] ioClassList;
89

    
90
	protected ICdmIO[] ioList;
91

    
92
	protected String[] ioBeans;
93

    
94
	/*user interaction*/
95
    private boolean askUserForHelp =false;
96

    
97

    
98
/* *****************CONSTRUCTOR *****************************/
99

    
100
	protected ImportConfiguratorBase(IInputTransformer transformer){
101
		super();
102
		setDbSchemaValidation(DbSchemaValidation.UPDATE);
103
		this.transformer = transformer;
104

    
105
	}
106

    
107
	abstract protected void makeIoClassList();
108

    
109
	@Override
110
    public IInputTransformer getTransformer() {
111
		return this.transformer;
112
	}
113

    
114
	@Override
115
    public void setTransformer(IInputTransformer transformer){
116
		this.transformer = transformer;
117
	}
118

    
119
	/**
120
	 * @param source the source to set
121
	 */
122
	public void setSource(SOURCE source) {
123
		this.source = source;
124
	}
125

    
126
	/**
127
	 * @param source the source to get
128
	 */
129
	@Override
130
    public SOURCE getSource() {
131
		return source;
132
	}
133

    
134
	@Override
135
    public boolean isValid(){
136
		boolean result = true;
137
		if (getSource() == null){
138
			//logger.warn("Connection to source could not be established");
139
			result = false;
140
		}
141
//Not valid any more as the importer may already have a destination
142
//		if (destination == null ){
143
//			logger.warn("Connection to Cdm could not be established");
144
//			result = false;
145
//		}
146

    
147
		return result;
148
	}
149

    
150

    
151

    
152
/* ****************** GETTER/SETTER **************************/
153

    
154

    
155
	public void setIoClassList(ICdmImport[] ioList){
156
		this.ioList = ioList;
157
	}
158

    
159
	@Override
160
    public Class<ICdmImport>[] getIoClassList(){
161
		if (ioClassList == null){
162
			makeIoClassList();
163
		}
164
		return ioClassList;
165
	}
166

    
167
	/**
168
	 * @param ioClassList
169
	 */
170
	public void setIoClassList(Class<ICdmImport>[] ioClassList){
171
		this.ioClassList = ioClassList;
172
	}
173

    
174
	@Override
175
    public CHECK getCheck() {
176
		return this.check;
177
	}
178

    
179
	@Override
180
    public void setCheck(CHECK check) {
181
		this.check = check;
182
	}
183

    
184

    
185
	/**
186
	 * @return the editor
187
	 */
188
	@Override
189
    public EDITOR getEditor() {
190
		return editor;
191
	}
192

    
193
	/**
194
	 * @param editor the editor to set
195
	 */
196
	@Override
197
    public void setEditor(EDITOR editor) {
198
		ImportConfiguratorBase.editor = editor;
199
	}
200

    
201
	/**
202
	 * If true, no errors occur if objects are not found that should exist. This may
203
	 * be needed e.g. when only subsets of the data are imported.
204
	 * Default value is <cod>false</code>.
205
	 * @return the ignoreNull
206
	 */
207
	@Override
208
    public boolean isIgnoreNull() {
209
		return ignoreNull;
210
	}
211

    
212
	/**
213
	 * @param ignoreNull the ignoreNull to set
214
	 */
215
	@Override
216
    public void setIgnoreNull(boolean ignoreNull) {
217
		this.ignoreNull = ignoreNull;
218
	}
219

    
220
	@Override
221
    public ICdmDataSource getDestination() {
222
		return destination;
223
	}
224
	@Override
225
    public void setDestination(ICdmDataSource destination) {
226
		this.destination = destination;
227
	}
228

    
229
	@Override
230
    public abstract Reference getSourceReference();
231
	@Override
232
    public void setSourceReference(Reference sourceReference) {
233
		this.sourceReference = sourceReference;
234
	}
235
	@Override
236
    public String getSourceReferenceTitle() {
237
		return getSourceReference().getTitleCache();
238
	}
239
	@Override
240
    public void setSourceReferenceTitle(String sourceReferenceTitle) {
241
		getSourceReference().setTitleCache(sourceReferenceTitle, true);
242
	}
243

    
244
	@Override
245
    public Person getCommentator() {
246
		return commentator;
247
	}
248

    
249
	@Override
250
    public void setCommentator(Person commentator) {
251
		this.commentator = commentator;
252
	}
253

    
254
	/**
255
	 * @return the nomenclaturalCode
256
	 */
257
	@Override
258
    public NomenclaturalCode getNomenclaturalCode() {
259
		return nomenclaturalCode;
260
	}
261

    
262

    
263
	/**
264
	 * @param nomenclaturalCode the nomenclaturalCode to set
265
	 */
266
	@Override
267
    public void setNomenclaturalCode(NomenclaturalCode nomenclaturalCode) {
268
		this.nomenclaturalCode = nomenclaturalCode;
269
	}
270

    
271
	@Override
272
    public UUID getClassificationUuid() {
273
		return classificationUuid;
274
	}
275

    
276

    
277
	@Override
278
    public void setClassificationUuid(UUID classificationUuid) {
279
		this.classificationUuid = classificationUuid;
280
	}
281

    
282

    
283
	@Override
284
    public UUID getSecUuid() {
285
		return secUuid;
286
	}
287
	@Override
288
    public void setSecUuid(UUID secUuid) {
289
		this.secUuid = secUuid;
290
	}
291

    
292
	/**
293
	 * @return the sourceSecId
294
	 */
295
	@Override
296
    public Object getSourceSecId() {
297
		return sourceSecId;
298
	}
299

    
300
	/**
301
	 * @param sourceSecId the sourceSecId to set
302
	 */
303
	public void setSourceSecId(Object sourceSecId) {
304
		this.sourceSecId = sourceSecId;
305
	}
306

    
307

    
308
	/**
309
	 * @return the featureMap
310
	 */
311
	public Map<Integer, Feature>  getFeatureMap() {
312
		return featureMap;
313
	}
314

    
315
	/**
316
	 * @param featureMap the featureMap to set
317
	 */
318
	public void setFeatureMap(Map<Integer, Feature>  featureMap) {
319
		this.featureMap = featureMap;
320
	}
321

    
322

    
323
	protected static Method getDefaultFunction(Class<?> clazz, String methodName){
324
		try {
325
			return clazz.getMethod(methodName, List.class) ;
326
		} catch (SecurityException e) {
327
			e.printStackTrace();
328
		} catch (NoSuchMethodException e) {
329
			e.printStackTrace();
330
		}
331
		return null;
332
	}
333

    
334
	@Override
335
    public String getDestinationNameString() {
336
		if (this.getDestination() == null) {
337
			return null;
338
		} else {
339
			return this.getDestination().getName().toString();
340
		}
341
	}
342

    
343
	@Override
344
    public String getSourceNameString() {
345
		if (this.getSource() == null){
346
			return null;
347
		}else{
348
			return this.getSource().toString();
349
		}
350
	}
351

    
352
	/**
353
	 * The classification name for the first classification.
354
	 * Needs only to be defined if the import does not handle the naming
355
	 * itself (e.g. by using the taxon sec. reference title cache)
356
	 * @param classificationName the classificationName to set
357
	 */
358
	public void setClassificationName(String classificationName) {
359
		this.classificationName = classificationName;
360
	}
361

    
362
	/**
363
	 * @return the classificationName
364
	 */
365
	public String getClassificationName() {
366
		return classificationName;
367
	}
368

    
369

    
370
	public UUID getSourceRefUuid() {
371
		return sourceRefUuid;
372
	}
373

    
374

    
375

    
376
	public void setSourceRefUuid(UUID sourceRefUuid) {
377
		this.sourceRefUuid = sourceRefUuid;
378
	}
379

    
380
	@Override
381
	public boolean isOmitTermLoading() {
382
		return false;
383
	}
384

    
385
	@Override
386
	public boolean isCreateNew(){
387
		return false;
388
	}
389

    
390
	@Override
391
    public UsernamePasswordAuthenticationToken getAuthenticationToken(){
392
		return this.authenticationToken;
393
	}
394

    
395
	/*user interaction*/
396
	public boolean isInteractWithUser() {
397
        return askUserForHelp;
398
    }
399

    
400
    public void setInteractWithUser (boolean interaction){
401
        askUserForHelp=interaction;
402
    }
403

    
404
    public UUID getUuidFeatureTree() {
405
        return uuidFeatureTree;
406
    }
407

    
408
    public void setUuidFeatureTree(UUID uuidFeatureTree) {
409
        this.uuidFeatureTree = uuidFeatureTree;
410
    }
411

    
412
    public String getFeatureTreeTitle() {
413
        return featureTreeTitle;
414
    }
415

    
416
    public void setFeatureTreeTitle(String featureTreeTitle) {
417
        this.featureTreeTitle = featureTreeTitle;
418
    }
419

    
420

    
421
    private static final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("YYYY-MM-dd");
422

    
423
    protected String getDateString(){
424
        return ZonedDateTime.now().format(formatter);
425

    
426
    }
427

    
428
    /**
429
     * If <code>false</code> auditing is switched off during import.
430
     * This is only applicable if an own application context is started
431
     * for the import/export. For imports into/from running application contexts
432
     * it has no affect.
433
     */
434
    public boolean isRegisterAuditing() {
435
        return hibernateConfig.getRegisterEnvers();
436
    }
437
    /**
438
     * @see #isRegisterAuditing()
439
     */
440
    public void setRegisterAuditing(boolean registerAuditing) {
441
        this.hibernateConfig.setRegisterEnvers(registerAuditing);
442
    }
443

    
444
}
(43-43/72)