some generics
[cdmlib.git] / cdmlib-io / src / main / java / eu / etaxonomy / cdm / io / common / ImportConfiguratorBase.java
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.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.Reference;
28
29 /**
30 * @author a.mueller
31 * @created 20.06.2008
32 * @param <STATE>
33 */
34 @Component
35 public abstract class ImportConfiguratorBase<STATE extends ImportStateBase, SOURCE> extends IoConfiguratorBase implements IImportConfigurator{
36 private static final Logger logger = Logger.getLogger(ImportConfiguratorBase.class);
37
38 //check
39 private CHECK check = CHECK.CHECK_AND_IMPORT;
40
41 //editor
42 static EDITOR editor = EDITOR.EDITOR_AS_ANNOTATION;
43
44
45 /**
46 * The transformer class to be used for Input
47 */
48 private IInputTransformer transformer;
49
50 //
51 // //TODO
52 // private boolean deleteAll = false;
53
54 //nullValues
55 private boolean ignoreNull = false;
56
57 //Nomenclatural Code
58 private NomenclaturalCode nomenclaturalCode = null;
59
60 private Map<Integer, Feature> featureMap = new HashMap<Integer, Feature>();
61
62 /* The classification name for the first classification.
63 * Needs only to be defined if the import does not handle the naming
64 * itself (e.g. by using the taxon sec. reference title cache)
65 */
66 private String classificationName = "Classification - no name";
67
68 private UUID classificationUuid = UUID.randomUUID();
69 //uuid of concept reference
70 private UUID secUuid = UUID.randomUUID();
71
72 private Object sourceSecId = -1;
73
74 private SOURCE source;
75 protected Reference sourceReference;
76 private UUID sourceRefUuid;
77 private ICdmDataSource destination;
78 private Person commentator = Person.NewTitledInstance("automatic CDM importer");
79
80 protected Class<ICdmIO>[] ioClassList;
81
82 protected ICdmIO[] ioList;
83
84 protected String[] ioBeans;
85
86 /* *****************CONSTRUCTOR *****************************/
87
88 public ImportConfiguratorBase(IInputTransformer transformer){
89 super();
90 setDbSchemaValidation(DbSchemaValidation.UPDATE);
91 this.transformer = transformer;
92
93 }
94
95 abstract protected void makeIoClassList();
96
97 /* (non-Javadoc)
98 * @see eu.etaxonomy.cdm.io.common.IImportConfigurator#getTransformer()
99 */
100 public IInputTransformer getTransformer() {
101 return this.transformer;
102 }
103
104 /* (non-Javadoc)
105 * @see eu.etaxonomy.cdm.io.common.IImportConfigurator#setTransformer(eu.etaxonomy.cdm.io.common.mapping.IInputTransformer)
106 */
107 public void setTransformer(IInputTransformer transformer){
108 this.transformer = transformer;
109 }
110
111
112
113
114 /**
115 * @param source the source to set
116 */
117 public void setSource(SOURCE source) {
118 this.source = source;
119 }
120
121
122 /**
123 * @param source the source to get
124 */
125 public SOURCE getSource() {
126 return source;
127 }
128
129
130
131 /* (non-Javadoc)
132 * @see eu.etaxonomy.cdm.io.common.IImportConfigurator#isValid()
133 */
134 public boolean isValid(){
135 boolean result = true;
136 if (source == null){
137 logger.warn("Connection to source could not be established");
138 result = false;
139 }
140 //Not valid any more as the importer may already have a destination
141 // if (destination == null ){
142 // logger.warn("Connection to Cdm could not be established");
143 // result = false;
144 // }
145
146 return result;
147 }
148
149
150
151 /* ****************** GETTER/SETTER **************************/
152
153 // /**
154 // * @return the state
155 // */
156 // public STATE getState() {
157 // return state;
158 // }
159 //
160 // /**
161 // * @param state the state to set
162 // */
163 // public void setState(STATE state) {
164 // this.state = state;
165 // }
166
167 public void setIoClassList(ICdmIO[] ioList){
168 this.ioList = ioList;
169 }
170
171 public Class<ICdmIO>[] getIoClassList(){
172 if (ioClassList == null){
173 makeIoClassList();
174 }
175 return ioClassList;
176 }
177
178 /**
179 * @param ioClassList
180 */
181 public void setIoClassList(Class<ICdmIO>[] ioClassList){
182 this.ioClassList = ioClassList;
183 }
184
185
186 /* (non-Javadoc)
187 * @see eu.etaxonomy.cdm.io.tcsrdf.IImportConfigurator#getCheck()
188 */
189 public CHECK getCheck() {
190 return this.check;
191 }
192
193 /* (non-Javadoc)
194 * @see eu.etaxonomy.cdm.io.common.IImportConfigurator#setCheck(eu.etaxonomy.cdm.io.common.IImportConfigurator.CHECK)
195 */
196 public void setCheck(CHECK check) {
197 this.check = check;
198 }
199
200
201 /**
202 * @return the editor
203 */
204 public EDITOR getEditor() {
205 return editor;
206 }
207
208 /**
209 * @param editor the editor to set
210 */
211 public void setEditor(EDITOR editor) {
212 ImportConfiguratorBase.editor = editor;
213 }
214
215 /**
216 * If true, no errors occur if objects are not found that should exist. This may
217 * be needed e.g. when only subsets of the data are imported.
218 * Default value is <cod>false</code>.
219 * @return the ignoreNull
220 */
221 public boolean isIgnoreNull() {
222 return ignoreNull;
223 }
224
225 /**
226 * @param ignoreNull the ignoreNull to set
227 */
228 public void setIgnoreNull(boolean ignoreNull) {
229 this.ignoreNull = ignoreNull;
230 }
231
232 /* (non-Javadoc)
233 * @see eu.etaxonomy.cdm.io.tcsrdf.IImportConfigurator#getDestination()
234 */
235 public ICdmDataSource getDestination() {
236 return destination;
237 }
238 /* (non-Javadoc)
239 * @see eu.etaxonomy.cdm.io.tcsrdf.IImportConfigurator#setDestination(eu.etaxonomy.cdm.database.ICdmDataSource)
240 */
241 public void setDestination(ICdmDataSource destination) {
242 this.destination = destination;
243 }
244
245
246 /* (non-Javadoc)
247 * @see eu.etaxonomy.cdm.io.tcsrdf.IImportConfigurator#getSourceReference()
248 */
249 public abstract Reference getSourceReference();
250 /* (non-Javadoc)
251 * @see eu.etaxonomy.cdm.io.tcsrdf.IImportConfigurator#setSourceReference(eu.etaxonomy.cdm.model.reference.Reference)
252 */
253 public void setSourceReference(Reference sourceReference) {
254 this.sourceReference = sourceReference;
255 }
256 /* (non-Javadoc)
257 * @see eu.etaxonomy.cdm.io.tcsrdf.IImportConfigurator#getSourceReferenceTitle()
258 */
259 public String getSourceReferenceTitle() {
260 return getSourceReference().getTitleCache();
261 }
262 /* (non-Javadoc)
263 * @see eu.etaxonomy.cdm.io.tcsrdf.IImportConfigurator#setSourceReferenceTitle(java.lang.String)
264 */
265 public void setSourceReferenceTitle(String sourceReferenceTitle) {
266 getSourceReference().setTitleCache(sourceReferenceTitle, true);
267 }
268
269
270 /* (non-Javadoc)
271 * @see eu.etaxonomy.cdm.io.tcsrdf.IImportConfigurator#getCommentator()
272 */
273 public Person getCommentator() {
274 return commentator;
275 }
276
277 /* (non-Javadoc)
278 * @see eu.etaxonomy.cdm.io.tcsrdf.IImportConfigurator#setCommentator(eu.etaxonomy.cdm.model.agent.Person)
279 */
280 public void setCommentator(Person commentator) {
281 this.commentator = commentator;
282 }
283
284 /**
285 * @return the nomenclaturalCode
286 */
287 public NomenclaturalCode getNomenclaturalCode() {
288 return nomenclaturalCode;
289 }
290
291
292 /**
293 * @param nomenclaturalCode the nomenclaturalCode to set
294 */
295 public void setNomenclaturalCode(NomenclaturalCode nomenclaturalCode) {
296 this.nomenclaturalCode = nomenclaturalCode;
297 }
298
299
300 /* (non-Javadoc)
301 * @see eu.etaxonomy.cdm.io.common.IImportConfigurator#getTreeUuid()
302 */
303 public UUID getClassificationUuid() {
304 return classificationUuid;
305 }
306
307
308 public void setClassificationUuid(UUID classificationUuid) {
309 this.classificationUuid = classificationUuid;
310 }
311
312 /* (non-Javadoc)
313 * @see eu.etaxonomy.cdm.io.common.IImportConfigurator#getSecUuid()
314 */
315 public UUID getSecUuid() {
316 return secUuid;
317 }
318 public void setSecUuid(UUID secUuid) {
319 this.secUuid = secUuid;
320 }
321
322 /**
323 * @return the sourceSecId
324 */
325 public Object getSourceSecId() {
326 return sourceSecId;
327 }
328
329 /**
330 * @param sourceSecId the sourceSecId to set
331 */
332 public void setSourceSecId(Object sourceSecId) {
333 this.sourceSecId = sourceSecId;
334 }
335
336
337 /**
338 * @return the featureMap
339 */
340 public Map<Integer, Feature> getFeatureMap() {
341 return featureMap;
342 }
343
344 /**
345 * @param featureMap the featureMap to set
346 */
347 public void setFeatureMap(Map<Integer, Feature> featureMap) {
348 this.featureMap = featureMap;
349 }
350
351
352 protected static Method getDefaultFunction(Class<?> clazz, String methodName){
353 try {
354 return clazz.getMethod(methodName, List.class) ;
355 } catch (SecurityException e) {
356 logger.error(e.getMessage());
357 e.printStackTrace();
358 } catch (NoSuchMethodException e) {
359 logger.error(e.getMessage());
360 e.printStackTrace();
361 }
362 return null;
363 }
364
365
366 /* (non-Javadoc)
367 * @see eu.etaxonomy.cdm.io.common.IIoConfigurator#getDestinationNameString()
368 */
369 public String getDestinationNameString() {
370 if (this.getDestination() == null) {
371 return null;
372 } else {
373 return this.getDestination().getName().toString();
374 }
375 }
376
377 /* (non-Javadoc)
378 * @see eu.etaxonomy.cdm.io.common.IImportConfigurator#getSourceNameString()
379 */
380 public String getSourceNameString() {
381 if (this.getSource() == null){
382 return null;
383 }else{
384 return this.getSource().toString();
385 }
386 }
387
388 /**
389 * The classification name for the first classification.
390 * Needs only to be defined if the import does not handle the naming
391 * itself (e.g. by using the taxon sec. reference title cache)
392 * @param classificationName the classificationName to set
393 */
394 public void setClassificationName(String classificationName) {
395 this.classificationName = classificationName;
396 }
397
398 /**
399 * @return the classificationName
400 */
401 public String getClassificationName() {
402 return classificationName;
403 }
404
405
406 public UUID getSourceRefUuid() {
407 return sourceRefUuid;
408 }
409
410
411
412 public void setSourceRefUuid(UUID sourceRefUuid) {
413 this.sourceRefUuid = sourceRefUuid;
414 }
415
416
417 }