| 1 | // $Id$ |
|---|
| 2 | /** |
|---|
| 3 | * Copyright (C) 2007 EDIT |
|---|
| 4 | * European Distributed Institute of Taxonomy |
|---|
| 5 | * http://www.e-taxonomy.eu |
|---|
| 6 | * |
|---|
| 7 | * The contents of this file are subject to the Mozilla Public License Version 1.1 |
|---|
| 8 | * See LICENSE.TXT at the top of this package for the full license terms. |
|---|
| 9 | */ |
|---|
| 10 | |
|---|
| 11 | package eu.etaxonomy.cdm.model.occurrence; |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | import javax.persistence.Entity; |
|---|
| 15 | import javax.persistence.FetchType; |
|---|
| 16 | import javax.persistence.ManyToOne; |
|---|
| 17 | import javax.xml.bind.annotation.XmlAccessType; |
|---|
| 18 | import javax.xml.bind.annotation.XmlAccessorType; |
|---|
| 19 | import javax.xml.bind.annotation.XmlElement; |
|---|
| 20 | import javax.xml.bind.annotation.XmlIDREF; |
|---|
| 21 | import javax.xml.bind.annotation.XmlRootElement; |
|---|
| 22 | import javax.xml.bind.annotation.XmlSchemaType; |
|---|
| 23 | import javax.xml.bind.annotation.XmlType; |
|---|
| 24 | |
|---|
| 25 | import org.apache.log4j.Logger; |
|---|
| 26 | import org.hibernate.annotations.Cascade; |
|---|
| 27 | import org.hibernate.annotations.CascadeType; |
|---|
| 28 | import org.hibernate.annotations.Index; |
|---|
| 29 | import org.hibernate.annotations.Table; |
|---|
| 30 | import org.hibernate.envers.Audited; |
|---|
| 31 | import org.hibernate.search.annotations.Field; |
|---|
| 32 | import org.hibernate.search.annotations.Indexed; |
|---|
| 33 | import org.hibernate.search.annotations.IndexedEmbedded; |
|---|
| 34 | import org.hibernate.validator.constraints.Length; |
|---|
| 35 | import org.springframework.beans.factory.annotation.Configurable; |
|---|
| 36 | |
|---|
| 37 | import eu.etaxonomy.cdm.model.agent.Institution; |
|---|
| 38 | import eu.etaxonomy.cdm.model.media.IdentifiableMediaEntity; |
|---|
| 39 | import eu.etaxonomy.cdm.strategy.cache.common.IIdentifiableEntityCacheStrategy; |
|---|
| 40 | import eu.etaxonomy.cdm.strategy.cache.common.IdentifiableEntityDefaultCacheStrategy; |
|---|
| 41 | import eu.etaxonomy.cdm.strategy.cache.occurrence.CollectionDefaultCacheStrategy; |
|---|
| 42 | import eu.etaxonomy.cdm.validation.annotation.NullOrNotEmpty; |
|---|
| 43 | |
|---|
| 44 | /** |
|---|
| 45 | * @author m.doering |
|---|
| 46 | * @version 1.0 |
|---|
| 47 | * @created 08-Nov-2007 13:06:16 |
|---|
| 48 | */ |
|---|
| 49 | @XmlAccessorType(XmlAccessType.FIELD) |
|---|
| 50 | @XmlType(name = "Collection", propOrder = { |
|---|
| 51 | "name", |
|---|
| 52 | "code", |
|---|
| 53 | "codeStandard", |
|---|
| 54 | "townOrLocation", |
|---|
| 55 | "institute", |
|---|
| 56 | "superCollection" |
|---|
| 57 | }) |
|---|
| 58 | @XmlRootElement(name = "Collection") |
|---|
| 59 | @Entity |
|---|
| 60 | @Indexed(index = "eu.etaxonomy.cdm.model.occurrence.Collection") |
|---|
| 61 | @Audited |
|---|
| 62 | @Configurable |
|---|
| 63 | @Table(appliesTo="Collection", indexes = { @Index(name = "collectionTitleCacheIndex", columnNames = { "titleCache" }) }) |
|---|
| 64 | public class Collection extends IdentifiableMediaEntity<IIdentifiableEntityCacheStrategy<Collection>> implements Cloneable{ |
|---|
| 65 | private static final long serialVersionUID = -7833674897174732255L; |
|---|
| 66 | private static final Logger logger = Logger.getLogger(Collection.class); |
|---|
| 67 | |
|---|
| 68 | @XmlElement(name = "Code") |
|---|
| 69 | @Field(index=org.hibernate.search.annotations.Index.UN_TOKENIZED) |
|---|
| 70 | @NullOrNotEmpty |
|---|
| 71 | @Length(max = 255) |
|---|
| 72 | private String code; |
|---|
| 73 | |
|---|
| 74 | @XmlElement(name = "CodeStandard") |
|---|
| 75 | @Field(index=org.hibernate.search.annotations.Index.UN_TOKENIZED) |
|---|
| 76 | @NullOrNotEmpty |
|---|
| 77 | @Length(max = 255) |
|---|
| 78 | private String codeStandard; |
|---|
| 79 | |
|---|
| 80 | @XmlElement(name = "Name") |
|---|
| 81 | @Field(index=org.hibernate.search.annotations.Index.TOKENIZED) |
|---|
| 82 | @NullOrNotEmpty |
|---|
| 83 | @Length(max = 255) |
|---|
| 84 | private String name; |
|---|
| 85 | |
|---|
| 86 | @XmlElement(name = "TownOrLocation") |
|---|
| 87 | @Field(index=org.hibernate.search.annotations.Index.TOKENIZED) |
|---|
| 88 | @NullOrNotEmpty |
|---|
| 89 | @Length(max = 255) |
|---|
| 90 | private String townOrLocation; |
|---|
| 91 | |
|---|
| 92 | @XmlElement(name = "Institution") |
|---|
| 93 | @XmlIDREF |
|---|
| 94 | @XmlSchemaType(name = "IDREF") |
|---|
| 95 | @ManyToOne(fetch = FetchType.LAZY) |
|---|
| 96 | @Cascade(CascadeType.SAVE_UPDATE) |
|---|
| 97 | @IndexedEmbedded |
|---|
| 98 | private Institution institute; |
|---|
| 99 | |
|---|
| 100 | @XmlElement(name = "SuperCollection") |
|---|
| 101 | @XmlIDREF |
|---|
| 102 | @XmlSchemaType(name = "IDREF") |
|---|
| 103 | @ManyToOne(fetch = FetchType.LAZY) |
|---|
| 104 | @Cascade(CascadeType.SAVE_UPDATE) |
|---|
| 105 | private Collection superCollection; |
|---|
| 106 | |
|---|
| 107 | |
|---|
| 108 | /** |
|---|
| 109 | * Factory method |
|---|
| 110 | * @return |
|---|
| 111 | */ |
|---|
| 112 | public static Collection NewInstance(){ |
|---|
| 113 | return new Collection(); |
|---|
| 114 | } |
|---|
| 115 | |
|---|
| 116 | /** |
|---|
| 117 | * Constructor |
|---|
| 118 | */ |
|---|
| 119 | protected Collection() { |
|---|
| 120 | super(); |
|---|
| 121 | this.cacheStrategy = new CollectionDefaultCacheStrategy(); |
|---|
| 122 | } |
|---|
| 123 | |
|---|
| 124 | public Institution getInstitute(){ |
|---|
| 125 | return this.institute; |
|---|
| 126 | } |
|---|
| 127 | |
|---|
| 128 | /** |
|---|
| 129 | * |
|---|
| 130 | * @param institute institute |
|---|
| 131 | */ |
|---|
| 132 | public void setInstitute(Institution institute){ |
|---|
| 133 | this.institute = institute; |
|---|
| 134 | } |
|---|
| 135 | |
|---|
| 136 | public String getCode(){ |
|---|
| 137 | return this.code; |
|---|
| 138 | } |
|---|
| 139 | |
|---|
| 140 | /** |
|---|
| 141 | * |
|---|
| 142 | * @param code code |
|---|
| 143 | */ |
|---|
| 144 | public void setCode(String code){ |
|---|
| 145 | this.code = code; |
|---|
| 146 | } |
|---|
| 147 | |
|---|
| 148 | public String getCodeStandard(){ |
|---|
| 149 | return this.codeStandard; |
|---|
| 150 | } |
|---|
| 151 | |
|---|
| 152 | /** |
|---|
| 153 | * |
|---|
| 154 | * @param codeStandard codeStandard |
|---|
| 155 | */ |
|---|
| 156 | public void setCodeStandard(String codeStandard){ |
|---|
| 157 | this.codeStandard = codeStandard; |
|---|
| 158 | } |
|---|
| 159 | |
|---|
| 160 | public String getName(){ |
|---|
| 161 | return this.name; |
|---|
| 162 | } |
|---|
| 163 | |
|---|
| 164 | /** |
|---|
| 165 | * |
|---|
| 166 | * @param name name |
|---|
| 167 | */ |
|---|
| 168 | public void setName(String name){ |
|---|
| 169 | this.name = name; |
|---|
| 170 | } |
|---|
| 171 | |
|---|
| 172 | public String getTownOrLocation(){ |
|---|
| 173 | return this.townOrLocation; |
|---|
| 174 | } |
|---|
| 175 | |
|---|
| 176 | /** |
|---|
| 177 | * |
|---|
| 178 | * @param townOrLocation townOrLocation |
|---|
| 179 | */ |
|---|
| 180 | public void setTownOrLocation(String townOrLocation){ |
|---|
| 181 | this.townOrLocation = townOrLocation; |
|---|
| 182 | } |
|---|
| 183 | |
|---|
| 184 | // @Override |
|---|
| 185 | // public String generateTitle(){ |
|---|
| 186 | // return ""; |
|---|
| 187 | // } |
|---|
| 188 | |
|---|
| 189 | public Collection getSuperCollection() { |
|---|
| 190 | return superCollection; |
|---|
| 191 | } |
|---|
| 192 | |
|---|
| 193 | public void setSuperCollection(Collection superCollection) { |
|---|
| 194 | this.superCollection = superCollection; |
|---|
| 195 | } |
|---|
| 196 | |
|---|
| 197 | |
|---|
| 198 | //*********** CLONE **********************************/ |
|---|
| 199 | |
|---|
| 200 | /** |
|---|
| 201 | * Clones <i>this</i> collection. This is a shortcut that enables to |
|---|
| 202 | * create a new instance that differs only slightly from <i>this</i> collection |
|---|
| 203 | * by modifying only some of the attributes.<BR> |
|---|
| 204 | * This method overrides the clone method from {@link IdentifiableMediaEntity IdentifiableMediaEntity}. |
|---|
| 205 | * |
|---|
| 206 | * @see eu.etaxonomy.cdm.model.media.IdentifiableMediaEntity#clone() |
|---|
| 207 | * @see java.lang.Object#clone() |
|---|
| 208 | */ |
|---|
| 209 | @Override |
|---|
| 210 | public Collection clone(){ |
|---|
| 211 | try{ |
|---|
| 212 | Collection result = (Collection)super.clone(); |
|---|
| 213 | //superCollection |
|---|
| 214 | result.setSuperCollection(this.superCollection); |
|---|
| 215 | //institute |
|---|
| 216 | result.setInstitute(this.institute); |
|---|
| 217 | //no changes to: code, codeStandard, name, townOrLocation |
|---|
| 218 | return result; |
|---|
| 219 | } catch (CloneNotSupportedException e) { |
|---|
| 220 | logger.warn("Object does not implement cloneable"); |
|---|
| 221 | e.printStackTrace(); |
|---|
| 222 | return null; |
|---|
| 223 | } |
|---|
| 224 | } |
|---|
| 225 | } |
|---|