Project

General

Profile

Download (9.97 KB) Statistics
| Branch: | Tag: | Revision:
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
import java.io.Serializable;
13
import java.util.ArrayList;
14
import java.util.List;
15
import java.util.Set;
16
import java.util.UUID;
17

    
18
import javax.xml.bind.annotation.XmlEnum;
19
import javax.xml.bind.annotation.XmlEnumValue;
20

    
21
import org.apache.log4j.Logger;
22

    
23
import eu.etaxonomy.cdm.model.common.Language;
24
import eu.etaxonomy.cdm.model.term.EnumeratedTermVoc;
25
import eu.etaxonomy.cdm.model.term.IEnumTerm;
26

    
27

    
28
/**
29
 * The reference type is used to define the type of a {@link Reference reference}.<BR>
30
 * When changing the type of a reference one must be careful with handling attached information.
31
 * E.g. changing the type of a reference from article to book section requires to either exchange
32
 * the in reference or to change the type of the in reference which may have further consequences.
33
 *
34
 * @author a.mueller
35
 * @since 20.09.2009
36
 */
37

    
38
//TODO hierarchies, see https://dev.e-taxonomy.eu/redmine/issues/3619
39
@XmlEnum
40
public enum ReferenceType implements IEnumTerm<ReferenceType>, Serializable{
41

    
42

    
43
	/**
44
	 * A reference of type section is a part-of another reference. Section is a generalized type for all
45
	 * references which are expected to be part of another reference (e.g. an article which is part of a journal,
46
	 * a book section which is part of a book) or which may have an in-reference
47
	 * such as books which may be part of a print series or websites which may be part of other websites.
48
	 * <BR>
49
	 * However, section as concrete type should only be used if no more specific type is available.
50
	 * This is usually the case for parts of other sections such parts of articles, parts of book sections, or
51
	 * similar cases).
52
	 *
53
	 * @see ISectionBase
54
	 */
55
	@XmlEnumValue("Section")
56
	Section(UUID.fromString("98035142-ca82-46c5-bbef-ad225f668644"), "Section", "SEC", null),
57

    
58
	//0
59
	/**
60
	 * Article in a journal.
61
	 * Article is a specialization of {@link #Section}.
62
	 */
63
	@XmlEnumValue("Article")
64
	Article(UUID.fromString("fddfb343-f652-4f33-b6cb-7c94daa2f1ec"), "Article", "ART", Section),
65
	//1
66
	@XmlEnumValue("Book")
67
	Book(UUID.fromString("9280876c-accb-4c47-873d-46bbf4296f18"), "Book", "BK", Section),
68
	//2
69
	/**
70
	 * A part in a book, e.g. a chapter.
71
	 * BookSection is a specialization of {@link #Section}
72
	 */
73
	@XmlEnumValue("Book Section")
74
	BookSection(UUID.fromString("b197435d-deec-46fa-9c66-e0e6c44c57fb"), "Book Section", "BS", Section),
75
	//3
76
	@XmlEnumValue("CD or DVD")
77
	CdDvd(UUID.fromString("7d7c9f56-d6fd-45aa-852f-b965afe08ec0"), "CD or DVD", "CD", null),
78
	//4
79
	@XmlEnumValue("Database")
80
	Database(UUID.fromString("a36dbaec-0536-4a20-9fbc-e1b10ba35ea6"), "Database", "DB", null),
81
	//5
82
	@XmlEnumValue("Generic")
83
	Generic(UUID.fromString("df149dd8-f2b4-421c-b478-acc4cce63f25"), "Generic", "GEN", null),
84
	//6
85
	@XmlEnumValue("Inproceedings")
86
	InProceedings(UUID.fromString("a84dae35-6708-4c3d-8bb6-41b989947fa2"), "In Proceedings", "IPR", Section),
87
	//7
88
	@XmlEnumValue("Journal")
89
	Journal(UUID.fromString("d8675c58-41cd-44fb-86be-e966bd4bc747"), "Journal", "JOU", null),
90
	//8
91
	@XmlEnumValue("Map")
92
	Map(UUID.fromString("f4acc990-a277-4d80-9192-bc04be4b1cab"), "Map", "MAP", null),
93
	//9
94
	@XmlEnumValue("Patent")
95
	Patent(UUID.fromString("e44e0e6b-a721-417c-9b03-01926ea0bf56"), "Patent", "PAT", null),
96
	//10
97
	@XmlEnumValue("Personal Communication")
98
	PersonalCommunication(UUID.fromString("4ba5607e-1b9d-473c-89dd-8f1c2d27ae50"), "Personal Communication", "PEC", null),
99
	//11
100
	@XmlEnumValue("Print Series")
101
	PrintSeries(UUID.fromString("d455f30d-2685-4f57-804a-3df5ba4e0888"), "Print Series", "SER", null),
102
	//12
103
	@XmlEnumValue("Proceedings")
104
	Proceedings(UUID.fromString("cd934865-cb25-41f1-a155-f344ccb0c57f"), "Proceedings", "PRO", Section),
105
	//13
106
	@XmlEnumValue("Report")
107
	Report(UUID.fromString("4d5459b8-b65b-47cb-9579-2fe7be360d04"), "Report", "REP", null),
108
	//14
109
	@XmlEnumValue("Thesis")
110
	Thesis(UUID.fromString("cd054393-4f5e-4842-b820-b820e5732d72"), "Thesis", "THE", null),
111
	//15
112
	@XmlEnumValue("Web Page")
113
	WebPage(UUID.fromString("1ed8b0df-0532-40ea-aef6-ee4361341165"), "Web Page", "WEB", null),
114

    
115
	;
116

    
117
	@SuppressWarnings("unused")
118
	private static final Logger logger = Logger.getLogger(ReferenceType.class);
119

    
120

    
121
	private ReferenceType(UUID uuid, String defaultString, String key, ReferenceType parent){
122
		delegateVocTerm = EnumeratedTermVoc.addTerm(getClass(), this, uuid, defaultString, key, parent);
123
	}
124

    
125
	/**
126
	 * Returns true if references of this type have volume information.
127
	 */
128
	public boolean isVolumeReference(){
129
		return (this == Article || isPrintedUnit() || this == Generic);
130
	}
131

    
132
	/**
133
	 * Returns true if references of this type are publications (inheriting from
134
	 * {@link IPublicationBase}) and therefore have a publisher and a publication place.
135
	 */
136
	public boolean isPublication(){
137
		return (this == CdDvd || this == Database || this == Generic
138
				|| this == Journal || isPrintedUnit() ||  this == PrintSeries
139
				|| this == Report  || this == Thesis
140
				|| this == WebPage || this == Map);
141
	}
142

    
143
	/**
144
	 * Returns true if references of this type are printed units (inheriting from
145
	 * {@link IPrintedUnitBase}) and therefore may have an editor, an in-series or an string
146
	 * representing the series (seriesPart).
147
	 */
148
	public boolean isPrintedUnit(){
149
		return (this == Book || this == Proceedings);
150
	}
151

    
152

    
153

    
154
	/**
155
	 * Returns true if references of this type are parts of other references (inheriting from
156
	 * {@link ISection}) and therefore may have an in-reference and pages.
157
	 */
158
	public boolean isSection(){
159
//		return (this == BookSection || this == InProceedings
160
//				|| isPrintedUnit() || this == Article );
161
		return this == Section || isKindOf(Section);
162
	}
163

    
164
	/**
165
	 * Provides the set of type which are applicable as in-references for
166
	 * the <code>subReferenceType</code> passed to this method:
167
	 *
168
	 * The type specific rules are:
169
	 * <ul>
170
     *     <li>Article -> Journal</li>
171
     *     <li>Book -> PrintSeries | Journal<br>(Journal is needed here to cover historic
172
     *     situations: In Ehrenberg's times (Phycology) some articles (prior to publication in a journal)
173
     *     were printed and delivered to colleagues and libraries (published preprints). Therefore it necessary to allow these as (small)
174
     *     books being a part of a Journal.)</li>
175
     *     <li>BookSection -> Book</li>
176
     *     <li>InProceedings -> Proceedings</li>
177
     *     <li>Section -> Article | Book | Thesis | Patent | Report | Webpage | inProceedings</li>
178
     * </ul>
179
     * In case the passed <code>subReferenceType</code> matches none of the above rules the returned set will be empty.
180
     * <p>
181
     * NOTE: If these constraints are being used in UI contexts, it might be sensible in specific situations to add {@link #Generic} and <code>null</code>
182
     * to the list in case it was not empty.
183
     *
184
	 * @param subReferenceType
185
	 *     The type of the part for which the possible in-refrence types are to be returned.
186
	 * @return a set, may be empty, never <code>null</code>
187
	 */
188
	public static List<ReferenceType> inReferenceContraints(ReferenceType subReferenceType){
189
	    List<ReferenceType> inRefTypes = new ArrayList<>();
190

    
191
        if(subReferenceType != null && !subReferenceType.equals(ReferenceType.Generic)){
192
            if(subReferenceType.isArticle()){
193
                inRefTypes.add(ReferenceType.Journal);
194
            } else if (subReferenceType == ReferenceType.BookSection) {
195
                inRefTypes.add(ReferenceType.Book);
196
            } else if (subReferenceType.isBook()) {
197
                inRefTypes.add(ReferenceType.PrintSeries);
198
                inRefTypes.add(ReferenceType.Journal);
199
            } else if (subReferenceType == ReferenceType.InProceedings) {
200
                inRefTypes.add(ReferenceType.Proceedings);
201
            } else if (subReferenceType == ReferenceType.Section) {
202
                inRefTypes.add(ReferenceType.Article);
203
                inRefTypes.add(ReferenceType.BookSection);
204
                inRefTypes.add(ReferenceType.Book);
205
                inRefTypes.add(ReferenceType.Thesis);
206
                inRefTypes.add(ReferenceType.Patent);
207
                inRefTypes.add(ReferenceType.Report);
208
                inRefTypes.add(ReferenceType.WebPage);
209
                inRefTypes.add(ReferenceType.InProceedings);
210
            } else if (subReferenceType == ReferenceType.WebPage) {
211
                inRefTypes.add(ReferenceType.WebPage);
212
                inRefTypes.add(ReferenceType.Database);
213
            }
214
        }
215

    
216
        return inRefTypes;
217
    }
218

    
219
// *************************** DELEGATE **************************************/
220

    
221
	private static EnumeratedTermVoc<ReferenceType> delegateVoc;
222
	private IEnumTerm<ReferenceType> delegateVocTerm;
223

    
224
	static {
225
		delegateVoc = EnumeratedTermVoc.getVoc(ReferenceType.class);
226
	}
227

    
228
	@Override
229
	public String getKey(){return delegateVocTerm.getKey();}
230

    
231
	@Override
232
    public String getLabel(){return delegateVocTerm.getLabel();}
233

    
234
	@Override
235
    public String getLabel(Language language){return delegateVocTerm.getLabel(language);}
236

    
237
	@Override
238
    public UUID getUuid() {return delegateVocTerm.getUuid();}
239

    
240
	@Override
241
    public ReferenceType getKindOf() {return delegateVocTerm.getKindOf();}
242

    
243
	@Override
244
    public Set<ReferenceType> getGeneralizationOf() {return delegateVocTerm.getGeneralizationOf();}
245

    
246
	@Override
247
	public boolean isKindOf(ReferenceType ancestor) {return delegateVocTerm.isKindOf(ancestor);	}
248

    
249
	@Override
250
    public Set<ReferenceType> getGeneralizationOf(boolean recursive) {return delegateVocTerm.getGeneralizationOf(recursive);}
251

    
252
	public static ReferenceType getByKey(String key){return delegateVoc.getByKey(key);}
253
    public static ReferenceType getByUuid(UUID uuid) {return delegateVoc.getByUuid(uuid);}
254

    
255
    /**
256
     * @return
257
     */
258
    public boolean isArticle() {
259
        return this == Article;
260
    }
261
    public boolean isBook() {
262
        return this == Book;
263
    }
264
    public boolean isBookSection() {
265
        return this == BookSection;
266
    }
267
    //TBC
268

    
269

    
270
}
(36-36/38)