StrictReferenceBase matchable
[cdmlib.git] / cdmlib-model / src / main / java / eu / etaxonomy / cdm / model / reference / Article.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.reference;
11
12
13 import javax.persistence.Entity;
14 import javax.persistence.FetchType;
15 import javax.persistence.ManyToOne;
16 import javax.persistence.Transient;
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.XmlElementRef;
21 import javax.xml.bind.annotation.XmlIDREF;
22 import javax.xml.bind.annotation.XmlRootElement;
23 import javax.xml.bind.annotation.XmlSchemaType;
24 import javax.xml.bind.annotation.XmlTransient;
25 import javax.xml.bind.annotation.XmlType;
26
27 import org.apache.log4j.Logger;
28 import org.hibernate.annotations.Cascade;
29 import org.hibernate.annotations.CascadeType;
30 import org.hibernate.envers.Audited;
31 import org.hibernate.search.annotations.Field;
32 import org.hibernate.search.annotations.Index;
33 import org.hibernate.search.annotations.Indexed;
34 import org.hibernate.search.annotations.IndexedEmbedded;
35 import org.springframework.beans.factory.annotation.Configurable;
36
37 import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase;
38 import eu.etaxonomy.cdm.model.common.TimePeriod;
39 import eu.etaxonomy.cdm.strategy.cache.reference.ArticleDefaultCacheStrategy;
40 import eu.etaxonomy.cdm.strategy.cache.reference.INomenclaturalReferenceCacheStrategy;
41
42
43 /**
44 * This class represents articles in a {@link Journal journal}. An article is an independent
45 * piece of prose written by an {@link TeamOrPersonBase author (team)} which is published among
46 * other articles within a particular issue of a journal.
47 * <P>
48 * This class corresponds, according to the TDWG ontology, to the publication type
49 * terms (from PublicationTypeTerm): <ul>
50 * <li> "JournalArticle"
51 * <li> "NewspaperArticle"
52 * <li> "MagazineArticle"
53 * </ul>
54 *
55 * @author m.doering
56 * @version 1.0
57 * @created 08-Nov-2007 13:06:10
58 */
59 @XmlAccessorType(XmlAccessType.FIELD)
60 @XmlType(name = "Article", propOrder = {
61 "volume",
62 "pages",
63 "series",
64 "inJournal"
65 })
66 @XmlRootElement(name = "Article")
67 @Entity
68 @Indexed(index = "eu.etaxonomy.cdm.model.reference.ReferenceBase")
69 @Audited
70 @Configurable
71 public class Article extends StrictReferenceBase<INomenclaturalReferenceCacheStrategy<Article>> implements INomenclaturalReference, IVolumeReference, Cloneable {
72 private static final long serialVersionUID = -1528079480114388117L;
73 private static final Logger logger = Logger.getLogger(Article.class);
74
75 @XmlElement(name = "Series")
76 @Field(index=Index.TOKENIZED)
77 private String series;
78
79 @XmlElement(name = "Volume")
80 @Field(index=Index.TOKENIZED)
81 private String volume;
82
83 @XmlElement(name = "Pages")
84 @Field(index=Index.TOKENIZED)
85 private String pages;
86
87 @XmlElement(name = "InJournal")
88 @XmlIDREF
89 @XmlSchemaType(name = "IDREF")
90 @ManyToOne(fetch = FetchType.LAZY)
91 @IndexedEmbedded
92 @Cascade(CascadeType.SAVE_UPDATE)
93 private Journal inJournal;
94
95
96 /**
97 * Class constructor: creates a new empty article instance
98 * only containing the {@link eu.etaxonomy.cdm.strategy.cache.reference.ArticleDefaultCacheStrategy default cache strategy}.
99 *
100 * @see eu.etaxonomy.cdm.strategy.cache.reference.ArticleDefaultCacheStrategy
101 */
102 protected Article(){
103 super();
104 this.cacheStrategy = ArticleDefaultCacheStrategy.NewInstance();
105 }
106
107 /**
108 * Creates a new empty article instance
109 * only containing the {@link eu.etaxonomy.cdm.strategy.cache.reference.ArticleDefaultCacheStrategy default cache strategy}.
110 *
111 * @see #Article()
112 * @see #NewInstance(Journal, TeamOrPersonBase, String, String, String, String, TimePeriod)
113 * @see eu.etaxonomy.cdm.strategy.cache.reference.ArticleDefaultCacheStrategy
114 */
115 public static Article NewInstance(){
116 Article result = new Article();
117 return result;
118 }
119
120 /**
121 * Creates a new article instance with the given values and with the
122 * {@link eu.etaxonomy.cdm.strategy.cache.reference.ArticleDefaultCacheStrategy default cache strategy}.
123 *
124 * @param inJournal the journal in which <i>this</i> article has
125 * been published
126 * @param authorTeam the team or person who wrote <i>this</i> article
127 * @param articleTitle the string representing the title of <i>this</i>
128 * article
129 * @param pages the string representing the pages in the journal
130 * issue where <i>this</i> article can be found
131 * @param series the string representing the series (within the
132 * journal) in which <i>this</i> article has been
133 * published
134 * @param volume the string representing the volume of the journal
135 * in which <i>this</i> article has been published
136 * @param datePublished the date (time period) in which <i>this</i>
137 * article has been published
138 * @see #NewInstance()
139 * @see Journal
140 * @see TeamOrPersonBase
141 * @see TimePeriod
142 * @see eu.etaxonomy.cdm.strategy.cache.reference.ArticleDefaultCacheStrategy
143 */
144 public static Article NewInstance(Journal inJournal, TeamOrPersonBase authorTeam, String articleTitle, String pages, String series, String volume, TimePeriod datePublished ){
145 Article result = new Article();
146 result.setInJournal(inJournal);
147 result.setTitle(articleTitle);
148 result.setPages(pages);
149 result.setAuthorTeam(authorTeam);
150 result.setSeries(series);
151 result.setDatePublished(datePublished);
152 result.setVolume(volume);
153 return result;
154 }
155
156
157
158 /**
159 * Returns the {@link Journal journal} in which <i>this</i> article has been published.
160 *
161 * @return the journal
162 * @see Journal
163 */
164 public Journal getInJournal(){
165 return this.inJournal;
166 }
167
168 /**
169 * @see #getInJournal()
170 */
171 public void setInJournal(Journal inJournal){
172 this.inJournal = inJournal;
173 }
174
175 /**
176 * Returns the string representing the series (within the journal) in which
177 * <i>this</i> article was published.
178 *
179 * @return the string identifying the series
180 */
181 public String getSeries(){
182 return this.series;
183 }
184
185 /**
186 * @see #getSeries()
187 */
188 public void setSeries(String series){
189 this.series = series;
190 }
191
192 /**
193 * Returns the string representing the volume of the journal in which
194 * <i>this</i> article was published.
195 *
196 * @return the string identifying the series
197 */
198 public String getVolume(){
199 return this.volume;
200 }
201
202 /**
203 * @see #getVolume()
204 */
205 public void setVolume(String volume){
206 this.volume = volume;
207 }
208
209 /**
210 * Returns the string representing the page(s) where the content of
211 * <i>this</i> article is located within the journal issue.
212 *
213 * @return the string with the pages corresponding to <i>this</i> article
214 */
215 public String getPages(){
216 return this.pages;
217 }
218
219 /**
220 * @see #getPages()
221 */
222 public void setPages(String pages){
223 this.pages = pages;
224 }
225
226
227 /**
228 * Returns a formatted string containing the entire reference citation,
229 * including authors, title, journal, pages, corresponding to <i>this</i>
230 * article.<BR>
231 * This method overrides the generic and inherited getCitation method
232 * from {@link StrictReferenceBase StrictReferenceBase}.
233 *
234 * @see #getNomenclaturalCitation(String)
235 * @see StrictReferenceBase#getCitation()
236 */
237 // @Override
238 // @Transient
239 // public String getCitation(){
240 // return nomRefBase.getCitation();
241 // }
242
243 /**
244 * Returns a formatted string containing the entire citation used for
245 * nomenclatural purposes based on <i>this</i> article - including
246 * (abbreviated) title of the journal but not authors of the article -
247 * and on the given details.
248 *
249 * @param microReference the string with the details (generally pages)
250 * within the journal
251 * @return the formatted string representing the
252 * nomenclatural citation
253 *
254 * @see #getCitation()
255 */
256 @Transient
257 public String getNomenclaturalCitation(String microReference) {
258 if (cacheStrategy == null){
259 logger.warn("No CacheStrategy defined for "+ this.getClass() + ": " + this.getUuid());
260 return null;
261 }else{
262 return cacheStrategy.getNomenclaturalCitation(this,microReference);
263 }
264 }
265
266
267 /**
268 * Generates, according to the {@link eu.etaxonomy.cdm.strategy.cache.reference.ArticleDefaultCacheStrategy default cache strategy}
269 * assigned to <i>this</i> article, a string that identifies <i>this</i>
270 * article and returns it. This string may be stored in the inherited
271 * {@link eu.etaxonomy.cdm.model.common.IdentifiableEntity#getTitleCache() titleCache} attribute.<BR>
272 * This method overrides the generic and inherited generateTitle method
273 * from {@link ReferenceBase ReferenceBase}.
274 *
275 * @return the string identifying <i>this</i> article
276 * @see #getCitation()
277 * @see eu.etaxonomy.cdm.model.common.IdentifiableEntity#getTitleCache()
278 * @see eu.etaxonomy.cdm.model.common.IdentifiableEntity#generateTitle()
279 */
280 // @Override
281 // public String generateTitle(){
282 // return nomRefBase.generateTitle();
283 // }
284
285 //*********** CLONE **********************************/
286
287
288 /**
289 * Clones <i>this</i> article. This is a shortcut that enables to
290 * create a new instance that differs only slightly from <i>this</i> article
291 * by modifying only some of the attributes.<BR>
292 * This method overrides the clone method from {@link StrictReferenceBase StrictReferenceBase}.
293 *
294 * @see StrictReferenceBase#clone()
295 * @see eu.etaxonomy.cdm.model.media.IdentifiableMediaEntity#clone()
296 * @see java.lang.Object#clone()
297 */
298 @Override
299 public Article clone(){
300 Article result = (Article)super.clone();
301 result.cacheStrategy = ArticleDefaultCacheStrategy.NewInstance();
302 //no changes to: inJournal, pages, series, volume
303 return result;
304 }
305
306
307 }