ref #5971: new main menu admin with cdm preference nomenclatural code and insert...
[taxeditor.git] / eu.etaxonomy.taxeditor.editor / src / main / java / eu / etaxonomy / taxeditor / editor / TaxonEditorInput.java
index a110a37b75848bd650037356b8958254cc18bc51..782cd3da554dda7a52435064945b114108542814 100644 (file)
@@ -9,8 +9,8 @@
 
 package eu.etaxonomy.taxeditor.editor;
 
+import java.util.ArrayList;
 import java.util.Arrays;
-import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
@@ -67,6 +67,7 @@ public class TaxonEditorInput  extends CdmEntitySessionInput implements IEditorI
     }
 
     private TaxonEditorInput(UUID uuid, CdmType type) {
+        super(true);
         this.conversation = CdmStore.createConversation();
         switch(type) {
         case PARENT_TAXON_NODE:
@@ -95,28 +96,8 @@ public class TaxonEditorInput  extends CdmEntitySessionInput implements IEditorI
      */
     private void initForTaxonNode(UUID taxonNodeUuid) {
 
-        List<String> taxonNodePropertyPaths = Arrays.asList(new String[] {
-                "taxon.annotations",
-                "taxon.markers",
-                "taxon.credits",
-                "taxon.extensions",
-                "taxon.rights",
-                "taxon.sources",
-                "taxon.descriptions",
-                "taxon.synonymRelations.relatedFrom.name.homotypicalGroup.typifiedNames",
-                "taxon.relationsToThisTaxon",
-                "taxon.relationsFromThisTaxon",
-                "taxon.taxonNodes",
-                "taxon.name.status",
-                "taxon.name.homotypicalGroup.typifiedNames",
-                "taxon.name.taxonBases",
-                "taxon.name.descriptions.descriptionElements",
-                "taxon.name.descriptions.markers"
 
-
-        });
-
-        TaxonNode taxonNode = CdmStore.getService(ITaxonNodeService.class).load(taxonNodeUuid, taxonNodePropertyPaths);
+        TaxonNode taxonNode = CdmStore.getService(ITaxonNodeService.class).load(taxonNodeUuid, getTaxonNodePropertyPaths());
 
         if(taxonNode == null){
             MessagingUtils.warningDialog("Not yet implemented", TaxonEditorInput.class, "Selected element is not type TaxonBase.");
@@ -126,29 +107,7 @@ public class TaxonEditorInput  extends CdmEntitySessionInput implements IEditorI
     }
 
     private void initForTaxonBase(UUID taxonBaseUuid) {
-
-
-        List<String> taxonBasePropertyPaths = Arrays.asList(new String[] {
-                "annotations",
-                "markers",
-                "credits",
-                "extensions",
-                "rights",
-                "sources",
-                "descriptions",
-                "relationsToThisTaxon",
-                "relationsFromThisTaxon",
-                "taxonNodes",
-                "name.status",
-                "name.nomenclaturalReference",
-                "synonymRelations.relatedFrom.name.status.type",
-                "synonymRelations.relatedFrom.name.nomenclaturalReference.inReference",
-                "name.taxonBases",
-                "name.descriptions.descriptionElements",
-                "name.descriptions.markers",
-                "name.homotypicalGroup.typifiedNames.taxonBases.synonymRelations.relatedFrom.name.*"
-        });
-        TaxonBase taxonBase = CdmStore.getService(ITaxonService.class).load(taxonBaseUuid, taxonBasePropertyPaths);
+        TaxonBase taxonBase = CdmStore.getService(ITaxonService.class).load(taxonBaseUuid, getTaxonBasePropertyPaths());
         if (taxonBase != null){
             if(taxonBase.isInstanceOf(Taxon.class)){
                 Taxon taxon = CdmBase.deproxy(taxonBase, Taxon.class);
@@ -172,7 +131,11 @@ public class TaxonEditorInput  extends CdmEntitySessionInput implements IEditorI
             }else if(taxonBase instanceof Synonym){
                 Synonym synonym = (Synonym) taxonBase;
 
-                Set<Taxon> taxa = synonym.getAcceptedTaxa();
+                Set<Taxon> taxa = new HashSet<>();
+                Taxon taxon = synonym.getAcceptedTaxon();
+                if (taxon != null){
+                       taxa.add(taxon);
+                }
                 setInputForMultipleTaxa(conversation, taxa);
             }
         }
@@ -212,9 +175,11 @@ public class TaxonEditorInput  extends CdmEntitySessionInput implements IEditorI
             if(taxonNode != null){
                 init(taxonNode);
             }
-        }else if(taxonNodes.size() == 0){
+        } else if (taxonNodes.size() == 0) {
             // this is an undesired state
-            MessagingUtils.warningDialog("Incorrect state", TaxonEditorInput.class, "The accepted taxon is not part of any classification. This should not have happened.");
+            MessagingUtils.warningDialog("Incorrect state",TaxonEditorInput.class,"The accepted "
+                    + "taxon is not part of any classification. Editing with the "
+                    + "name editor is currently not implemented. Try to edit the taxon with the bulk editor.");
         }
     }
 
@@ -377,8 +342,8 @@ public class TaxonEditorInput  extends CdmEntitySessionInput implements IEditorI
     public boolean equals(Object obj) {
         if (TaxonEditorInput.class.equals(obj.getClass())
                 && getTaxon() != null
-                && getTaxon().equals(((TaxonEditorInput) obj).getTaxon())){
-            if(((TaxonEditorInput) obj).getInitiallySelectedTaxonBase() != null){
+                && getTaxon().equals(((TaxonEditorInput) obj).getTaxon())) {
+            if (((TaxonEditorInput) obj).getInitiallySelectedTaxonBase() != null){
                 setInitiallySelectedTaxonBase(((TaxonEditorInput) obj).getInitiallySelectedTaxonBase());
             }
             return true;
@@ -493,39 +458,59 @@ public class TaxonEditorInput  extends CdmEntitySessionInput implements IEditorI
      */
     @Override
     public void merge() {
-        CdmStore.getService(ITaxonNodeService.class).merge(taxonNode);
+       CdmStore.getService(ITaxonNodeService.class).merge(taxonNode, true);
+
     }
 
     @Override
     public Map<Object, List<String>> getPropertyPathsMap() {
-        Map<Object, List<String>> propertyPathsMap = new HashMap<Object, List<String>>();
-//        List<String> taxonNameBasePropertyPaths = Arrays.asList(new String[] {
-//                "status",
-//                "taxonBases.taxonNodes",
-//                "homotypicalGroup.typifiedNames.taxonBases.synonymRelations",
-//                "taxonBases.relationsToThisTaxon",
-//                "taxonBases.relationsFromThisTaxon",
-//                "descriptions"
-//        });
-//         propertyPathsMap.put(TaxonNameBase.class, taxonNameBasePropertyPaths);
-//
-//         List<String> taxonBasePropertyPaths = Arrays.asList(new String[] {
-//                 "taxon.annotations",
-//                 "taxon.markers",
-//                 "taxon.credits",
-//                 "taxon.extensions",
-//                 "taxon.rights",
-//                 "taxon.sources",
-//                 "taxon.descriptions"
-//         });
-//        propertyPathsMap.put(TaxonNode.class, taxonBasePropertyPaths);
-//       List<String> homotypicalGroupPropertyPaths = Arrays.asList(new String[] {
-//                "typifiedNames.taxonBases.synonymRelations.relatedFrom.name",
-//                "typifiedNames.taxonBases.synonymRelations.relatedFrom.name.status"
-//        });
-//       propertyPathsMap.put(HomotypicalGroup.class, homotypicalGroupPropertyPaths);
-//       return propertyPathsMap;
         return null;
     }
 
+    private List<String> getTaxonNodePropertyPaths() {
+        List<String> taxonNodePropertyPaths = new ArrayList<String>();
+        for(String propertyPath : getTaxonBasePropertyPaths()) {
+            taxonNodePropertyPaths.add("taxon." + propertyPath);
+        }
+        return taxonNodePropertyPaths;
+    }
+
+    private List<String> getTaxonBasePropertyPaths() {
+        List<String> taxonBasePropertyPaths = Arrays.asList(new String[] {
+                "sec",
+                "createdBy",
+                "updatedBy",
+                "annotations",
+                "markers",
+                "credits",
+                "extensions",
+                "rights",
+                "sources",
+                "descriptions",
+                "relationsToThisTaxon",
+                "relationsFromThisTaxon",
+                "taxonNodes",
+                "descriptions.descriptionElements.feature",
+                "descriptions.descriptionElements.area",
+                "descriptions.descriptionElements.status",
+                "descriptions.markers",
+                "name.descriptions",
+                "name.typeDesignations",
+                "name.status",
+                "name.nomenclaturalReference.inReference",
+                "name.taxonBases.taxonNodes",
+                "name.relationsFromThisName",
+                "name.relationsToThisName",
+                "name.homotypicalGroup.typifiedNames.taxonBases.synonymRelations.synonym.name.status",
+                "name.homotypicalGroup.typifiedNames.relationsToThisName.fromName",
+                "synonymRelations.synonym.name.status.type",
+                "synonymRelations.synonym.name.relationsToThisName.fromName",
+                "synonymRelations.synonym.name.nomenclaturalReference.inReference.authorship",
+                "synonymRelations.synonym.name.nomenclaturalReference.authorship",
+                "synonymRelations.synonym.name.homotypicalGroup.typifiedNames.taxonBases.synonymRelations"
+        });
+
+        return taxonBasePropertyPaths;
+    }
+
 }