fix #8849 fix NPE for synonyms without accepted taxon in details view and some code...
authorAndreas Müller <a.mueller@bgbm.org>
Fri, 29 May 2020 09:09:53 +0000 (11:09 +0200)
committerAndreas Müller <a.mueller@bgbm.org>
Fri, 29 May 2020 09:09:53 +0000 (11:09 +0200)
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/e4/details/DetailsViewerE4.java

index c51a2e4d2692ab2426f5643921dc9cb1971b983b..4416d174f288f25679e260261f731ceac914ef8a 100755 (executable)
@@ -459,29 +459,31 @@ public class DetailsViewerE4 extends AbstractCdmDataViewerE4 {
             requiredCrud = EnumSet.of(CRUD.UPDATE);
         }
         boolean hasPermission = CdmStore.currentAuthentiationHasPermission(StoreUtil.getCdmEntity(getInput()), requiredCrud);
-        TaxonBase taxonBase = (TaxonBase)getInput();
-        Taxon acceptedTaxon = null;
-        if (taxonBase instanceof Taxon){
-            acceptedTaxon = (Taxon)taxonBase;
-        }else{
-           acceptedTaxon = ((Synonym)taxonBase).getAcceptedTaxon();
-        }
-        Set<TaxonNode> nodes = acceptedTaxon.getTaxonNodes();
-        // check for subtree permissions as well.
         if (hasPermission){
-            for (TaxonNode node: nodes){
-                hasPermission &= CdmStore.currentAuthentiationHasPermission(node, requiredCrud);
-                if (!hasPermission){
-                    //check whether there are explicit TaxonNode rights
-                    boolean taxonnodePermissionExists = false;
-                    Collection<? extends GrantedAuthority> authorities = CdmStore.getCurrentAuthentiation().getAuthorities();
-                    for (GrantedAuthority grantedAuthority: authorities){
-                        if (grantedAuthority.getAuthority().startsWith("TAXONNODE")){
-                            taxonnodePermissionExists = true;
+            // check for subtree permissions as well.
+            TaxonBase<?> taxonBase = (TaxonBase<?>)getInput();
+            Taxon acceptedTaxon = null;
+            if (taxonBase instanceof Taxon){
+                acceptedTaxon = (Taxon)taxonBase;
+            }else{
+                acceptedTaxon = ((Synonym)taxonBase).getAcceptedTaxon();
+            }
+            if (acceptedTaxon != null){ //needs discussion if synonyms without accepted taxon should never be filtered by subtree permission(current implementation). See also #8849
+                Set<TaxonNode> nodes = acceptedTaxon.getTaxonNodes();
+                for (TaxonNode node: nodes){
+                    hasPermission &= CdmStore.currentAuthentiationHasPermission(node, requiredCrud);
+                    if (!hasPermission){
+                        //check whether there are explicit TaxonNode rights
+                        boolean taxonnodePermissionExists = false;
+                        Collection<? extends GrantedAuthority> authorities = CdmStore.getCurrentAuthentiation().getAuthorities();
+                        for (GrantedAuthority grantedAuthority: authorities){
+                            if (grantedAuthority.getAuthority().startsWith("TAXONNODE")){
+                                taxonnodePermissionExists = true;
+                            }
+                        }
+                        if (!taxonnodePermissionExists){
+                            hasPermission = true;
                         }
-                    }
-                    if (!taxonnodePermissionExists){
-                        hasPermission = true;
                     }
                 }
             }