Project

General

Profile

Download (8.7 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.util.List;
14
import java.util.UUID;
15

    
16
import org.apache.log4j.Logger;
17
import org.springframework.stereotype.Component;
18

    
19
import eu.etaxonomy.cdm.api.application.CdmApplicationController;
20
import eu.etaxonomy.cdm.database.DbSchemaValidation;
21
import eu.etaxonomy.cdm.database.ICdmDataSource;
22
import eu.etaxonomy.cdm.model.agent.Person;
23
import eu.etaxonomy.cdm.model.common.Language;
24
import eu.etaxonomy.cdm.model.description.Feature;
25
import eu.etaxonomy.cdm.model.name.NomenclaturalCode;
26
import eu.etaxonomy.cdm.model.reference.ReferenceBase;
27

    
28
/**
29
 * @author a.mueller
30
 * @created 20.06.2008
31
 * @version 1.0
32
 */
33
@Component
34
public abstract class ImportConfiguratorBase<STATE extends ImportStateBase> extends IoConfiguratorBase implements IImportConfigurator{
35
	private static final Logger logger = Logger.getLogger(ImportConfiguratorBase.class);
36

    
37
	private STATE state;
38
	
39
	
40
	//check
41
	private CHECK check = CHECK.CHECK_AND_IMPORT;
42
	
43
	//editor
44
	static EDITOR editor = EDITOR.EDITOR_AS_ANNOTATION;
45
	
46
	//TODO
47
	private boolean deleteAll = false;
48
		
49
	//nullValues
50
	private boolean ignoreNull = false;
51
	
52
	//Nomenclatural Code
53
	private NomenclaturalCode nomenclaturalCode = null;
54
	
55
	private MapWrapper<Feature> featureMap = new MapWrapper<Feature>(null);
56
	
57
	//uuid of concept reference
58
	private UUID  secUuid = UUID.randomUUID();
59
	private Object sourceSecId = -1;
60
	
61
	private Object source;
62
	protected ReferenceBase sourceReference;
63
	private ICdmDataSource destination;
64
	private Person commentator =  Person.NewTitledInstance("automatic BerlinModel2CDM importer");
65
	
66
	private Language factLanguage = Language.ENGLISH();
67
	private CdmApplicationController cdmApp = null;
68
	protected Class<ICdmIO>[] ioClassList;
69
	
70
	protected ICdmIO[] ioList;
71
	
72
	protected String[] ioBeans;
73
	
74
	
75
/* *****************CONSTRUCTOR *****************************/
76
	
77
	public ImportConfiguratorBase(){
78
		super();
79
		setDbSchemaValidation(DbSchemaValidation.UPDATE);
80
	}
81
	
82
	abstract protected void makeIoClassList();
83
	
84
	/**
85
	 * @param source the source to set
86
	 */
87
	public void setSource(Object source) {
88
		this.source = source;
89
	}
90
	
91
	
92
	/**
93
	 * @param source the source to get
94
	 */
95
	public Object getSource() {
96
		return source;
97
	}
98
	
99

    
100

    
101
	/* (non-Javadoc)
102
	 * @see eu.etaxonomy.cdm.io.common.IImportConfigurator#isValid()
103
	 */
104
	public boolean isValid(){
105
		boolean result = true;
106
		if (source == null){
107
			logger.warn("Connection to BerlinModel could not be established");
108
			result = false;
109
		}
110
//		if (destination == null){
111
//			logger.warn("Connection to Cdm could not be established");
112
//			result = false;
113
//		}
114
		
115
		return result;
116
	}
117
	
118
	
119
	
120
/* ****************** GETTER/SETTER **************************/	
121

    
122
//	/**
123
//	 * @return the state
124
//	 */
125
//	public STATE getState() {
126
//		return state;
127
//	}
128
//
129
//	/**
130
//	 * @param state the state to set
131
//	 */
132
//	public void setState(STATE state) {
133
//		this.state = state;
134
//	}
135
	
136
	public void setIoClassList(ICdmIO[] ioList){
137
		this.ioList = ioList;
138
	}
139
	
140
	public Class<ICdmIO>[] getIoClassList(){
141
		if (ioClassList == null){
142
			makeIoClassList();
143
		}
144
		return ioClassList;
145
	}
146

    
147
	/**
148
	 * @param ioClassList
149
	 */
150
	public void setIoClassList(Class<ICdmIO>[] ioClassList){
151
		this.ioClassList = ioClassList;
152
	}
153
	
154
	/* (non-Javadoc)
155
	 * @see eu.etaxonomy.cdm.io.tcsrdf.IImportConfigurator#isDeleteAll()
156
	 */
157
	public boolean isDeleteAll() {
158
		return deleteAll;
159
	}
160
	/* (non-Javadoc)
161
	 * @see eu.etaxonomy.cdm.io.tcsrdf.IImportConfigurator#setDeleteAll(boolean)
162
	 */
163
	public void setDeleteAll(boolean deleteAll) {
164
		this.deleteAll = deleteAll;
165
	}
166

    
167
	
168
	/* (non-Javadoc)
169
	 * @see eu.etaxonomy.cdm.io.tcsrdf.IImportConfigurator#getCheck()
170
	 */
171
	public CHECK getCheck() {
172
		return this.check;
173
	}
174
	
175
	/* (non-Javadoc)
176
	 * @see eu.etaxonomy.cdm.io.common.IImportConfigurator#setCheck(eu.etaxonomy.cdm.io.common.IImportConfigurator.CHECK)
177
	 */
178
	public void setCheck(CHECK check) {
179
		this.check = check;
180
	}
181
	
182
	
183
	/**
184
	 * @return the editor
185
	 */
186
	public EDITOR getEditor() {
187
		return editor;
188
	}
189

    
190
	/**
191
	 * @param editor the editor to set
192
	 */
193
	public void setEditor(EDITOR editor) {
194
		ImportConfiguratorBase.editor = editor;
195
	}
196

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

    
207
	/**
208
	 * @param ignoreNull the ignoreNull to set
209
	 */
210
	public void setIgnoreNull(boolean ignoreNull) {
211
		this.ignoreNull = ignoreNull;
212
	}
213

    
214
	/* (non-Javadoc)
215
	 * @see eu.etaxonomy.cdm.io.tcsrdf.IImportConfigurator#getDestination()
216
	 */
217
	public ICdmDataSource getDestination() {
218
		return destination;
219
	}
220
	/* (non-Javadoc)
221
	 * @see eu.etaxonomy.cdm.io.tcsrdf.IImportConfigurator#setDestination(eu.etaxonomy.cdm.database.ICdmDataSource)
222
	 */
223
	public void setDestination(ICdmDataSource destination) {
224
		this.destination = destination;
225
	}
226

    
227

    
228
	/* (non-Javadoc)
229
	 * @see eu.etaxonomy.cdm.io.tcsrdf.IImportConfigurator#getSourceReference()
230
	 */
231
	public abstract ReferenceBase getSourceReference();
232
	/* (non-Javadoc)
233
	 * @see eu.etaxonomy.cdm.io.tcsrdf.IImportConfigurator#setSourceReference(eu.etaxonomy.cdm.model.reference.ReferenceBase)
234
	 */
235
	public void setSourceReference(ReferenceBase sourceReference) {
236
		this.sourceReference = sourceReference;
237
	}
238
	/* (non-Javadoc)
239
	 * @see eu.etaxonomy.cdm.io.tcsrdf.IImportConfigurator#getSourceReferenceTitle()
240
	 */
241
	public String getSourceReferenceTitle() {
242
		return getSourceReference().getTitleCache();
243
	}
244
	/* (non-Javadoc)
245
	 * @see eu.etaxonomy.cdm.io.tcsrdf.IImportConfigurator#setSourceReferenceTitle(java.lang.String)
246
	 */
247
	public void setSourceReferenceTitle(String sourceReferenceTitle) {
248
		getSourceReference().setTitleCache(sourceReferenceTitle);
249
	}
250

    
251

    
252
	/* (non-Javadoc)
253
	 * @see eu.etaxonomy.cdm.io.tcsrdf.IImportConfigurator#getCommentator()
254
	 */
255
	public Person getCommentator() {
256
		return commentator;
257
	}
258

    
259
	/* (non-Javadoc)
260
	 * @see eu.etaxonomy.cdm.io.tcsrdf.IImportConfigurator#setCommentator(eu.etaxonomy.cdm.model.agent.Person)
261
	 */
262
	public void setCommentator(Person commentator) {
263
		this.commentator = commentator;
264
	}
265

    
266

    
267
	/* (non-Javadoc)
268
	 * @see eu.etaxonomy.cdm.io.tcsrdf.IImportConfigurator#getFactLanguage()
269
	 */
270
	public Language getFactLanguage() {
271
		return factLanguage;
272
	}
273

    
274

    
275
	/* (non-Javadoc)
276
	 * @see eu.etaxonomy.cdm.io.tcsrdf.IImportConfigurator#setFactLanguage(eu.etaxonomy.cdm.model.common.Language)
277
	 */
278
	public void setFactLanguage(Language factLanguage) {
279
		this.factLanguage = factLanguage;
280
	}
281

    
282

    
283
	/**
284
	 * @return the nomenclaturalCode
285
	 */
286
	public NomenclaturalCode getNomenclaturalCode() {
287
		return nomenclaturalCode;
288
	}
289

    
290

    
291
	/**
292
	 * @param nomenclaturalCode the nomenclaturalCode to set
293
	 */
294
	public void setNomenclaturalCode(NomenclaturalCode nomenclaturalCode) {
295
		this.nomenclaturalCode = nomenclaturalCode;
296
	}
297

    
298

    
299
	/**
300
	 * @return the secUuid
301
	 */
302
	public UUID getSecUuid() {
303
		return secUuid;
304
	}
305

    
306

    
307
	/**
308
	 * @param secUuid the secUuid to set
309
	 */
310
	public void setSecUuid(UUID secUuid) {
311
		this.secUuid = secUuid;
312
	}
313

    
314
	/**
315
	 * @return the sourceSecId
316
	 */
317
	public Object getSourceSecId() {
318
		return sourceSecId;
319
	}
320

    
321
	/**
322
	 * @param sourceSecId the sourceSecId to set
323
	 */
324
	public void setSourceSecId(Object sourceSecId) {
325
		this.sourceSecId = sourceSecId;
326
	}
327
	
328

    
329
	/**
330
	 * @return the featureMap
331
	 */
332
	public MapWrapper<Feature> getFeatureMap() {
333
		return featureMap;
334
	}
335

    
336
	/**
337
	 * @param featureMap the featureMap to set
338
	 */
339
	public void setFeatureMap(MapWrapper<Feature> featureMap) {
340
		this.featureMap = featureMap;
341
	}
342

    
343
	
344
	protected static Method getDefaultFunction(Class<?> clazz, String methodName){
345
		try {
346
			return clazz.getMethod(methodName, List.class) ;
347
		} catch (SecurityException e) {
348
			logger.error(e.getMessage());
349
			e.printStackTrace();
350
		} catch (NoSuchMethodException e) {
351
			logger.error(e.getMessage());
352
			e.printStackTrace();
353
		}
354
		return null;
355
	}
356
	
357

    
358
	/* (non-Javadoc)
359
	 * @see eu.etaxonomy.cdm.io.common.IIoConfigurator#getDestinationNameString()
360
	 */
361
	public String getDestinationNameString() {
362
		if (this.getDestination() == null) {
363
			return null;
364
		} else {
365
			return (String)this.getDestination().getName();
366
		}
367
	}
368

    
369

    
370
}
(26-26/38)