1
2
3
4
5
6
7
8
9
10 package eu.etaxonomy.cdm.io.berlinModel;
11
12 import java.sql.ResultSet;
13 import java.sql.SQLException;
14 import java.util.UUID;
15
16 import org.apache.log4j.Logger;
17
18 import eu.etaxonomy.cdm.common.ResultWrapper;
19 import eu.etaxonomy.cdm.model.common.Language;
20 import eu.etaxonomy.cdm.model.common.OrderedTermVocabulary;
21 import eu.etaxonomy.cdm.model.common.RelationshipBase;
22 import eu.etaxonomy.cdm.model.common.RelationshipTermBase;
23 import eu.etaxonomy.cdm.model.common.Representation;
24 import eu.etaxonomy.cdm.model.description.AbsenceTerm;
25 import eu.etaxonomy.cdm.model.description.Feature;
26 import eu.etaxonomy.cdm.model.description.PresenceAbsenceTermBase;
27 import eu.etaxonomy.cdm.model.description.PresenceTerm;
28 import eu.etaxonomy.cdm.model.name.HybridRelationshipType;
29 import eu.etaxonomy.cdm.model.name.NameRelationshipType;
30 import eu.etaxonomy.cdm.model.name.NomenclaturalStatus;
31 import eu.etaxonomy.cdm.model.name.NomenclaturalStatusType;
32 import eu.etaxonomy.cdm.model.name.Rank;
33 import eu.etaxonomy.cdm.model.name.SpecimenTypeDesignationStatus;
34 import eu.etaxonomy.cdm.model.reference.ISectionBase;
35 import eu.etaxonomy.cdm.model.reference.ReferenceBase;
36 import eu.etaxonomy.cdm.model.reference.ReferenceType;
37 import eu.etaxonomy.cdm.model.taxon.Synonym;
38 import eu.etaxonomy.cdm.model.taxon.SynonymRelationshipType;
39 import eu.etaxonomy.cdm.model.taxon.Taxon;
40 import eu.etaxonomy.cdm.model.taxon.TaxonBase;
41 import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType;
42 import eu.etaxonomy.cdm.strategy.exceptions.UnknownCdmTypeException;
43
44
45
46
47
48
49 public final class BerlinModelTransformer {
50 private static final Logger logger = Logger.getLogger(BerlinModelTransformer.class);
51
52
53
54 public static int REF_ARTICLE = 1;
55 public static int REF_PART_OF_OTHER_TITLE = 2;
56 public static int REF_BOOK = 3;
57 public static int REF_DATABASE = 4;
58 public static int REF_INFORMAL = 5;
59 public static int REF_NOT_APPLICABLE = 6;
60 public static int REF_WEBSITE = 7;
61 public static int REF_CD = 8;
62 public static int REF_JOURNAL = 9;
63 public static int REF_UNKNOWN = 10;
64 public static int REF_PRINT_SERIES = 55;
65 public static int REF_CONFERENCE_PROCEEDINGS = 56;
66 public static int REF_JOURNAL_VOLUME = 57;
67
68
69
70
71 public static int NAME_ST_NOM_INVAL = 1;
72 public static int NAME_ST_NOM_ILLEG = 2;
73 public static int NAME_ST_NOM_NUD = 3;
74 public static int NAME_ST_NOM_REJ = 4;
75 public static int NAME_ST_NOM_REJ_PROP = 5;
76 public static int NAME_ST_NOM_UTIQUE_REJ = 6;
77 public static int NAME_ST_NOM_UTIQUE_REJ_PROP = 7;
78 public static int NAME_ST_NOM_CONS = 8;
79 public static int NAME_ST_NOM_CONS_PROP = 9;
80 public static int NAME_ST_ORTH_CONS = 10;
81 public static int NAME_ST_ORTH_CONS_PROP = 11;
82 public static int NAME_ST_NOM_SUPERFL = 12;
83 public static int NAME_ST_NOM_AMBIG = 13;
84 public static int NAME_ST_NOM_PROVIS = 14;
85 public static int NAME_ST_NOM_DUB = 15;
86 public static int NAME_ST_NOM_NOV = 16;
87 public static int NAME_ST_NOM_CONFUS = 17;
88 public static int NAME_ST_NOM_ALTERN = 18;
89 public static int NAME_ST_COMB_INVAL = 19;
90
91
92
93 public static int NAME_REL_IS_BASIONYM_FOR = 1;
94 public static int NAME_REL_IS_LATER_HOMONYM_OF = 2;
95 public static int NAME_REL_IS_REPLACED_SYNONYM_FOR = 3;
96 public static int NAME_REL_IS_VALIDATION_OF = 4;
97 public static int NAME_REL_IS_LATER_VALIDATION_OF = 5;
98 public static int NAME_REL_IS_TYPE_OF = 6;
99 public static int NAME_REL_IS_CONSERVED_TYPE_OF =7;
100 public static int NAME_REL_IS_REJECTED_TYPE_OF = 8;
101 public static int NAME_REL_IS_FIRST_PARENT_OF = 9;
102 public static int NAME_REL_IS_SECOND_PARENT_OF = 10;
103 public static int NAME_REL_IS_FEMALE_PARENT_OF = 11;
104 public static int NAME_REL_IS_MALE_PARENT_OF = 12;
105 public static int NAME_REL_IS_CONSERVED_AGAINST =13;
106 public static int NAME_REL_IS_REJECTED_IN_FAVOUR_OF = 14;
107 public static int NAME_REL_IS_TREATED_AS_LATER_HOMONYM_OF = 15;
108 public static int NAME_REL_IS_ORTHOGRAPHIC_VARIANT_OF = 16;
109 public static int NAME_REL_HAS_SAME_TYPE_AS = 18;
110 public static int NAME_REL_IS_LECTOTYPE_OF = 61;
111 public static int NAME_REL_TYPE_NOT_DESIGNATED = 62;
112
113
114 public static String NAME_FACT_PROTOLOGUE = "Protologue";
115 public static String NAME_FACT_ALSO_PUBLISHED_IN = "Also published in";
116
117
118 public static int TAX_REL_IS_INCLUDED_IN = 1;
119 public static int TAX_REL_IS_SYNONYM_OF = 2;
120 public static int TAX_REL_IS_MISAPPLIED_NAME_OF = 3;
121 public static int TAX_REL_IS_PROPARTE_SYN_OF = 4;
122 public static int TAX_REL_IS_PARTIAL_SYN_OF = 5;
123 public static int TAX_REL_IS_HETEROTYPIC_SYNONYM_OF = 6;
124 public static int TAX_REL_IS_HOMOTYPIC_SYNONYM_OF = 7;
125 public static int TAX_REL_IS_PROPARTE_HOMOTYPIC_SYNONYM_OF = 101;
126 public static int TAX_REL_IS_PROPARTE_HETEROTYPIC_SYNONYM_OF = 102;
127 public static int TAX_REL_IS_PARTIAL_HOMOTYPIC_SYNONYM_OF = 103;
128 public static int TAX_REL_IS_PARTIAL_HETEROTYPIC_SYNONYM_OF = 104;
129
130
131
132
133 public static int T_STATUS_ACCEPTED = 1;
134 public static int T_STATUS_SYNONYM = 2;
135 public static int T_STATUS_PARTIAL_SYN = 3;
136 public static int T_STATUS_PRO_PARTE_SYN = 4;
137 public static int T_STATUS_UNRESOLVED = 5;
138 public static int T_STATUS_ORPHANED = 6;
139
140
141
142 public static int FACT_DESCRIPTION = 1;
143 public static int FACT_GROWTH_FORM = 2;
144 public static int FACT_HARDINESS = 3;
145 public static int FACT_ECOLOGY = 4;
146 public static int FACT_PHENOLOGY = 5;
147 public static int FACT_KARYOLOGY = 6;
148 public static int FACT_ILLUSTRATION = 7;
149 public static int FACT_IDENTIFICATION = 8;
150 public static int FACT_OBSERVATION = 9;
151 public static int FACT_DISTRIBUTION_EM = 10;
152 public static int FACT_DISTRIBUTION_WORLD = 11;
153
154 public static UUID uuidRelNameCombIned = UUID.fromString("dde8a2e7-bf9e-42ec-b186-d5bde9c9c128");
155
156 static NomenclaturalStatusType nomStatusCombIned;
157 public static NomenclaturalStatusType nomStatusTypeAbbrev2NewNomStatusType(String nomStatus){
158 NomenclaturalStatusType result = null;
159 if (nomStatus == null){
160 return null;
161 }else if (nomStatus.equalsIgnoreCase("comb. ined.")){
162 if (nomStatusCombIned == null){
163 nomStatusCombIned = new NomenclaturalStatusType();
164 Representation representation = Representation.NewInstance("comb. ined.", "comb. ined.", "comb. ined.", Language.LATIN());
165 nomStatusCombIned.addRepresentation(representation);
166 nomStatusCombIned.setUuid(uuidRelNameCombIned);
167 NomenclaturalStatusType.ALTERNATIVE().getVocabulary().addTerm(nomStatusCombIned);
168 }
169 result = nomStatusCombIned;
170 }
171 return result;
172 }
173
174
175 public static NomenclaturalStatus nomStatusFkToNomStatus(int nomStatusFk, String nomStatusLabel) throws UnknownCdmTypeException{
176 if (nomStatusFk == NAME_ST_NOM_INVAL){
177 return NomenclaturalStatus.NewInstance(NomenclaturalStatusType.INVALID());
178 }else if (nomStatusFk == NAME_ST_NOM_ILLEG){
179 return NomenclaturalStatus.NewInstance(NomenclaturalStatusType.ILLEGITIMATE());
180 }else if (nomStatusFk == NAME_ST_NOM_NUD){
181 return NomenclaturalStatus.NewInstance(NomenclaturalStatusType.NUDUM());
182 }else if (nomStatusFk == NAME_ST_NOM_REJ){
183 return NomenclaturalStatus.NewInstance(NomenclaturalStatusType.REJECTED());
184 }else if (nomStatusFk == NAME_ST_NOM_REJ_PROP){
185 return NomenclaturalStatus.NewInstance(NomenclaturalStatusType.REJECTED_PROP());
186 }else if (nomStatusFk == NAME_ST_NOM_UTIQUE_REJ){
187 return NomenclaturalStatus.NewInstance(NomenclaturalStatusType.UTIQUE_REJECTED());
188 }else if (nomStatusFk == NAME_ST_NOM_UTIQUE_REJ_PROP){
189 return NomenclaturalStatus.NewInstance(NomenclaturalStatusType.UTIQUE_REJECTED_PROP());
190 }else if (nomStatusFk == NAME_ST_NOM_CONS){
191 return NomenclaturalStatus.NewInstance(NomenclaturalStatusType.CONSERVED());
192 }else if (nomStatusFk == NAME_ST_NOM_CONS_PROP){
193 return NomenclaturalStatus.NewInstance(NomenclaturalStatusType.CONSERVED_PROP());
194 }else if (nomStatusFk == NAME_ST_ORTH_CONS){
195 return NomenclaturalStatus.NewInstance(NomenclaturalStatusType.ORTHOGRAPHY_CONSERVED());
196 }else if (nomStatusFk == NAME_ST_ORTH_CONS_PROP){
197 return NomenclaturalStatus.NewInstance(NomenclaturalStatusType.ORTHOGRAPHY_CONSERVED_PROP());
198 }else if (nomStatusFk == NAME_ST_NOM_SUPERFL){
199 return NomenclaturalStatus.NewInstance(NomenclaturalStatusType.SUPERFLUOUS());
200 }else if (nomStatusFk == NAME_ST_NOM_AMBIG){
201 return NomenclaturalStatus.NewInstance(NomenclaturalStatusType.AMBIGUOUS());
202 }else if (nomStatusFk == NAME_ST_NOM_PROVIS){
203 return NomenclaturalStatus.NewInstance(NomenclaturalStatusType.PROVISIONAL());
204 }else if (nomStatusFk == NAME_ST_NOM_DUB){
205 return NomenclaturalStatus.NewInstance(NomenclaturalStatusType.DOUBTFUL());
206 }else if (nomStatusFk == NAME_ST_NOM_NOV){
207 return NomenclaturalStatus.NewInstance(NomenclaturalStatusType.NOVUM());
208 }else if (nomStatusFk == NAME_ST_NOM_CONFUS){
209 return NomenclaturalStatus.NewInstance(NomenclaturalStatusType.CONFUSUM());
210 }else if (nomStatusFk == NAME_ST_NOM_ALTERN){
211 return NomenclaturalStatus.NewInstance(NomenclaturalStatusType.ALTERNATIVE());
212 }else if (nomStatusFk == NAME_ST_COMB_INVAL){
213 return NomenclaturalStatus.NewInstance(NomenclaturalStatusType.COMBINATION_INVALID());
214 }else {
215 NomenclaturalStatusType statusType = nomStatusTypeAbbrev2NewNomStatusType(nomStatusLabel);
216 NomenclaturalStatus result = NomenclaturalStatus.NewInstance(statusType);
217 if (result != null){
218 return result;
219 }
220 throw new UnknownCdmTypeException("Unknown NomenclaturalStatus (id=" + Integer.valueOf(nomStatusFk).toString() + ")");
221 }
222 }
223
224
225
226 public static SpecimenTypeDesignationStatus typeStatusId2TypeStatus (int typeStatusId) throws UnknownCdmTypeException{
227 switch (typeStatusId){
228 case 0: return null;
229 case 1: return SpecimenTypeDesignationStatus.HOLOTYPE();
230 case 2: return SpecimenTypeDesignationStatus.LECTOTYPE();
231 case 3: return SpecimenTypeDesignationStatus.NEOTYPE();
232 case 4: return SpecimenTypeDesignationStatus.EPITYPE();
233 case 5: return SpecimenTypeDesignationStatus.ISOLECTOTYPE();
234 case 6: return SpecimenTypeDesignationStatus.ISONEOTYPE();
235 case 7: return SpecimenTypeDesignationStatus.ISOTYPE();
236 case 8: return SpecimenTypeDesignationStatus.PARANEOTYPE();
237 case 9: return SpecimenTypeDesignationStatus.PARATYPE();
238 case 10: return SpecimenTypeDesignationStatus.SECOND_STEP_LECTOTYPE();
239 case 11: return SpecimenTypeDesignationStatus.SECOND_STEP_NEOTYPE();
240 case 12: return SpecimenTypeDesignationStatus.SYNTYPE();
241 case 21: return SpecimenTypeDesignationStatus.ICONOTYPE();
242 case 22: return SpecimenTypeDesignationStatus.PHOTOTYPE();
243 default: {
244 throw new UnknownCdmTypeException("Unknown TypeDesignationStatus (id=" + Integer.valueOf(typeStatusId).toString() + ")");
245 }
246 }
247 }
248
249
250 public static TaxonRelationshipType taxonRelId2TaxonRelType (int relTaxonTypeId, ResultWrapper<Boolean> isInverse) throws UnknownCdmTypeException{
251 isInverse.setValue(false);
252 switch (relTaxonTypeId){
253 case 0: return null;
254 case 11: return TaxonRelationshipType.CONGRUENT_TO();
255 case 12: isInverse.setValue(true); return TaxonRelationshipType.INCLUDES();
256 case 13: isInverse.setValue(true); return TaxonRelationshipType.CONGRUENT_OR_INCLUDES();
257 case 14: return TaxonRelationshipType.INCLUDES();
258 case 15: return TaxonRelationshipType.CONGRUENT_OR_INCLUDES();
259 case 16: return TaxonRelationshipType.INCLUDED_OR_INCLUDES();
260 case 17: return TaxonRelationshipType.CONGRUENT_OR_INCLUDED_OR_INCLUDES();
261 case 18: return TaxonRelationshipType.OVERLAPS();
262 case 19: return TaxonRelationshipType.CONGRUENT_OR_OVERLAPS();
263 case 20: isInverse.setValue(true); return TaxonRelationshipType.INCLUDES_OR_OVERLAPS();
264 case 21: isInverse.setValue(true); return TaxonRelationshipType.CONGRUENT_OR_INCLUDES_OR_OVERLAPS();
265 case 22: return TaxonRelationshipType.INCLUDES_OR_OVERLAPS();
266 case 23: return TaxonRelationshipType.CONGRUENT_OR_INCLUDES_OR_OVERLAPS();
267 case 24: return TaxonRelationshipType.INCLUDED_OR_INCLUDES_OR_OVERLAPS();
268
269 case 26: return TaxonRelationshipType.OVERLAPS();
270
271
272
273 case 43: return TaxonRelationshipType.CONGRUENT_TO();
274 default: {
275 throw new UnknownCdmTypeException("Unknown TypeDesignationStatus (id=" + Integer.valueOf(relTaxonTypeId).toString() + ")");
276 }
277 }
278 }
279
280
281 public static HybridRelationshipType relNameId2HybridRel (int relNameId) throws UnknownCdmTypeException{
282 switch (relNameId){
283 case 0: return null;
284 case 9: return HybridRelationshipType.FIRST_PARENT();
285 case 10: return HybridRelationshipType.SECOND_PARENT();
286 case 11: return HybridRelationshipType.FEMALE_PARENT();
287 case 12: return HybridRelationshipType.MALE_PARENT();
288 default: {
289 throw new UnknownCdmTypeException("Unknown HybridRelationshipType (id=" + Integer.valueOf(relNameId).toString() + ")");
290 }
291 }
292 }
293
294
295 public static PresenceAbsenceTermBase<?> occStatus2PresenceAbsence (int occStatusId) throws UnknownCdmTypeException{
296 switch (occStatusId){
297 case 0: return null;
298 case 110: return AbsenceTerm.CULTIVATED_REPORTED_IN_ERROR();
299 case 120: return PresenceTerm.CULTIVATED();
300 case 210: return AbsenceTerm.INTRODUCED_REPORTED_IN_ERROR();
301 case 220: return PresenceTerm.INTRODUCED_PRESENCE_QUESTIONABLE();
302 case 230: return PresenceTerm.INTRODUCED_FORMERLY_INTRODUCED();
303 case 240: return PresenceTerm.INTRODUCED_DOUBTFULLY_INTRODUCED();
304 case 250: return PresenceTerm.INTRODUCED();
305 case 260: return PresenceTerm.INTRODUCED_UNCERTAIN_DEGREE_OF_NATURALISATION();
306 case 270: return PresenceTerm.INTRODUCED_ADVENTITIOUS();
307 case 280: return PresenceTerm.INTRODUCED_NATURALIZED();
308 case 310: return AbsenceTerm.NATIVE_REPORTED_IN_ERROR();
309 case 320: return PresenceTerm.NATIVE_PRESENCE_QUESTIONABLE();
310 case 330: return PresenceTerm.NATIVE_FORMERLY_NATIVE();
311 case 340: return PresenceTerm.NATIVE_DOUBTFULLY_NATIVE();
312 case 350: return PresenceTerm.NATIVE();
313 case 999: {
314 logger.info("endemic for EM can not be transformed in legal status. Used 'PRESENT' instead");
315
316 return PresenceTerm.PRESENT();
317 }
318 default: {
319 throw new UnknownCdmTypeException("Unknown occurrence status (id=" + Integer.valueOf(occStatusId).toString() + ")");
320 }
321 }
322 }
323
324
325
326 public static Feature factCategory2Feature (int factCategoryId) throws UnknownCdmTypeException{
327 switch (factCategoryId){
328 case 0: return null;
329 case 1: return Feature.DESCRIPTION();
330 case 4: return Feature.ECOLOGY();
331 case 5: return Feature.PHENOLOGY();
332 case 12: return Feature.COMMON_NAME();
333 case 13: return Feature.OCCURRENCE();
334 case 99: return Feature.CITATION();
335 default: {
336 throw new UnknownCdmTypeException("Unknown FactCategory (id=" + Integer.valueOf(factCategoryId).toString() + ")");
337 }
338 }
339 }
340
341
342 public static UUID uuidRankCollSpecies = UUID.fromString("e14630ee-9446-4bb4-a7b7-4c3881bc5d94");
343 static Rank collSpeciesRank;
344
345
346
347
348 private static Rank rankId2NewRank(Integer rankId) {
349 Rank result = null;
350 if (rankId == null){
351 return null;
352 }else if (rankId == 57){
353 if (collSpeciesRank == null){
354 collSpeciesRank = new Rank();
355 Representation representation = Representation.NewInstance("Collective species", "Coll. species", "coll.", Language.ENGLISH());
356 collSpeciesRank.addRepresentation(representation);
357 collSpeciesRank.setUuid(uuidRankCollSpecies);
358 OrderedTermVocabulary<Rank> voc = (OrderedTermVocabulary<Rank>)Rank.SPECIES().getVocabulary();
359 voc.addTermBelow(collSpeciesRank, Rank.SPECIESGROUP());
360 }
361 result = collSpeciesRank;
362 }
363 return result;
364 }
365
366 public static Rank rankId2Rank (ResultSet rs, boolean useUnknown) throws UnknownCdmTypeException{
367 Rank result;
368 try {
369 int rankId = rs.getInt("rankFk");
370
371 String abbrev = rs.getString("rankAbbrev");
372 String rankName = rs.getString("rank");
373 if (logger.isDebugEnabled()){logger.debug(rankId);}
374 if (logger.isDebugEnabled()){logger.debug(abbrev);}
375 if (logger.isDebugEnabled()){logger.debug(rankName);}
376
377 try {
378 result = Rank.getRankByNameOrAbbreviation(abbrev);
379 } catch (UnknownCdmTypeException e) {
380 try {
381 result = Rank.getRankByNameOrAbbreviation(rankName);
382 } catch (UnknownCdmTypeException e1) {
383 switch (rankId){
384 case 0: return null;
385 case 1: return Rank.KINGDOM();
386 case 3: return Rank.SUBKINGDOM();
387 case 5: return Rank.PHYLUM();
388 case 7: return Rank.SUBPHYLUM();
389 case 8: return Rank.DIVISION();
390 case 9: return Rank.SUBDIVISION();
391 case 10: return Rank.CLASS();
392 case 13: return Rank.SUBCLASS();
393 case 16: return Rank.SUPERORDER();
394 case 18: return Rank.ORDER();
395 case 19: return Rank.SUBORDER();
396 case 20: return Rank.FAMILY();
397 case 25: return Rank.SUBFAMILY();
398 case 30: return Rank.TRIBE();
399 case 35: return Rank.SUBTRIBE();
400 case 40: return Rank.GENUS();
401 case 42: return Rank.SUBGENUS();
402 case 45: return Rank.SECTION_BOTANY();
403 case 47: return Rank.SUBSECTION_BOTANY();
404 case 50: return Rank.SERIES();
405 case 52: return Rank.SUBSERIES();
406 case 58: return Rank.SPECIESAGGREGATE();
407 case 59: return Rank.SPECIESGROUP();
408 case 60: return Rank.SPECIES();
409 case 61: return Rank.GREX();
410 case 65: return Rank.SUBSPECIES();
411 case 68: return Rank.CONVAR();
412 case 70: return Rank.VARIETY();
413 case 73: return Rank.SUBVARIETY();
414 case 80: return Rank.FORM();
415 case 82: return Rank.SUBFORM();
416 case 84: return Rank.SPECIALFORM();
417 case 98: return Rank.INFRAGENERICTAXON();
418 case 99: return Rank.INFRASPECIFICTAXON();
419
420 case 750: return Rank.SUPERCLASS();
421 case 780: return Rank.INFRACLASS();
422 case 820: return Rank.INFRAORDER();
423
424 case 830: return Rank.SUPERFAMILY();
425
426 default: {
427 Rank rank = rankId2NewRank(57);
428 if (rank != null){
429 return rank;
430 }
431 if (useUnknown){
432 logger.error("Rank unknown: " + rankId + ". Created UNKNOWN_RANK");
433 return Rank.UNKNOWN_RANK();
434 }
435 throw new UnknownCdmTypeException("Unknown Rank id" + Integer.valueOf(rankId).toString());
436 }
437 }
438 }
439 }
440 return result;
441 } catch (SQLException e) {
442 e.printStackTrace();
443 logger.warn("Exception occurred. Created UNKNOWN_RANK instead");
444 return Rank.UNKNOWN_RANK();
445 }
446 }
447
448 public static Integer rank2RankId (Rank rank){
449 if (rank == null){
450 return null;
451 }
452 else if (rank.equals(Rank.KINGDOM())){ return 1;}
453 else if (rank.equals(Rank.SUBKINGDOM())){ return 3;}
454 else if (rank.equals(Rank.PHYLUM())){ return 5;}
455 else if (rank.equals(Rank.SUBPHYLUM())){ return 7;}
456 else if (rank.equals(Rank.DIVISION())){ return 8;}
457 else if (rank.equals(Rank.SUBDIVISION())){ return 9;}
458
459 else if (rank.equals(Rank.CLASS())){ return 10;}
460 else if (rank.equals(Rank.SUBCLASS())){ return 13;}
461 else if (rank.equals(Rank.SUPERORDER())){ return 16;}
462 else if (rank.equals(Rank.ORDER())){ return 18;}
463 else if (rank.equals(Rank.SUBORDER())){ return 19;}
464 else if (rank.equals(Rank.FAMILY())){ return 20;}
465 else if (rank.equals(Rank.SUBFAMILY())){ return 25;}
466 else if (rank.equals(Rank.TRIBE())){ return 30;}
467 else if (rank.equals(Rank.SUBTRIBE())){ return 35;}
468 else if (rank.equals(Rank.GENUS())){ return 40;}
469 else if (rank.equals(Rank.SUBGENUS())){ return 42;}
470 else if (rank.equals(Rank.SECTION_BOTANY())){ return 45;}
471 else if (rank.equals(Rank.SUBSECTION_BOTANY())){ return 47;}
472 else if (rank.equals(Rank.SERIES())){ return 50;}
473 else if (rank.equals(Rank.SUBSERIES())){ return 52;}
474 else if (rank.equals(Rank.SPECIESAGGREGATE())){ return 58;}
475
476
477 else if (rank.equals(Rank.SPECIES())){ return 60;}
478 else if (rank.equals(Rank.SUBSPECIES())){ return 65;}
479 else if (rank.equals(Rank.CONVAR())){ return 68;}
480 else if (rank.equals(Rank.VARIETY())){ return 70;}
481 else if (rank.equals(Rank.SUBVARIETY())){ return 73;}
482 else if (rank.equals(Rank.FORM())){ return 80;}
483 else if (rank.equals(Rank.SUBFORM())){ return 82;}
484 else if (rank.equals(Rank.SPECIALFORM())){ return 84;}
485 else if (rank.equals(Rank.INFRAGENERICTAXON())){ return 98;}
486 else if (rank.equals(Rank.INFRASPECIFICTAXON())){ return 99;}
487
488 else if (rank.equals(Rank.SUPERCLASS())){ return 750;}
489 else if (rank.equals(Rank.INFRACLASS())){ return 780;}
490 else if (rank.equals(Rank.INFRAORDER())){ return 820;}
491 else if (rank.equals(Rank.SUPERFAMILY())){ return 830;}
492
493 else {
494
495 logger.warn("Rank not yet supported in Berlin Model: "+ rank.getLabel());
496 return null;
497 }
498 }
499
500 public static Integer textData2FactCategoryFk (Feature feature){
501 if (feature == null){return null;}
502 if (feature.equals(Feature.DESCRIPTION())){
503 return 1;
504 }else if (feature.equals(Feature.ECOLOGY())){
505 return 4;
506 }else if (feature.equals(Feature.PHENOLOGY())){
507 return 5;
508 }else if (feature.equals(Feature.COMMON_NAME())){
509 return 12;
510 }else if (feature.equals(Feature.OCCURRENCE())){
511 return 13;
512 }else if (feature.equals(Feature.CITATION())){
513 return 99;
514 }else{
515 logger.debug("Unknown Feature.");
516 return null;
517 }
518 }
519
520
521 public static Integer taxonBase2statusFk (TaxonBase<?> taxonBase){
522 if (taxonBase == null){return null;}
523 if (taxonBase.isInstanceOf(Taxon.class)){
524 return T_STATUS_ACCEPTED;
525 }else if (taxonBase.isInstanceOf(Synonym.class)){
526 return T_STATUS_SYNONYM;
527 }else{
528 logger.warn("Unknown ");
529 return T_STATUS_UNRESOLVED;
530 }
531
532
533
534
535
536 }
537
538 public static Integer ref2refCategoryId (ReferenceBase<?> ref){
539 if (ref == null){
540 return null;
541 }
542 else if (ref.getType().equals(ReferenceType.Article)){ return REF_ARTICLE;}
543 else if (ref instanceof ISectionBase){ return REF_PART_OF_OTHER_TITLE;}
544 else if (ref.getType().equals(ReferenceType.Book)){ return REF_BOOK;}
545 else if (ref.getType().equals(ReferenceType.Database)){ return REF_DATABASE;}
546
547
548 else if (ref.getType().equals(ReferenceType.WebPage)){ return REF_WEBSITE;}
549 else if (ref.getType().equals(ReferenceType.CdDvd)){ return REF_CD;}
550 else if (ref.getType().equals(ReferenceType.Journal)){ return REF_JOURNAL;}
551 else if (ref.getType().equals(ReferenceType.Generic)){ return REF_UNKNOWN;}
552 else if (ref.getType().equals(ReferenceType.PrintSeries)){
553 logger.warn("Print Series is not a standard Berlin Model category");
554 return REF_PRINT_SERIES;
555 }
556 else if (ref.getType().equals(ReferenceType.Proceedings)){
557 logger.warn("Proceedings is not a standard Berlin Model category");
558 return REF_CONFERENCE_PROCEEDINGS;
559 }
560
561 else if (ref.getType().equals(ReferenceType.Patent)){ return REF_NOT_APPLICABLE;}
562 else if (ref.getType().equals(ReferenceType.PersonalCommunication)){ return REF_INFORMAL;}
563 else if (ref.getType().equals(ReferenceType.Report)){ return REF_NOT_APPLICABLE;}
564 else if (ref.getType().equals(ReferenceType.Thesis)){ return REF_NOT_APPLICABLE;}
565 else if (ref.getType().equals(ReferenceType.Report)){ return REF_NOT_APPLICABLE;}
566
567 else {
568
569 logger.warn("Reference type not yet supported in Berlin Model: "+ ref.getClass().getSimpleName());
570 return null;
571 }
572 }
573
574
575 public static Integer taxRelation2relPtQualifierFk (RelationshipBase<?,?,?> rel){
576 if (rel == null){
577 return null;
578 }
579
580
581
582 RelationshipTermBase<?> type = rel.getType();
583 if (type.equals(TaxonRelationshipType.TAXONOMICALLY_INCLUDED_IN())) {return TAX_REL_IS_INCLUDED_IN;
584 }else if (type.equals(TaxonRelationshipType.MISAPPLIED_NAME_FOR())) {return TAX_REL_IS_MISAPPLIED_NAME_OF;
585 }else if (type.equals(SynonymRelationshipType.SYNONYM_OF())) {return TAX_REL_IS_SYNONYM_OF;
586 }else if (type.equals(SynonymRelationshipType.HOMOTYPIC_SYNONYM_OF())) {return TAX_REL_IS_HOMOTYPIC_SYNONYM_OF;
587 }else if (type.equals(SynonymRelationshipType.HETEROTYPIC_SYNONYM_OF())) {return TAX_REL_IS_HETEROTYPIC_SYNONYM_OF;
588 }else if (type.equals(TaxonRelationshipType.CONGRUENT_TO())) {return 11;
589
590
591
592
593
594
595
596 }else {
597
598 logger.warn("Relationship type not yet supported by Berlin Model export: "+ rel.getType());
599 return null;
600 }
601 }
602
603 public static Integer nomStatus2nomStatusFk (NomenclaturalStatusType status){
604 if (status == null){
605 return null;
606 }
607 if (status.equals(NomenclaturalStatusType.INVALID())) {return NAME_ST_NOM_INVAL;
608 }else if (status.equals(NomenclaturalStatusType.ILLEGITIMATE())) {return NAME_ST_NOM_ILLEG;
609 }else if (status.equals(NomenclaturalStatusType.NUDUM())) {return NAME_ST_NOM_NUD;
610 }else if (status.equals(NomenclaturalStatusType.REJECTED())) {return NAME_ST_NOM_REJ;
611 }else if (status.equals(NomenclaturalStatusType.REJECTED_PROP())) {return NAME_ST_NOM_REJ_PROP;
612 }else if (status.equals(NomenclaturalStatusType.UTIQUE_REJECTED())) {return NAME_ST_NOM_UTIQUE_REJ;
613 }else if (status.equals(NomenclaturalStatusType.UTIQUE_REJECTED_PROP())) {return NAME_ST_NOM_UTIQUE_REJ_PROP;
614 }else if (status.equals(NomenclaturalStatusType.CONSERVED())) {return NAME_ST_NOM_CONS;
615
616 }else if (status.equals(NomenclaturalStatusType.CONSERVED_PROP())) {return NAME_ST_NOM_CONS_PROP;
617 }else if (status.equals(NomenclaturalStatusType.ORTHOGRAPHY_CONSERVED())) {return NAME_ST_ORTH_CONS;
618 }else if (status.equals(NomenclaturalStatusType.ORTHOGRAPHY_CONSERVED_PROP())) {return NAME_ST_ORTH_CONS_PROP;
619 }else if (status.equals(NomenclaturalStatusType.SUPERFLUOUS())) {return NAME_ST_NOM_SUPERFL;
620 }else if (status.equals(NomenclaturalStatusType.AMBIGUOUS())) {return NAME_ST_NOM_AMBIG;
621 }else if (status.equals(NomenclaturalStatusType.PROVISIONAL())) {return NAME_ST_NOM_PROVIS;
622 }else if (status.equals(NomenclaturalStatusType.DOUBTFUL())) {return NAME_ST_NOM_DUB;
623 }else if (status.equals(NomenclaturalStatusType.NOVUM())) {return NAME_ST_NOM_NOV;
624
625 }else if (status.equals(NomenclaturalStatusType.CONFUSUM())) {return NAME_ST_NOM_CONFUS;
626 }else if (status.equals(NomenclaturalStatusType.ALTERNATIVE())) {return NAME_ST_NOM_ALTERN;
627 }else if (status.equals(NomenclaturalStatusType.COMBINATION_INVALID())) {return NAME_ST_COMB_INVAL;
628
629 }else {
630
631 logger.warn("NomStatus type not yet supported by Berlin Model export: "+ status);
632 return null;
633 }
634 }
635
636
637
638 public static Integer nameRel2RelNameQualifierFk (RelationshipBase<?,?,?> rel){
639 if (rel == null){
640 return null;
641 }
642 RelationshipTermBase<?> type = rel.getType();
643 if (type.equals(NameRelationshipType.BASIONYM())) {return NAME_REL_IS_BASIONYM_FOR;
644 }else if (type.equals(NameRelationshipType.LATER_HOMONYM())) {return NAME_REL_IS_LATER_HOMONYM_OF;
645 }else if (type.equals(NameRelationshipType.REPLACED_SYNONYM())) {return NAME_REL_IS_REPLACED_SYNONYM_FOR;
646
647 }else if (type.equals(NameRelationshipType.VALIDATED_BY_NAME())) {return NAME_REL_IS_VALIDATION_OF;
648 }else if (type.equals(NameRelationshipType.LATER_VALIDATED_BY_NAME())) {return NAME_REL_IS_LATER_VALIDATION_OF;
649 }else if (type.equals(NameRelationshipType.CONSERVED_AGAINST())) {return NAME_REL_IS_CONSERVED_AGAINST;
650
651
652 }else if (type.equals(NameRelationshipType.TREATED_AS_LATER_HOMONYM())) {return NAME_REL_IS_TREATED_AS_LATER_HOMONYM_OF;
653 }else if (type.equals(NameRelationshipType.ORTHOGRAPHIC_VARIANT())) {return NAME_REL_IS_ORTHOGRAPHIC_VARIANT_OF;
654 }else {
655
656 logger.warn("Relationship type not yet supported by Berlin Model export: "+ rel.getType());
657 return null;
658 }
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679 }
680
681 }