Project

General

Profile

Download (7.29 KB) Statistics
| Branch: | Tag: | Revision:
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.logging.log4j.LogManager;import org.apache.logging.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
public enum DescriptionType implements IEnumTerm<DescriptionType>{
28

    
29
    /**
30
     * The description has been computed by a machine, e.g. by aggregation or any
31
     * other algorithm. Usually such descriptions should not be edited by users manually.
32
     * {@link DescriptionType#COMPUTED} is a base type for more specific types such as
33
     * {@link DescriptionType#AGGREGATED}
34
     */
35
    @XmlEnumValue("COM")
36
    COMPUTED(UUID.fromString("7048c64e-9e61-41ed-b561-5765bc8e4ba2"), "Computed", "COM", null),
37

    
38
    /**
39
     * The description has been computed by a machine by aggregation of data.
40
     * Usually such descriptions should not be edited by users manually.
41
     */
42
    @XmlEnumValue("AGG")
43
    AGGREGATED(UUID.fromString("d1c02cbf-e27c-49ee-919a-7393d953ef36"), "Aggregated", "AGG", COMPUTED),
44

    
45
    /**
46
     * The description has been computed by a machine by aggregation of distribution data.
47
     * Usually such descriptions should not be edited by users manually.
48
     */
49
    @XmlEnumValue("AGD")
50
    AGGREGATED_DISTRIBUTION(UUID.fromString("7f4ceecc-aa97-4f97-8a79-ed390c44fe76"), "Aggregated Distribution", "AGD", AGGREGATED),
51

    
52
    /**
53
     * The description has been computed by a machine by aggregation of structured descriptive data.
54
     * Usually such descriptions should not be edited by users manually.
55
     */
56
    @XmlEnumValue("AGSD")
57
    AGGREGATED_STRUC_DESC(UUID.fromString("a613459c-82af-45ff-b950-cc769a7bb486"), "Aggregated Structured Descriptions", "AGSD", AGGREGATED),
58

    
59
    /**
60
     * Description is a clone which was used to fix a certain state of data to define
61
     * it as a source for e.g. computed data.
62
     * E.g. when computing a taxon description the underlying specimen descriptions might
63
     * be cloned and locked for editing to keep them as exact source for the computed
64
     * taxon description.
65
     */
66
    @XmlEnumValue("CLO")
67
    CLONE_FOR_SOURCE(UUID.fromString("2d58416f-506b-40c5-bdb6-60b6735c92d3"), "Clone", "CLO", null),
68

    
69
    /**
70
     * Kind of a marker to define that data comes from a secondary source. E.g. if
71
     * taxon descriptions are computed mostly on primary data (e.g. specimen descriptions)
72
     * some data might come from literature though to complete the description.
73
     * This literature data then should be marked as "secondary data"
74
     */
75
    @XmlEnumValue("SEC")
76
    SECONDARY_DATA(UUID.fromString("382e6b00-9725-4877-bd50-18ee263fe90e"), "Secondary Data", "SEC", null),
77

    
78
    /**
79
     * If Descriptions are aggregated for e.g. taxon descriptions, often explicit data for some parameters
80
     * are missing as all underlying data have the same value on this parameter.
81
     * A description can be defined to hold default values for these parameters.
82
     */
83
    @XmlEnumValue("DVA")
84
    DEFAULT_VALUES_FOR_AGGREGATION(UUID.fromString("e4a51ab3-7040-4f60-9d08-51782c2255a1"), "Default Values for Aggregation", "DVA", null),
85

    
86
    /**
87
     * Designated descriptions for {@link IndividualsAssociation}s of specimens to taxa.
88
     */
89
    @XmlEnumValue("IAS")
90
    INDIVIDUALS_ASSOCIATION(UUID.fromString("b8a1346d-9521-4ea2-ada8-c6774cf9175a"), "Specimens", "IAS", null),
91

    
92

    
93
    ;
94

    
95
    @SuppressWarnings("unused")
96
    private static final Logger logger = LogManager.getLogger(DescriptionType.class);
97

    
98

    
99
    private DescriptionType(UUID uuid, String defaultString, String key, DescriptionType parent){
100
        delegateVocTerm = EnumeratedTermVoc.addTerm(getClass(), this, uuid, defaultString, key, parent);
101
    }
102

    
103
// *************************** DELEGATE **************************************/
104

    
105
    private static EnumeratedTermVoc<DescriptionType> delegateVoc;
106
    private IEnumTerm<DescriptionType> delegateVocTerm;
107

    
108
    static {
109
        delegateVoc = EnumeratedTermVoc.getVoc(DescriptionType.class);
110
    }
111

    
112
    @Override
113
    public String getKey(){return delegateVocTerm.getKey();}
114

    
115
    @Override
116
    public String getLabel(){return delegateVocTerm.getLabel();}
117

    
118
    @Override
119
    public String getLabel(Language language){return delegateVocTerm.getLabel(language);}
120

    
121
    @Override
122
    public UUID getUuid() {return delegateVocTerm.getUuid();}
123

    
124
    @Override
125
    public DescriptionType getKindOf() {return delegateVocTerm.getKindOf();}
126

    
127
    @Override
128
    public Set<DescriptionType> getGeneralizationOf() {return delegateVocTerm.getGeneralizationOf();}
129

    
130
    @Override
131
    public boolean isKindOf(DescriptionType ancestor) {return delegateVocTerm.isKindOf(ancestor);   }
132

    
133
    @Override
134
    public Set<DescriptionType> getGeneralizationOf(boolean recursive) {return delegateVocTerm.getGeneralizationOf(recursive);}
135

    
136
    public static DescriptionType getByKey(String key){return delegateVoc.getByKey(key);}
137
    public static DescriptionType getByUuid(UUID uuid) {return delegateVoc.getByUuid(uuid);}
138

    
139

    
140
    /**
141
     * Returns true if the given set contains the type {@link #COMPUTED} computed or one of
142
     * it's sub-types.<BR><BR>
143
     * Note: Computed is a base type. It has children like {@link #AGGREGATED}.
144
     * Also for them this method returns <code>true</code>.
145
     */
146
    public static boolean isComputed(EnumSet<DescriptionType> set) {
147
        return includesType(set, COMPUTED);
148
    }
149

    
150
    public static boolean isAggregated(EnumSet<DescriptionType> set) {
151
        return includesType(set, AGGREGATED);
152
    }
153

    
154
    public static boolean isAggregatedDistribution(EnumSet<DescriptionType> set) {
155
        return includesType(set, AGGREGATED_DISTRIBUTION);
156
    }
157

    
158
    public static boolean isAggregatedStructuredDescription(EnumSet<DescriptionType> set) {
159
        return includesType(set, AGGREGATED_STRUC_DESC);
160
    }
161

    
162
    public static boolean isCloneForSource(EnumSet<DescriptionType> set) {
163
        return includesType(set, DescriptionType.CLONE_FOR_SOURCE);
164
    }
165

    
166
    public static boolean isSecondaryData(EnumSet<DescriptionType> set) {
167
        return includesType(set, DescriptionType.SECONDARY_DATA);
168
    }
169

    
170
    public static boolean isDefaultForAggregation(EnumSet<DescriptionType> set) {
171
        return includesType(set, DescriptionType.DEFAULT_VALUES_FOR_AGGREGATION);
172
    }
173

    
174
    public static boolean isSpecimenDescription(EnumSet<DescriptionType> set) {
175
        return includesType(set, DescriptionType.INDIVIDUALS_ASSOCIATION);
176
    }
177

    
178
    protected static boolean includesType(EnumSet<DescriptionType> set, DescriptionType state) {
179
        EnumSet<DescriptionType> all;
180
        if (state.getGeneralizationOf(true).isEmpty()){
181
            all = EnumSet.noneOf(DescriptionType.class);
182
        }else{
183
            all = EnumSet.copyOf(state.getGeneralizationOf(true));
184
        }
185
        all.add(state);
186
        for (DescriptionType st : all){
187
            if (set.contains(st)){
188
                return true;
189
            }
190
        }
191
        return false;
192
    }
193

    
194

    
195

    
196
}
(7-7/38)