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.
9 package eu
.etaxonomy
.cdm
.io
.common
;
11 import java
.lang
.reflect
.Method
;
12 import java
.util
.HashMap
;
13 import java
.util
.List
;
15 import java
.util
.UUID
;
17 import org
.joda
.time
.DateTime
;
18 import org
.joda
.time
.format
.DateTimeFormat
;
19 import org
.joda
.time
.format
.DateTimeFormatter
;
20 import org
.springframework
.security
.authentication
.UsernamePasswordAuthenticationToken
;
21 import org
.springframework
.stereotype
.Component
;
23 import eu
.etaxonomy
.cdm
.database
.DbSchemaValidation
;
24 import eu
.etaxonomy
.cdm
.database
.ICdmDataSource
;
25 import eu
.etaxonomy
.cdm
.io
.common
.mapping
.IInputTransformer
;
26 import eu
.etaxonomy
.cdm
.model
.agent
.Person
;
27 import eu
.etaxonomy
.cdm
.model
.description
.Feature
;
28 import eu
.etaxonomy
.cdm
.model
.name
.NomenclaturalCode
;
29 import eu
.etaxonomy
.cdm
.model
.reference
.OriginalSourceType
;
30 import eu
.etaxonomy
.cdm
.model
.reference
.Reference
;
35 * @param <STATE> the import state
38 public abstract class ImportConfiguratorBase
<STATE
extends ImportStateBase
, SOURCE
>
39 extends IoConfiguratorBase
40 implements IImportConfigurator
{
42 private static final long serialVersionUID
= 7223140465020160905L;
45 private CHECK check
= CHECK
.CHECK_AND_IMPORT
;
48 static EDITOR editor
= EDITOR
.EDITOR_AS_ANNOTATION
;
51 * The transformer class to be used for Input
53 private IInputTransformer transformer
;
55 private UUID uuidFeatureTree
;
57 private String featureTreeTitle
;
60 private NomenclaturalCode nomenclaturalCode
= null;
62 private Map
<Integer
, Feature
> featureMap
= new HashMap
<>();
64 /* The classification name for the first classification.
65 * Needs only to be defined if the import does not handle the naming
66 * itself (e.g. by using the taxon sec. reference title cache)
68 private String classificationName
= "Classification - no name";
70 private UUID classificationUuid
= UUID
.randomUUID();
71 //uuid of concept reference
72 private UUID secUuid
= UUID
.randomUUID();
74 private Object sourceSecId
= -1;
76 private SOURCE source
;
77 protected Reference sourceReference
;
78 private UUID sourceRefUuid
;
79 private OriginalSourceType sourceType
= OriginalSourceType
.Import
;
80 private ICdmDataSource destination
;
81 private Person commentator
= Person
.NewTitledInstance("automatic CDM importer");
83 @SuppressWarnings("rawtypes")
84 protected Class
<ICdmImport
>[] ioClassList
;
86 @SuppressWarnings("rawtypes")
87 protected ICdmIO
[] ioList
;
89 protected String
[] ioBeans
;
92 private boolean askUserForHelp
=false;
94 /* *****************CONSTRUCTOR *****************************/
96 protected ImportConfiguratorBase(IInputTransformer transformer
){
97 setDbSchemaValidation(DbSchemaValidation
.VALIDATE
);
98 this.transformer
= transformer
;
101 abstract protected void makeIoClassList();
104 public IInputTransformer
getTransformer() {
105 return this.transformer
;
108 public void setTransformer(IInputTransformer transformer
){
109 this.transformer
= transformer
;
113 public SOURCE
getSource() {
116 public void setSource(SOURCE source
) {
117 this.source
= source
;
121 public boolean isValid(){
122 boolean result
= true;
123 if (getSource() == null){
124 //logger.warn("Connection to source could not be established");
127 //Not valid any more as the importer may already have a destination
128 // if (destination == null ){
129 // logger.warn("Connection to Cdm could not be established");
136 /* ****************** GETTER/SETTER **************************/
139 public void setIoClassList(ICdmImport
[] ioList
){
140 this.ioList
= ioList
;
144 public Class
<ICdmImport
>[] getIoClassList(){
145 if (ioClassList
== null){
150 public void setIoClassList(Class
<ICdmImport
>[] ioClassList
){
151 this.ioClassList
= ioClassList
;
155 public CHECK
getCheck() {
159 public void setCheck(CHECK check
) {
164 public EDITOR
getEditor() {
168 public void setEditor(EDITOR editor
) {
169 ImportConfiguratorBase
.editor
= editor
;
173 public ICdmDataSource
getDestination() {
177 public void setDestination(ICdmDataSource destination
) {
178 this.destination
= destination
;
182 public abstract Reference
getSourceReference();
184 public void setSourceReference(Reference sourceReference
) {
185 this.sourceReference
= sourceReference
;
189 public String
getSourceReferenceTitle() {
190 return getSourceReference().getTitleCache();
193 public void setSourceReferenceTitle(String sourceReferenceTitle
) {
194 getSourceReference().setTitleCache(sourceReferenceTitle
, true);
198 public Person
getCommentator() {
202 public void setCommentator(Person commentator
) {
203 this.commentator
= commentator
;
207 public NomenclaturalCode
getNomenclaturalCode() {
208 return nomenclaturalCode
;
211 public void setNomenclaturalCode(NomenclaturalCode nomenclaturalCode
) {
212 this.nomenclaturalCode
= nomenclaturalCode
;
216 public UUID
getClassificationUuid() {
217 return classificationUuid
;
220 public void setClassificationUuid(UUID classificationUuid
) {
221 this.classificationUuid
= classificationUuid
;
225 public UUID
getSecUuid() {
229 public void setSecUuid(UUID secUuid
) {
230 this.secUuid
= secUuid
;
234 public Object
getSourceSecId() {
237 public void setSourceSecId(Object sourceSecId
) {
238 this.sourceSecId
= sourceSecId
;
241 public Map
<Integer
, Feature
> getFeatureMap() {
244 public void setFeatureMap(Map
<Integer
, Feature
> featureMap
) {
245 this.featureMap
= featureMap
;
248 protected static Method
getDefaultFunction(Class
<?
> clazz
, String methodName
){
250 return clazz
.getMethod(methodName
, List
.class) ;
251 } catch (SecurityException e
) {
253 } catch (NoSuchMethodException e
) {
260 public String
getDestinationNameString() {
261 if (this.getDestination() == null) {
264 return this.getDestination().getName().toString();
269 public String
getSourceNameString() {
270 if (this.getSource() == null){
273 return this.getSource().toString();
278 * The classification name for the first classification.
279 * Needs only to be defined if the import does not handle the naming
280 * itself (e.g. by using the taxon sec. reference title cache)
282 public void setClassificationName(String classificationName
) {
283 this.classificationName
= classificationName
;
285 public String
getClassificationName() {
286 return classificationName
;
289 public UUID
getSourceRefUuid() {
290 return sourceRefUuid
;
292 public void setSourceRefUuid(UUID sourceRefUuid
) {
293 this.sourceRefUuid
= sourceRefUuid
;
296 public OriginalSourceType
getSourceType() {
299 public void setSourceType(OriginalSourceType sourceType
) {
300 this.sourceType
= sourceType
;
304 public boolean isOmitTermLoading() {
309 public boolean isCreateNew(){
314 public UsernamePasswordAuthenticationToken
getAuthenticationToken(){
315 return this.authenticationToken
;
319 public boolean isInteractWithUser() {
320 return askUserForHelp
;
322 public void setInteractWithUser (boolean interaction
){
323 askUserForHelp
=interaction
;
326 public UUID
getUuidFeatureTree() {
327 return uuidFeatureTree
;
329 public void setUuidFeatureTree(UUID uuidFeatureTree
) {
330 this.uuidFeatureTree
= uuidFeatureTree
;
333 public String
getFeatureTreeTitle() {
334 return featureTreeTitle
;
336 public void setFeatureTreeTitle(String featureTreeTitle
) {
337 this.featureTreeTitle
= featureTreeTitle
;
340 private static final DateTimeFormatter formatter
= DateTimeFormat
.forPattern("YYYY-MM-dd");
342 protected String
getDateString(){
343 return formatter
.print(new DateTime());
347 * If <code>false</code> auditing is switched off during import.
348 * This is only applicable if an own application context is started
349 * for the import/export. For imports into/from running application contexts
352 public boolean isRegisterAuditing() {
353 return hibernateConfig
.getRegisterEnvers();
356 * @see #isRegisterAuditing()
358 public void setRegisterAuditing(boolean registerAuditing
) {
359 this.hibernateConfig
.setRegisterEnvers(registerAuditing
);