Project

General

Profile

Download (9.15 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2007 EDIT
3
* European Distributed Institute of Taxonomy 
4
* http://www.e-taxonomy.eu
5
* 
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.
8
*/
9

    
10
package eu.etaxonomy.cdm.io.berlinModel.in;
11

    
12
import java.io.File;
13
import java.lang.reflect.Method;
14
import java.net.MalformedURLException;
15
import java.net.URL;
16
import java.util.HashSet;
17
import java.util.Set;
18

    
19
import org.apache.log4j.Logger;
20

    
21
import eu.etaxonomy.cdm.database.ICdmDataSource;
22
import eu.etaxonomy.cdm.io.berlinModel.in.BerlinModelTaxonImport.PublishMarkerChooser;
23
import eu.etaxonomy.cdm.io.berlinModel.in.validation.BerlinModelGeneralImportValidator;
24
import eu.etaxonomy.cdm.io.common.IImportConfigurator;
25
import eu.etaxonomy.cdm.io.common.ImportConfiguratorBase;
26
import eu.etaxonomy.cdm.io.common.ImportStateBase;
27
import eu.etaxonomy.cdm.io.common.Source;
28
import eu.etaxonomy.cdm.io.common.mapping.IInputTransformer;
29
import eu.etaxonomy.cdm.model.name.NomenclaturalCode;
30
import eu.etaxonomy.cdm.model.reference.ReferenceBase;
31
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
32
import eu.etaxonomy.cdm.model.taxon.Synonym;
33

    
34
/**
35
 * @author a.mueller
36
 * @created 20.03.2008
37
 * @version 1.0
38
 */
39
public class BerlinModelImportConfigurator extends ImportConfiguratorBase<BerlinModelImportState> implements IImportConfigurator{
40
	private static Logger logger = Logger.getLogger(BerlinModelImportConfigurator.class);
41

    
42
	public static BerlinModelImportConfigurator NewInstance(Source berlinModelSource, ICdmDataSource destination){
43
			return new BerlinModelImportConfigurator(berlinModelSource, destination);
44
	}
45

    
46
	private PublishMarkerChooser taxonPublishMarker = PublishMarkerChooser.ALL;
47
	
48
	//TODO
49
	private static IInputTransformer defaultTransformer = null;
50
	
51
	private boolean doCommonNames = true;
52
	
53
	
54
	/* Max number of records to be saved with one service call */
55
	private int recordsPerTransaction = 1000;
56

    
57
	private Method namerelationshipTypeMethod;
58
	private Method uuidForDefTermMethod;
59
	private Method userTransformationMethod;
60
	private Method nameTypeDesignationStatusMethod;
61
	
62
	private Set<Synonym> proParteSynonyms = new HashSet<Synonym>();
63
	private Set<Synonym> partialSynonyms = new HashSet<Synonym>();
64
	
65
	// NameFact stuff
66
	private URL mediaUrl;
67
	private File mediaPath;
68
	private int maximumNumberOfNameFacts;
69
	private boolean isIgnore0AuthorTeam = false;
70
	
71
	protected void makeIoClassList(){
72
		ioClassList = new Class[]{
73
				BerlinModelGeneralImportValidator.class
74
				, BerlinModelUserImport.class
75
				, BerlinModelAuthorImport.class
76
				, BerlinModelAuthorTeamImport.class
77
				, BerlinModelRefDetailImport.class
78
				, BerlinModelReferenceImport.class
79
				, BerlinModelTaxonNameImport.class
80
				, BerlinModelTaxonNameRelationImport.class
81
				, BerlinModelNameStatusImport.class
82
				, BerlinModelNameFactsImport.class
83
				, BerlinModelTypesImport.class
84
				, BerlinModelTaxonImport.class
85
				, BerlinModelTaxonRelationImport.class
86
				, BerlinModelCommonNamesImport.class
87
				, BerlinModelFactsImport.class
88
				, BerlinModelOccurrenceImport.class
89
				, BerlinModelOccurrenceSourceImport.class
90
				, BerlinModelWebMarkerCategoryImport.class
91
				, BerlinModelWebMarkerImport.class
92
		};	
93
	}
94
	
95
	
96
	
97
	/* (non-Javadoc)
98
	 * @see eu.etaxonomy.cdm.io.common.IImportConfigurator#getNewState()
99
	 */
100
	public ImportStateBase getNewState() {
101
		return new BerlinModelImportState(this);
102
	}
103

    
104

    
105

    
106
	/**
107
	 * @param berlinModelSource
108
	 * @param sourceReference
109
	 * @param destination
110
	 */
111
	private BerlinModelImportConfigurator(Source berlinModelSource, ICdmDataSource destination) {
112
	   super(defaultTransformer);
113
	   setNomenclaturalCode(NomenclaturalCode.ICBN); //default for Berlin Model
114
	   setSource(berlinModelSource);
115
	   setDestination(destination);
116
	}
117
	
118
	
119
	public Source getSource() {
120
		return (Source)super.getSource();
121
	}
122
	public void setSource(Source berlinModelSource) {
123
		super.setSource(berlinModelSource);
124
	}
125

    
126
	/* (non-Javadoc)
127
	 * @see eu.etaxonomy.cdm.io.tcsrdf.IImportConfigurator#getSourceReference()
128
	 */
129
	public ReferenceBase getSourceReference() {
130
		ReferenceFactory refFactory = ReferenceFactory.newInstance();
131
		if (sourceReference == null){
132
			sourceReference =  refFactory.newDatabase();
133
			if (getSource() != null){
134
				sourceReference.setTitleCache(getSource().getDatabase(), true);
135
			}
136
		}
137
		return sourceReference;
138
	}
139

    
140

    
141
	/* (non-Javadoc)
142
	 * @see eu.etaxonomy.cdm.io.common.IImportConfigurator#getSourceNameString()
143
	 */
144
	public String getSourceNameString() {
145
		if (this.getSource() == null){
146
			return null;
147
		}else{
148
			return this.getSource().getDatabase();
149
		}
150
	}
151
	
152
	protected void addProParteSynonym(Synonym proParteSynonym){
153
		this.proParteSynonyms.add(proParteSynonym);
154
	}
155
	
156
	protected boolean isProParteSynonym(Synonym synonym){
157
		return this.proParteSynonyms.contains(synonym);
158
	}
159
	
160
	protected void addPartialSynonym(Synonym partialSynonym){
161
		this.partialSynonyms.add(partialSynonym);
162
	}
163
	
164
	protected boolean isPartialSynonym(Synonym synonym){
165
		return this.partialSynonyms.contains(synonym);
166
	}
167

    
168
	/**
169
	 * @return the mediaUrl
170
	 */
171
	public URL getMediaUrl() {
172
		return mediaUrl;
173
	}
174

    
175
	/**
176
	 * @param mediaUrl the mediaUrl to set
177
	 */
178
	public void setMediaUrl(URL mediaUrl) {
179
		this.mediaUrl = mediaUrl;
180
	}
181

    
182
	/**
183
	 * @return the mediaPath
184
	 */
185
	public File getMediaPath() {
186
		return mediaPath;
187
	}
188

    
189
	/**
190
	 * @param mediaPath the mediaPath to set
191
	 */
192
	public void setMediaPath(File mediaPath) {
193
		this.mediaPath = mediaPath;
194
	}
195
	
196
	public void setMediaPath(String mediaPathString){
197
		this.mediaPath = new File(mediaPathString);
198
	}
199

    
200
	public void setMediaUrl(String mediaUrlString) {
201
		try {
202
			this.mediaUrl = new URL(mediaUrlString);
203
		} catch (MalformedURLException e) {
204
			logger.error("Could not set mediaUrl because it was malformed: " + mediaUrlString);
205
		}
206
	}
207

    
208
	/**
209
	 * @return the maximumNumberOfNameFacts
210
	 */
211
	public int getMaximumNumberOfNameFacts() {
212
		return maximumNumberOfNameFacts;
213
	}
214

    
215
	/**
216
	 * set to 0 for unlimited
217
	 * 
218
	 * @param maximumNumberOfNameFacts the maximumNumberOfNameFacts to set
219
	 */
220
	public void setMaximumNumberOfNameFacts(int maximumNumberOfNameFacts) {
221
		this.maximumNumberOfNameFacts = maximumNumberOfNameFacts;
222
	}
223

    
224
	/**
225
	 * If true, an authorTeam with authorTeamId = 0 is not imported (casus Salvador)
226
	 * @return the isIgnore0AuthorTeam
227
	 */
228
	public boolean isIgnore0AuthorTeam() {
229
		return isIgnore0AuthorTeam;
230
	}
231

    
232
	/**
233
	 * @param isIgnore0AuthorTeam the isIgnore0AuthorTeam to set
234
	 */
235
	public void setIgnore0AuthorTeam(boolean isIgnore0AuthorTeam) {
236
		this.isIgnore0AuthorTeam = isIgnore0AuthorTeam;
237
	}
238

    
239
	/**
240
	 * @return the namerelationshipTypeMethod
241
	 */
242
	public Method getNamerelationshipTypeMethod() {
243
		return namerelationshipTypeMethod;
244
	}
245

    
246
	/**
247
	 * @param namerelationshipTypeMethod the namerelationshipTypeMethod to set
248
	 */
249
	public void setNamerelationshipTypeMethod(Method namerelationshipTypeMethod) {
250
		this.namerelationshipTypeMethod = namerelationshipTypeMethod;
251
	}
252
	
253
	/**
254
	 * @return the taxonPublishMarker
255
	 */
256
	public BerlinModelTaxonImport.PublishMarkerChooser getTaxonPublishMarker() {
257
		return taxonPublishMarker;
258
	}
259

    
260
	/**
261
	 * @param taxonPublishMarker the taxonPublishMarker to set
262
	 */
263
	public void setTaxonPublishMarker(
264
			BerlinModelTaxonImport.PublishMarkerChooser taxonPublishMarker) {
265
		this.taxonPublishMarker = taxonPublishMarker;
266
	}
267

    
268

    
269

    
270
	/**
271
	 * @return the uuidForDefTermMethod
272
	 */
273
	public Method getUuidForDefTermMethod() {
274
		return uuidForDefTermMethod;
275
	}
276

    
277
	/**
278
	 * @param uuidForDefTermMethod the uuidForDefTermMethod to set
279
	 */
280
	public void setUuidForDefTermMethod(Method uuidForDefTermMethod) {
281
		this.uuidForDefTermMethod = uuidForDefTermMethod;
282
	}
283

    
284
	/**
285
	 * @return the userTransformationMethod
286
	 */
287
	public Method getUserTransformationMethod() {
288
		return userTransformationMethod;
289
	}
290

    
291
	/**
292
	 * @param userTransformationMethod the userTransformationMethod to set
293
	 */
294
	public void setUserTransformationMethod(Method userTransformationMethod) {
295
		this.userTransformationMethod = userTransformationMethod;
296
	}
297

    
298

    
299

    
300
	/**
301
	 * @return the nameTypeDesignationStatusMethod
302
	 */
303
	public Method getNameTypeDesignationStatusMethod() {
304
		return nameTypeDesignationStatusMethod;
305
	}
306

    
307

    
308
	/**
309
	 * @param nameTypeDesignationStatusMethod the nameTypeDesignationStatusMethod to set
310
	 */
311
	public void setNameTypeDesignationStatusMethod(
312
			Method nameTypeDesignationStatusMethod) {
313
		this.nameTypeDesignationStatusMethod = nameTypeDesignationStatusMethod;
314
	}
315
	
316
	/**
317
	 * @return the limitSave
318
	 */
319
	public int getRecordsPerTransaction() {
320
		return recordsPerTransaction;
321
	}
322

    
323
	/**
324
	 * @param limitSave the limitSave to set
325
	 */
326
	public void setRecordsPerTransaction(int recordsPerTransaction) {
327
		this.recordsPerTransaction = recordsPerTransaction;
328
	}
329

    
330

    
331
	public boolean isDoCommonNames() {
332
		return doCommonNames;
333
	}
334

    
335

    
336
	/**
337
	 * @param doCommonNames
338
	 */
339
	public void setDoCommonNames(boolean doCommonNames) {
340
		this.doCommonNames = doCommonNames;
341
		
342
	}
343

    
344

    
345

    
346

    
347
}
(6-6/21)