From cf57e316175d86dc0e767fafe97a0d0af8bfde0c Mon Sep 17 00:00:00 2001 From: MatthieuBarbet Date: Wed, 26 Feb 2025 09:36:17 +0100 Subject: [PATCH] Feat: no exception if dateformat and no date provided --- .../io/arlas/server/core/services/ExploreService.java | 6 ++++-- .../main/java/io/arlas/server/core/utils/CheckParams.java | 7 ++++++- .../server/tests/rest/explore/AbstractFilteredTest.java | 8 -------- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/arlas-core/src/main/java/io/arlas/server/core/services/ExploreService.java b/arlas-core/src/main/java/io/arlas/server/core/services/ExploreService.java index b07a34a01..727bf6fd0 100644 --- a/arlas-core/src/main/java/io/arlas/server/core/services/ExploreService.java +++ b/arlas-core/src/main/java/io/arlas/server/core/services/ExploreService.java @@ -147,7 +147,8 @@ public void applyFilter(Filter filter, FluidSearchService fluidSearch) throws Ar if (filter.f != null && !filter.f.isEmpty()) { CollectionReference collectionReference = fluidSearch.getCollectionReference(); if (!filterFHasDateQuery(filter, collectionReference) && !StringUtil.isNullOrEmpty(filter.dateformat)) { - throw new BadRequestException("dateformat is specified but no date field is queried in f filter (gt, lt, gte, lte or range operations)"); + filter.dateformat = null; + LOGGER.warn("dateformat is specified but no date field is queried in f filter (gt, lt, gte, lte or range operations)"); } for (MultiValueFilter f : filter.f) { fluidSearch = fluidSearch.filter(f, filter.dateformat, filter.righthand); @@ -169,7 +170,8 @@ public void applyPartitionFilter(List filters, FluidSearchService fluidS if (f.f != null && !f.f.isEmpty()) { CollectionReference collectionReference = fluidSearch.getCollectionReference(); if (!filterFHasDateQuery(f, collectionReference) && !StringUtil.isNullOrEmpty(f.dateformat)) { - throw new BadRequestException("dateformat is specified but no date field is queried in f filter (gt, lt, gte, lte or range operations)"); + f.dateformat = null; + LOGGER.warn("dateformat is specified but no date field is queried in f filter (gt, lt, gte, lte or range operations)"); } } } diff --git a/arlas-core/src/main/java/io/arlas/server/core/utils/CheckParams.java b/arlas-core/src/main/java/io/arlas/server/core/utils/CheckParams.java index c57496697..c05da1ea4 100644 --- a/arlas-core/src/main/java/io/arlas/server/core/utils/CheckParams.java +++ b/arlas-core/src/main/java/io/arlas/server/core/utils/CheckParams.java @@ -36,6 +36,8 @@ import org.joda.time.format.DateTimeFormat; import org.locationtech.jts.geom.Geometry; import org.locationtech.jts.geom.Polygon; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.text.DateFormat; import java.text.ParseException; @@ -78,6 +80,7 @@ public class CheckParams { public static final String RAW_GEOMETRIES_NULL_OR_EMPTY = "'geometries' should not be null nor empty"; public static final List GEO_AGGREGATION_TYPE_ENUMS = Arrays.asList(AggregationTypeEnum.geohash, AggregationTypeEnum.geotile, AggregationTypeEnum.geohex); + protected static final Logger LOGGER = LoggerFactory.getLogger(CheckParams.class); public CheckParams() { } @@ -161,7 +164,9 @@ public static void checkGeoFilter(List> geoStrings) thr public static void checkFilter(Filter filter) throws ArlasException { if ((filter.f == null || filter.f.isEmpty()) && !StringUtil.isNullOrEmpty(filter.dateformat)) { - throw new BadRequestException("Date format is specified but no date field is queried in f filter"); + LOGGER.warn("Date format is specified but no date field is queried in f filter"); + // Dont check the dateformat if no date filter provided + return; } checkDateFormat(filter.dateformat); } diff --git a/arlas-tests/src/test/java/io/arlas/server/tests/rest/explore/AbstractFilteredTest.java b/arlas-tests/src/test/java/io/arlas/server/tests/rest/explore/AbstractFilteredTest.java index 41c5eee0d..d4dc641d4 100644 --- a/arlas-tests/src/test/java/io/arlas/server/tests/rest/explore/AbstractFilteredTest.java +++ b/arlas-tests/src/test/java/io/arlas/server/tests/rest/explore/AbstractFilteredTest.java @@ -2083,14 +2083,6 @@ public void testInvalidFilterParameters() throws Exception { handleInvalidParameters(givenFilterableRequestParams().param("f", request.filter.f.get(0).get(0).toString()) .param("dateformat", request.filter.dateformat).when().get(getUrlPath("geodata")).then()); handleInvalidParameters(header(request.filter)); - - // DATEFORMAT : format set when no date field is queried - request.filter.f = Arrays.asList(new MultiValueFilter<>(new Expression("params.job", OperatorEnum.like, "Architect"))); - request.filter.dateformat = "dd-MM-yyyy"; - handleInvalidParameters(post(request)); - handleInvalidParameters(givenFilterableRequestParams().param("f", request.filter.f.get(0).get(0).toString()) - .param("dateformat", request.filter.dateformat).when().get(getUrlPath("geodata")).then()); - handleInvalidParameters(header(request.filter)); } @Test