diff --git a/src/main/java/mil/dds/anet/beans/search/ReportSearchQuery.java b/src/main/java/mil/dds/anet/beans/search/ReportSearchQuery.java index 71d4499e16..dc92102ea6 100644 --- a/src/main/java/mil/dds/anet/beans/search/ReportSearchQuery.java +++ b/src/main/java/mil/dds/anet/beans/search/ReportSearchQuery.java @@ -113,6 +113,10 @@ public static enum EngagementStatus { @GraphQLQuery @GraphQLInputField private Boolean sensitiveInfo; + @GraphQLQuery + @GraphQLInputField + private String withinPolygon; + // internal search parameter: private boolean systemSearch; @@ -361,6 +365,14 @@ public void setSensitiveInfo(Boolean sensitiveInfo) { this.sensitiveInfo = sensitiveInfo; } + public String getWithinPolygon() { + return withinPolygon; + } + + public void setWithinPolygon(String withinPolygon) { + this.withinPolygon = withinPolygon; + } + @JsonIgnore public boolean isSystemSearch() { return systemSearch; diff --git a/src/main/java/mil/dds/anet/search/AbstractReportSearcher.java b/src/main/java/mil/dds/anet/search/AbstractReportSearcher.java index 94cc087b03..7321baab84 100644 --- a/src/main/java/mil/dds/anet/search/AbstractReportSearcher.java +++ b/src/main/java/mil/dds/anet/search/AbstractReportSearcher.java @@ -272,11 +272,17 @@ protected void buildQuery(Set subFields, ReportSearchQuery query) { } } + if (query.getWithinPolygon() != null) { + addWithinPolygon(query); + } + addOrderByClauses(qb, query); } protected abstract void addTextQuery(ReportSearchQuery query); + protected abstract void addWithinPolygon(ReportSearchQuery query); + protected abstract void addBatchClause(ReportSearchQuery query); @SuppressWarnings("unchecked") diff --git a/src/main/java/mil/dds/anet/search/mssql/MssqlReportSearcher.java b/src/main/java/mil/dds/anet/search/mssql/MssqlReportSearcher.java index 45fb339054..5abff654e1 100644 --- a/src/main/java/mil/dds/anet/search/mssql/MssqlReportSearcher.java +++ b/src/main/java/mil/dds/anet/search/mssql/MssqlReportSearcher.java @@ -71,6 +71,14 @@ protected void addTextQuery(ReportSearchQuery query) { qb.addSqlArg("fullTextQuery", qb.getFullTextQuery(text)); } + @Override + protected void addWithinPolygon(ReportSearchQuery query) { + qb.addWhereClause(String.format( + "\"locationUuid\" IN (SELECT \"uuid\" FROM locations WHERE " + + "\"gis_point\".STWithin(geometry::STGeomFromText('%1$s', 3857)) = 1)", + query.getWithinPolygon())); + } + @Override protected void addBatchClause(ReportSearchQuery query) { addBatchClause(outerQb, query); diff --git a/src/main/java/mil/dds/anet/search/pg/PostgresqlReportSearcher.java b/src/main/java/mil/dds/anet/search/pg/PostgresqlReportSearcher.java index 375b760ec4..5fb141dc7a 100644 --- a/src/main/java/mil/dds/anet/search/pg/PostgresqlReportSearcher.java +++ b/src/main/java/mil/dds/anet/search/pg/PostgresqlReportSearcher.java @@ -6,6 +6,7 @@ import mil.dds.anet.beans.Report; import mil.dds.anet.beans.lists.AnetBeanList; import mil.dds.anet.beans.search.ISearchQuery.SortOrder; +import mil.dds.anet.beans.search.LocationSearchQuery; import mil.dds.anet.beans.search.ReportSearchQuery; import mil.dds.anet.database.mappers.ReportMapper; import mil.dds.anet.search.AbstractReportSearcher; @@ -43,6 +44,14 @@ protected void addTextQuery(ReportSearchQuery query) { addFullTextSearch("reports", query.getText(), query.isSortByPresent()); } + @Override + protected void addWithinPolygon(ReportSearchQuery query) { + qb.addWhereClause(String.format( + "\"locationUuid\" IN (SELECT \"uuid\" FROM locations WHERE ST_Within(\"gis_point\", " + + "ST_GeomFromText('%1$s', 3857)))", + query.getWithinPolygon())); + } + @Override protected void addBatchClause(ReportSearchQuery query) { addBatchClause(qb, query);