Project

General

Profile

Download (9.52 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

    
18
import eu.etaxonomy.cdm.api.application.CdmApplicationController;
19
import eu.etaxonomy.cdm.database.DataSourceNotFoundException;
20
import eu.etaxonomy.cdm.database.DbSchemaValidation;
21
import eu.etaxonomy.cdm.database.ICdmDataSource;
22
import eu.etaxonomy.cdm.io.common.IImportConfigurator.CHECK;
23
import eu.etaxonomy.cdm.model.agent.Person;
24
import eu.etaxonomy.cdm.model.common.Language;
25
import eu.etaxonomy.cdm.model.common.init.TermNotFoundException;
26
import eu.etaxonomy.cdm.model.description.Feature;
27
import eu.etaxonomy.cdm.model.name.NomenclaturalCode;
28
import eu.etaxonomy.cdm.model.reference.ReferenceBase;
29

    
30
/**
31
 * @author a.mueller
32
 * @created 20.06.2008
33
 * @version 1.0
34
 */
35
public abstract class ImportConfiguratorBase extends IoConfiguratorBase {
36
	
37
	private static final Logger logger = Logger.getLogger(ImportConfiguratorBase.class);
38

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

    
92
	/* (non-Javadoc)
93
	 * @see eu.etaxonomy.cdm.io.tcs.IImportConfigurator#isValid()
94
	 */
95
	public boolean isValid(){
96
		boolean result = true;
97
		if (source == null){
98
			logger.warn("Connection to BerlinModel could not be established");
99
			result = false;
100
		}
101
		if (destination == null){
102
			logger.warn("Connection to Cdm could not be established");
103
			result = false;
104
		}
105
		
106
		return result;
107
	}
108
	
109
	
110
	
111
/* ****************** GETTER/SETTER **************************/	
112
	/* (non-Javadoc)
113
	 * @see eu.etaxonomy.cdm.io.tcs.IImportConfigurator#isDeleteAll()
114
	 */
115
	public boolean isDeleteAll() {
116
		return deleteAll;
117
	}
118
	/* (non-Javadoc)
119
	 * @see eu.etaxonomy.cdm.io.tcs.IImportConfigurator#setDeleteAll(boolean)
120
	 */
121
	public void setDeleteAll(boolean deleteAll) {
122
		this.deleteAll = deleteAll;
123
	}
124
	/* (non-Javadoc)
125
	 * @see eu.etaxonomy.cdm.io.tcs.IImportConfigurator#isDoAuthors()
126
	 */
127
	
128
	/* (non-Javadoc)
129
	 * @see eu.etaxonomy.cdm.io.tcs.IImportConfigurator#getCheck()
130
	 */
131
	public CHECK getCheck() {
132
		return this.check;
133
	}
134
	
135
	/* (non-Javadoc)
136
	 * @see eu.etaxonomy.cdm.io.tcs.IImportConfigurator#setCheck(eu.etaxonomy.cdm.io.tcs.TcsImportConfigurator.CHECK)
137
	 */
138
	public void setCheck(CHECK check) {
139
		this.check = check;
140
	}
141
	
142
	
143
	/**
144
	 * If true, no errors occurs if objects are not found that should exist. This may
145
	 * be needed e.g. when only subsets of the data are imported.
146
	 * Default value is <cod>false</code>.
147
	 * @return the ignoreNull
148
	 */
149
	public boolean isIgnoreNull() {
150
		return ignoreNull;
151
	}
152

    
153
	/**
154
	 * @param ignoreNull the ignoreNull to set
155
	 */
156
	public void setIgnoreNull(boolean ignoreNull) {
157
		this.ignoreNull = ignoreNull;
158
	}
159

    
160
	/* (non-Javadoc)
161
	 * @see eu.etaxonomy.cdm.io.tcs.IImportConfigurator#getDestination()
162
	 */
163
	public ICdmDataSource getDestination() {
164
		return destination;
165
	}
166
	/* (non-Javadoc)
167
	 * @see eu.etaxonomy.cdm.io.tcs.IImportConfigurator#setDestination(eu.etaxonomy.cdm.database.ICdmDataSource)
168
	 */
169
	public void setDestination(ICdmDataSource destination) {
170
		this.destination = destination;
171
	}
172

    
173

    
174
	/* (non-Javadoc)
175
	 * @see eu.etaxonomy.cdm.io.tcs.IImportConfigurator#getSourceReference()
176
	 */
177
	public abstract ReferenceBase getSourceReference();
178
	/* (non-Javadoc)
179
	 * @see eu.etaxonomy.cdm.io.tcs.IImportConfigurator#setSourceReference(eu.etaxonomy.cdm.model.reference.ReferenceBase)
180
	 */
181
	public void setSourceReference(ReferenceBase sourceReference) {
182
		this.sourceReference = sourceReference;
183
	}
184
	/* (non-Javadoc)
185
	 * @see eu.etaxonomy.cdm.io.tcs.IImportConfigurator#getSourceReferenceTitle()
186
	 */
187
	public String getSourceReferenceTitle() {
188
		return getSourceReference().getTitleCache();
189
	}
190
	/* (non-Javadoc)
191
	 * @see eu.etaxonomy.cdm.io.tcs.IImportConfigurator#setSourceReferenceTitle(java.lang.String)
192
	 */
193
	public void setSourceReferenceTitle(String sourceReferenceTitle) {
194
		getSourceReference().setTitleCache(sourceReferenceTitle);
195
	}
196

    
197

    
198
	/* (non-Javadoc)
199
	 * @see eu.etaxonomy.cdm.io.tcs.IImportConfigurator#getCommentator()
200
	 */
201
	public Person getCommentator() {
202
		return commentator;
203
	}
204

    
205
	/* (non-Javadoc)
206
	 * @see eu.etaxonomy.cdm.io.tcs.IImportConfigurator#setCommentator(eu.etaxonomy.cdm.model.agent.Person)
207
	 */
208
	public void setCommentator(Person commentator) {
209
		this.commentator = commentator;
210
	}
211

    
212

    
213
	/* (non-Javadoc)
214
	 * @see eu.etaxonomy.cdm.io.tcs.IImportConfigurator#getFactLanguage()
215
	 */
216
	public Language getFactLanguage() {
217
		return factLanguage;
218
	}
219

    
220

    
221
	/* (non-Javadoc)
222
	 * @see eu.etaxonomy.cdm.io.tcs.IImportConfigurator#setFactLanguage(eu.etaxonomy.cdm.model.common.Language)
223
	 */
224
	public void setFactLanguage(Language factLanguage) {
225
		this.factLanguage = factLanguage;
226
	}
227

    
228

    
229
	/**
230
	 * @return the nomenclaturalCode
231
	 */
232
	public NomenclaturalCode getNomenclaturalCode() {
233
		return nomenclaturalCode;
234
	}
235

    
236

    
237
	/**
238
	 * @param nomenclaturalCode the nomenclaturalCode to set
239
	 */
240
	public void setNomenclaturalCode(NomenclaturalCode nomenclaturalCode) {
241
		this.nomenclaturalCode = nomenclaturalCode;
242
	}
243

    
244

    
245
	/**
246
	 * @return the secUuid
247
	 */
248
	public UUID getSecUuid() {
249
		return secUuid;
250
	}
251

    
252

    
253
	/**
254
	 * @param secUuid the secUuid to set
255
	 */
256
	public void setSecUuid(UUID secUuid) {
257
		this.secUuid = secUuid;
258
	}
259

    
260
	/**
261
	 * @return the sourceSecId
262
	 */
263
	public Object getSourceSecId() {
264
		return sourceSecId;
265
	}
266

    
267
	/**
268
	 * @param sourceSecId the sourceSecId to set
269
	 */
270
	public void setSourceSecId(Object sourceSecId) {
271
		this.sourceSecId = sourceSecId;
272
	}
273
	
274
	public Class<ICdmIO>[] getIoClassList(){
275
		return ioClassList;
276
	}
277
	
278

    
279
	/**
280
	 * @return the featureMap
281
	 */
282
	public MapWrapper<Feature> getFeatureMap() {
283
		return featureMap;
284
	}
285

    
286
	/**
287
	 * @param featureMap the featureMap to set
288
	 */
289
	public void setFeatureMap(MapWrapper<Feature> featureMap) {
290
		this.featureMap = featureMap;
291
	}
292

    
293
	
294
	/**
295
	 * Returns a <code>CdmApplicationController</code> created by the values of this configuration.
296
	 * If a controller was already created before the last created controller is returned.
297
	 * @return
298
	 */
299
	public CdmApplicationController getCdmAppController(){
300
		return getCdmAppController(false);
301
	}
302
	
303
	/**
304
	 * Returns a new instance of <code>CdmApplicationController</code> created by the values of this configuration.
305
	 * @return
306
	 */
307
	public CdmApplicationController getNewCdmAppController(){
308
		return getCdmAppController(true, false);
309
	}
310
	
311
	/**
312
	 * Returns a <code>CdmApplicationController</code> created by the values of this configuration.
313
	 * If create new is true always a new controller is returned, else the last created controller is returned. If no controller has
314
	 * been created before a new controller is returned.
315
	 * @return
316
	 */
317
	public CdmApplicationController getCdmAppController(boolean createNew){
318
		return getCdmAppController(createNew, false);
319
	}
320
	
321
	
322
	/**
323
	 * Returns a <code>CdmApplicationController</code> created by the values of this configuration.
324
	 * If create new is true always a new controller is returned, else the last created controller is returned. If no controller has
325
	 * been created before a new controller is returned.
326
	 * @return
327
	 */
328
	public CdmApplicationController getCdmAppController(boolean createNew, boolean omitTermLoading){
329
		if (cdmApp == null || createNew == true){
330
			try {
331
				cdmApp = CdmApplicationController.NewInstance(this.getDestination(), this.getDbSchemaValidation(), omitTermLoading);
332
			} catch (DataSourceNotFoundException e) {
333
				logger.error("could not connect to destination database");
334
				return null;
335
			}catch (TermNotFoundException e) {
336
				logger.error("could not find needed term in destination datasource");
337
				return null;
338
			}
339
		}
340
		return cdmApp;
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
}
(14-14/20)