Project

General

Profile

Download (3.47 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.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, true ),
23
    ALL_SAMEVALUE("ALSV", "All sources with highest status",
24
                                 true , true, true , true, false),
25
    DESCRIPTION("DESC","Link to underlying description",
26
                                 true , true, false, true, true ),
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, boolean supportsWithinTaxon,
38
            boolean supportsToParent, boolean supportsOriginalSourceType, boolean supportsDistribution, boolean supportsStructuredDescription) {
39
        this.key = key;
40
        this.label = message;
41
        this.supportsWithinTaxon = supportsWithinTaxon;
42
        this.supportsToParent = supportsToParent;
43
        this.supportsOriginalSourceType = supportsOriginalSourceType;
44
        Set<AggregationType> aggTypes = new HashSet<>();
45
        if (supportsDistribution){
46
            aggTypes.add(AggregationType.Distribution);
47
        }
48
        if (supportsStructuredDescription){
49
            aggTypes.add(AggregationType.StructuredDescription);
50
        }
51
        this.supportedAggregationTypes = EnumSet.copyOf(aggTypes);
52
    }
53

    
54
    @Override
55
    public String getKey() {
56
        return key;
57
    }
58

    
59
    @Override
60
    public String getLabel() {
61
        return label;
62
    }
63

    
64
    @Override
65
    public String getLabel(Language language) {
66
        //TODO i18n not yet implemented for AggregationMode
67
        return label;
68
    }
69

    
70
    public boolean isSupportsWithinTaxon() {
71
        return supportsWithinTaxon;
72
    }
73

    
74
    public boolean isSupportsToParent() {
75
        return supportsToParent;
76
    }
77

    
78
    public boolean isSupportsOriginalSourceType(){
79
        return supportsOriginalSourceType;
80
    }
81

    
82
    /**
83
     * Returns a list of {@link AggregationSourceMode}s available for the
84
     * given {@link AggregationMode} and {@link AggregationType}
85
     */
86
    public static List<AggregationSourceMode> list(AggregationMode aggregationMode, AggregationType type){
87
        List<AggregationSourceMode> result = new ArrayList<>();
88
        for(AggregationSourceMode mode : values()){
89
            if (type != null && !mode.supportedAggregationTypes.contains(type)){
90
                continue;
91
            }
92
            if (aggregationMode == AggregationMode.WithinTaxon && mode.supportsWithinTaxon){
93
                result.add(mode);
94
            }else if (aggregationMode == AggregationMode.ToParent && mode.supportsToParent){
95
                result.add(mode);
96
            }
97
        }
98
        return result;
99
    }
100
 }
(2-2/11)