Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UP-4964: Fix configuration of BranchingRenderingPipeline on uP5 #1050

Merged
merged 8 commits into from
Nov 22, 2017

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

/** Describes the entry point into the uPortal rendering pipeline. */
public interface IPortalRenderingPipeline {

/**
* <code>renderState</code> method orchestrates the rendering pipeline which includes worker
* dispatching, and the rendering process from layout access, to channel rendering, to writing
Expand All @@ -31,6 +32,6 @@ public interface IPortalRenderingPipeline {
* @param res the <code>HttpServletResponse</code>
* @exception PortalException if an error occurs
*/
public void renderState(HttpServletRequest req, HttpServletResponse res)
void renderState(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
/**
* Licensed to Apereo under one or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information regarding copyright ownership. Apereo
* licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use
* this file except in compliance with the License. You may obtain a copy of the License at the
* following location:
*
* <p>http://www.apache.org/licenses/LICENSE-2.0
*
* <p>Unless required by applicable law or agreed to in writing, software distributed under the
* License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apereo.portal.rendering;

import java.io.IOException;
import java.util.function.Predicate;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Required;

/**
* Offers an alternative to the "standard" rendering pipeline if certain conditions (encapsulated in
* a <code>Predicate</code>) are satisfied. If the specified <code>Predicate</code> returns <code>
* true</code>, the alternate path will be followed.
*
* <p>This class is an extension point for uPortal adopters. Beans of this type are automatically
* detected and processed by the uPortal rendering infrastructure. Multiple <code>
* RenderingPipelineBranchPoint</code> beans will be ordered based on their <code>order</code>
* properties. Beans with a lower order score are processed before beans with a higher order.
*
* @since 5.0
*/
public class RenderingPipelineBranchPoint implements Comparable<RenderingPipelineBranchPoint> {

protected final Logger logger = LoggerFactory.getLogger(getClass());

private int order = Integer.MAX_VALUE; // default -- last position

// dependency-injected
private Predicate<HttpServletRequest> predicate;

// dependency-injected
private IPortalRenderingPipeline alternatePipe;

public void setOrder(int order) {
this.order = order;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❓ what happens if two branch points have the same order?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One of them (randomly selected) will be processed first. IMHO that's fine. The alternative would be detecting the circumstance and throwing an exception.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps logging a warning is a good middle ground.

}

@Required
public void setPredicate(Predicate<HttpServletRequest> predicate) {
this.predicate = predicate;
}

@Required
public void setAlternatePipe(IPortalRenderingPipeline alternatePipe) {
this.alternatePipe = alternatePipe;
}

/**
* Checks this bean's <code>Predicate</code> to see if the alternate rendering path should be
* followed. If so, it will follow the path and return <code>true</code>; if not, it will
* immediately return <code>false</code>;
*
* @param request The current <code>HttpServletRequest</code>
* @param response The current <code>HttpServletResponse</code>
* @return <code>true</code> if the alternate path was followed, otherwise <code>false</code>
* indicating that the next {@link RenderingPipelineBranchPoint} should be attempted or the
* standard pipeline should be used
*/
public boolean renderStateIfApplicable(
final HttpServletRequest request, final HttpServletResponse response)
throws ServletException, IOException {

final boolean rslt = predicate.test(request);
if (rslt) {
logger.debug(
"Using alternate pipe [{}] for branch point with order={}",
alternatePipe,
order);
alternatePipe.renderState(request, response);
} else {
logger.debug(
"Bypassing alternate pipe [{}] for branch point with order={}",
alternatePipe,
order);
}
return rslt;
}

@Override
public String toString() {
return "RenderingPipelineBranchPoint with predicate ["
+ predicate
+ "] proceeds down pipe ["
+ alternatePipe
+ "] when the predicate is true.";
}

@Override
public int compareTo(RenderingPipelineBranchPoint branchPoint) {
return Integer.compare(order, branchPoint.order);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*/
package org.apereo.portal.rendering.predicates;

import com.google.common.base.Predicate;
import java.util.function.Predicate;
import javax.servlet.http.HttpServletRequest;
import org.apereo.portal.url.IPortalRequestInfo;
import org.apereo.portal.url.IUrlSyntaxProvider;
Expand All @@ -37,7 +37,7 @@ public class FocusedOnOnePortletPredicate implements Predicate<HttpServletReques
private IUrlSyntaxProvider urlSyntaxProvider;

@Override
public boolean apply(final HttpServletRequest request) {
public boolean test(final HttpServletRequest request) {

final IPortalRequestInfo portalRequestInfo =
this.urlSyntaxProvider.getPortalRequestInfo(request);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*/
package org.apereo.portal.rendering.predicates;

import com.google.common.base.Predicate;
import java.util.function.Predicate;
import javax.servlet.http.HttpServletRequest;
import org.apereo.portal.user.IUserInstance;
import org.apereo.portal.user.IUserInstanceManager;
Expand All @@ -27,7 +27,7 @@ public class GuestUserPredicate implements Predicate<HttpServletRequest> {
private IUserInstanceManager userInstanceManager;

@Override
public boolean apply(final HttpServletRequest request) {
public boolean test(final HttpServletRequest request) {

final IUserInstance userInstance = this.userInstanceManager.getUserInstance(request);
return userInstance.getPerson().isGuest();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*/
package org.apereo.portal.rendering.predicates;

import com.google.common.base.Predicate;
import java.util.function.Predicate;
import javax.servlet.http.HttpServletRequest;
import org.apereo.portal.user.IUserInstance;
import org.apereo.portal.user.IUserInstanceManager;
Expand All @@ -27,7 +27,7 @@ public class NotGuestUserPredicate implements Predicate<HttpServletRequest> {
private IUserInstanceManager userInstanceManager;

@Override
public boolean apply(final HttpServletRequest request) {
public boolean test(final HttpServletRequest request) {

final IUserInstance userInstance = this.userInstanceManager.getUserInstance(request);
return !userInstance.getPerson().isGuest();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*/
package org.apereo.portal.rendering.predicates;

import com.google.common.base.Predicate;
import java.util.function.Predicate;
import javax.servlet.http.HttpServletRequest;
import org.apereo.portal.user.IUserInstance;
import org.apereo.portal.user.IUserInstanceManager;
Expand All @@ -41,7 +41,7 @@ public class ProfileFNamePredicate implements Predicate<HttpServletRequest> {
private String profileFNameToMatch;

@Override
public boolean apply(final HttpServletRequest request) {
public boolean test(final HttpServletRequest request) {

final IUserInstance userInstance = this.userInstanceManager.getUserInstance(request);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
*/
package org.apereo.portal.rendering.predicates;

import com.google.common.base.Predicate;
import java.util.Iterator;
import java.util.function.Predicate;
import javax.servlet.http.HttpServletRequest;
import org.apereo.portal.portlet.om.IPortletDefinition;
import org.apereo.portal.portlet.om.IPortletPreference;
Expand All @@ -24,7 +24,7 @@
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

public class RenderOnWebFlagSet implements Predicate<HttpServletRequest> {
public class RenderOnWebFlagSetPredicate implements Predicate<HttpServletRequest> {

protected final Logger logger = LoggerFactory.getLogger(getClass());

Expand All @@ -36,7 +36,7 @@ public void setUtils(RequestRenderingPipelineUtils u) {
}

@Override
public boolean apply(final HttpServletRequest request) {
public boolean test(final HttpServletRequest request) {
try {
final IPortletDefinition portletDefinition =
utils.getPortletDefinitionFromServletRequest(request);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*/
package org.apereo.portal.rendering.predicates;

import com.google.common.base.Predicate;
import java.util.function.Predicate;
import javax.servlet.http.HttpServletRequest;
import org.apereo.portal.url.IPortalRequestInfo;
import org.apereo.portal.url.IUrlSyntaxProvider;
Expand All @@ -29,7 +29,7 @@
*
* @since 4.2
*/
public class URLInSpecificState implements Predicate<HttpServletRequest> {
public class URLInSpecificStatePredicate implements Predicate<HttpServletRequest> {

protected final Logger logger = LoggerFactory.getLogger(getClass());

Expand All @@ -40,7 +40,7 @@ public class URLInSpecificState implements Predicate<HttpServletRequest> {
private boolean isNegated;

@Override
public boolean apply(final HttpServletRequest request) {
public boolean test(final HttpServletRequest request) {

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