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;
144 if (getSource() == null){
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
;
195 public CHECK
getCheck() {
200 public void setCheck(CHECK check
) {
209 public EDITOR
getEditor() {
214 * @param editor the editor to set
217 public void setEditor(EDITOR editor
) {
218 ImportConfiguratorBase
.editor
= editor
;
222 * If true, no errors occur if objects are not found that should exist. This may
223 * be needed e.g. when only subsets of the data are imported.
224 * Default value is <cod>false</code>.
225 * @return the ignoreNull
228 public boolean isIgnoreNull() {
233 * @param ignoreNull the ignoreNull to set
236 public void setIgnoreNull(boolean ignoreNull
) {
237 this.ignoreNull
= ignoreNull
;
241 public ICdmDataSource
getDestination() {
245 public void setDestination(ICdmDataSource destination
) {
246 this.destination
= destination
;
250 public abstract Reference
getSourceReference();
252 public void setSourceReference(Reference sourceReference
) {
253 this.sourceReference
= sourceReference
;
256 public String
getSourceReferenceTitle() {
257 return getSourceReference().getTitleCache();
260 public void setSourceReferenceTitle(String sourceReferenceTitle
) {
261 getSourceReference().setTitleCache(sourceReferenceTitle
, true);
265 public Person
getCommentator() {
270 public void setCommentator(Person commentator
) {
271 this.commentator
= commentator
;
275 * @return the nomenclaturalCode
278 public NomenclaturalCode
getNomenclaturalCode() {
279 return nomenclaturalCode
;
284 * @param nomenclaturalCode the nomenclaturalCode to set
287 public void setNomenclaturalCode(NomenclaturalCode nomenclaturalCode
) {
288 this.nomenclaturalCode
= nomenclaturalCode
;
293 * @see eu.etaxonomy.cdm.io.common.IImportConfigurator#getTreeUuid()
296 public UUID
getClassificationUuid() {
297 return classificationUuid
;
302 public void setClassificationUuid(UUID classificationUuid
) {
303 this.classificationUuid
= classificationUuid
;
308 public UUID
getSecUuid() {
312 public void setSecUuid(UUID secUuid
) {
313 this.secUuid
= secUuid
;
317 * @return the sourceSecId
320 public Object
getSourceSecId() {
325 * @param sourceSecId the sourceSecId to set
327 public void setSourceSecId(Object sourceSecId
) {
328 this.sourceSecId
= sourceSecId
;
333 * @return the featureMap
335 public Map
<Integer
, Feature
> getFeatureMap() {
340 * @param featureMap the featureMap to set
342 public void setFeatureMap(Map
<Integer
, Feature
> featureMap
) {
343 this.featureMap
= featureMap
;
347 protected static Method
getDefaultFunction(Class
<?
> clazz
, String methodName
){
349 return clazz
.getMethod(methodName
, List
.class) ;
350 } catch (SecurityException e
) {
351 logger
.error(e
.getMessage());
353 } catch (NoSuchMethodException e
) {
354 logger
.error(e
.getMessage());
362 * @see eu.etaxonomy.cdm.io.common.IIoConfigurator#getDestinationNameString()
365 public String
getDestinationNameString() {
366 if (this.getDestination() == null) {
369 return this.getDestination().getName().toString();
374 * @see eu.etaxonomy.cdm.io.common.IImportConfigurator#getSourceNameString()
377 public String
getSourceNameString() {
378 if (this.getSource() == null){
381 return this.getSource().toString();
386 * The classification name for the first classification.
387 * Needs only to be defined if the import does not handle the naming
388 * itself (e.g. by using the taxon sec. reference title cache)
389 * @param classificationName the classificationName to set
391 public void setClassificationName(String classificationName
) {
392 this.classificationName
= classificationName
;
396 * @return the classificationName
398 public String
getClassificationName() {
399 return classificationName
;
403 public UUID
getSourceRefUuid() {
404 return sourceRefUuid
;
409 public void setSourceRefUuid(UUID sourceRefUuid
) {
410 this.sourceRefUuid
= sourceRefUuid
;
414 * @see eu.etaxonomy.cdm.io.common.IImportConfigurator#isOmitTermLoading()
417 public boolean isOmitTermLoading() {
422 * @see eu.etaxonomy.cdm.io.common.IImportConfigurator#isCreateNew()
425 public boolean isCreateNew(){
430 public UsernamePasswordAuthenticationToken
getAuthenticationToken(){
431 return this.authenticationToken
;
435 public boolean isInteractWithUser() {
436 return askUserForHelp
;
439 public void setInteractWithUser (boolean interaction
){
440 askUserForHelp
=interaction
;