Skip to content

Commit

Permalink
Feat: no exception if dateformat and no date provided
Browse files Browse the repository at this point in the history
  • Loading branch information
mbarbet committed Feb 26, 2025
1 parent c0fc153 commit 8c063fb
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<Expression> f : filter.f) {
fluidSearch = fluidSearch.filter(f, filter.dateformat, filter.righthand);
Expand All @@ -169,7 +170,8 @@ public void applyPartitionFilter(List<Filter> 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)");
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,13 @@
import io.arlas.server.core.model.enumerations.*;
import io.arlas.server.core.model.request.*;
import io.arlas.server.core.model.response.FieldType;
import io.arlas.server.core.services.ExploreService;
import org.apache.commons.lang3.StringUtils;
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;
Expand Down Expand Up @@ -78,6 +81,7 @@ public class CheckParams {
public static final String RAW_GEOMETRIES_NULL_OR_EMPTY = "'geometries' should not be null nor empty";

public static final List<AggregationTypeEnum> GEO_AGGREGATION_TYPE_ENUMS = Arrays.asList(AggregationTypeEnum.geohash, AggregationTypeEnum.geotile, AggregationTypeEnum.geohex);
protected static final Logger LOGGER = LoggerFactory.getLogger(CheckParams.class);

public CheckParams() {
}
Expand Down Expand Up @@ -161,7 +165,9 @@ public static void checkGeoFilter(List<MultiValueFilter<String>> 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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8c063fb

Please sign in to comment.