1
|
/**
|
2
|
* Copyright (C) 2008 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*/
|
6
|
|
7
|
package eu.etaxonomy.cdm.io.common;
|
8
|
|
9
|
import org.apache.log4j.Logger;
|
10
|
|
11
|
import eu.etaxonomy.cdm.database.ICdmDataSource;
|
12
|
import eu.etaxonomy.cdm.io.common.IExportConfigurator.CHECK;
|
13
|
import eu.etaxonomy.cdm.model.reference.IDatabase;
|
14
|
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
|
15
|
|
16
|
/**
|
17
|
* @author a.babadshanjan
|
18
|
* @created 16.11.2008
|
19
|
*/
|
20
|
public abstract class ExportConfiguratorBase<DESTINATION extends Object> extends IoConfiguratorBase {
|
21
|
|
22
|
private static final Logger logger = Logger.getLogger(ExportConfiguratorBase.class);
|
23
|
|
24
|
private CHECK check = CHECK.EXPORT_WITHOUT_CHECK;
|
25
|
|
26
|
private ICdmDataSource source;
|
27
|
private DESTINATION destination;
|
28
|
protected IDatabase sourceReference;
|
29
|
protected Class<ICdmIO>[] ioClassList;
|
30
|
|
31
|
|
32
|
public ExportConfiguratorBase(){
|
33
|
super();
|
34
|
//setDbSchemaValidation(DbSchemaValidation.UPDATE);
|
35
|
makeIoClassList();
|
36
|
}
|
37
|
|
38
|
abstract protected void makeIoClassList();
|
39
|
|
40
|
public ICdmDataSource getSource() {
|
41
|
return source;
|
42
|
}
|
43
|
|
44
|
public void setSource(ICdmDataSource source) {
|
45
|
this.source = source;
|
46
|
}
|
47
|
|
48
|
/**
|
49
|
* @param source the source to get
|
50
|
*/
|
51
|
public DESTINATION getDestination() {
|
52
|
return destination;
|
53
|
}
|
54
|
|
55
|
/**
|
56
|
* @param source the source to set
|
57
|
*/
|
58
|
public void setDestination(DESTINATION destination) {
|
59
|
this.destination = destination;
|
60
|
}
|
61
|
|
62
|
|
63
|
|
64
|
/* (non-Javadoc)
|
65
|
* @see eu.etaxonomy.cdm.io.common.ImportConfiguratorBase#getSourceReference()
|
66
|
*/
|
67
|
// @Override
|
68
|
public IDatabase getSourceReference() {
|
69
|
//TODO //needed
|
70
|
ReferenceFactory refFactory = ReferenceFactory.newInstance();
|
71
|
if (this.sourceReference == null){
|
72
|
sourceReference = refFactory.newDatabase();
|
73
|
if (getSource() != null){
|
74
|
sourceReference.setTitleCache(getSource().getDatabase(), true);
|
75
|
}
|
76
|
}
|
77
|
return sourceReference;
|
78
|
}
|
79
|
|
80
|
public Class<ICdmIO>[] getIoClassList(){
|
81
|
return ioClassList;
|
82
|
}
|
83
|
|
84
|
/* (non-Javadoc)
|
85
|
* @see eu.etaxonomy.cdm.io.tcsrdf.IImportConfigurator#getCheck()
|
86
|
*/
|
87
|
public CHECK getCheck() {
|
88
|
return this.check;
|
89
|
}
|
90
|
|
91
|
/* (non-Javadoc)
|
92
|
* @see eu.etaxonomy.cdm.io.tcsrdf.IImportConfigurator#setCheck(eu.etaxonomy.cdm.io.tcsrdf.TcsRdfImportConfigurator.CHECK)
|
93
|
*/
|
94
|
public void setCheck(CHECK check) {
|
95
|
this.check = check;
|
96
|
}
|
97
|
|
98
|
/* (non-Javadoc)
|
99
|
* @see eu.etaxonomy.cdm.io.tcsrdf.IExportConfigurator#getDbSchemaValidation()
|
100
|
*/
|
101
|
// public DbSchemaValidation getDbSchemaValidation() {
|
102
|
// return dbSchemaValidation;
|
103
|
// }
|
104
|
|
105
|
// /**
|
106
|
// * Returns a <code>CdmApplicationController</code> created by the values of this configuration.
|
107
|
// * If a controller was already created before the last created controller is returned.
|
108
|
// * @return
|
109
|
// */
|
110
|
// public CdmApplicationController getCdmAppController(){
|
111
|
// return getCdmAppController(false);
|
112
|
// }
|
113
|
//
|
114
|
// /**
|
115
|
// * Returns a new instance of <code>CdmApplicationController</code> created by the values of this configuration.
|
116
|
// * @return
|
117
|
// */
|
118
|
// public CdmApplicationController getNewCdmAppController(){
|
119
|
// return getCdmAppController(true, false);
|
120
|
// }
|
121
|
//
|
122
|
// /**
|
123
|
// * Returns a <code>CdmApplicationController</code> created by the values of this configuration.
|
124
|
// * If create new is true always a new controller is returned, else the last created controller is returned. If no controller has
|
125
|
// * been created before a new controller is returned.
|
126
|
// * @return
|
127
|
// */
|
128
|
// public CdmApplicationController getCdmAppController(boolean createNew){
|
129
|
// return getCdmAppController(createNew, false);
|
130
|
// }
|
131
|
//
|
132
|
//
|
133
|
// /**
|
134
|
// * Returns a <code>CdmApplicationController</code> created by the values of this configuration.
|
135
|
// * If create new is true always a new controller is returned, else the last created controller is returned. If no controller has
|
136
|
// * been created before a new controller is returned.
|
137
|
// * @return
|
138
|
// */
|
139
|
// public CdmApplicationController getCdmAppController(boolean createNew, boolean omitTermLoading){
|
140
|
// if (cdmApp == null || createNew == true){
|
141
|
// try {
|
142
|
// cdmApp = CdmApplicationController.NewInstance(this.getSource(), this.getDbSchemaValidation(), omitTermLoading);
|
143
|
// } catch (DataSourceNotFoundException e) {
|
144
|
// logger.error("could not connect to destination database");
|
145
|
// return null;
|
146
|
// }catch (TermNotFoundException e) {
|
147
|
// logger.error("could not find needed term in destination datasource");
|
148
|
// return null;
|
149
|
// }
|
150
|
// }
|
151
|
// return cdmApp;
|
152
|
// }
|
153
|
|
154
|
|
155
|
/**
|
156
|
* @return
|
157
|
*/
|
158
|
public boolean isValid(){
|
159
|
boolean result = true;
|
160
|
// if (source == null && this.getCdmAppController() == null ){
|
161
|
// logger.warn("Connection to CDM could not be established");
|
162
|
// result = false;
|
163
|
// }
|
164
|
if (destination == null){
|
165
|
logger.warn("Invalid export destination");
|
166
|
result = false;
|
167
|
}
|
168
|
|
169
|
return result;
|
170
|
}
|
171
|
|
172
|
public String getSourceNameString() {
|
173
|
if (this.getSource() == null) {
|
174
|
return null;
|
175
|
} else {
|
176
|
return (String)this.getSource().getName();
|
177
|
}
|
178
|
}
|
179
|
|
180
|
}
|