Repository: hydroshare/hydroshare

Issue:
Bounding Box Filter Not Working in REST API
Looking at the current implementation of the bounding box filter here: https://github.com/hydroshare/hydroshare/blob/c861f97af96dbdbe4d9e61c27fd1c48175e2d9aa/hs_core/hydroshare/users.py#L316-L344, it seems like we need to specify a `coverage_type` value of either `box` or `point` before the bounding box parameters of `north`, `east`, `west`, and `south` are taken into account. Running a query without specifying `coverage_type` but only the bounding box params results in no filtering, for example see:

 * [hydroshare-philadelphia-20170728.json.txt](https://github.com/hydroshare/hydroshare/files/1184197/hydroshare-philadelphia-20170728.json.txt)
 * [hydroshare-seattle-20170728.json.txt](https://github.com/hydroshare/hydroshare/files/1184196/hydroshare-seattle-20170728.json.txt)

Both are queries for a 1 sq km box in Philadelphia, PA and Seattle, WA and have identical results.

However, if a `coverage_type` is specified, the server crashes and returns an `500 INTERNAL SERVER ERROR`:

```http
$ http --print Hh https://www.hydroshare.org/hsapi/resource/ full_text_search==water north==47.599816005559326 west==-122.32020458774991 east==-122.30687060756253 south==47.608806399331975 coverage_type==box

GET /hsapi/resource/?full_text_search=water&north=47.599816005559326&west=-122.32020458774991&east=-122.30687060756253&south=47.608806399331975&coverage_type=box HTTP/1.1
Accept: */*
Accept-Encoding: gzip, deflate
Connection: keep-alive
Host: www.hydroshare.org
User-Agent: HTTPie/0.9.9

HTTP/1.1 500 INTERNAL SERVER ERROR
Connection: keep-alive
Content-Language: en
Content-Type: text/html; charset=utf-8
Date: Fri, 28 Jul 2017 20:40:32 GMT
Server: nginx/1.11.10
Set-Cookie: csrftoken=pCK7rkhd7eQc9iB8RoBuVbSnhu4rumui; expires=Fri, 27-Jul-2018 20:40:32 GMT; Max-Age=31449600; Path=/
Transfer-Encoding: chunked
Vary: Cookie, Accept-Language
```

Also try this URL: https://www.hydroshare.org/hsapi/resource/?full_text_search=water&north=47.599816005559326&west=-122.32020458774991&east=-122.30687060756253&south=47.608806399331975&coverage_type=box


Discussion:
/cc @aphelionz @aufdenkampe @emiliom @ajrobbins

Resolving patch:
diff --git a/hs_core/hydroshare/users.py b/hs_core/hydroshare/users.py
--- a/hs_core/hydroshare/users.py
+++ b/hs_core/hydroshare/users.py
@@ -1,4 +1,5 @@
 import json
+import logging
 
 from django.core.exceptions import PermissionDenied
 from django.contrib.auth.models import User, Group
@@ -18,6 +19,8 @@
 VIEW = 'view'
 PUBLIC = 'public'
 
+log = logging.getLogger(__name__)
+
 
 def create_account(
         email, username=None, first_name=None, last_name=None, superuser=None, groups=None,
@@ -332,13 +335,16 @@ def get_resource_list(creator=None, group=None, user=None, owner=None, from_date
                 coverages.add(coverage.id)
 
         for coverage in Coverage.objects.filter(type="point"):
-            coverage_shape = Point(
-                coverage.value.get('east', None),
-                coverage.value.get('north', None),
-            )
-
-            if search_polygon.intersects(coverage_shape):
-                coverages.add(coverage.id)
+            try:
+                coverage_shape = Point(
+                    coverage.value.get('east', None),
+                    coverage.value.get('north', None),
+                )
+
+                if search_polygon.intersects(coverage_shape):
+                    coverages.add(coverage.id)
+            except Exception as e:
+                log.error("Coverage value invalid for coverage id %d" % coverage.id)
 
         coverage_hits = (Coverage.objects.filter(id__in=coverages))
         q.append(Q(object_id__in=coverage_hits.values_list('object_id', flat=True)))


Test patch: