ref #9356: hotfix solution
authorKatja Luther <k.luther@bgbm.org>
Fri, 11 Dec 2020 08:48:23 +0000 (09:48 +0100)
committerKatja Luther <k.luther@bgbm.org>
Fri, 11 Dec 2020 08:48:23 +0000 (09:48 +0100)
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/description/SourceComparator.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/name/TypeDesignationSection.java

index 3b7f496f3b7fb75b4f0ddbf69e11cbb587c17e66..3e37e3acd665dac8e89c5c64d1bb0f1bc2eefa38 100644 (file)
@@ -26,6 +26,7 @@ public class SourceComparator  <T extends OriginalSourceBase> implements Compara
         if (o2 instanceof DescriptionElementSource){
             isDescriptionElementSource2 = true;
         }
+        int result = 0;
         if (isDescriptionElementSource1 != isDescriptionElementSource2){
             if (isDescriptionElementSource1){
                 return -1;
@@ -38,18 +39,18 @@ public class SourceComparator  <T extends OriginalSourceBase> implements Compara
         Reference citation1 = o1.getCitation();
         Reference citation2 = o2.getCitation();
 
-        int result = 0;
+
 
         // the newly created should always be on top
         if (id1 == 0){
             if(id2!=0) {
-                result = -1;
+                return -1;
             }
             else{
                 result = 0;
             }
         } else if(id2==0){
-            result = 1;
+            return 1;
         }
 
         // sort by type (Primary taxonomic > Primary Media > others
@@ -59,20 +60,20 @@ public class SourceComparator  <T extends OriginalSourceBase> implements Compara
                 result = 0;
             }
             else{
-                result = 1;
+                result = -1;
             }
         } else if (type2 == null){
-            result = -1;
+            result = 1;
         } else if(type1.equals(type2)){
             result = 0;
         } else if (type1.equals(OriginalSourceType.PrimaryTaxonomicSource)){
-            result = -1;
-        } else if (type2.equals(OriginalSourceType.PrimaryTaxonomicSource)){
             result = 1;
-        } else if (type1.equals(OriginalSourceType.PrimaryMediaSource)){
+        } else if (type2.equals(OriginalSourceType.PrimaryTaxonomicSource)){
             result = -1;
-        } else if (type2.equals(OriginalSourceType.PrimaryMediaSource)){
+        } else if (type1.equals(OriginalSourceType.PrimaryMediaSource)){
             result = 1;
+        } else if (type2.equals(OriginalSourceType.PrimaryMediaSource)){
+            result = -1;
         }
 
         //sort by citation title cache if types are equal
@@ -82,11 +83,19 @@ public class SourceComparator  <T extends OriginalSourceBase> implements Compara
             }
 
             if(o2.getCreated()!=null && o1.getCreated()!=null){
-                result = o2.getCreated().compareTo(o1.getCreated());
+                result = o1.getCreated().compareTo(o2.getCreated());
+            }else if (o1.getCreated() == null ){
+                if (o2.getCreated() == null){
+                    result = 0;
+                }else{
+                    return -1;
+                }
+            }else if (o2.getCreated() == null){
+                return 1;
             }
             if (result == 0){
                 //default fallback
-                return o1.getId() - o2.getId();
+                return o1.getUuid().compareTo(o2.getUuid());
             }
         }
         return result;
index 491f3f968a7539a6fdbbb69f9a3532446aaee486..cfe0d310acbb52b41daedf17f66b6763ab1e5b37 100644 (file)
@@ -25,7 +25,7 @@ import org.eclipse.swt.graphics.ImageData;
 import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
 import eu.etaxonomy.cdm.api.service.INameService;
 import eu.etaxonomy.cdm.api.service.UpdateResult;
-import eu.etaxonomy.cdm.api.service.name.TypeDesignationComparator;
+import eu.etaxonomy.cdm.api.service.name.TypeDesignationStatusComparator;
 import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
 import eu.etaxonomy.cdm.model.name.NameTypeDesignation;
 import eu.etaxonomy.cdm.model.name.Rank;
@@ -164,7 +164,39 @@ public class TypeDesignationSection extends AbstractEntityCollectionSection<Taxo
 
        @Override
        public Comparator<TypeDesignationBase> getComparator() {
-        return new TypeDesignationComparator();
+        return new Comparator<TypeDesignationBase>(){
+
+            //TODO: this is only a workaround to avoid a cdmlib hotfix this needs to be reverted for next release!!
+            private TypeDesignationStatusComparator statusComparator = new TypeDesignationStatusComparator();
+
+            @SuppressWarnings("unchecked")
+            @Override
+            public int compare(TypeDesignationBase o1, TypeDesignationBase o2) {
+
+                if (o1 == null && o2 == null){
+                    return 0;
+                }
+                if(o1==null){
+                    return 1;
+                }
+                if(o2==null){
+                    return -1;
+                }
+                int result = 0;
+                if(o1.getTypeStatus()==null ){
+                    if (o2.getTypeStatus() != null){
+                        return 1;
+                    }
+                }
+                if (o2.getTypeStatus() == null){
+                    return -1;
+                }
+                if(result == 0 && (o1.getTypeStatus() == null || o2.getTypeStatus() == null)){
+                    return o1.getUuid().compareTo(o2.getUuid());
+                }
+                return statusComparator.compare(o1.getTypeStatus(), o2.getTypeStatus()) ;
+            }
+        };
        }
 
        @Override