package org.jasig.portal.rendering.predicates;

import com.google.common.base.Predicate;
import org.jasig.portal.url.IPortalRequestInfo;
import org.jasig.portal.url.IUrlSyntaxProvider;
import org.jasig.portal.url.UrlState;
import org.springframework.beans.factory.annotation.Autowired;

import javax.servlet.http.HttpServletRequest;

/**
 * Answers whether a given HttpServletRequest represents one that the rendering pipeline will focus on rendering just
 * one portlet (e.g., maximized, or exclusive).
 * @since uPortal 4.2
 */
public class FocusedOnOnePortletPredicate
    implements Predicate<HttpServletRequest> {

    // auto-wired.
    private IUrlSyntaxProvider urlSyntaxProvider;

    @Override
    public boolean apply(final HttpServletRequest request) {

        final IPortalRequestInfo portalRequestInfo = this.urlSyntaxProvider.getPortalRequestInfo(request);

        // true when there is a portal request and that request is not for a portal in NORMAL state
        // i.e. portal is in some other state, like Maximized or Exclusive or Detached.
        // false otherwise. False when portalRequestInfo is null because unknown portal state is not
        // focused-on-one-portlet portal state.
        return (null != portalRequestInfo &&
                ! (UrlState.NORMAL.equals(portalRequestInfo.getUrlState())));
    }

    @Autowired
    public void setUrlSyntaxProvider(IUrlSyntaxProvider urlSyntaxProvider) {
        this.urlSyntaxProvider = urlSyntaxProvider;
    }
}

@@ -212,24 +212,81 @@
 l.UrlState;%0A
+import org.slf4j.Logger;%0Aimport org.slf4j.LoggerFactory;%0A
 import org.s
@@ -666,24 +666,98 @@
 Request%3E %7B%0A%0A
+    protected final Logger logger = LoggerFactory.getLogger(getClass());%0A%0A
     // auto-
@@ -994,24 +994,480 @@
 (request);%0A%0A
+        if (null == portalRequestInfo) %7B%0A            logger.warn(%22Portal request info was not available for this request, %22 +%0A                    %22so assuming that it does not represent focus on one portlet.%22);%0A            // False when portalRequestInfo is null because unknown portal state is not%0A            // focused-on-one-portlet portal state.%0A            return false;%0A        %7D%0A%0A        final UrlState urlState = portalRequestInfo.getUrlState();%0A%0A
         // t
@@ -1673,138 +1673,223 @@
 ise.
- False when portalRequestInfo is null because unknown portal state is not%0A        //
+%0A        final boolean doesRequestFocusOnOnePortlet = (! (UrlState.NORMAL.equals(urlState)));%0A%0A        logger.debug(%22Determined request with UrlState %7B%7D %7B%7D
  focus
-ed-on-one-
+ on one 
 portlet
- portal s
+.%22,%0A                urlS
 tate
-.%0A
+,%0A 
         
 retu
@@ -1888,121 +1888,112 @@
     
-return (null != portalRequestInfo &&%0A                ! (UrlState.NORMAL.equals(portalRequestInfo.getUrlState())))
+       doesRequestFocusOnOnePortlet ? %22does%22 : %22does not%22);%0A%0A        return doesRequestFocusOnOnePortlet
 ;%0A  

Add logging in FocusedOnOnePortletPredicate.