Project

General

Profile

Download (11.8 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.util.ArrayList;
13
import java.util.List;
14
import java.util.Set;
15
import java.util.UUID;
16

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

    
20
import org.apache.logging.log4j.LogManager;import org.apache.logging.log4j.Logger;
21

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

    
26

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

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

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

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

    
113
	;
114

    
115
	@SuppressWarnings("unused")
116
	private static final Logger logger = LogManager.getLogger(ReferenceType.class);
117

    
118

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

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

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

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

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

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

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

    
214
        return inRefTypes;
215
    }
216

    
217
// *************************** DELEGATE **************************************/
218

    
219
	private static EnumeratedTermVoc<ReferenceType> delegateVoc;
220
	private IEnumTerm<ReferenceType> delegateVocTerm;
221

    
222
	static {
223
		delegateVoc = EnumeratedTermVoc.getVoc(ReferenceType.class);
224
	}
225

    
226
	@Override
227
	public String getKey(){return delegateVocTerm.getKey();}
228

    
229
	@Override
230
    public String getLabel(){return delegateVocTerm.getLabel();}
231

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

    
235
	@Override
236
    public UUID getUuid() {return delegateVocTerm.getUuid();}
237

    
238
	@Override
239
    public ReferenceType getKindOf() {return delegateVocTerm.getKindOf();}
240

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

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

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

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

    
253
// *********************************** END DELEGATE *************************************/
254

    
255
    public boolean isArticle() {
256
        return this == Article;
257
    }
258
    public boolean isBook() {
259
        return this == Book;
260
    }
261
    public boolean isBookSection() {
262
        return this == BookSection;
263
    }
264
    public boolean isWebPage() {
265
        return this == WebPage;
266
    }
267
    public boolean isDatabase() {
268
        return this == Database;
269
    }
270
    public boolean isMap() {
271
        return this == Map;
272
    }
273
    public boolean isPatent() {
274
        return this == Patent;
275
    }
276
    public boolean isGeneric() {
277
        return this == Generic;
278
    }
279
    public boolean isCdDvd() {
280
        return this == CdDvd;
281
    }
282
    public boolean isProceedings() {
283
        return this == Proceedings;
284
    }
285
    public boolean isInProceedings() {
286
        return this == InProceedings;
287
    }
288
    public boolean isJournal() {
289
        return this == Journal;
290
    }
291
    public boolean isPersonalCommunication() {
292
        return this == PersonalCommunication;
293
    }
294
    public boolean isThesis() {
295
        return this == Thesis;
296
    }
297
    public boolean isPrintSeries() {
298
        return this == PrintSeries;
299
    }
300
    /**
301
     * @return <code>true</code> if this type is exactly {@link ReferenceType#Section}
302
     * @see ReferenceType#isSection()
303
     */
304
    public boolean isSectionOnly() {
305
        return this == Section;
306
    }
307

    
308
    /**
309
     * Returns <code>true</code> if the type of the reference originally corresponded to a cache strategy
310
     * which inherited from {@link NomRefDefaultCacheStrategyBase}.
311
     */
312
    public boolean isNomRef(){
313
        switch (this){
314
            case Article:
315
            case Book:
316
            case BookSection:
317
            case CdDvd:
318
            case Generic:
319
            case Section:
320
            case Thesis:
321
            case WebPage:
322
                return true;
323

    
324
            case Journal:
325
            default:
326
                return false;
327
        }
328
    }
329
}
(39-39/41)