Merge branch 'release/5.19.0'
authorjenkins <jenkins-int@bgbm.org>
Thu, 28 Jan 2021 12:56:07 +0000 (13:56 +0100)
committerjenkins <jenkins-int@bgbm.org>
Thu, 28 Jan 2021 12:56:07 +0000 (13:56 +0100)
1  2 
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/newWizard/NewTaxonNodeWizard.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/description/SourceComparator.java

index e3285560fcf08c610181d6f6a7a78c026c4b0894,ad6bf55ff73f0afcbaa9bc6a6b4af13fc7788ed2..f222948442126dd4defe9a3e9a1f054460a035b7
@@@ -1,6 -1,11 +1,11 @@@
  /**
-  *
-  */
+ * Copyright (C) 2007 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.taxeditor.newWizard;
  
  import java.util.Map;
@@@ -20,7 -25,6 +25,7 @@@ import eu.etaxonomy.cdm.model.descripti
  import eu.etaxonomy.cdm.model.taxon.ITaxonTreeNode;
  import eu.etaxonomy.cdm.model.taxon.TaxonNode;
  import eu.etaxonomy.cdm.model.taxon.TaxonNodeStatus;
 +import eu.etaxonomy.cdm.persistence.dto.MergeResult;
  import eu.etaxonomy.cdm.persistence.dto.TaxonNodeDto;
  import eu.etaxonomy.taxeditor.l10n.Messages;
  import eu.etaxonomy.taxeditor.model.MessagingUtils;
