Project

General

Profile

Revision 34062138

ID340621386d51da62e6c2dd5e834e67f0762114fd
Parent f922cb22
Child 887eb4d0

Added by Andreas Müller about 1 year ago

ref #7959 rename DescriptionState -> DescriptionType and fix bug for enum loading

View differences:

cdmlib-model/src/main/java/eu/etaxonomy/cdm/hibernate/EnumUserType.java
25 25
import org.jadira.usertype.dateandtime.shared.spi.AbstractUserType;
26 26

  
27 27
import eu.etaxonomy.cdm.model.common.AuthorityType;
28
import eu.etaxonomy.cdm.model.description.DescriptionType;
28 29
import eu.etaxonomy.cdm.model.media.ExternalLinkType;
29 30
import eu.etaxonomy.cdm.model.metadata.CdmMetaDataPropertyName;
30 31
import eu.etaxonomy.cdm.model.molecular.SequenceDirection;
......
141 142
            return PermissionClass.getByKey(val);
142 143
        }else if (clazz.equals(CRUD.class)){
143 144
            return CRUD.getByKey(val);
145
        }else if (clazz.equals(DescriptionType.class)){
146
            return DescriptionType.getByKey(val);
144 147
        }else{
145 148
        	throw new IllegalArgumentException(String.format("EnumType %s not supported by %s.", clazz.getSimpleName(), EnumUserType.class.getSimpleName()));
146 149
        }
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/description/DescriptionBase.java
145 145
    @XmlAttribute(name ="Operations")
146 146
    @NotNull
147 147
    @Type(type = "eu.etaxonomy.cdm.hibernate.EnumSetUserType",
148
        parameters = {@org.hibernate.annotations.Parameter(name  = "enumClass", value = "eu.etaxonomy.cdm.model.description.DescriptionState")}
148
        parameters = {@org.hibernate.annotations.Parameter(name  = "enumClass", value = "eu.etaxonomy.cdm.model.description.DescriptionType")}
149 149
    )
150
    private EnumSet<DescriptionState> types = EnumSet.noneOf(DescriptionState.class);
150
    private EnumSet<DescriptionType> types = EnumSet.noneOf(DescriptionType.class);
151 151

  
152 152
//******************************** GETTER / SETTER ***************************/
153 153

  
......
264 264
        this.isDefault = isDefault;
265 265
    }
