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
Add support for intersection groups #131
Merged
phillcunnington
merged 1 commit into
cuppa-framework:master
from
alx75:add_support_for_intersection_groups
Feb 16, 2018
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
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
48 changes: 48 additions & 0 deletions
48
cuppa/src/main/java/org/forgerock/cuppa/internal/filters/expression/AndCondition.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,48 @@ | ||
/* | ||
* Copyright 2018 ForgeRock AS. | ||
* | ||
* Licensed 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 | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* 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.forgerock.cuppa.internal.filters.expression; | ||
|
||
import java.util.Collection; | ||
import java.util.Collections; | ||
|
||
/** | ||
* A condition that composes other conditions with a logical AND. | ||
*/ | ||
class AndCondition extends ConditionWrapper { | ||
|
||
public static final AndCondition EMPTY = new AndCondition(Collections.emptyList()); | ||
private final Collection<Condition> conditions; | ||
|
||
/** | ||
* Constructor. | ||
* | ||
* @param conditions a list of condition to compose. | ||
*/ | ||
AndCondition(Collection<Condition> conditions) { | ||
this.conditions = Collections.unmodifiableCollection(conditions); | ||
} | ||
|
||
@Override | ||
public boolean shouldRun(Collection<String> tags) { | ||
return conditions.stream().allMatch(c -> c.shouldRun(tags)); | ||
} | ||
|
||
@Override | ||
public ConditionWrapper setConditions(Collection<Condition> conditions) { | ||
return new AndCondition(conditions); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
cuppa/src/main/java/org/forgerock/cuppa/internal/filters/expression/Condition.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,35 @@ | ||
/* | ||
* Copyright 2018 ForgeRock AS. | ||
* | ||
* Licensed 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 | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* 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.forgerock.cuppa.internal.filters.expression; | ||
|
||
import java.util.Collection; | ||
|
||
/** | ||
* A condition used by {@link ExpressionTagTestBlockFilter}. | ||
*/ | ||
@FunctionalInterface | ||
public interface Condition { | ||
|
||
/** | ||
* Check if the list of tags is compliant with the condition. | ||
* | ||
* @param tags The collection of tags. | ||
* @return true if the condition complies with the tags supplied, false otherwise. | ||
*/ | ||
boolean shouldRun(Collection<String> tags); | ||
|
||
} |
58 changes: 58 additions & 0 deletions
58
cuppa/src/main/java/org/forgerock/cuppa/internal/filters/expression/ConditionFactory.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,58 @@ | ||
package org.forgerock.cuppa.internal.filters.expression; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
/** | ||
* A factory to creates {@link ConditionWrapper}. | ||
*/ | ||
final class ConditionFactory { | ||
|
||
/** | ||
* link the operator to an instance of {@link Condition}. | ||
*/ | ||
enum ConditionEnum { | ||
AND("and", AndCondition.EMPTY), | ||
OR("or", OrCondition.EMPTY), | ||
NOT("not", NotCondition.EMPTY); | ||
|
||
private String operator; | ||
private ConditionWrapper condition; | ||
|
||
ConditionEnum(String operator, ConditionWrapper condition) { | ||
this.operator = operator; | ||
this.condition = condition; | ||
} | ||
|
||
/** | ||
* Get a ConditionEnum fron an string operator. | ||
* @param operator The operator we want to get the associated enum | ||
* @return The ConditionEnum | ||
*/ | ||
static ConditionEnum getFromOperator(String operator) { | ||
return Arrays.stream(ConditionEnum.values()) | ||
.filter(c -> c.operator.equals(operator)) | ||
.findFirst() | ||
.orElseThrow(() -> new IllegalArgumentException(operator + " is not supported. The list of " | ||
+ "supported operator is and, or, not")); | ||
} | ||
|
||
Condition getCondition(List<Condition> tags) { | ||
return condition.setConditions(tags); | ||
} | ||
} | ||
|
||
private ConditionFactory() { | ||
} | ||
|
||
/** | ||
* Create a {@link Condition}. | ||
* @param operator The operator we want to create a condition for. | ||
* @param tags The list of conditions that {@link ConditionWrapper} will include. | ||
* @return A condition | ||
*/ | ||
static Condition get(String operator, List<Condition> tags) { | ||
return ConditionEnum.getFromOperator(operator.trim().toLowerCase()) | ||
.getCondition(tags); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
cuppa/src/main/java/org/forgerock/cuppa/internal/filters/expression/ConditionWrapper.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,16 @@ | ||
package org.forgerock.cuppa.internal.filters.expression; | ||
|
||
import java.util.Collection; | ||
|
||
/** | ||
* A condition wrapper for Condition that needs to wrap other conditions. | ||
*/ | ||
abstract class ConditionWrapper implements Condition { | ||
|
||
/** | ||
* Create a new Condition with the given conditions. | ||
* @param conditions the collection of conditions | ||
* @return a new condition | ||
*/ | ||
abstract ConditionWrapper setConditions(Collection<Condition> conditions); | ||
} |
41 changes: 41 additions & 0 deletions
41
cuppa/src/main/java/org/forgerock/cuppa/internal/filters/expression/ContainsCondition.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,41 @@ | ||
/* | ||
* Copyright 2018 ForgeRock AS. | ||
* | ||
* Licensed 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 | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* 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.forgerock.cuppa.internal.filters.expression; | ||
|
||
import java.util.Collection; | ||
|
||
/** | ||
* A condition that checks if a tag is contains in a collection of tags. | ||
*/ | ||
class ContainsCondition implements Condition { | ||
|
||
private String tag; | ||
|
||
/** | ||
* Constructor. | ||
* | ||
* @param tag A group/tag we want to search for. | ||
*/ | ||
ContainsCondition(String tag) { | ||
this.tag = tag; | ||
} | ||
|
||
@Override | ||
public boolean shouldRun(Collection<String> tags) { | ||
return tags.contains(tag); | ||
} | ||
} |
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.
I feel like there shouldn't be a need for 2 tag block filters. But saying that i'd like to look at trying to make changes to allow the groups expression to be an extension to Cuppa core. I will look at that separate to this PR though.