Operation history implemented for ChangeCompositeToMisappliedName.
[taxeditor.git] / eclipseprojects / eu.etaxonomy.taxeditor / src / eu / etaxonomy / taxeditor / model / CdmUtil.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.taxeditor.model;
11
12 import org.apache.log4j.Logger;
13
14 import eu.etaxonomy.cdm.api.service.ITaxonService;
15 import eu.etaxonomy.cdm.model.name.BotanicalName;
16 import eu.etaxonomy.cdm.model.name.HomotypicalGroup;
17 import eu.etaxonomy.cdm.model.name.NomenclaturalCode;
18 import eu.etaxonomy.cdm.model.name.NonViralName;
19 import eu.etaxonomy.cdm.model.name.Rank;
20 import eu.etaxonomy.cdm.model.name.TaxonNameBase;
21 import eu.etaxonomy.cdm.model.reference.ReferenceBase;
22 import eu.etaxonomy.cdm.model.taxon.Synonym;
23 import eu.etaxonomy.cdm.model.taxon.SynonymRelationshipType;
24 import eu.etaxonomy.cdm.model.taxon.Taxon;
25 import eu.etaxonomy.cdm.strategy.parser.INonViralNameParser;
26 import eu.etaxonomy.cdm.strategy.parser.NonViralNameParserImpl;
27 import eu.etaxonomy.taxeditor.TaxEditorPlugin;
28
29 /**
30 * @author p.ciardelli
31 * @created 26.05.2008
32 * @version 1.0
33 */
34 public class CdmUtil {
35 private static final Logger logger = Logger.getLogger(CdmUtil.class);
36
37 static INonViralNameParser nonViralNameParser;
38
39 /**
40 * Checks whether synonym's name is the basionym of the taxon's name.
41 *
42 * @param taxon
43 * @param synonym
44 * @return
45 */
46 public static boolean isSynonymBasionym(Taxon taxon, Synonym synonym) {
47 TaxonNameBase synonymName = synonym.getName();
48 TaxonNameBase taxonName = taxon.getName();
49 if (taxonName == null || synonymName == null) {
50 return false;
51 }
52 TaxonNameBase basionymName = taxonName.getBasionym();
53 if (synonymName.equals(basionymName)) {
54 return true;
55 }
56 return false;
57 }
58
59 /**
60 * Checks whether name belongs to the same homotypic group as taxon's name.
61 *
62 * @param name
63 * @param taxon
64 * @return
65 */
66 public static boolean isNameHomotypic(TaxonNameBase name, Taxon taxon) {
67 TaxonNameBase taxonName = taxon.getName();
68 if (taxonName == null || name == null) {
69 return false;
70 }
71 HomotypicalGroup homotypicGroup = taxonName.getHomotypicalGroup();
72 if (homotypicGroup == null) {
73 return false;
74 }
75 if (homotypicGroup.equals(name.getHomotypicalGroup())) {
76 return true;
77 }
78 return false;
79 }
80
81 /**
82 * Returns whatever is currently considered the display name for Taxon
83 * objects. Currently titleCache.
84 *
85 * @param taxon
86 * @return
87 */
88 public static String getDisplayName(Taxon taxon) {
89 TaxonNameBase name = taxon.getName();
90 if (name == null) {
91 return "";
92 }
93 return name.getTitleCache();
94 }
95
96 private static INonViralNameParser getNonViralNameParser() {
97 if (nonViralNameParser == null) {
98 nonViralNameParser = NonViralNameParserImpl.NewInstance();
99 }
100 return nonViralNameParser;
101 }
102
103 public static TaxonNameBase parseFullReference(String fullReference,
104 NomenclaturalCode nomCode, Rank rank) {
105 return getNonViralNameParser().parseFullReference(fullReference,
106 nomCode, rank);
107 }
108
109 public static void parseFullName(NonViralName nameToBeFilled,
110 String fullNameString, Rank rank, boolean makeEmpty) {
111 BotanicalName name;
112 getNonViralNameParser().parseFullName(nameToBeFilled, fullNameString,
113 rank, makeEmpty);
114 }
115
116 public static ReferenceBase getSessionDefaultSec() {
117 return null;
118 }
119
120 public static void makeTaxonSynonym(Taxon oldTaxon,
121 Taxon newAcceptedTaxon, SynonymRelationshipType synonymType,
122 ReferenceBase citation, String citationMicroReference) {
123 ITaxonService taxonService = TaxEditorPlugin.getDefault()
124 .getTaxonService();
125 taxonService.makeTaxonSynonym(oldTaxon, newAcceptedTaxon, synonymType,
126 citation, citationMicroReference);
127 }
128 }