266 266

  
267
    public EnumSet<DescriptionState> getTypes() {
267
    public EnumSet<DescriptionType> getTypes() {
268 268
        return types;
269 269
    }
270
    public void setTypes(EnumSet<DescriptionState> types) {
270
    public void setTypes(EnumSet<DescriptionType> types) {
271 271
        this.types = types;
272 272
    }
273 273

  
......
347 347
    }
348 348

  
349 349
    /**
350
     * if this is of type {@link DescriptionState#COMPUTED} computed.<BR><BR>
351
     * Note: Computed is a base type. It has children like {@link DescriptionState#AGGREGATED}.
350
     * if this is of type {@link DescriptionType#COMPUTED} computed.<BR><BR>
351
     * Note: Computed is a base type. It has children like {@link DescriptionType#AGGREGATED}.
352 352
     * Also for them this method returns <code>true</code>.
353 353
     */
354 354
    public boolean isComputed() {
355
        return DescriptionState.isComputed(types);
355
        return DescriptionType.isComputed(types);
356 356
    }
357 357
    public boolean isAggregated() {
358
        return DescriptionState.includesType(types, DescriptionState.AGGREGATED);
358
        return DescriptionType.includesType(types, DescriptionType.AGGREGATED);
359 359
    }
360 360
    public boolean isCloneForSource() {
361
        return DescriptionState.includesType(types, DescriptionState.CLONE_FOR_SOURCE);
361
        return DescriptionType.includesType(types, DescriptionType.CLONE_FOR_SOURCE);
362 362
    }
363
    public static boolean isDefaultForAggregation(EnumSet<DescriptionState> set) {
364
        return DescriptionState.includesType(set, DescriptionState.DEFAULT_VALUES_FOR_AGGREGATION);
363
    public static boolean isDefaultForAggregation(EnumSet<DescriptionType> set) {
364
        return DescriptionType.includesType(set, DescriptionType.DEFAULT_VALUES_FOR_AGGREGATION);
365 365
    }
366
    public static boolean isSecondaryData(EnumSet<DescriptionState> set) {
367
        return DescriptionState.includesType(set, DescriptionState.SECONDARY_DATA);
366
    public static boolean isSecondaryData(EnumSet<DescriptionType> set) {
367
        return DescriptionType.includesType(set, DescriptionType.SECONDARY_DATA);
368 368
    }
369 369

  
370 370

  
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/description/DescriptionState.java
1
/**
2
* Copyright (C) 2019 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
package eu.etaxonomy.cdm.model.description;
10

  
11
import java.util.EnumSet;
12
import java.util.Set;
13
import java.util.UUID;
14

  
15
import javax.xml.bind.annotation.XmlEnumValue;
16

  
17
import org.apache.log4j.Logger;
18

  
19
import eu.etaxonomy.cdm.model.common.Language;
20
import eu.etaxonomy.cdm.model.term.EnumeratedTermVoc;
21
import eu.etaxonomy.cdm.model.term.IEnumTerm;
22

  
23
/**
24
 * @author a.mueller
25
 * @since 14.08.2019
26
 *
27
 */
28
public enum DescriptionState implements IEnumTerm<DescriptionState>{
29

  
30
    @XmlEnumValue("COM")
31
    COMPUTED(UUID.fromString("7048c64e-9e61-41ed-b561-5765bc8e4ba2"), "Computed", "COM", null),
32

  
33
    @XmlEnumValue("AGG")
34
    AGGREGATED(UUID.fromString("d1c02cbf-e27c-49ee-919a-7393d953ef36"), "Aggregated", "AGG", COMPUTED),
35

  
36
    @XmlEnumValue("CLO")
37
    CLONE_FOR_SOURCE(UUID.fromString("2d58416f-506b-40c5-bdb6-60b6735c92d3"), "Clone", "CLO", null),
38

  
39
    @XmlEnumValue("SEC")
40
    SECONDARY_DATA(UUID.fromString("382e6b00-9725-4877-bd50-18ee263fe90e"), "Secondary Data", "SEC", null),
41

  
42
    /**
43
     * If Descriptions are aggregated, these values can be taken as default if explicit values do not exist.
44
     */
45
    @XmlEnumValue("DVA")
46
    DEFAULT_VALUES_FOR_AGGREGATION(UUID.fromString("e4a51ab3-7040-4f60-9d08-51782c2255a1"), "Default Values for Aggregation", "DVA", null),
47

  
48
    ;
49

  
50
    @SuppressWarnings("unused")
51
    private static final Logger logger = Logger.getLogger(DescriptionState.class);
52

  
53

  
54
    private DescriptionState(UUID uuid, String defaultString, String key, DescriptionState parent){
55
        delegateVocTerm = EnumeratedTermVoc.addTerm(getClass(), this, uuid, defaultString, key, parent);
56
    }
57

  
58
// *************************** DELEGATE **************************************/
59

  
60
    private static EnumeratedTermVoc<DescriptionState> delegateVoc;
61
    private IEnumTerm<DescriptionState> delegateVocTerm;
62

  
63
    static {
64
        delegateVoc = EnumeratedTermVoc.getVoc(DescriptionState.class);
65
    }
66

  
67
    @Override
68
    public String getKey(){return delegateVocTerm.getKey();}
69

  
70
    @Override
71
    public String getMessage(){return delegateVocTerm.getMessage();}
72

  
73
    @Override
74
    public String getMessage(Language language){return delegateVocTerm.getMessage(language);}
75

  
76
    @Override
77
    public UUID getUuid() {return delegateVocTerm.getUuid();}
78

  
79
    @Override
80
    public DescriptionState getKindOf() {return delegateVocTerm.getKindOf();}
81

  
82
    @Override
83
    public Set<DescriptionState> getGeneralizationOf() {return delegateVocTerm.getGeneralizationOf();}
84

  
85
    @Override
86
    public boolean isKindOf(DescriptionState ancestor) {return delegateVocTerm.isKindOf(ancestor);   }
87

  
88
    @Override
89
    public Set<DescriptionState> getGeneralizationOf(boolean recursive) {return delegateVocTerm.getGeneralizationOf(recursive);}
90

  
91
    public static DescriptionState getByKey(String key){return delegateVoc.getByKey(key);}
92
    public static DescriptionState getByUuid(UUID uuid) {return delegateVoc.getByUuid(uuid);}
93

  
94

  
95
    /**
96
     * Returns true if the given set contains the type {@link #COMPUTED} computed or one of
97
     * it's sub-types.<BR><BR>
98
     * Note: Computed is a base type. It has children like {@link #AGGREGATED}.
99
     * Also for them this method returns <code>true</code>.
100
     */
101
    public static boolean isComputed(EnumSet<DescriptionState> set) {
102
        return includesType(set, COMPUTED);
103
    }
104

  
105
    public static boolean isAggregated(EnumSet<DescriptionState> set) {
106
        return includesType(set, AGGREGATED);
107
    }
108

  
109
    public static boolean isCloneForSource(EnumSet<DescriptionState> set) {
110
        return includesType(set, DescriptionState.CLONE_FOR_SOURCE);
111
    }
112

  
113
    public static boolean isSecondaryData(EnumSet<DescriptionState> set) {
114
        return includesType(set, DescriptionState.SECONDARY_DATA);
115
    }
116

  
117
    public static boolean isDefaultForAggregation(EnumSet<DescriptionState> set) {
118
        return includesType(set, DescriptionState.DEFAULT_VALUES_FOR_AGGREGATION);
119
    }
120

  
121
    /**
122
     * @param set
123
     * @return
124
     */
125
    protected static boolean includesType(EnumSet<DescriptionState> set, DescriptionState state) {
126
        EnumSet<DescriptionState> all = EnumSet.copyOf(state.getGeneralizationOf(true));
127
        all.add(state);
128
        for (DescriptionState st : all){
129
            if (set.contains(st)){
130
                return true;
131
            }
132
        }
133
        return false;
134
    }
135

  
136

  
137

  
138
}
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/description/DescriptionType.java
1
/**
2
* Copyright (C) 2019 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
package eu.etaxonomy.cdm.model.description;
10

  
11
import java.util.EnumSet;
12
import java.util.Set;
13
import java.util.UUID;
14

  
15
import javax.xml.bind.annotation.XmlEnumValue;
16

  
17
import org.apache.log4j.Logger;
18

  
19
import eu.etaxonomy.cdm.model.common.Language;
20
import eu.etaxonomy.cdm.model.term.EnumeratedTermVoc;
21
import eu.etaxonomy.cdm.model.term.IEnumTerm;
22

  
23
/**
24
 * @author a.mueller
25
 * @since 14.08.2019
26
 *
27
 */
28
public enum DescriptionType implements IEnumTerm<DescriptionType>{
29

  
30
    @XmlEnumValue("COM")
31
    COMPUTED(UUID.fromString("7048c64e-9e61-41ed-b561-5765bc8e4ba2"), "Computed", "COM", null),
32

  
33
    @XmlEnumValue("AGG")
34
    AGGREGATED(UUID.fromString("d1c02cbf-e27c-49ee-919a-7393d953ef36"), "Aggregated", "AGG", COMPUTED),
35

  
36
    @XmlEnumValue("CLO")
37
    CLONE_FOR_SOURCE(UUID.fromString("2d58416f-506b-40c5-bdb6-60b6735c92d3"), "Clone", "CLO", null),
38

  
39
    @XmlEnumValue("SEC")
40
    SECONDARY_DATA(UUID.fromString("382e6b00-9725-4877-bd50-18ee263fe90e"), "Secondary Data", "SEC", null),
41

  
42
    /**
43
     * If Descriptions are aggregated, these values can be taken as default if explicit values do not exist.
44
     */
45
    @XmlEnumValue("DVA")
46
    DEFAULT_VALUES_FOR_AGGREGATION(UUID.fromString("e4a51ab3-7040-4f60-9d08-51782c2255a1"), "Default Values for Aggregation", "DVA", null),
47

  
48
    ;
49

  
50
    @SuppressWarnings("unused")
51
    private static final Logger logger = Logger.getLogger(DescriptionType.class);
52

  
53

  
54
    private DescriptionType(UUID uuid, String defaultString, String key, DescriptionType parent){
55
        delegateVocTerm = EnumeratedTermVoc.addTerm(getClass(), this, uuid, defaultString, key, parent);
56
    }
57

  
58
// *************************** DELEGATE **************************************/
59

  
60
    private static EnumeratedTermVoc<DescriptionType> delegateVoc;
61
    private IEnumTerm<DescriptionType> delegateVocTerm;
62

  
63
    static {
64
        delegateVoc = EnumeratedTermVoc.getVoc(DescriptionType.class);
65
    }
66

  
67
    @Override
68
    public String getKey(){return delegateVocTerm.getKey();}
69

  
70
    @Override
71
    public String getMessage(){return delegateVocTerm.getMessage();}
72

  
73
    @Override
74
    public String getMessage(Language language){return delegateVocTerm.getMessage(language);}
75

  
76
    @Override
77
    public UUID getUuid() {return delegateVocTerm.getUuid();}
78

  
79
    @Override
80
    public DescriptionType getKindOf() {return delegateVocTerm.getKindOf();}
81

  
82
    @Override
83
    public Set<DescriptionType> getGeneralizationOf() {return delegateVocTerm.getGeneralizationOf();}
84

  
85
    @Override
86
    public boolean isKindOf(DescriptionType ancestor) {return delegateVocTerm.isKindOf(ancestor);   }
87

  
88
    @Override
89
    public Set<DescriptionType> getGeneralizationOf(boolean recursive) {return delegateVocTerm.getGeneralizationOf(recursive);}
90

  
91
    public static DescriptionType getByKey(String key){return delegateVoc.getByKey(key);}
92
    public static DescriptionType getByUuid(UUID uuid) {return delegateVoc.getByUuid(uuid);}
93

  
94

  
95
    /**
96
     * Returns true if the given set contains the type {@link #COMPUTED} computed or one of
97
     * it's sub-types.<BR><BR>
98
     * Note: Computed is a base type. It has children like {@link #AGGREGATED}.
99
     * Also for them this method returns <code>true</code>.
100
     */
101
    public static boolean isComputed(EnumSet<DescriptionType> set) {
102
        return includesType(set, COMPUTED);
103
    }
104

  
105
    public static boolean isAggregated(EnumSet<DescriptionType> set) {
106
        return includesType(set, AGGREGATED);
107
    }
108

  
109
    public static boolean isCloneForSource(EnumSet<DescriptionType> set) {
110
        return includesType(set, DescriptionType.CLONE_FOR_SOURCE);
111
    }
112

  
113
    public static boolean isSecondaryData(EnumSet<DescriptionType> set) {
114
        return includesType(set, DescriptionType.SECONDARY_DATA);
115
    }
116

  
117
    public static boolean isDefaultForAggregation(EnumSet<DescriptionType> set) {
118
        return includesType(set, DescriptionType.DEFAULT_VALUES_FOR_AGGREGATION);
119
    }
120

  
121
    /**
122
     * @param set
123
     * @return
124
     */
125
    protected static boolean includesType(EnumSet<DescriptionType> set, DescriptionType state) {
126
        EnumSet<DescriptionType> all = EnumSet.copyOf(state.getGeneralizationOf(true));
127
        all.add(state);
128
        for (DescriptionType st : all){
129
            if (set.contains(st)){
130
                return true;
131
            }
132
        }
133
        return false;
134
    }
135

  
136

  
137

  
138
}

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)