Skip to content

Commit

Permalink
#3043: Add method for location search with polygon values
Browse files Browse the repository at this point in the history
  • Loading branch information
oayvazoglusim committed Jun 24, 2020
1 parent 50987dc commit 06dff05
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/main/java/mil/dds/anet/beans/search/LocationSearchQuery.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ public class LocationSearchQuery extends AbstractSearchQuery<LocationSearchSortB
@GraphQLInputField
private LocationStatus status;

@GraphQLQuery
@GraphQLInputField
private String withinPolygon;

public LocationSearchQuery() {
super(LocationSearchSortBy.NAME);
}
Expand All @@ -22,4 +26,12 @@ public void setStatus(LocationStatus status) {
this.status = status;
}

public String getWithinPolygon() {
return withinPolygon;
}

public void setWithinPolygon(String withinPolygon) {
this.withinPolygon = withinPolygon;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,18 @@ protected void buildQuery(LocationSearchQuery query) {
qb.addSqlArg("userUuid", DaoUtils.getUuid(query.getUser()));
}

if (query.getWithinPolygon() != null) {
addWithinPolygon(qb, query);
}

addOrderByClauses(qb, query);
}

protected abstract void addTextQuery(LocationSearchQuery query);

protected abstract void addWithinPolygon(AbstractSearchQueryBuilder<?, ?> qb,
LocationSearchQuery query);

protected void addOrderByClauses(AbstractSearchQueryBuilder<?, ?> qb, LocationSearchQuery query) {
switch (query.getSortBy()) {
case CREATED_AT:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,9 @@ protected void addOrderByClauses(AbstractSearchQueryBuilder<?, ?> qb, LocationSe
super.addOrderByClauses(qb, query);
}

@Override
protected void addWithinPolygon(AbstractSearchQueryBuilder<?, ?> qb, LocationSearchQuery query) {
// TODO
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,12 @@ protected void addOrderByClauses(AbstractSearchQueryBuilder<?, ?> qb, LocationSe
super.addOrderByClauses(qb, query);
}

@Override
protected void addWithinPolygon(AbstractSearchQueryBuilder<?, ?> qb, LocationSearchQuery query) {
qb.addWhereClause(String.format(
"\"uuid\" IN (SELECT \"uuid\" FROM locations WHERE ST_Within(\"gis_point\", "
+ "ST_MakePolygon( ST_GeomFromText('%1$s', 3857))))",
query.getWithinPolygon()));
}

}

0 comments on commit 06dff05

Please sign in to comment.