Berlin Model import ->in and import state class
[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.net.MalformedURLException;
14 import java.net.URL;
15 import java.util.HashSet;
16 import java.util.Set;
17
18 import org.apache.log4j.Logger;
19
20 import eu.etaxonomy.cdm.database.ICdmDataSource;
21 import eu.etaxonomy.cdm.io.berlinModel.out.BerlinModelExportConfigurator;
22 import eu.etaxonomy.cdm.io.berlinModel.out.BerlinModelExportState;
23 import eu.etaxonomy.cdm.io.common.IImportConfigurator;
24 import eu.etaxonomy.cdm.io.common.ImportConfiguratorBase;
25 import eu.etaxonomy.cdm.io.common.Source;
26 import eu.etaxonomy.cdm.model.name.NomenclaturalCode;
27 import eu.etaxonomy.cdm.model.reference.Database;
28 import eu.etaxonomy.cdm.model.reference.ReferenceBase;
29 import eu.etaxonomy.cdm.model.taxon.Synonym;
30
31 /**
32 * @author a.mueller
33 * @created 20.03.2008
34 * @version 1.0
35 */
36 public class BerlinModelImportConfigurator extends ImportConfiguratorBase implements IImportConfigurator{
37 private static Logger logger = Logger.getLogger(BerlinModelImportConfigurator.class);
38
39 public static BerlinModelImportConfigurator NewInstance(Source berlinModelSource, ICdmDataSource destination){
40 return new BerlinModelImportConfigurator(berlinModelSource, destination);
41 }
42
43 private BerlinModelImportState<BerlinModelImportConfigurator> state;
44
45
46 private Set<Synonym> proParteSynonyms = new HashSet<Synonym>();
47 private Set<Synonym> partialSynonyms = new HashSet<Synonym>();
48
49 // NameFact stuff
50 private URL mediaUrl;
51 private File mediaPath;
52 private int maximumNumberOfNameFacts;
53 private boolean isIgnore0AuthorTeam = false;
54
55 protected void makeIoClassList(){
56 ioClassList = new Class[]{
57 BerlinModelAuthorImport.class,
58 BerlinModelAuthorTeamImport.class
59 , BerlinModelReferenceImport.class
60 , BerlinModelTaxonNameImport.class
61 , BerlinModelTaxonNameRelationImport.class
62 , BerlinModelNameStatusImport.class
63 , BerlinModelNameFactsImport.class
64 , BerlinModelTypesImport.class
65 , BerlinModelTaxonImport.class
66 , BerlinModelTaxonRelationImport.class
67 , BerlinModelFactsImport.class
68 , BerlinModelOccurrenceImport.class
69 };
70
71 }
72
73 /**
74 * @param berlinModelSource
75 * @param sourceReference
76 * @param destination
77 */
78 private BerlinModelImportConfigurator(Source berlinModelSource, ICdmDataSource destination) {
79 super();
80 setNomenclaturalCode(NomenclaturalCode.ICBN); //default for Berlin Model
81 setSource(berlinModelSource);
82 setDestination(destination);
83 }
84
85
86 public Source getSource() {
87 return (Source)super.getSource();
88 }
89 public void setSource(Source berlinModelSource) {
90 super.setSource(berlinModelSource);
91 }
92
93 /* (non-Javadoc)
94 * @see eu.etaxonomy.cdm.io.tcsrdf.IImportConfigurator#getSourceReference()
95 */
96 public ReferenceBase getSourceReference() {
97 if (sourceReference == null){
98 sourceReference = Database.NewInstance();
99 if (getSource() != null){
100 sourceReference.setTitleCache(getSource().getDatabase());
101 }
102 }
103 return sourceReference;
104 }
105
106
107 /* (non-Javadoc)
108 * @see eu.etaxonomy.cdm.io.common.IImportConfigurator#getSourceNameString()
109 */
110 public String getSourceNameString() {
111 if (this.getSource() == null){
112 return null;
113 }else{
114 return this.getSource().getDatabase();
115 }
116 }
117
118 protected void addProParteSynonym(Synonym proParteSynonym){
119 this.proParteSynonyms.add(proParteSynonym);
120 }
121
122 protected boolean isProParteSynonym(Synonym synonym){
123 return this.proParteSynonyms.contains(synonym);
124 }
125
126 protected void addPartialSynonym(Synonym partialSynonym){
127 this.partialSynonyms.add(partialSynonym);
128 }
129
130 protected boolean isPartialSynonym(Synonym synonym){
131 return this.partialSynonyms.contains(synonym);
132 }
133
134 /**
135 * @return the mediaUrl
136 */
137 public URL getMediaUrl() {
138 return mediaUrl;
139 }
140
141 /**
142 * @param mediaUrl the mediaUrl to set
143 */
144 public void setMediaUrl(URL mediaUrl) {
145 this.mediaUrl = mediaUrl;
146 }
147
148 /**
149 * @return the mediaPath
150 */
151 public File getMediaPath() {
152 return mediaPath;
153 }
154
155 /**
156 * @param mediaPath the mediaPath to set
157 */
158 public void setMediaPath(File mediaPath) {
159 this.mediaPath = mediaPath;
160 }
161
162 public void setMediaPath(String mediaPathString){
163 this.mediaPath = new File(mediaPathString);
164 }
165
166 public void setMediaUrl(String mediaUrlString) {
167 try {
168 this.mediaUrl = new URL(mediaUrlString);
169 } catch (MalformedURLException e) {
170 logger.error("Could not set mediaUrl because it was malformed: " + mediaUrlString);
171 }
172 }
173
174 /**
175 * @return the maximumNumberOfNameFacts
176 */
177 public int getMaximumNumberOfNameFacts() {
178 return maximumNumberOfNameFacts;
179 }
180
181 /**
182 * set to 0 for unlimited
183 *
184 * @param maximumNumberOfNameFacts the maximumNumberOfNameFacts to set
185 */
186 public void setMaximumNumberOfNameFacts(int maximumNumberOfNameFacts) {
187 this.maximumNumberOfNameFacts = maximumNumberOfNameFacts;
188 }
189
190 /**
191 * If true, an authorTeam with authorTeamId = 0 is not imported (casus Salvador)
192 * @return the isIgnore0AuthorTeam
193 */
194 public boolean isIgnore0AuthorTeam() {
195 return isIgnore0AuthorTeam;
196 }
197
198 /**
199 * @param isIgnore0AuthorTeam the isIgnore0AuthorTeam to set
200 */
201 public void setIgnore0AuthorTeam(boolean isIgnore0AuthorTeam) {
202 this.isIgnore0AuthorTeam = isIgnore0AuthorTeam;
203 }
204
205 /**
206 * @return the state
207 */
208 protected BerlinModelImportState<BerlinModelImportConfigurator> getState() {
209 return state;
210 }
211
212 /**
213 * @param state the state to set
214 */
215 protected void setState(
216 BerlinModelImportState<BerlinModelImportConfigurator> state) {
217 this.state = state;
218 }
219
220
221
222
223 }