-
Notifications
You must be signed in to change notification settings - Fork 273
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
Changes from 6 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
a2cb332
UP-4964: Move BranchingRenderingPipelineTest.java, RedirectRendering…
drewwills 83a083f
UP-4964: Convert renderingPipelineContext.xml -> RenderingPipelineCo…
drewwills b92b22e
UP-4964: Exchange com.google.common.base.Predicate (Google Guava) f…
drewwills 3fb10ba
UP-4964: Refactor BranchingRenderingPipeline -> RenderingPipelineBra…
drewwills 2e5f422
UP-4964: Add support for RenderingPipelineBranchPoint beans to Rende…
drewwills c1cbb4f
UP-4964: Allow CI to finish
drewwills 62bc84d
UP-4964: Restore (and update) the BranchingRenderingPipeline to main…
drewwills c876312
UP-4964: Add documentation for the uPortal Rendering Pipeline, inclu…
drewwills File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
88 changes: 0 additions & 88 deletions
88
uPortal-rendering/src/main/java/org/apereo/portal/rendering/BranchingRenderingPipeline.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
108 changes: 108 additions & 0 deletions
108
...tal-rendering/src/main/java/org/apereo/portal/rendering/RenderingPipelineBranchPoint.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
@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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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
?There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.