(no commit message)
[cdmlib.git] / cdmlib-model / src / main / java / eu / etaxonomy / cdm / model / name / HomotypicalGroup.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.model.name;
11
12 import java.util.ArrayList;
13 import java.util.HashSet;
14 import java.util.List;
15 import java.util.Set;
16
17 import javax.persistence.Entity;
18 import javax.persistence.OneToMany;
19 import javax.persistence.Transient;
20
21 import org.apache.log4j.Logger;
22 import org.hibernate.annotations.Cascade;
23 import org.hibernate.annotations.CascadeType;
24
25 import eu.etaxonomy.cdm.model.common.AnnotatableEntity;
26 import eu.etaxonomy.cdm.model.occurrence.Specimen;
27 import eu.etaxonomy.cdm.model.reference.ReferenceBase;
28 import eu.etaxonomy.cdm.model.taxon.Synonym;
29 import eu.etaxonomy.cdm.model.taxon.SynonymRelationship;
30 import eu.etaxonomy.cdm.model.taxon.TaxonBase;
31
32 @Entity
33 public class HomotypicalGroup extends AnnotatableEntity {
34 static Logger logger = Logger.getLogger(HomotypicalGroup.class);
35
36 protected Set<TaxonNameBase> typifiedNames = new HashSet();
37 protected Set<SpecimenTypeDesignation> typeDesignations = new HashSet();
38
39 public HomotypicalGroup() {
40 super();
41 // TODO Auto-generated constructor stub
42 }
43
44
45 @OneToMany
46 public Set<TaxonNameBase> getTypifiedNames() {
47 return typifiedNames;
48 }
49 protected void setTypifiedNames(Set<TaxonNameBase> typifiedNames) {
50 this.typifiedNames = typifiedNames;
51 }
52 public void addTypifiedName(TaxonNameBase typifiedName) {
53 typifiedName.setHomotypicalGroup(this);
54 }
55 public void removeTypifiedName(TaxonNameBase typifiedName) {
56 typifiedName.setHomotypicalGroup(null);
57 }
58
59
60 @OneToMany
61 @Cascade({CascadeType.SAVE_UPDATE})
62 public Set<SpecimenTypeDesignation> getTypeDesignations() {
63 return typeDesignations;
64 }
65 protected void setTypeDesignations(Set<SpecimenTypeDesignation> typeDesignations) {
66 this.typeDesignations = typeDesignations;
67 }
68 public void addTypeDesignation(SpecimenTypeDesignation typeDesignation) {
69 typeDesignation.setHomotypicalGroup(this);
70 }
71 public void removeTypeDesignation(SpecimenTypeDesignation typeDesignation) {
72 typeDesignation.setHomotypicalGroup(null);
73 }
74 public void addTypeDesignation(Specimen typeSpecimen, TypeDesignationStatus status, ReferenceBase citation, String citationMicroReference, String originalNameString) {
75 SpecimenTypeDesignation td = new SpecimenTypeDesignation(this, typeSpecimen, status, citation, citationMicroReference, originalNameString);
76 td.setHomotypicalGroup(this);
77 }
78
79 /**
80 * Retrieves the synonyms of reference sec that are part of this homotypical group.
81 * If other names are part of this group that are not considered synonyms in the respective sec-reference,
82 * then they will not be included in the resultset.
83 * @param sec
84 * @return
85 */
86 @Transient
87 public List<Synonym> getSynonymsInGroup(ReferenceBase sec){
88 List<Synonym> result = new ArrayList();
89 for (TaxonNameBase n:this.getTypifiedNames()){
90 for (Synonym s:n.getSynonyms()){
91 if (s.getSec().equals(sec)){
92 result.add(s);
93 }
94 }
95 }
96 // TODO: sort result list according to date first published, see nomenclatural reference
97 return result;
98 }
99 }