Skip to content
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

Feat: no exception if dateformat and no date provided #1006

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -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;
Expand Down Expand Up @@ -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<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 +164,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
Loading