@@@ -29,7 -33,7 +34,7 @@@ import eu.etaxonomy.taxeditor.ui.sectio
  import eu.etaxonomy.taxeditor.ui.section.classification.TaxonNodeWizardPage;
  
  /**
-  * <p>NewTaxonNodeWizard class.</p>
+  * NewTaxonNodeWizard class.
   *
   * @author n.hoffmann
   * @created Sep 15, 2009
@@@ -73,18 -77,15 +78,15 @@@ public class NewTaxonNodeWizard extend
                if (status == null){
                    notes = null;
                }
-               result = CdmStore.getService(ITaxonNodeService.class).createNewTaxonNode(parent.getUuid(), taxon, source, parent.getMicroReference(),
+               result = CdmStore.getService(ITaxonNodeService.class).createNewTaxonNode(parent.getUuid(), taxon, source, parent.getMicroReference(),
                         status, notes);
  
                if (result.isOk()){
                    this.setEntity((TaxonNode)result.getCdmEntity());
-                     this.getEntity().getTaxon().setPublish(taxon.isPublish());
-                     MergeResult<TaxonNode> mergeResult = CdmStore.getService(ITaxonNodeService.class).merge(this.getEntity(), true);
-                     this.setEntity(mergeResult.getMergedEntity());
                      CdmApplicationState.getCurrentDataChangeService()
                               .fireChangeEvent(new CdmChangeEvent(Action.Create, result.getUpdatedObjects(), NewTaxonNodeWizard.class), true);
-                     CdmApplicationState.getCurrentDataChangeService()
-                     .fireChangeEvent(new CdmChangeEvent(Action.Create, mergeResult.getMergedEntity(), NewTaxonNodeWizard.class), true);
  
                     }else{
                         setSuccess(false);
          }
      }
  
- //    @Override
- //    protected TaxonNode createNewEntity() {
- //        if(getSelection() != null){
- //            Object selectedObject = getSelection().getFirstElement();
- //            if(selectedObject instanceof TaxonNodeDto){
- //                TaxonNodeDto taxonNodeDto = (TaxonNodeDto) selectedObject;
- //                    TaxonNode node =  CdmStore.getService(ITaxonNodeService.class).load(taxonNodeDto.getUuid());
- //                    Reference sec = node.getTaxon() != null? node.getTaxon().getSec():null;
- //                    Taxon newTaxon = Taxon.NewInstance(TaxonNameFactory.NewNameInstance(PreferencesUtil.getPreferredNomenclaturalCode(), null), sec);
- //                    TaxonNode child = node.addChildTaxon(newTaxon, null, null);
- //
- //                return child;
- //
- //            }
- //        }
- //
- //        return null;
- //    }
      public boolean openInEditor() {
          return isOpenInEditor ;
      }
              }
          }
      }
- }
+ }
index 3e37e3acd665dac8e89c5c64d1bb0f1bc2eefa38,8f4e885cbd5f357b76d381bfc89e85d6b658f0b7..a01f31295166e1319578efb49b51f14275ca2d1e
@@@ -1,6 -1,13 +1,13 @@@
+ /**
+ * Copyright (C) 2007 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.taxeditor.ui.section.description;
  
  import java.util.Comparator;
  
  import eu.etaxonomy.cdm.model.description.DescriptionElementSource;
@@@ -11,22 -18,29 +18,30 @@@ import eu.etaxonomy.cdm.model.reference
  /**
   * @author pplitzner
   * @date Apr 13, 2016
-  *
   */
  public class SourceComparator  <T extends OriginalSourceBase> implements Comparator<T> {
      @Override
      public int compare(T o1, T o2) {
-         int id1 = o1.getId();
-         int id2 = o2.getId();
+         //same and null compare, to be on the save side
+         if (o1 == o2){
+             return 0;
+         }else if (o1 == null){
+             return -1;
+         }else if (o2 == null){
+             return 1;
+         }
          boolean isDescriptionElementSource1 = false;
          boolean isDescriptionElementSource2 = false;
-         if (o1 instanceof DescriptionElementSource){
+         if (o1.isInstanceOf(DescriptionElementSource.class)){
              isDescriptionElementSource1 = true;
          }
-         if (o2 instanceof DescriptionElementSource){
+         if (o2.isInstanceOf(DescriptionElementSource.class)){
              isDescriptionElementSource2 = true;
          }
 +        int result = 0;
          if (isDescriptionElementSource1 != isDescriptionElementSource2){
              if (isDescriptionElementSource1){
                  return -1;
                  return 1;
              }
          }
-         OriginalSourceType type1 = o1.getType();
-         OriginalSourceType type2 = o2.getType();
-         Reference citation1 = o1.getCitation();
-         Reference citation2 = o2.getCitation();
  
          // the newly created should always be on top
-         if (id1 == 0){
-             if(id2!=0) {
-                 return -1;
-             }
-             else{
-                 result = 0;
-             }
-         } else if(id2==0){
+         if (!o1.isPersited() && o2.isPersited()) {
+             return -1;
+         } else if(o1.isPersited() && !o2.isPersited()){
              return 1;
          }
  
          // sort by type (Primary taxonomic > Primary Media > others
          // alphabetically by reference title cache)
-         else if (type1 == null){
-             if(type2==null){
-                 result = 0;
-             }
-             else{
-                 result = -1;
+         OriginalSourceType type1 = o1.getType();
+         OriginalSourceType type2 = o2.getType();
+         if (type1 == null){
+             if (type2!=null){
+                 return -1;
              }
          } else if (type2 == null){
-             result = 1;
+             return 1;
          } else if(type1.equals(type2)){
-             result = 0;
+             //continue with citation compare
          } else if (type1.equals(OriginalSourceType.PrimaryTaxonomicSource)){
-             result = 1;
+             return 1;
          } else if (type2.equals(OriginalSourceType.PrimaryTaxonomicSource)){
-             result = -1;
+             return -1;
          } else if (type1.equals(OriginalSourceType.PrimaryMediaSource)){
-             result = 1;
+             return 1;
          } else if (type2.equals(OriginalSourceType.PrimaryMediaSource)){
-             result = -1;
+             return -1;
          }
  
+         int result;
          //sort by citation title cache if types are equal
-         if (result == 0){
-             if(citation1!=null && citation2!=null){
-                 result = citation1.getTitleCache().compareTo(citation2.getTitleCache());
+         Reference citation1 = o1.getCitation();
+         Reference citation2 = o2.getCitation();
+         if(citation1!=null && citation2!=null){
+             result = citation1.getTitleCache().compareTo(citation2.getTitleCache());
+             if (result != 0){
+                 return result;
              }
+         }
  
-             if(o2.getCreated()!=null && o1.getCreated()!=null){
-                 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;
+         //sort by created
+         if(o2.getCreated()!=null && o1.getCreated()!=null){
+             result = o1.getCreated().compareTo(o2.getCreated());
+             if (result != 0){
+                 return result;
              }
-             if (result == 0){
-                 //default fallback
-                 return o1.getUuid().compareTo(o2.getUuid());
+         }else if (o1.getCreated() == null){
+             if (o2.getCreated() != null){
+                 return -1;
              }
+         }else if (o2.getCreated() == null){
+             return 1;
          }
-         return result;
  
+         //default fallback
+         return o1.getUuid().compareTo(o2.getUuid());
      }
- }
+ }