3e87e9df4e246c70c9cc45e96609fb2eee89570e
[cdmlib.git] / cdmlib-io / src / main / java / eu / etaxonomy / cdm / io / berlinModel / in / BerlinModelImportConfigurator.java
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.common.IImportConfigurator;
23 import eu.etaxonomy.cdm.io.common.ImportConfiguratorBase;
24 import eu.etaxonomy.cdm.io.common.ImportStateBase;
25 import eu.etaxonomy.cdm.io.common.Source;
26 import eu.etaxonomy.cdm.model.name.NomenclaturalCode;
27 import eu.etaxonomy.cdm.model.reference.IDatabase;
28 import eu.etaxonomy.cdm.model.reference.ReferenceBase;
29 import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
30 import eu.etaxonomy.cdm.model.taxon.Synonym;
31 import eu.etaxonomy.cdm.io.berlinModel.in.BerlinModelTaxonImport.PublishMarkerChooser;
32
33 /**
34 * @author a.mueller
35 * @created 20.03.2008
36 * @version 1.0
37 */
38 public class BerlinModelImportConfigurator extends ImportConfiguratorBase<BerlinModelImportState> implements IImportConfigurator{
39 private static Logger logger = Logger.getLogger(BerlinModelImportConfigurator.class);
40
41 public static BerlinModelImportConfigurator NewInstance(Source berlinModelSource, ICdmDataSource destination){
42 return new BerlinModelImportConfigurator(berlinModelSource, destination);
43 }
44
45 private PublishMarkerChooser taxonPublishMarker = PublishMarkerChooser.ALL;
46
47 private Method namerelationshipTypeMethod;
48 private Method uuidForDefTermMethod;
49 private Method userTransformationMethod;
50 private Method nameTypeDesignationStatusMethod;
51
52 private Set<Synonym> proParteSynonyms = new HashSet<Synonym>();
53 private Set<Synonym> partialSynonyms = new HashSet<Synonym>();
54
55 // NameFact stuff
56 private URL mediaUrl;
57 private File mediaPath;
58 private int maximumNumberOfNameFacts;
59 private boolean isIgnore0AuthorTeam = false;
60
61 protected void makeIoClassList(){
62 ioClassList = new Class[]{
63 BerlinModelGeneralImport.class,
64 BerlinModelUserImport.class,
65 BerlinModelAuthorImport.class,
66 BerlinModelAuthorTeamImport.class
67 , BerlinModelReferenceImport.class
68 , BerlinModelTaxonNameImport.class
69 , BerlinModelTaxonNameRelationImport.class
70 , BerlinModelNameStatusImport.class
71 , BerlinModelNameFactsImport.class
72 , BerlinModelTypesImport.class
73 , BerlinModelTaxonImport.class
74 , BerlinModelTaxonRelationImport.class
75 , BerlinModelFactsImport.class
76 , BerlinModelOccurrenceImport.class
77 , BerlinModelWebMarkerCategoryImport.class
78 , BerlinModelWebMarkerImport.class
79 };
80 }
81
82
83
84 /* (non-Javadoc)
85 * @see eu.etaxonomy.cdm.io.common.IImportConfigurator#getNewState()
86 */
87 public ImportStateBase getNewState() {
88 return new BerlinModelImportState(this);
89 }
90
91
92
93 /**
94 * @param berlinModelSource
95 * @param sourceReference
96 * @param destination
97 */
98 private BerlinModelImportConfigurator(Source berlinModelSource, ICdmDataSource destination) {
99 super();
100 setNomenclaturalCode(NomenclaturalCode.ICBN); //default for Berlin Model
101 setSource(berlinModelSource);
102 setDestination(destination);
103 }
104
105
106 public Source getSource() {
107 return (Source)super.getSource();
108 }
109 public void setSource(Source berlinModelSource) {
110 super.setSource(berlinModelSource);
111 }
112
113 /* (non-Javadoc)
114 * @see eu.etaxonomy.cdm.io.tcsrdf.IImportConfigurator#getSourceReference()
115 */
116 public ReferenceBase getSourceReference() {
117 ReferenceFactory refFactory = ReferenceFactory.newInstance();
118 if (sourceReference == null){
119 sourceReference = refFactory.newDatabase();
120 if (getSource() != null){
121 sourceReference.setTitleCache(getSource().getDatabase());
122 }
123 }
124 return sourceReference;
125 }
126
127
128 /* (non-Javadoc)
129 * @see eu.etaxonomy.cdm.io.common.IImportConfigurator#getSourceNameString()
130 */
131 public String getSourceNameString() {
132 if (this.getSource() == null){
133 return null;
134 }else{
135 return this.getSource().getDatabase();
136 }
137 }
138
139 protected void addProParteSynonym(Synonym proParteSynonym){
140 this.proParteSynonyms.add(proParteSynonym);
141 }
142
143 protected boolean isProParteSynonym(Synonym synonym){
144 return this.proParteSynonyms.contains(synonym);
145 }
146
147 protected void addPartialSynonym(Synonym partialSynonym){
148 this.partialSynonyms.add(partialSynonym);
149 }
150
151 protected boolean isPartialSynonym(Synonym synonym){
152 return this.partialSynonyms.contains(synonym);
153 }
154
155 /**
156 * @return the mediaUrl
157 */
158 public URL getMediaUrl() {
159 return mediaUrl;
160 }
161
162 /**
163 * @param mediaUrl the mediaUrl to set
164 */
165 public void setMediaUrl(URL mediaUrl) {
166 this.mediaUrl = mediaUrl;
167 }
168
169 /**
170 * @return the mediaPath
171 */
172 public File getMediaPath() {
173 return mediaPath;
174 }
175
176 /**
177 * @param mediaPath the mediaPath to set
178 */
179 public void setMediaPath(File mediaPath) {
180 this.mediaPath = mediaPath;
181 }
182
183 public void setMediaPath(String mediaPathString){
184 this.mediaPath = new File(mediaPathString);
185 }
186
187 public void setMediaUrl(String mediaUrlString) {
188 try {
189 this.mediaUrl = new URL(mediaUrlString);
190 } catch (MalformedURLException e) {
191 logger.error("Could not set mediaUrl because it was malformed: " + mediaUrlString);
192 }
193 }
194
195 /**
196 * @return the maximumNumberOfNameFacts
197 */
198 public int getMaximumNumberOfNameFacts() {
199 return maximumNumberOfNameFacts;
200 }
201
202 /**
203 * set to 0 for unlimited
204 *
205 * @param maximumNumberOfNameFacts the maximumNumberOfNameFacts to set
206 */
207 public void setMaximumNumberOfNameFacts(int maximumNumberOfNameFacts) {
208 this.maximumNumberOfNameFacts = maximumNumberOfNameFacts;
209 }
210
211 /**
212 * If true, an authorTeam with authorTeamId = 0 is not imported (casus Salvador)
213 * @return the isIgnore0AuthorTeam
214 */
215 public boolean isIgnore0AuthorTeam() {
216 return isIgnore0AuthorTeam;
217 }
218
219 /**
220 * @param isIgnore0AuthorTeam the isIgnore0AuthorTeam to set
221 */
222 public void setIgnore0AuthorTeam(boolean isIgnore0AuthorTeam) {
223 this.isIgnore0AuthorTeam = isIgnore0AuthorTeam;
224 }
225
226 /**
227 * @return the namerelationshipTypeMethod
228 */
229 public Method getNamerelationshipTypeMethod() {
230 return namerelationshipTypeMethod;
231 }
232
233 /**
234 * @param namerelationshipTypeMethod the namerelationshipTypeMethod to set
235 */
236 public void setNamerelationshipTypeMethod(Method namerelationshipTypeMethod) {
237 this.namerelationshipTypeMethod = namerelationshipTypeMethod;
238 }
239
240 /**
241 * @return the taxonPublishMarker
242 */
243 public BerlinModelTaxonImport.PublishMarkerChooser getTaxonPublishMarker() {
244 return taxonPublishMarker;
245 }
246
247 /**
248 * @param taxonPublishMarker the taxonPublishMarker to set
249 */
250 public void setTaxonPublishMarker(
251 BerlinModelTaxonImport.PublishMarkerChooser taxonPublishMarker) {
252 this.taxonPublishMarker = taxonPublishMarker;
253 }
254
255
256
257 /**
258 * @return the uuidForDefTermMethod
259 */
260 public Method getUuidForDefTermMethod() {
261 return uuidForDefTermMethod;
262 }
263
264 /**
265 * @param uuidForDefTermMethod the uuidForDefTermMethod to set
266 */
267 public void setUuidForDefTermMethod(Method uuidForDefTermMethod) {
268 this.uuidForDefTermMethod = uuidForDefTermMethod;
269 }
270
271 /**
272 * @return the userTransformationMethod
273 */
274 public Method getUserTransformationMethod() {
275 return userTransformationMethod;
276 }
277
278 /**
279 * @param userTransformationMethod the userTransformationMethod to set
280 */
281 public void setUserTransformationMethod(Method userTransformationMethod) {
282 this.userTransformationMethod = userTransformationMethod;
283 }
284
285
286
287 /**
288 * @return the nameTypeDesignationStatusMethod
289 */
290 public Method getNameTypeDesignationStatusMethod() {
291 return nameTypeDesignationStatusMethod;
292 }
293
294
295 /**
296 * @param nameTypeDesignationStatusMethod the nameTypeDesignationStatusMethod to set
297 */
298 public void setNameTypeDesignationStatusMethod(
299 Method nameTypeDesignationStatusMethod) {
300 this.nameTypeDesignationStatusMethod = nameTypeDesignationStatusMethod;
301 }
302
303 }