2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
10 package eu
.etaxonomy
.cdm
.io
.common
;
12 import java
.lang
.reflect
.Method
;
13 import java
.util
.HashMap
;
14 import java
.util
.List
;
16 import java
.util
.UUID
;
18 import org
.apache
.log4j
.Logger
;
19 import org
.springframework
.stereotype
.Component
;
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
;
35 public abstract class ImportConfiguratorBase
<STATE
extends ImportStateBase
, SOURCE
> extends IoConfiguratorBase
implements IImportConfigurator
{
36 private static final Logger logger
= Logger
.getLogger(ImportConfiguratorBase
.class);
39 private CHECK check
= CHECK
.CHECK_AND_IMPORT
;
42 static EDITOR editor
= EDITOR
.EDITOR_AS_ANNOTATION
;
46 * The transformer class to be used for Input
48 private IInputTransformer transformer
;
52 // private boolean deleteAll = false;
55 private boolean ignoreNull
= false;
58 private NomenclaturalCode nomenclaturalCode
= null;
60 private Map
<Integer
, Feature
> featureMap
= new HashMap
<Integer
, Feature
>();
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)
66 private String classificationName
= "Classification - no name";
68 private UUID classificationUuid
= UUID
.randomUUID();
69 //uuid of concept reference
70 private UUID secUuid
= UUID
.randomUUID();
72 private Object sourceSecId
= -1;
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");
80 protected Class
<ICdmIO
>[] ioClassList
;
82 protected ICdmIO
[] ioList
;
84 protected String
[] ioBeans
;
86 /* *****************CONSTRUCTOR *****************************/
88 public ImportConfiguratorBase(IInputTransformer transformer
){
90 setDbSchemaValidation(DbSchemaValidation
.UPDATE
);
91 this.transformer
= transformer
;
95 abstract protected void makeIoClassList();
98 * @see eu.etaxonomy.cdm.io.common.IImportConfigurator#getTransformer()
100 public IInputTransformer
getTransformer() {
101 return this.transformer
;
105 * @see eu.etaxonomy.cdm.io.common.IImportConfigurator#setTransformer(eu.etaxonomy.cdm.io.common.mapping.IInputTransformer)
107 public void setTransformer(IInputTransformer transformer
){
108 this.transformer
= transformer
;
115 * @param source the source to set
117 public void setSource(SOURCE source
) {
118 this.source
= source
;
123 * @param source the source to get
125 public SOURCE
getSource() {
132 * @see eu.etaxonomy.cdm.io.common.IImportConfigurator#isValid()
134 public boolean isValid(){
135 boolean result
= true;
137 logger
.warn("Connection to source could not be established");
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");
151 /* ****************** GETTER/SETTER **************************/
154 // * @return the state
156 // public STATE getState() {
161 // * @param state the state to set
163 // public void setState(STATE state) {
164 // this.state = state;
167 public void setIoClassList(ICdmIO
[] ioList
){
168 this.ioList
= ioList
;
171 public Class
<ICdmIO
>[] getIoClassList(){
172 if (ioClassList
== null){
181 public void setIoClassList(Class
<ICdmIO
>[] ioClassList
){
182 this.ioClassList
= ioClassList
;
187 * @see eu.etaxonomy.cdm.io.tcsrdf.IImportConfigurator#getCheck()
189 public CHECK
getCheck() {
194 * @see eu.etaxonomy.cdm.io.common.IImportConfigurator#setCheck(eu.etaxonomy.cdm.io.common.IImportConfigurator.CHECK)
196 public void setCheck(CHECK check
) {
204 public EDITOR
getEditor() {
209 * @param editor the editor to set
211 public void setEditor(EDITOR editor
) {
212 ImportConfiguratorBase
.editor
= editor
;
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
221 public boolean isIgnoreNull() {
226 * @param ignoreNull the ignoreNull to set
228 public void setIgnoreNull(boolean ignoreNull
) {
229 this.ignoreNull
= ignoreNull
;
233 * @see eu.etaxonomy.cdm.io.tcsrdf.IImportConfigurator#getDestination()
235 public ICdmDataSource
getDestination() {
239 * @see eu.etaxonomy.cdm.io.tcsrdf.IImportConfigurator#setDestination(eu.etaxonomy.cdm.database.ICdmDataSource)
241 public void setDestination(ICdmDataSource destination
) {
242 this.destination
= destination
;
247 * @see eu.etaxonomy.cdm.io.tcsrdf.IImportConfigurator#getSourceReference()
249 public abstract Reference
getSourceReference();
251 * @see eu.etaxonomy.cdm.io.tcsrdf.IImportConfigurator#setSourceReference(eu.etaxonomy.cdm.model.reference.Reference)
253 public void setSourceReference(Reference sourceReference
) {
254 this.sourceReference
= sourceReference
;
257 * @see eu.etaxonomy.cdm.io.tcsrdf.IImportConfigurator#getSourceReferenceTitle()
259 public String
getSourceReferenceTitle() {
260 return getSourceReference().getTitleCache();
263 * @see eu.etaxonomy.cdm.io.tcsrdf.IImportConfigurator#setSourceReferenceTitle(java.lang.String)
265 public void setSourceReferenceTitle(String sourceReferenceTitle
) {
266 getSourceReference().setTitleCache(sourceReferenceTitle
, true);
271 * @see eu.etaxonomy.cdm.io.tcsrdf.IImportConfigurator#getCommentator()
273 public Person
getCommentator() {
278 * @see eu.etaxonomy.cdm.io.tcsrdf.IImportConfigurator#setCommentator(eu.etaxonomy.cdm.model.agent.Person)
280 public void setCommentator(Person commentator
) {
281 this.commentator
= commentator
;
285 * @return the nomenclaturalCode
287 public NomenclaturalCode
getNomenclaturalCode() {
288 return nomenclaturalCode
;
293 * @param nomenclaturalCode the nomenclaturalCode to set
295 public void setNomenclaturalCode(NomenclaturalCode nomenclaturalCode
) {
296 this.nomenclaturalCode
= nomenclaturalCode
;
301 * @see eu.etaxonomy.cdm.io.common.IImportConfigurator#getTreeUuid()
303 public UUID
getClassificationUuid() {
304 return classificationUuid
;
308 public void setClassificationUuid(UUID classificationUuid
) {
309 this.classificationUuid
= classificationUuid
;
313 * @see eu.etaxonomy.cdm.io.common.IImportConfigurator#getSecUuid()
315 public UUID
getSecUuid() {
318 public void setSecUuid(UUID secUuid
) {
319 this.secUuid
= secUuid
;
323 * @return the sourceSecId
325 public Object
getSourceSecId() {
330 * @param sourceSecId the sourceSecId to set
332 public void setSourceSecId(Object sourceSecId
) {
333 this.sourceSecId
= sourceSecId
;
338 * @return the featureMap
340 public Map
<Integer
, Feature
> getFeatureMap() {
345 * @param featureMap the featureMap to set
347 public void setFeatureMap(Map
<Integer
, Feature
> featureMap
) {
348 this.featureMap
= featureMap
;
352 protected static Method
getDefaultFunction(Class
<?
> clazz
, String methodName
){
354 return clazz
.getMethod(methodName
, List
.class) ;
355 } catch (SecurityException e
) {
356 logger
.error(e
.getMessage());
358 } catch (NoSuchMethodException e
) {
359 logger
.error(e
.getMessage());
367 * @see eu.etaxonomy.cdm.io.common.IIoConfigurator#getDestinationNameString()
369 public String
getDestinationNameString() {
370 if (this.getDestination() == null) {
373 return this.getDestination().getName().toString();
378 * @see eu.etaxonomy.cdm.io.common.IImportConfigurator#getSourceNameString()
380 public String
getSourceNameString() {
381 if (this.getSource() == null){
384 return this.getSource().toString();
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
394 public void setClassificationName(String classificationName
) {
395 this.classificationName
= classificationName
;
399 * @return the classificationName
401 public String
getClassificationName() {
402 return classificationName
;
406 public UUID
getSourceRefUuid() {
407 return sourceRefUuid
;
412 public void setSourceRefUuid(UUID sourceRefUuid
) {
413 this.sourceRefUuid
= sourceRefUuid
;