Skip to content

Commit

Permalink
HotFix coordinate out of range
Browse files Browse the repository at this point in the history
  • Loading branch information
mbarbet committed Mar 1, 2019
1 parent cdf9fd2 commit 79d0958
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
18 changes: 17 additions & 1 deletion arlas-core/src/main/java/io/arlas/server/core/FluidSearch.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,15 @@
import org.elasticsearch.search.aggregations.support.ValuesSourceAggregationBuilder;
import org.elasticsearch.search.sort.SortBuilders;
import org.elasticsearch.search.sort.SortOrder;
import org.locationtech.jts.operation.valid.IsValidOp;
import org.locationtech.jts.operation.valid.TopologyValidationError;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.util.*;
import java.util.regex.Pattern;
import java.util.stream.Collectors;


public class FluidSearch {
Expand All @@ -67,6 +70,7 @@ public class FluidSearch {
public static final String INVALID_OPERATOR = "Operand does not equal one of the following values : 'eq', gte', 'gt', 'lte', 'lt', 'like' or 'ne'. ";
public static final String INVALID_Q_FILTER = "Invalid parameter. Please specify the text to search directly or '{fieldname}:{text to search}'. ";
public static final String INVALID_WKT = "Invalid WKT geometry.";
public static final String INVALID_WKT_RANGE = "Invalid WKT geometry.Coordinate out of range";
public static final String INVALID_BBOX = "Invalid BBOX";
public static final String INVALID_SIZE = "Invalid size parameter.";
public static final String INVALID_FROM = "Invalid from parameter.";
Expand Down Expand Up @@ -792,10 +796,22 @@ else if (order.equals(Order.desc))
}

private Geometry readWKT(String geometry) throws ArlasException {
WKTReader wkt = new WKTReader();
GeometryFactory geometryFactory = new GeometryFactory(new PrecisionModel(), 4326);
Envelope affectedBounds = new Envelope(-360, 360, -180, 180);
WKTReader wkt = new WKTReader(geometryFactory);
Geometry polygon = null;
try {
polygon = wkt.read(geometry);
List<Coordinate> filteredCoord = Arrays.stream(polygon.getCoordinates()).filter(coordinate -> affectedBounds.contains(coordinate)).collect(Collectors.toList());
if(filteredCoord.size() != polygon.getCoordinates().length){
throw new InvalidParameterException(INVALID_WKT_RANGE);
}
IsValidOp vaildOp = new IsValidOp(polygon);
TopologyValidationError err = vaildOp.getValidationError();
if (err != null)
{
throw new InvalidParameterException(INVALID_WKT);
}
} catch (ParseException ex) {
throw new InvalidParameterException(INVALID_WKT);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -666,6 +666,12 @@ public void testInvalidFilterParameters() throws Exception {
handleInvalidParameters(header(request.filter));
request.filter.gwithin = null;

request.filter.gintersect = Arrays.asList(new MultiValueFilter<>("POLYGON((1000 10000,10 -10,0 -10,1000 10000))"));
handleInvalidParameters(post(request));
handleInvalidParameters(get("gintersect", request.filter.gintersect.get(0).get(0)));
handleInvalidParameters(header(request.filter));
request.filter.gintersect = null;

request.filter.notgwithin = Arrays.asList(new MultiValueFilter<>("POLYGON((10 10,10 -10,0 -10))"));
handleInvalidParameters(post(request));
handleInvalidParameters(get("notgwithin", request.filter.notgwithin.get(0).get(0)));
Expand Down

0 comments on commit 79d0958

Please sign in to comment.