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
.springframework
.security
.authentication
.UsernamePasswordAuthenticationToken
;
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
{
39 private CHECK check
= CHECK
.CHECK_AND_IMPORT
;
42 static EDITOR editor
= EDITOR
.EDITOR_AS_ANNOTATION
;
45 * The transformer class to be used for Input
47 private IInputTransformer transformer
;
51 // private boolean deleteAll = false;
54 private boolean ignoreNull
= false;
57 private NomenclaturalCode nomenclaturalCode
= null;
59 private Map
<Integer
, Feature
> featureMap
= new HashMap
<Integer
, Feature
>();
61 /* The classification name for the first classification.
62 * Needs only to be defined if the import does not handle the naming
63 * itself (e.g. by using the taxon sec. reference title cache)
65 private String classificationName
= "Classification - no name";
67 private UUID classificationUuid
= UUID
.randomUUID();
68 //uuid of concept reference
69 private UUID secUuid
= UUID
.randomUUID();
71 private Object sourceSecId
= -1;
73 private SOURCE source
;
74 protected Reference sourceReference
;
75 private UUID sourceRefUuid
;
76 private ICdmDataSource destination
;
77 private Person commentator
= Person
.NewTitledInstance("automatic CDM importer");
79 protected Class
<ICdmImport
>[] ioClassList
;
81 protected ICdmIO
[] ioList
;
83 protected String
[] ioBeans
;
86 private boolean askUserForHelp
=false;
89 /* *****************CONSTRUCTOR *****************************/
91 protected ImportConfiguratorBase(IInputTransformer transformer
){
93 setDbSchemaValidation(DbSchemaValidation
.UPDATE
);
94 this.transformer
= transformer
;
98 abstract protected void makeIoClassList();
101 public IInputTransformer
getTransformer() {
102 return this.transformer
;
106 public void setTransformer(IInputTransformer transformer
){
107 this.transformer
= transformer
;
111 * @param source the source to set
113 public void setSource(SOURCE source
) {
114 this.source
= source
;
118 * @param source the source to get
121 public SOURCE
getSource() {
126 public boolean isValid(){
127 boolean result
= true;
128 if (getSource() == null){
129 //logger.warn("Connection to source could not be established");
132 //Not valid any more as the importer may already have a destination
133 // if (destination == null ){
134 // logger.warn("Connection to Cdm could not be established");
143 /* ****************** GETTER/SETTER **************************/
146 public void setIoClassList(ICdmImport
[] ioList
){
147 this.ioList
= ioList
;
151 public Class
<ICdmImport
>[] getIoClassList(){
152 if (ioClassList
== null){
161 public void setIoClassList(Class
<ICdmImport
>[] ioClassList
){
162 this.ioClassList
= ioClassList
;
166 public CHECK
getCheck() {
171 public void setCheck(CHECK check
) {
180 public EDITOR
getEditor() {
185 * @param editor the editor to set
188 public void setEditor(EDITOR editor
) {
189 ImportConfiguratorBase
.editor
= editor
;
193 * If true, no errors occur if objects are not found that should exist. This may
194 * be needed e.g. when only subsets of the data are imported.
195 * Default value is <cod>false</code>.
196 * @return the ignoreNull
199 public boolean isIgnoreNull() {
204 * @param ignoreNull the ignoreNull to set
207 public void setIgnoreNull(boolean ignoreNull
) {
208 this.ignoreNull
= ignoreNull
;
212 public ICdmDataSource
getDestination() {
216 public void setDestination(ICdmDataSource destination
) {
217 this.destination
= destination
;
221 public abstract Reference
getSourceReference();
223 public void setSourceReference(Reference sourceReference
) {
224 this.sourceReference
= sourceReference
;
227 public String
getSourceReferenceTitle() {
228 return getSourceReference().getTitleCache();
231 public void setSourceReferenceTitle(String sourceReferenceTitle
) {
232 getSourceReference().setTitleCache(sourceReferenceTitle
, true);
236 public Person
getCommentator() {
241 public void setCommentator(Person commentator
) {
242 this.commentator
= commentator
;
246 * @return the nomenclaturalCode
249 public NomenclaturalCode
getNomenclaturalCode() {
250 return nomenclaturalCode
;
255 * @param nomenclaturalCode the nomenclaturalCode to set
258 public void setNomenclaturalCode(NomenclaturalCode nomenclaturalCode
) {
259 this.nomenclaturalCode
= nomenclaturalCode
;
263 public UUID
getClassificationUuid() {
264 return classificationUuid
;
269 public void setClassificationUuid(UUID classificationUuid
) {
270 this.classificationUuid
= classificationUuid
;
275 public UUID
getSecUuid() {
279 public void setSecUuid(UUID secUuid
) {
280 this.secUuid
= secUuid
;
284 * @return the sourceSecId
287 public Object
getSourceSecId() {
292 * @param sourceSecId the sourceSecId to set
294 public void setSourceSecId(Object sourceSecId
) {
295 this.sourceSecId
= sourceSecId
;
300 * @return the featureMap
302 public Map
<Integer
, Feature
> getFeatureMap() {
307 * @param featureMap the featureMap to set
309 public void setFeatureMap(Map
<Integer
, Feature
> featureMap
) {
310 this.featureMap
= featureMap
;
314 protected static Method
getDefaultFunction(Class
<?
> clazz
, String methodName
){
316 return clazz
.getMethod(methodName
, List
.class) ;
317 } catch (SecurityException e
) {
319 } catch (NoSuchMethodException e
) {
326 public String
getDestinationNameString() {
327 if (this.getDestination() == null) {
330 return this.getDestination().getName().toString();
335 public String
getSourceNameString() {
336 if (this.getSource() == null){
339 return this.getSource().toString();
344 * The classification name for the first classification.
345 * Needs only to be defined if the import does not handle the naming
346 * itself (e.g. by using the taxon sec. reference title cache)
347 * @param classificationName the classificationName to set
349 public void setClassificationName(String classificationName
) {
350 this.classificationName
= classificationName
;
354 * @return the classificationName
356 public String
getClassificationName() {
357 return classificationName
;
361 public UUID
getSourceRefUuid() {
362 return sourceRefUuid
;
367 public void setSourceRefUuid(UUID sourceRefUuid
) {
368 this.sourceRefUuid
= sourceRefUuid
;
372 public boolean isOmitTermLoading() {
377 public boolean isCreateNew(){
382 public UsernamePasswordAuthenticationToken
getAuthenticationToken(){
383 return this.authenticationToken
;
387 public boolean isInteractWithUser() {
388 return askUserForHelp
;
391 public void setInteractWithUser (boolean interaction
){
392 askUserForHelp
=interaction
;