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.api.service.description;
|
10
|
|
11
|
import java.util.ArrayList;
|
12
|
import java.util.EnumSet;
|
13
|
import java.util.HashSet;
|
14
|
import java.util.List;
|
15
|
import java.util.Set;
|
16
|
|
17
|
import eu.etaxonomy.cdm.model.common.Language;
|
18
|
import eu.etaxonomy.cdm.model.term.IKeyTerm;
|
19
|
|
20
|
public enum AggregationSourceMode implements IKeyTerm{
|
21
|
NONE("NO", "None", true , true, false, true, true ),
|
22
|
ALL("ALL", "All sources", true , true, true , true, false), //for now we do not support structured descriptions, may change in future
|
23
|
ALL_SAMEVALUE("ALSV", "All sources with highest status",
|
24
|
true , true, true , true, false), //does not make sense for struc. descriptions
|
25
|
DESCRIPTION("DESC","Link to underlying description",
|
26
|
true , true, false, true, true ), //probably not really supported for distributions yet, at least not for "within taxon"
|
27
|
TAXON("TAX","Link to child taxon",
|
28
|
false, true, false, true, true );
|
29
|
|
30
|
final private String key;
|
31
|
final private String label;
|
32
|
final private boolean supportsWithinTaxon;
|
33
|
final private boolean supportsToParent;
|
34
|
final private boolean supportsOriginalSourceType;
|
35
|
final private EnumSet<AggregationType> supportedAggregationTypes;
|
36
|
|
37
|
private AggregationSourceMode(String key, String message,
|
38
|
boolean supportsWithinTaxon, boolean supportsToParent,
|
39
|
boolean supportsOriginalSourceType,
|
40
|
boolean supportsDistribution, boolean supportsStructuredDescription) {
|
41
|
|
42
|
this.key = key;
|
43
|
this.label = message;
|
44
|
this.supportsWithinTaxon = supportsWithinTaxon;
|
45
|
this.supportsToParent = supportsToParent;
|
46
|
this.supportsOriginalSourceType = supportsOriginalSourceType;
|
47
|
Set<AggregationType> aggTypes = new HashSet<>();
|
48
|
if (supportsDistribution){
|
49
|
aggTypes.add(AggregationType.Distribution);
|
50
|
}
|
51
|
if (supportsStructuredDescription){
|
52
|
aggTypes.add(AggregationType.StructuredDescription);
|
53
|
}
|
54
|
this.supportedAggregationTypes = EnumSet.copyOf(aggTypes);
|
55
|
}
|
56
|
|
57
|
@Override
|
58
|
public String getKey() {
|
59
|
return key;
|
60
|
}
|
61
|
|
62
|
@Override
|
63
|
public String getLabel() {
|
64
|
return label;
|
65
|
}
|
66
|
|
67
|
@Override
|
68
|
public String getLabel(Language language) {
|
69
|
//TODO i18n not yet implemented for AggregationMode
|
70
|
return label;
|
71
|
}
|
72
|
|
73
|
public boolean isSupportsWithinTaxon() {
|
74
|
return supportsWithinTaxon;
|
75
|
}
|
76
|
|
77
|
public boolean isSupportsToParent() {
|
78
|
return supportsToParent;
|
79
|
}
|
80
|
|
81
|
public boolean isSupportsOriginalSourceType(){
|
82
|
return supportsOriginalSourceType;
|
83
|
}
|
84
|
|
85
|
public boolean isNone(){
|
86
|
return this == NONE;
|
87
|
}
|
88
|
|
89
|
public boolean isTaxon(){
|
90
|
return this == TAXON;
|
91
|
}
|
92
|
|
93
|
/**
|
94
|
* Returns a list of {@link AggregationSourceMode}s available for the
|
95
|
* given {@link AggregationMode} and {@link AggregationType}
|
96
|
*/
|
97
|
public static List<AggregationSourceMode> list(AggregationMode aggregationMode, AggregationType type){
|
98
|
List<AggregationSourceMode> result = new ArrayList<>();
|
99
|
for(AggregationSourceMode mode : values()){
|
100
|
if (type != null && !mode.supportedAggregationTypes.contains(type)){
|
101
|
continue;
|
102
|
}
|
103
|
if (aggregationMode == AggregationMode.WithinTaxon && mode.supportsWithinTaxon){
|
104
|
result.add(mode);
|
105
|
}else if (aggregationMode == AggregationMode.ToParent && mode.supportsToParent){
|
106
|
result.add(mode);
|
107
|
}
|
108
|
}
|
109
|
return result;
|
110
|
}
|
111
|
}
|