| 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.agent; |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | import java.util.HashSet; |
|---|
| 14 | import java.util.Set; |
|---|
| 15 | |
|---|
| 16 | import javax.persistence.Entity; |
|---|
| 17 | import javax.persistence.FetchType; |
|---|
| 18 | import javax.persistence.ManyToMany; |
|---|
| 19 | import javax.persistence.ManyToOne; |
|---|
| 20 | import javax.validation.constraints.Size; |
|---|
| 21 | import javax.xml.bind.annotation.XmlAccessType; |
|---|
| 22 | import javax.xml.bind.annotation.XmlAccessorType; |
|---|
| 23 | import javax.xml.bind.annotation.XmlElement; |
|---|
| 24 | import javax.xml.bind.annotation.XmlElementWrapper; |
|---|
| 25 | import javax.xml.bind.annotation.XmlIDREF; |
|---|
| 26 | import javax.xml.bind.annotation.XmlRootElement; |
|---|
| 27 | import javax.xml.bind.annotation.XmlSchemaType; |
|---|
| 28 | import javax.xml.bind.annotation.XmlType; |
|---|
| 29 | |
|---|
| 30 | import org.apache.log4j.Logger; |
|---|
| 31 | import org.hibernate.annotations.Cascade; |
|---|
| 32 | import org.hibernate.annotations.CascadeType; |
|---|
| 33 | import org.hibernate.envers.Audited; |
|---|
| 34 | import org.hibernate.search.annotations.Field; |
|---|
| 35 | import org.hibernate.search.annotations.Index; |
|---|
| 36 | import org.hibernate.search.annotations.Indexed; |
|---|
| 37 | import org.springframework.beans.factory.annotation.Configurable; |
|---|
| 38 | |
|---|
| 39 | import eu.etaxonomy.cdm.strategy.cache.agent.InstitutionDefaultCacheStrategy; |
|---|
| 40 | import eu.etaxonomy.cdm.strategy.cache.common.IIdentifiableEntityCacheStrategy; |
|---|
| 41 | import eu.etaxonomy.cdm.validation.annotation.NullOrNotEmpty; |
|---|
| 42 | |
|---|
| 43 | /** |
|---|
| 44 | * This class represents public or private institutions. |
|---|
| 45 | * It includes name, contact details and institution type. |
|---|
| 46 | * <P> |
|---|
| 47 | * This class corresponds to: <ul> |
|---|
| 48 | * <li> Institution according to the TDWG ontology |
|---|
| 49 | * <li> Institution according to the TCS |
|---|
| 50 | * <li> Organisation (Institution) according to the ABCD schema |
|---|
| 51 | * </ul> |
|---|
| 52 | * |
|---|
| 53 | * @author m.doering |
|---|
| 54 | * @version 1.0 |
|---|
| 55 | * @created 08-Nov-2007 13:06:29 |
|---|
| 56 | */ |
|---|
| 57 | @XmlAccessorType(XmlAccessType.FIELD) |
|---|
| 58 | @XmlType(name = "Institution", propOrder = { |
|---|
| 59 | "code", |
|---|
| 60 | "name", |
|---|
| 61 | "types", |
|---|
| 62 | "isPartOf" |
|---|
| 63 | }) |
|---|
| 64 | @XmlRootElement(name = "Institution") |
|---|
| 65 | @Entity |
|---|
| 66 | @Indexed(index = "eu.etaxonomy.cdm.model.agent.AgentBase") |
|---|
| 67 | @Audited |
|---|
| 68 | @Configurable |
|---|
| 69 | public class Institution extends AgentBase<IIdentifiableEntityCacheStrategy<Institution>> { |
|---|
| 70 | private static final long serialVersionUID = -951321271656955808L; |
|---|
| 71 | public static final Logger logger = Logger.getLogger(Institution.class); |
|---|
| 72 | |
|---|
| 73 | @XmlElement(name = "Code") |
|---|
| 74 | @Field(index=Index.TOKENIZED) |
|---|
| 75 | @NullOrNotEmpty |
|---|
| 76 | @Size(max = 255) |
|---|
| 77 | private String code; |
|---|
| 78 | |
|---|
| 79 | @XmlElement(name = "Name") |
|---|
| 80 | @Field(index=Index.TOKENIZED) |
|---|
| 81 | @NullOrNotEmpty |
|---|
| 82 | @Size(max = 255) |
|---|
| 83 | private String name; |
|---|
| 84 | |
|---|
| 85 | @XmlElementWrapper(name = "Types", nillable = true) |
|---|
| 86 | @XmlElement(name = "Type") |
|---|
| 87 | @XmlIDREF |
|---|
| 88 | @XmlSchemaType(name = "IDREF") |
|---|
| 89 | @ManyToMany(fetch = FetchType.LAZY) |
|---|
| 90 | private Set<InstitutionType> types; |
|---|
| 91 | |
|---|
| 92 | @XmlElement(name = "IsPartOf") |
|---|
| 93 | @XmlIDREF |
|---|
| 94 | @XmlSchemaType(name = "IDREF") |
|---|
| 95 | @ManyToOne(fetch = FetchType.LAZY) |
|---|
| 96 | @Cascade(CascadeType.SAVE_UPDATE) |
|---|
| 97 | private Institution isPartOf; |
|---|
| 98 | |
|---|
| 99 | /** |
|---|
| 100 | * Creates a new empty institution instance. |
|---|
| 101 | */ |
|---|
| 102 | public static Institution NewInstance(){ |
|---|
| 103 | return new Institution(); |
|---|
| 104 | } |
|---|
| 105 | |
|---|
| 106 | |
|---|
| 107 | /** |
|---|
| 108 | * Class constructor. |
|---|
| 109 | */ |
|---|
| 110 | public Institution() { |
|---|
| 111 | super(); |
|---|
| 112 | this.cacheStrategy = new InstitutionDefaultCacheStrategy(); |
|---|
| 113 | } |
|---|
| 114 | |
|---|
| 115 | /** |
|---|
| 116 | * Returns the set of institution {@link InstitutionType types} (categories) |
|---|
| 117 | * used to describe or circumscribe <i>this</i> institution's activities. |
|---|
| 118 | * Institution types are items of a controlled {@link eu.etaxonomy.cdm.model.common.TermVocabulary vocabulary}. |
|---|
| 119 | * |
|---|
| 120 | * @return the set of institution types |
|---|
| 121 | * @see InstitutionType |
|---|
| 122 | */ |
|---|
| 123 | public Set<InstitutionType> getTypes(){ |
|---|
| 124 | if(types == null) { |
|---|
| 125 | this.types = new HashSet<InstitutionType>(); |
|---|
| 126 | } |
|---|
| 127 | return this.types; |
|---|
| 128 | } |
|---|
| 129 | |
|---|
| 130 | /** |
|---|
| 131 | * Adds a new institutional type (from the corresponding {@link eu.etaxonomy.cdm.model.common.TermVocabulary vocabulary}) |
|---|
| 132 | * to the set of institution types of <i>this</i> institution. |
|---|
| 133 | * |
|---|
| 134 | * @param t any type of institution |
|---|
| 135 | * @see #getTypes() |
|---|
| 136 | * @see InstitutionType |
|---|
| 137 | */ |
|---|
| 138 | public void addType(InstitutionType t){ |
|---|
| 139 | getTypes().add(t); |
|---|
| 140 | } |
|---|
| 141 | |
|---|
| 142 | /** |
|---|
| 143 | * Removes one element from the set of institution types for <i>this</i> institution. |
|---|
| 144 | * |
|---|
| 145 | * @param t the institution type which should be deleted |
|---|
| 146 | * @see #getTypes() |
|---|
| 147 | */ |
|---|
| 148 | public void removeType(InstitutionType t){ |
|---|
| 149 | getTypes().remove(t); |
|---|
| 150 | } |
|---|
| 151 | |
|---|
| 152 | /** |
|---|
| 153 | * Returns the parent institution of this institution. |
|---|
| 154 | * This is for instance the case when this institution is a herbarium |
|---|
| 155 | * belonging to a parent institution such as a museum. |
|---|
| 156 | */ |
|---|
| 157 | public Institution getIsPartOf(){ |
|---|
| 158 | return this.isPartOf; |
|---|
| 159 | } |
|---|
| 160 | |
|---|
| 161 | /** |
|---|
| 162 | * Assigns a parent institution to which this institution belongs. |
|---|
| 163 | * |
|---|
| 164 | * @param isPartOf the parent institution |
|---|
| 165 | * @see #getIsPartOf() |
|---|
| 166 | */ |
|---|
| 167 | public void setIsPartOf(Institution parentInstitution){ |
|---|
| 168 | this.isPartOf = parentInstitution; |
|---|
| 169 | } |
|---|
| 170 | |
|---|
| 171 | /** |
|---|
| 172 | * Returns the string representing the code (can also be an acronym or initials) |
|---|
| 173 | * by which this institution is known among experts. |
|---|
| 174 | */ |
|---|
| 175 | public String getCode(){ |
|---|
| 176 | return this.code; |
|---|
| 177 | } |
|---|
| 178 | /** |
|---|
| 179 | * @see #getCode() |
|---|
| 180 | */ |
|---|
| 181 | public void setCode(String code){ |
|---|
| 182 | this.code = code; |
|---|
| 183 | } |
|---|
| 184 | |
|---|
| 185 | |
|---|
| 186 | /** |
|---|
| 187 | * Returns the full name, as distinct from a code, an acronym or initials, |
|---|
| 188 | * by which this institution is generally known. |
|---|
| 189 | */ |
|---|
| 190 | public String getName(){ |
|---|
| 191 | return this.name; |
|---|
| 192 | } |
|---|
| 193 | /** |
|---|
| 194 | * @see #getName() |
|---|
| 195 | */ |
|---|
| 196 | public void setName(String name){ |
|---|
| 197 | this.name = name; |
|---|
| 198 | } |
|---|
| 199 | |
|---|
| 200 | //*********************** CLONE ********************************************************/ |
|---|
| 201 | |
|---|
| 202 | /** |
|---|
| 203 | * Clones <i>this</i> Institution. This is a shortcut that enables to create |
|---|
| 204 | * a new instance that differs only slightly from <i>this</i> Institution. |
|---|
| 205 | * |
|---|
| 206 | * @see eu.etaxonomy.cdm.model.media.IdentifiableMediaEntity |
|---|
| 207 | * @see java.lang.Object#clone() |
|---|
| 208 | */ |
|---|
| 209 | @Override |
|---|
| 210 | public Object clone() { |
|---|
| 211 | try{ |
|---|
| 212 | Institution result = (Institution) super.clone(); |
|---|
| 213 | //no changes to code, isPartOf, name, types |
|---|
| 214 | return result; |
|---|
| 215 | }catch (CloneNotSupportedException e){ |
|---|
| 216 | logger.warn("Object does not implement cloneable"); |
|---|
| 217 | e.printStackTrace(); |
|---|
| 218 | return null; |
|---|
| 219 | } |
|---|
| 220 | } |
|---|
| 221 | } |
|---|