ref #5973: add new preference predicate for description handling in
authorKatja Luther <k.luther@bgbm.org>
Tue, 10 Oct 2023 13:08:49 +0000 (15:08 +0200)
committerKatja Luther <k.luther@bgbm.org>
Tue, 10 Oct 2023 13:10:42 +0000 (15:10 +0200)
distr editor

cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/metadata/DistributionDescription.java [new file with mode: 0644]
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/metadata/PreferencePredicate.java
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/dto/TaxonDescriptionDTO.java

diff --git a/cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/metadata/DistributionDescription.java b/cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/metadata/DistributionDescription.java
new file mode 100644 (file)
index 0000000..5fd118c
--- /dev/null
@@ -0,0 +1,57 @@
+// $Id$
+/**
+* Copyright (C) 2023 EDIT
+* European Distributed Institute of Taxonomy
+* http://www.e-taxonomy.eu
+*
+* The contents of this file are subject to the Mozilla Public License Version 1.1
+* See LICENSE.TXT at the top of this package for the full license terms.
+*/
+package eu.etaxonomy.cdm.model.metadata;
+
+/**
+ * @author katjaluther
+ * @date 10.10.2023
+ *
+ */
+public enum DistributionDescription implements IKeyLabel{
+    AlwaysDefault("AlwaysDefault", "Always use default description"),
+    OwnDescriptionForDistributions("OwnDescription", "Use own description for distributions"),
+    DescriptionsPerSource("DescriptionPerSource", "Every source has its own description");
+
+
+    private String label;
+    private String key;
+
+    private DistributionDescription(String key, String label) {
+        this.key = key;
+        this.label = label;
+    }
+
+    @Override
+    public String getLabel() {
+
+        return label;
+    }
+
+    @Override
+    public String getKey() {
+
+        return key;
+    }
+
+    @Override
+    public String toString() {
+        return key;
+    }
+
+    public static DistributionDescription byKey(String key){
+        for (DistributionDescription distributionDesc : values()){
+            if (distributionDesc.key.equals(key)){
+                return distributionDesc;
+            }
+        }
+        throw new IllegalArgumentException();
+    }
+
+}
index 9c88de9284389b3f21f9739a319e057b7a9761c9..f909a0466cc57b07dcd299e524d908eaaf482969 100644 (file)
@@ -100,7 +100,7 @@ public enum PreferencePredicate
     DisplayOfStatusInCombo(UUID.fromString("a8ff1763-987f-4935-aaba-910f3a870d07"), "Distribution Editor: Display of Status", "distribution.editor.status.combo_display", TermComboEnum.TermDisplayPlusTitle),
     DisplayOfAreasInDistributionEditor(UUID.fromString("7b671bba-1b7f-4cb9-bbac-c914518a4bf8"), "Distribution Editor: Display of Areas", "distribution.editor.areas.displayAreas",  TermDisplayEnum.Title),
     NumberOfVisibleStatusInDropDown(UUID.fromString("5e5ed585-2212-4d07-bbaf-c5e19a61dace"), "Distribution Editor: Number of visible status in drop down", "distribution.editor.status.numberVisibleStatus",  10),
-    OwnDescriptionForDistributionEditor(UUID.fromString("38282571-049c-473e-bec3-bde6f65f796a"), "Distribution Editor: Create distribution editor TaxonDescription", "distribution.editor.distributionOwnDescription",  Boolean.FALSE),
+    DescriptionForDistributionEditor(UUID.fromString("38282571-049c-473e-bec3-bde6f65f796a"), "Distribution Editor: Create distribution editor TaxonDescription", "distribution.editor.distributionOwnDescription",  DistributionDescription.AlwaysDefault),
     AvailableDistributionAreaTerms(UUID.fromString("34469acc-9e23-4f95-92d4-1695e02cb5a0"), "Available Distribution Area Terms", "distribution.area.terms", null),  //default: all/no filter
 
     //Character matrix
index d6cc021cacfd29ff2916c4b6e5ceb8621abe5693..d6f2f1e69e3b4533f28584e80afdc9e81faa7f23 100755 (executable)
@@ -29,18 +29,15 @@ public class TaxonDescriptionDTO implements Serializable{
     UUID taxonUUID;
     Set<TaxonDescription> descriptions = new HashSet();
 
-    public TaxonDescriptionDTO(Taxon taxon, boolean onlyUseDefault){
+    public TaxonDescriptionDTO(Taxon taxon, boolean alwaysUseDefault){
        this.taxonUUID = taxon.getUuid();
 
         for (TaxonDescription desc: taxon.getDescriptions()){
             if (desc.isDefault()) {
                 descriptions.add(desc);
-                if (onlyUseDefault) {
-                    break;
-                }
             }
         }
-        if (descriptions.isEmpty() || !onlyUseDefault) {
+        if (descriptions.isEmpty() || !alwaysUseDefault) {
             for (TaxonDescription desc: taxon.getDescriptions()){
                 if (desc.isComputed()) {
                     continue;