From 2d947aa8da061bec69e24c882d4ab7dad4010aa2 Mon Sep 17 00:00:00 2001 From: brig Date: Fri, 27 Oct 2023 18:17:01 +0200 Subject: [PATCH 1/3] server: allow regexp in meta filters --- .../com/walmartlabs/concord/db/PgUtils.java | 4 +++ .../server/process/queue/FilterUtils.java | 8 ++++- .../server/process/queue/ProcessFilter.java | 4 ++- .../server/process/queue/FilterUtilsTest.java | 30 +++++++++++++++++++ 4 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 server/impl/src/test/java/com/walmartlabs/concord/server/process/queue/FilterUtilsTest.java diff --git a/server/db/src/main/java/com/walmartlabs/concord/db/PgUtils.java b/server/db/src/main/java/com/walmartlabs/concord/db/PgUtils.java index cd304dd04c..56d504bb62 100644 --- a/server/db/src/main/java/com/walmartlabs/concord/db/PgUtils.java +++ b/server/db/src/main/java/com/walmartlabs/concord/db/PgUtils.java @@ -85,6 +85,10 @@ public static Condition jsonbTextNotExistsByPath(Field field, List {1} ?? {2}", field, inline(toPath(path)), DSL.value(value)); } + public static Condition jsonbTextMatch(Field field, List path, String value) { + return DSL.condition("{0} #>> {1} ~ {2}", field, inline(toPath(path)), DSL.value(value)); + } + /** * Returns a JOOQ field "now - d" where "d" is the specified duration. * The result is rounded down to seconds. diff --git a/server/impl/src/main/java/com/walmartlabs/concord/server/process/queue/FilterUtils.java b/server/impl/src/main/java/com/walmartlabs/concord/server/process/queue/FilterUtils.java index ee07411d93..c7cd70ed75 100644 --- a/server/impl/src/main/java/com/walmartlabs/concord/server/process/queue/FilterUtils.java +++ b/server/impl/src/main/java/com/walmartlabs/concord/server/process/queue/FilterUtils.java @@ -55,7 +55,9 @@ public final class FilterUtils { SuffixMapping.of(".notEndsWith", ProcessFilter.FilterType.NOT_ENDS_WITH), SuffixMapping.of(".ge", ProcessFilter.FilterType.GREATER_OR_EQUALS), - SuffixMapping.of(".len", ProcessFilter.FilterType.LESS_OR_EQUALS_OR_NULL) + SuffixMapping.of(".len", ProcessFilter.FilterType.LESS_OR_EQUALS_OR_NULL), + + SuffixMapping.of(".rm", ProcessFilter.FilterType.REGEXP_MATCH) }; public static List parseDate(String paramName, UriInfo uriInfo) { @@ -152,6 +154,10 @@ public static void applyJson(SelectQuery q, Field column, List m = new MultivaluedHashMap<>(); + m.put("test.rm", Collections.singletonList("myValue")); + + UriInfo uriInfo = mock(UriInfo.class); + when(uriInfo.getQueryParameters()).thenReturn(m); + + List filter = FilterUtils.parseJson("test", uriInfo); + assertEquals(1, filter.size()); + assertEquals(REGEXP_MATCH, filter.get(0).type()); + assertEquals("myValue", filter.get(0).value()); + } +} From b973042fa81dde8148492bf585cb991e29002380 Mon Sep 17 00:00:00 2001 From: brig Date: Mon, 25 Dec 2023 11:31:30 +0100 Subject: [PATCH 2/3] license header up --- .../server/process/queue/FilterUtilsTest.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/server/impl/src/test/java/com/walmartlabs/concord/server/process/queue/FilterUtilsTest.java b/server/impl/src/test/java/com/walmartlabs/concord/server/process/queue/FilterUtilsTest.java index 1b8474df75..21c5720617 100644 --- a/server/impl/src/test/java/com/walmartlabs/concord/server/process/queue/FilterUtilsTest.java +++ b/server/impl/src/test/java/com/walmartlabs/concord/server/process/queue/FilterUtilsTest.java @@ -1,5 +1,25 @@ package com.walmartlabs.concord.server.process.queue; +/*- + * ***** + * Concord + * ----- + * Copyright (C) 2017 - 2023 Walmart Inc. + * ----- + * 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. + * ===== + */ + import org.junit.jupiter.api.Test; import javax.ws.rs.core.MultivaluedHashMap; From 2e2367780a864b5aeb93294001e0466da10638e4 Mon Sep 17 00:00:00 2001 From: brig Date: Mon, 25 Dec 2023 19:04:28 +0100 Subject: [PATCH 3/3] review up: rm -> regexp --- .../walmartlabs/concord/server/process/queue/FilterUtils.java | 2 +- .../concord/server/process/queue/FilterUtilsTest.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/server/impl/src/main/java/com/walmartlabs/concord/server/process/queue/FilterUtils.java b/server/impl/src/main/java/com/walmartlabs/concord/server/process/queue/FilterUtils.java index c7cd70ed75..924dbc1561 100644 --- a/server/impl/src/main/java/com/walmartlabs/concord/server/process/queue/FilterUtils.java +++ b/server/impl/src/main/java/com/walmartlabs/concord/server/process/queue/FilterUtils.java @@ -57,7 +57,7 @@ public final class FilterUtils { SuffixMapping.of(".ge", ProcessFilter.FilterType.GREATER_OR_EQUALS), SuffixMapping.of(".len", ProcessFilter.FilterType.LESS_OR_EQUALS_OR_NULL), - SuffixMapping.of(".rm", ProcessFilter.FilterType.REGEXP_MATCH) + SuffixMapping.of(".regexp", ProcessFilter.FilterType.REGEXP_MATCH) }; public static List parseDate(String paramName, UriInfo uriInfo) { diff --git a/server/impl/src/test/java/com/walmartlabs/concord/server/process/queue/FilterUtilsTest.java b/server/impl/src/test/java/com/walmartlabs/concord/server/process/queue/FilterUtilsTest.java index 21c5720617..c06a2dc7b7 100644 --- a/server/impl/src/test/java/com/walmartlabs/concord/server/process/queue/FilterUtilsTest.java +++ b/server/impl/src/test/java/com/walmartlabs/concord/server/process/queue/FilterUtilsTest.java @@ -37,7 +37,7 @@ public class FilterUtilsTest { @Test public void testRegularExpressionMatch() { MultivaluedHashMap m = new MultivaluedHashMap<>(); - m.put("test.rm", Collections.singletonList("myValue")); + m.put("test.regexp", Collections.singletonList("myValue")); UriInfo uriInfo = mock(UriInfo.class); when(uriInfo.getQueryParameters()).thenReturn(m);