package com.celements.menu.access;

import java.util.Map;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.xwiki.component.annotation.Component;
import org.xwiki.component.annotation.Requirement;
import org.xwiki.model.reference.DocumentReference;

@Component
public class MenuAccessService implements IMenuAccessServiceRole {

  private static Log LOGGER = LogFactory.getFactory().getInstance(
      MenuAccessService.class);

  @Requirement
  Map<String, IMenuAccessProviderRole> accessProviderMap;

  public boolean hasview(DocumentReference menuBarDocRef) {
    if (accessProviderMap != null) {
      boolean hasview = false;
      boolean allowForDeny = true;
      for (IMenuAccessProviderRole accessProvider : accessProviderMap.values()) {
        try {
          boolean newHasView = accessProvider.hasview(menuBarDocRef);
          if (!newHasView && accessProvider.denyView(menuBarDocRef)) {
            return false;
          } else if (allowForDeny) {
            hasview |= newHasView;
          }
        } catch (NoAccessDefinedException noAccExp) {
          LOGGER.debug("skip Access Provider [" + accessProvider.getClass() + "] because"
              + " of NoAccessDefinedException on [" + menuBarDocRef + "].", noAccExp);
        } catch (Exception exp) {
          LOGGER.error("Access Provider [" + accessProvider.getClass() + "] failed for"
              + " hasview on [" + menuBarDocRef + "].", exp);
        }
      }
      return hasview;
    }
    return false;
  }

}

@@ -258,41 +258,113 @@
 iki.
-model.reference.DocumentReference
+context.Execution;%0Aimport org.xwiki.model.reference.DocumentReference;%0A%0Aimport com.xpn.xwiki.XWikiContext
 ;%0A%0A@
@@ -615,16 +615,175 @@
 erMap;%0A%0A
+  @Requirement%0A  Execution execution;%0A%0A  private XWikiContext getContext() %7B%0A    return (XWikiContext)execution.getContext().getProperty(%22xwikicontext%22);%0A  %7D%0A%0A
   public
@@ -1117,68 +1117,525 @@
     
-if (!newHasView && accessProvider.denyView(menuBarDocRef)) %7B
+LOGGER.debug(%22check has view for %5B%22 + getContext().getUser() + %22%5D on %5B%22%0A              + menuBarDocRef + %22%5D and provider %5B%22 + accessProvider.getClass() + %22%5D%22%0A              + %22 results in %5B%22 + newHasView + %22%5D.%22);%0A          if (!newHasView && accessProvider.denyView(menuBarDocRef)) %7B%0A            LOGGER.debug(%22deny view for %5B%22 + getContext().getUser() + %22%5D on %5B%22%0A                + menuBarDocRef + %22%5D and provider %5B%22 + accessProvider.getClass() + %22%5D%22%0A                + %22 thus returning false and cancel hasview check.%22);
 %0A   
@@ -2170,24 +2170,167 @@
   %7D%0A      %7D%0A
+      LOGGER.debug(%22deny view for %5B%22 + getContext().getUser() + %22%5D on %5B%22%0A          + menuBarDocRef + %22%5D ends with result %5B%22 + hasview + %22%5D.%22);%0A
       return

add logging for MenuAccessService