| 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.occurrence; |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | import java.util.HashSet; |
|---|
| 15 | import java.util.Set; |
|---|
| 16 | |
|---|
| 17 | import javax.persistence.Entity; |
|---|
| 18 | import javax.persistence.FetchType; |
|---|
| 19 | import javax.persistence.ManyToMany; |
|---|
| 20 | import javax.persistence.ManyToOne; |
|---|
| 21 | import javax.persistence.Transient; |
|---|
| 22 | import javax.xml.bind.annotation.XmlAccessType; |
|---|
| 23 | import javax.xml.bind.annotation.XmlAccessorType; |
|---|
| 24 | import javax.xml.bind.annotation.XmlElement; |
|---|
| 25 | import javax.xml.bind.annotation.XmlElementWrapper; |
|---|
| 26 | import javax.xml.bind.annotation.XmlIDREF; |
|---|
| 27 | import javax.xml.bind.annotation.XmlRootElement; |
|---|
| 28 | import javax.xml.bind.annotation.XmlSchemaType; |
|---|
| 29 | import javax.xml.bind.annotation.XmlType; |
|---|
| 30 | |
|---|
| 31 | import org.apache.log4j.Logger; |
|---|
| 32 | import org.hibernate.annotations.Cascade; |
|---|
| 33 | import org.hibernate.annotations.CascadeType; |
|---|
| 34 | import org.hibernate.envers.Audited; |
|---|
| 35 | import org.hibernate.search.annotations.Indexed; |
|---|
| 36 | import org.hibernate.search.annotations.IndexedEmbedded; |
|---|
| 37 | import org.joda.time.Partial; |
|---|
| 38 | |
|---|
| 39 | import eu.etaxonomy.cdm.model.agent.AgentBase; |
|---|
| 40 | import eu.etaxonomy.cdm.model.common.EventBase; |
|---|
| 41 | import eu.etaxonomy.cdm.model.reference.Reference; |
|---|
| 42 | import eu.etaxonomy.cdm.model.taxon.TaxonBase; |
|---|
| 43 | |
|---|
| 44 | /** |
|---|
| 45 | * @author m.doering |
|---|
| 46 | * @version 1.0 |
|---|
| 47 | * @created 08-Nov-2007 13:06:21 |
|---|
| 48 | */ |
|---|
| 49 | @XmlAccessorType(XmlAccessType.FIELD) |
|---|
| 50 | @XmlType(name = "DeterminationEvent", propOrder = { |
|---|
| 51 | "identifiedUnit", |
|---|
| 52 | "taxon", |
|---|
| 53 | "modifier", |
|---|
| 54 | "preferredFlag", |
|---|
| 55 | "setOfReferences" |
|---|
| 56 | }) |
|---|
| 57 | @XmlRootElement(name = "DeterminationEvent") |
|---|
| 58 | @Entity |
|---|
| 59 | @Indexed |
|---|
| 60 | @Audited |
|---|
| 61 | public class DeterminationEvent extends EventBase { |
|---|
| 62 | private static final Logger logger = Logger.getLogger(DeterminationEvent.class); |
|---|
| 63 | |
|---|
| 64 | @XmlElement(name = "IdentifiedUnit") |
|---|
| 65 | @XmlIDREF |
|---|
| 66 | @XmlSchemaType(name = "IDREF") |
|---|
| 67 | @ManyToOne(fetch = FetchType.LAZY) |
|---|
| 68 | @Cascade(CascadeType.SAVE_UPDATE) |
|---|
| 69 | private SpecimenOrObservationBase identifiedUnit; |
|---|
| 70 | |
|---|
| 71 | @XmlElement(name = "Taxon") |
|---|
| 72 | @XmlIDREF |
|---|
| 73 | @XmlSchemaType(name = "IDREF") |
|---|
| 74 | @ManyToOne(fetch = FetchType.LAZY) |
|---|
| 75 | @IndexedEmbedded |
|---|
| 76 | @Cascade(CascadeType.SAVE_UPDATE) |
|---|
| 77 | private TaxonBase taxon; |
|---|
| 78 | |
|---|
| 79 | @XmlElement(name = "Modifier") |
|---|
| 80 | @XmlIDREF |
|---|
| 81 | @XmlSchemaType(name = "IDREF") |
|---|
| 82 | @ManyToOne(fetch = FetchType.LAZY) |
|---|
| 83 | private DeterminationModifier modifier; |
|---|
| 84 | |
|---|
| 85 | @XmlElement(name = "PreferredFlag") |
|---|
| 86 | private boolean preferredFlag; |
|---|
| 87 | |
|---|
| 88 | @XmlElementWrapper(name = "SetOfReferences") |
|---|
| 89 | @XmlElement(name = "Reference") |
|---|
| 90 | @XmlIDREF |
|---|
| 91 | @XmlSchemaType(name = "IDREF") |
|---|
| 92 | @ManyToMany(fetch = FetchType.LAZY) |
|---|
| 93 | private Set<Reference> setOfReferences = new HashSet<Reference>(); |
|---|
| 94 | |
|---|
| 95 | |
|---|
| 96 | |
|---|
| 97 | /** |
|---|
| 98 | * Factory method |
|---|
| 99 | * @return |
|---|
| 100 | */ |
|---|
| 101 | public static DeterminationEvent NewInstance(){ |
|---|
| 102 | return new DeterminationEvent(); |
|---|
| 103 | } |
|---|
| 104 | |
|---|
| 105 | /** |
|---|
| 106 | * Constructor |
|---|
| 107 | */ |
|---|
| 108 | protected DeterminationEvent() { |
|---|
| 109 | super(); |
|---|
| 110 | } |
|---|
| 111 | |
|---|
| 112 | public DeterminationModifier getModifier() { |
|---|
| 113 | return modifier; |
|---|
| 114 | } |
|---|
| 115 | |
|---|
| 116 | public void setModifier(DeterminationModifier modifier) { |
|---|
| 117 | this.modifier = modifier; |
|---|
| 118 | } |
|---|
| 119 | |
|---|
| 120 | public TaxonBase getTaxon(){ |
|---|
| 121 | return this.taxon; |
|---|
| 122 | } |
|---|
| 123 | |
|---|
| 124 | /** |
|---|
| 125 | * |
|---|
| 126 | * @param taxon taxon |
|---|
| 127 | */ |
|---|
| 128 | public void setTaxon(TaxonBase taxon){ |
|---|
| 129 | this.taxon = taxon; |
|---|
| 130 | } |
|---|
| 131 | |
|---|
| 132 | @Transient |
|---|
| 133 | public Partial getIdentificationDate(){ |
|---|
| 134 | return this.getTimeperiod().getStart(); |
|---|
| 135 | } |
|---|
| 136 | |
|---|
| 137 | /** |
|---|
| 138 | * |
|---|
| 139 | * @param identificationDate identificationDate |
|---|
| 140 | */ |
|---|
| 141 | public void setIdentificationDate(Partial identificationDate){ |
|---|
| 142 | this.getTimeperiod().setStart(identificationDate); |
|---|
| 143 | } |
|---|
| 144 | |
|---|
| 145 | @Transient |
|---|
| 146 | public AgentBase getDeterminer() { |
|---|
| 147 | return this.getActor(); |
|---|
| 148 | } |
|---|
| 149 | |
|---|
| 150 | public void setDeterminer(AgentBase determiner) { |
|---|
| 151 | this.setActor(determiner); |
|---|
| 152 | } |
|---|
| 153 | |
|---|
| 154 | public SpecimenOrObservationBase getIdentifiedUnit() { |
|---|
| 155 | return identifiedUnit; |
|---|
| 156 | } |
|---|
| 157 | |
|---|
| 158 | public void setIdentifiedUnit(SpecimenOrObservationBase identifiedUnit) { |
|---|
| 159 | this.identifiedUnit = identifiedUnit; |
|---|
| 160 | } |
|---|
| 161 | |
|---|
| 162 | public boolean getPreferredFlag() { |
|---|
| 163 | return preferredFlag; |
|---|
| 164 | } |
|---|
| 165 | |
|---|
| 166 | public void setPreferredFlag(boolean preferredFlag) { |
|---|
| 167 | this.preferredFlag = preferredFlag; |
|---|
| 168 | } |
|---|
| 169 | |
|---|
| 170 | public Set<Reference> getReferences() { |
|---|
| 171 | return setOfReferences; |
|---|
| 172 | } |
|---|
| 173 | |
|---|
| 174 | public void setReferences(Set<Reference> references) { |
|---|
| 175 | this.setOfReferences = references; |
|---|
| 176 | } |
|---|
| 177 | |
|---|
| 178 | public void addReference(Reference reference) { |
|---|
| 179 | this.setOfReferences.add(reference); |
|---|
| 180 | } |
|---|
| 181 | |
|---|
| 182 | //*********** CLONE **********************************/ |
|---|
| 183 | |
|---|
| 184 | /** |
|---|
| 185 | * Clones <i>this</i> determination event. This is a shortcut that enables to |
|---|
| 186 | * create a new instance that differs only slightly from <i>this</i> determination event |
|---|
| 187 | * by modifying only some of the attributes.<BR> |
|---|
| 188 | * This method overrides the clone method from {@link EventBase EventBase}. |
|---|
| 189 | * |
|---|
| 190 | * @see EventBase#clone() |
|---|
| 191 | * @see java.lang.Object#clone() |
|---|
| 192 | */ |
|---|
| 193 | @Override |
|---|
| 194 | public DeterminationEvent clone(){ |
|---|
| 195 | try{ |
|---|
| 196 | DeterminationEvent result = (DeterminationEvent)super.clone(); |
|---|
| 197 | //type |
|---|
| 198 | result.setIdentifiedUnit(this.getIdentifiedUnit()); |
|---|
| 199 | //modifier |
|---|
| 200 | result.setModifier(this.getModifier()); |
|---|
| 201 | //taxon |
|---|
| 202 | result.setTaxon(this.getTaxon()); //TODO |
|---|
| 203 | //no changes to: preferredFlag |
|---|
| 204 | return result; |
|---|
| 205 | } catch (CloneNotSupportedException e) { |
|---|
| 206 | logger.warn("Object does not implement cloneable"); |
|---|
| 207 | e.printStackTrace(); |
|---|
| 208 | return null; |
|---|
| 209 | } |
|---|
| 210 | } |
|---|
| 211 | |
|---|
| 212 | |
|---|
| 213 | |
|---|
| 214 | } |
|---|