Skip to content

Commit

Permalink
#4504 Add column value filters
Browse files Browse the repository at this point in the history
  • Loading branch information
stroomdev66 committed Oct 23, 2024
1 parent f114514 commit fc59ab3
Show file tree
Hide file tree
Showing 24 changed files with 1,695 additions and 1,085 deletions.
4 changes: 2 additions & 2 deletions stroom-app/src/main/resources/ui/noauth/swagger/stroom.json
Original file line number Diff line number Diff line change
Expand Up @@ -14223,7 +14223,7 @@
"condition" : {
"type" : "string",
"description" : "The condition of the predicate term",
"enum" : [ "CONTAINS", "EQUALS", "STARTS_WITH", "ENDS_WITH", "NOT_EQUALS", "GREATER_THAN", "GREATER_THAN_OR_EQUAL_TO", "LESS_THAN", "LESS_THAN_OR_EQUAL_TO", "BETWEEN", "IN", "IN_DICTIONARY", "IN_FOLDER", "IS_DOC_REF", "IS_USER_REF", "IS_NULL", "IS_NOT_NULL", "MATCHES_REGEX", "OF_DOC_REF", "USER_HAS_PERM", "USER_HAS_OWNER", "USER_HAS_DELETE", "USER_HAS_EDIT", "USER_HAS_VIEW", "USER_HAS_USE" ]
"enum" : [ "CONTAINS", "EQUALS", "STARTS_WITH", "ENDS_WITH", "NOT_EQUALS", "GREATER_THAN", "GREATER_THAN_OR_EQUAL_TO", "LESS_THAN", "LESS_THAN_OR_EQUAL_TO", "BETWEEN", "IN", "IN_DICTIONARY", "IN_FOLDER", "IS_DOC_REF", "IS_USER_REF", "IS_NULL", "IS_NOT_NULL", "MATCHES_REGEX", "WORD_BOUNDARY", "OF_DOC_REF", "USER_HAS_PERM", "USER_HAS_OWNER", "USER_HAS_DELETE", "USER_HAS_EDIT", "USER_HAS_VIEW", "USER_HAS_USE" ]
},
"docRef" : {
"$ref" : "#/components/schemas/DocRef"
Expand Down Expand Up @@ -21025,7 +21025,7 @@
"properties" : {
"condition" : {
"type" : "string",
"enum" : [ "CONTAINS", "EQUALS", "STARTS_WITH", "ENDS_WITH", "NOT_EQUALS", "GREATER_THAN", "GREATER_THAN_OR_EQUAL_TO", "LESS_THAN", "LESS_THAN_OR_EQUAL_TO", "BETWEEN", "IN", "IN_DICTIONARY", "IN_FOLDER", "IS_DOC_REF", "IS_USER_REF", "IS_NULL", "IS_NOT_NULL", "MATCHES_REGEX", "OF_DOC_REF", "USER_HAS_PERM", "USER_HAS_OWNER", "USER_HAS_DELETE", "USER_HAS_EDIT", "USER_HAS_VIEW", "USER_HAS_USE" ]
"enum" : [ "CONTAINS", "EQUALS", "STARTS_WITH", "ENDS_WITH", "NOT_EQUALS", "GREATER_THAN", "GREATER_THAN_OR_EQUAL_TO", "LESS_THAN", "LESS_THAN_OR_EQUAL_TO", "BETWEEN", "IN", "IN_DICTIONARY", "IN_FOLDER", "IS_DOC_REF", "IS_USER_REF", "IS_NULL", "IS_NOT_NULL", "MATCHES_REGEX", "WORD_BOUNDARY", "OF_DOC_REF", "USER_HAS_PERM", "USER_HAS_OWNER", "USER_HAS_DELETE", "USER_HAS_EDIT", "USER_HAS_VIEW", "USER_HAS_USE" ]
},
"from" : {
"type" : "string"
Expand Down
2 changes: 2 additions & 0 deletions stroom-app/src/main/resources/ui/noauth/swagger/stroom.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10433,6 +10433,7 @@ components:
- IS_NULL
- IS_NOT_NULL
- MATCHES_REGEX
- WORD_BOUNDARY
- OF_DOC_REF
- USER_HAS_PERM
- USER_HAS_OWNER
Expand Down Expand Up @@ -16336,6 +16337,7 @@ components:
- IS_NULL
- IS_NOT_NULL
- MATCHES_REGEX
- WORD_BOUNDARY
- OF_DOC_REF
- USER_HAS_PERM
- USER_HAS_OWNER
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
import stroom.query.api.v2.ConditionalFormattingRule;
import stroom.query.api.v2.ExpressionOperator;
import stroom.query.api.v2.Row;
import stroom.query.common.v2.ExpressionPredicateBuilder.QueryFieldIndex;
import stroom.query.common.v2.ExpressionPredicateBuilder.ValuesPredicate;
import stroom.query.common.v2.ExpressionPredicateBuilder.ValueFunctionFactories;
import stroom.query.common.v2.format.Formatter;
import stroom.query.common.v2.format.FormatterFactory;
import stroom.query.language.functions.Val;
Expand All @@ -17,6 +16,7 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.function.Predicate;

public class ConditionalFormattingRowCreator implements ItemMapper<Row> {

Expand All @@ -26,14 +26,14 @@ public class ConditionalFormattingRowCreator implements ItemMapper<Row> {
private final KeyFactory keyFactory;
private final ErrorConsumer errorConsumer;
private final Formatter[] columnFormatters;
private final ValuesPredicate rowFilter;
private final Predicate<Val[]> rowFilter;
private final List<RuleAndMatcher> rules;

private ConditionalFormattingRowCreator(final int[] columnIndexMapping,
final KeyFactory keyFactory,
final ErrorConsumer errorConsumer,
final Formatter[] columnFormatters,
final ValuesPredicate rowFilter,
final Predicate<Val[]> rowFilter,
final List<RuleAndMatcher> rules) {
this.columnIndexMapping = columnIndexMapping;
this.keyFactory = keyFactory;
Expand All @@ -60,9 +60,9 @@ public static Optional<ItemMapper<Row>> create(final List<Column> originalColumn
.toList();
if (!activeRules.isEmpty()) {
final List<RuleAndMatcher> ruleAndMatchers = new ArrayList<>();
final QueryFieldIndex queryFieldIndex = RowUtil.createColumnNameQueryFieldIndex(newColumns);
final ValueFunctionFactories<Val[]> queryFieldIndex = RowUtil.createColumnNameValExtractor(newColumns);
for (final ConditionalFormattingRule rule : activeRules) {
final Optional<ValuesPredicate> optionalValuesPredicate =
final Optional<Predicate<Val[]>> optionalValuesPredicate =
ExpressionPredicateBuilder.create(rule.getExpression(), queryFieldIndex, dateTimeSettings);
optionalValuesPredicate.ifPresent(columnExpressionMatcher ->
ruleAndMatchers.add(new RuleAndMatcher(rule, columnExpressionMatcher)));
Expand All @@ -71,7 +71,7 @@ public static Optional<ItemMapper<Row>> create(final List<Column> originalColumn
if (!ruleAndMatchers.isEmpty()) {
final int[] columnIndexMapping = RowUtil.createColumnIndexMapping(originalColumns, newColumns);
final Formatter[] formatters = RowUtil.createFormatters(newColumns, formatterFactory);
final Optional<ValuesPredicate> rowFilter = FilteredRowCreator
final Optional<Predicate<Val[]>> rowFilter = FilteredRowCreator
.createValuesPredicate(newColumns,
applyValueFilters,
rowFilterExpression,
Expand All @@ -97,13 +97,12 @@ public final Row create(final Item item) {

// Create values array.
final Val[] values = RowUtil.createValuesArray(item, columnIndexMapping);
final ValValues valValues = new ValValues(values);
if (rowFilter.test(valValues)) {
if (rowFilter.test(values)) {
// Find a matching rule.
ConditionalFormattingRule matchingRule = null;
for (final RuleAndMatcher ruleAndMatcher : rules) {
try {
final boolean match = ruleAndMatcher.matcher.test(valValues);
final boolean match = ruleAndMatcher.matcher.test(values);
if (match) {
matchingRule = ruleAndMatcher.rule;
break;
Expand Down Expand Up @@ -163,7 +162,7 @@ public boolean hidesRows() {
return true;
}

private record RuleAndMatcher(ConditionalFormattingRule rule, ValuesPredicate matcher) {
private record RuleAndMatcher(ConditionalFormattingRule rule, Predicate<Val[]> matcher) {

}
}
Loading

0 comments on commit fc59ab3

Please sign in to comment.