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
.security
.authentication
.UsernamePasswordAuthenticationToken
;
20 import org
.springframework
.stereotype
.Component
;
22 import eu
.etaxonomy
.cdm
.database
.DbSchemaValidation
;
23 import eu
.etaxonomy
.cdm
.database
.ICdmDataSource
;
24 import eu
.etaxonomy
.cdm
.io
.common
.mapping
.IInputTransformer
;
25 import eu
.etaxonomy
.cdm
.model
.agent
.Person
;
26 import eu
.etaxonomy
.cdm
.model
.description
.Feature
;
27 import eu
.etaxonomy
.cdm
.model
.name
.NomenclaturalCode
;
28 import eu
.etaxonomy
.cdm
.model
.reference
.Reference
;
36 public abstract class ImportConfiguratorBase
<STATE
extends ImportStateBase
, SOURCE
> extends IoConfiguratorBase
implements IImportConfigurator
{
37 private static final Logger logger
= Logger
.getLogger(ImportConfiguratorBase
.class);
40 private CHECK check
= CHECK
.CHECK_AND_IMPORT
;
43 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
;
87 private boolean askUserForHelp
=false;
90 /* *****************CONSTRUCTOR *****************************/
92 public ImportConfiguratorBase(IInputTransformer transformer
){
94 setDbSchemaValidation(DbSchemaValidation
.UPDATE
);
95 this.transformer
= transformer
;
99 abstract protected void makeIoClassList();
102 * @see eu.etaxonomy.cdm.io.common.IImportConfigurator#getTransformer()
105 public IInputTransformer
getTransformer() {
106 return this.transformer
;
110 * @see eu.etaxonomy.cdm.io.common.IImportConfigurator#setTransformer(eu.etaxonomy.cdm.io.common.mapping.IInputTransformer)
113 public void setTransformer(IInputTransformer transformer
){
114 this.transformer
= transformer
;
121 * @param source the source to set
123 public void setSource(SOURCE source
) {
124 this.source
= source
;
129 * @param source the source to get
132 public SOURCE
getSource() {
139 * @see eu.etaxonomy.cdm.io.common.IImportConfigurator#isValid()
142 public boolean isValid(){
143 boolean result
= true;
145 logger
.warn("Connection to source could not be established");
148 //Not valid any more as the importer may already have a destination
149 // if (destination == null ){
150 // logger.warn("Connection to Cdm could not be established");
159 /* ****************** GETTER/SETTER **************************/
162 // * @return the state
164 // public STATE getState() {
169 // * @param state the state to set
171 // public void setState(STATE state) {
172 // this.state = state;
175 public void setIoClassList(ICdmIO
[] ioList
){
176 this.ioList
= ioList
;
180 public Class
<ICdmIO
>[] getIoClassList(){
181 if (ioClassList
== null){
190 public void setIoClassList(Class
<ICdmIO
>[] ioClassList
){
191 this.ioClassList
= ioClassList
;
196 * @see eu.etaxonomy.cdm.io.tcsrdf.IImportConfigurator#getCheck()
199 public CHECK
getCheck() {
204 * @see eu.etaxonomy.cdm.io.common.IImportConfigurator#setCheck(eu.etaxonomy.cdm.io.common.IImportConfigurator.CHECK)
207 public void setCheck(CHECK check
) {
216 public EDITOR
getEditor() {
221 * @param editor the editor to set
224 public void setEditor(EDITOR editor
) {
225 ImportConfiguratorBase
.editor
= editor
;
229 * If true, no errors occur if objects are not found that should exist. This may
230 * be needed e.g. when only subsets of the data are imported.
231 * Default value is <cod>false</code>.
232 * @return the ignoreNull
235 public boolean isIgnoreNull() {
240 * @param ignoreNull the ignoreNull to set
243 public void setIgnoreNull(boolean ignoreNull
) {
244 this.ignoreNull
= ignoreNull
;
248 * @see eu.etaxonomy.cdm.io.tcsrdf.IImportConfigurator#getDestination()
251 public ICdmDataSource
getDestination() {
255 * @see eu.etaxonomy.cdm.io.tcsrdf.IImportConfigurator#setDestination(eu.etaxonomy.cdm.database.ICdmDataSource)
258 public void setDestination(ICdmDataSource destination
) {
259 this.destination
= destination
;
264 * @see eu.etaxonomy.cdm.io.tcsrdf.IImportConfigurator#getSourceReference()
267 public abstract Reference
getSourceReference();
269 * @see eu.etaxonomy.cdm.io.tcsrdf.IImportConfigurator#setSourceReference(eu.etaxonomy.cdm.model.reference.Reference)
272 public void setSourceReference(Reference sourceReference
) {
273 this.sourceReference
= sourceReference
;
276 * @see eu.etaxonomy.cdm.io.tcsrdf.IImportConfigurator#getSourceReferenceTitle()
279 public String
getSourceReferenceTitle() {
280 return getSourceReference().getTitleCache();
283 * @see eu.etaxonomy.cdm.io.tcsrdf.IImportConfigurator#setSourceReferenceTitle(java.lang.String)
286 public void setSourceReferenceTitle(String sourceReferenceTitle
) {
287 getSourceReference().setTitleCache(sourceReferenceTitle
, true);
292 * @see eu.etaxonomy.cdm.io.tcsrdf.IImportConfigurator#getCommentator()
295 public Person
getCommentator() {
300 * @see eu.etaxonomy.cdm.io.tcsrdf.IImportConfigurator#setCommentator(eu.etaxonomy.cdm.model.agent.Person)
303 public void setCommentator(Person commentator
) {
304 this.commentator
= commentator
;
308 * @return the nomenclaturalCode
311 public NomenclaturalCode
getNomenclaturalCode() {
312 return nomenclaturalCode
;
317 * @param nomenclaturalCode the nomenclaturalCode to set
320 public void setNomenclaturalCode(NomenclaturalCode nomenclaturalCode
) {
321 this.nomenclaturalCode
= nomenclaturalCode
;
326 * @see eu.etaxonomy.cdm.io.common.IImportConfigurator#getTreeUuid()
329 public UUID
getClassificationUuid() {
330 return classificationUuid
;
335 public void setClassificationUuid(UUID classificationUuid
) {
336 this.classificationUuid
= classificationUuid
;
340 * @see eu.etaxonomy.cdm.io.common.IImportConfigurator#getSecUuid()
343 public UUID
getSecUuid() {
347 public void setSecUuid(UUID secUuid
) {
348 this.secUuid
= secUuid
;
352 * @return the sourceSecId
355 public Object
getSourceSecId() {
360 * @param sourceSecId the sourceSecId to set
362 public void setSourceSecId(Object sourceSecId
) {
363 this.sourceSecId
= sourceSecId
;
368 * @return the featureMap
370 public Map
<Integer
, Feature
> getFeatureMap() {
375 * @param featureMap the featureMap to set
377 public void setFeatureMap(Map
<Integer
, Feature
> featureMap
) {
378 this.featureMap
= featureMap
;
382 protected static Method
getDefaultFunction(Class
<?
> clazz
, String methodName
){
384 return clazz
.getMethod(methodName
, List
.class) ;
385 } catch (SecurityException e
) {
386 logger
.error(e
.getMessage());
388 } catch (NoSuchMethodException e
) {
389 logger
.error(e
.getMessage());
397 * @see eu.etaxonomy.cdm.io.common.IIoConfigurator#getDestinationNameString()
400 public String
getDestinationNameString() {
401 if (this.getDestination() == null) {
404 return this.getDestination().getName().toString();
409 * @see eu.etaxonomy.cdm.io.common.IImportConfigurator#getSourceNameString()
412 public String
getSourceNameString() {
413 if (this.getSource() == null){
416 return this.getSource().toString();
421 * The classification name for the first classification.
422 * Needs only to be defined if the import does not handle the naming
423 * itself (e.g. by using the taxon sec. reference title cache)
424 * @param classificationName the classificationName to set
426 public void setClassificationName(String classificationName
) {
427 this.classificationName
= classificationName
;
431 * @return the classificationName
433 public String
getClassificationName() {
434 return classificationName
;
438 public UUID
getSourceRefUuid() {
439 return sourceRefUuid
;
444 public void setSourceRefUuid(UUID sourceRefUuid
) {
445 this.sourceRefUuid
= sourceRefUuid
;
449 * @see eu.etaxonomy.cdm.io.common.IImportConfigurator#isOmitTermLoading()
452 public boolean isOmitTermLoading() {
457 * @see eu.etaxonomy.cdm.io.common.IImportConfigurator#isCreateNew()
460 public boolean isCreateNew(){
465 public UsernamePasswordAuthenticationToken
getAuthenticationToken(){
466 return this.authenticationToken
;
470 public boolean isInteractWithUser() {
471 return askUserForHelp
;
474 public void setInteractWithUser (boolean interaction
){
475 askUserForHelp
=interaction
;