#4716 reduicing clutter in the lucene index and solving performance problems which...
[cdmlib.git] / cdmlib-model / src / main / java / eu / etaxonomy / cdm / model / media / RightsType.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.media;
11
12 import java.util.HashMap;
13 import java.util.Map;
14 import java.util.UUID;
15
16 import javax.persistence.Entity;
17 import javax.xml.bind.annotation.XmlAccessType;
18 import javax.xml.bind.annotation.XmlAccessorType;
19 import javax.xml.bind.annotation.XmlRootElement;
20 import javax.xml.bind.annotation.XmlType;
21
22 import org.apache.log4j.Logger;
23 import org.hibernate.envers.Audited;
24
25 import eu.etaxonomy.cdm.model.common.DefinedTermBase;
26 import eu.etaxonomy.cdm.model.common.TermType;
27 import eu.etaxonomy.cdm.model.common.TermVocabulary;
28
29 /**
30 * @author m.doering
31 * @created 08-Nov-2007 13:06:50
32 */
33 @XmlAccessorType(XmlAccessType.FIELD)
34 @XmlType(name = "RightsType")
35 @XmlRootElement(name = "RightsType")
36 @Entity
37 //@Indexed disabled to reduce clutter in indexes, since this type is not used by any search
38 //@Indexed(index = "eu.etaxonomy.cdm.model.common.DefinedTermBase")
39 @Audited
40 public class RightsType extends DefinedTermBase<RightsType> {
41 private static final long serialVersionUID = -5823263624000932116L;
42 private static final Logger logger = Logger.getLogger(RightsType.class);
43
44 protected static Map<UUID, RightsType> termMap = null;
45
46
47 /**
48 * Factory method
49 * @return
50 */
51 public static RightsType NewInstance(){
52 logger.debug("NewInstance");
53 return new RightsType();
54 }
55
56 /**
57 * Factory method
58 * @return
59 */
60 public static RightsType NewInstance(String text, String label, String labelAbbrev){
61 return new RightsType(text, label, labelAbbrev);
62 }
63
64 //***************** CONSTRUCTOR **************************************/
65
66 //for javassist only
67 @Deprecated
68 protected RightsType() {
69 super(TermType.RightsType);
70 }
71
72 /**
73 * Constructor
74 */
75 private RightsType(String term, String label, String labelAbbrev) {
76 super(TermType.RightsType, term, label, labelAbbrev);
77 }
78
79
80
81 // ************************************* MTEHODS ***************************************************/
82
83 /* (non-Javadoc)
84 * @see eu.etaxonomy.cdm.model.common.DefinedTermBase#resetTerms()
85 */
86 @Override
87 public void resetTerms(){
88 termMap = null;
89 }
90
91 protected static RightsType getTermByUuid(UUID uuid){
92 if (termMap == null || termMap.isEmpty()){
93 return getTermByClassAndUUID(RightsType.class, uuid);
94 } else {
95 return termMap.get(uuid);
96 }
97 }
98
99 /**
100 * http://purl.org/dc/terms/accessRights
101 */
102 public static final RightsType ACCESS_RIGHTS(){
103 return getTermByUuid(uuidAccessRights);
104 }
105
106 public static final RightsType COPYRIGHT(){
107 return getTermByUuid(uuidCopyright);
108 }
109
110 public static final RightsType LICENSE(){
111 return getTermByUuid(uuidLicense);
112 }
113
114 private static final UUID uuidLicense = UUID.fromString("67c0d47e-8985-1014-8845-c84599f9992c");
115 private static final UUID uuidCopyright = UUID.fromString("d1ef838e-b195-4f28-b8eb-0d3be080bd37");
116 private static final UUID uuidAccessRights = UUID.fromString("a50b4def-b3ac-4508-b50a-e0f249e3a1d7");
117
118
119 @Override
120 protected void setDefaultTerms(TermVocabulary<RightsType> termVocabulary) {
121 termMap = new HashMap<UUID, RightsType>();
122 for (RightsType term : termVocabulary.getTerms()){
123 termMap.put(term.getUuid(), term);
124 }
125 }
126
127 }