2 * Copyright (C) 2009 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
9 package eu
.etaxonomy
.cdm
.model
.permission
;
12 import java
.util
.UUID
;
14 import org
.apache
.logging
.log4j
.LogManager
;
15 import org
.apache
.logging
.log4j
.Logger
;
17 import eu
.etaxonomy
.cdm
.model
.CdmBaseType
;
18 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
19 import eu
.etaxonomy
.cdm
.model
.common
.Language
;
20 import eu
.etaxonomy
.cdm
.model
.term
.EnumeratedTermVoc
;
21 import eu
.etaxonomy
.cdm
.model
.term
.IEnumTerm
;
24 * see also {@link CdmBaseType}
27 * @author a.kohlbecker
31 public enum PermissionClass
implements IEnumTerm
<PermissionClass
>{
34 ANNOTATION("Annotation"),
35 ANNOTATIONTYPE("AnnotationType"),
36 CDMMETADATA("CdmMetaData"),
37 CLASSIFICATION("Classification"),
38 COLLECTION("Collectioni"),
39 DEFINEDTERM("DefinedTerm"),
40 DERIVATIONEVENT("DerivationEvent"),
41 DESCRIPTIONBASE("Description"),
42 DESCRIPTIONELEMENTBASE("DescriptionElement"),
43 DESCRIPTIONELEMENTSOURCE("DescriptionElementSource"),
44 DESCRIPTIVEDATASET("DescriptiveDataSet"),
45 EXTENSION("Extension"),
46 EXTENSIONTYPE("ExtensionType"),
50 GATHERINGEVENT("GatheringEvent"),
51 GRANTEDAUTHORITYIMPL("GrantedAuthorityImpl"),
53 HOMOTYPICALGROUP("HomotypicalGroup"),
54 HYBRIDRELATIONSHIP("HybridRelationship"),
55 IDENTIFIABLESOURCE("IdentifiableSource"),
56 IDENTIFIER("Identifier"),
57 KEYSTATEMENT("KeyStatement"),
59 LANGUAGESTRING("LanguageString"),
61 MARKERTYPE("MarkerType"),
63 MEDIAREPRESENTATION("MediaRepresentation"),
64 MEDIAREPRESENTATIONPART("MediaRepresentationPart"),
65 NAMEDAREA("NamedArea"),
66 NAMEDAREALEVEL("NamedAreaLevel"),
67 NAMEDSOURCE("NamedSource"),
68 NAMERELATIONSHIP("NameRelationship"),
69 NAMETYPEDESIGNATION("NameTypeDesignation"),
70 NOMENCLATURALSTATUS("NomenclaturalStatus"),
71 NOMENCLATURALSOURCE("NomenclaturalSource"),
72 NOMENCLATURALSTATUSTYPE("NomenclaturalStatusType"),
73 PRESENCEABSENCETERM("PresenceAbsenceTerm"),
74 POLYTOMOUSKEY("PolytomousKey"),
75 POLYTOMOUSKEYNODE("PolytomousKeyNode"),
77 REFERENCE("Reference"),
78 REGISTRATION("Registration"),
79 REPRESENTATION("Representation"),
80 SECUNDUMSOURCE("SecundumSource"),
82 SPECIMENOROBSERVATIONBASE("SpecimenOrObservation"),
83 SPECIMENTYPEDESIGNATION("SpecimenTypeDesignation"),
84 STATEDATA("StateData"),
85 STATISTICALMEASUREMENTVALUE("StatisticalMeasurementValue"),
86 TAXONBASE("TaxonBase"),
87 TAXONNAME("TaxonName"),
88 TAXONNODE("TaxonNode"),
89 TAXONRELATIONSHIP("TaxonRelationship"),
90 TEAMORPERSONBASE("TeamOrPerson"),
91 TERMVOCABULARY("TermVocabulary"),
92 TEXTUALTYPEDESIGNATION("TextualTypeDesignation"),
96 private static final Logger logger
= LogManager
.getLogger();
98 private PermissionClass(String key
){
99 //we have no UUIDs defined yet, but needed for tests
100 this(UUID
.randomUUID(), key
, key
, null);
103 private PermissionClass(UUID uuid
, String defaultString
, String key
){
104 this(uuid
, defaultString
, key
, null);
107 private PermissionClass(UUID uuid
, String defaultString
, String key
, PermissionClass parent
){
108 delegateVocTerm
= EnumeratedTermVoc
.addTerm(getClass(), this, uuid
, defaultString
, key
, parent
);
111 // *************************** DELEGATE **************************************/
113 private static EnumeratedTermVoc
<PermissionClass
> delegateVoc
;
114 private IEnumTerm
<PermissionClass
> delegateVocTerm
;
117 delegateVoc
= EnumeratedTermVoc
.getVoc(PermissionClass
.class);
121 public String
getKey(){return delegateVocTerm
.getKey();}
124 public String
getLabel(){return delegateVocTerm
.getLabel();}
127 public String
getLabel(Language language
){return delegateVocTerm
.getLabel(language
);}
130 public UUID
getUuid() {return delegateVocTerm
.getUuid();}
133 public PermissionClass
getKindOf() {return delegateVocTerm
.getKindOf();}
136 public Set
<PermissionClass
> getGeneralizationOf() {return delegateVocTerm
.getGeneralizationOf();}
139 public boolean isKindOf(PermissionClass ancestor
) {return delegateVocTerm
.isKindOf(ancestor
); }
142 public Set
<PermissionClass
> getGeneralizationOf(boolean recursive
) {return delegateVocTerm
.getGeneralizationOf(recursive
);}
144 public static PermissionClass
getByKey(String key
){return delegateVoc
.getByKey(key
);}
145 public static PermissionClass
getByUuid(UUID uuid
) {return delegateVoc
.getByUuid(uuid
);}
147 // ************************ METHODS *******************************/
150 * return the appropriate CdmPermissionClass for the given Object
153 * @return the CdmPermissionClass or null
155 public static PermissionClass
getValueOf(CdmBase cdmBase
){
156 return PermissionClass
.getValueOf(cdmBase
.getClass());
160 * Return the appropriate CdmPermissionClass for the given Object
163 * @return the CdmPermissionClass or null
165 public static PermissionClass
getValueOf(Class clazz
){
167 PermissionClass permissionClass
= doValueOf(clazz
);
168 if(permissionClass
== null) {
169 logger
.error("Permission class support for " + clazz
+ " not implemented");
171 return permissionClass
;
174 private static PermissionClass
doValueOf(Class
<?
> clazz
) {
176 String normalizedName
= clazz
.getSimpleName().toUpperCase();
177 return PermissionClass
.valueOf(normalizedName
);
178 } catch(IllegalArgumentException e
){
179 if (CdmBase
.class.isAssignableFrom(clazz
)){
180 return doValueOf(clazz
.getSuperclass());