-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #292 from ral-facilities/feature/query-params-sear…
…ch-api-#259 Query Parameters Inputs for Search API
- Loading branch information
Showing
15 changed files
with
2,660 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ venv/ | |
.idea/ | ||
*.pyc | ||
logs.log* | ||
config.json | ||
config.json* | ||
.vscode/ | ||
.nox/ | ||
.python-version | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
from abc import ABC, abstractstaticmethod | ||
|
||
|
||
class QueryFilterFactory(ABC): | ||
@abstractstaticmethod | ||
def get_query_filter(request_filter, entity_name=None): # noqa: B902, N805 | ||
""" | ||
Given a filter, return a matching Query filter object | ||
:param request_filter: The filter to create the QueryFilter for | ||
:type request_filter: :class:`dict` | ||
:param entity_name: Entity name of the endpoint, optional (only used for search | ||
API, not DataGateway API) | ||
:type entity_name: :class:`str` | ||
:return: The QueryFilter object created | ||
""" | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
class NestedWhereFilters: | ||
def __init__(self, lhs, rhs, joining_operator): | ||
""" | ||
Class to represent nested conditions that use different boolean operators e.g. | ||
`(A OR B) AND (C OR D)`. This works by joining the two conditions with a boolean | ||
operator | ||
:param lhs: Left hand side of the condition - either a string condition, WHERE | ||
filter or instance of this class | ||
:type lhs: Any class that has `__str__()` implemented, but use cases will be for | ||
:class:`str` or :class:`SearchAPIWhereFilter` or :class:`NestedWhereFilters` | ||
:param rhs: Right hand side of the condition - either a string condition, WHERE | ||
filter or instance of this class | ||
:type rhs: Any class that has `__str__()` implemented, but use cases will be for | ||
:class:`str` or :class:`SearchAPIWhereFilter` or :class:`NestedWhereFilters` | ||
:param joining_operator: Boolean operator used to join the conditions of `lhs` | ||
`rhs` (e.g. `AND` or `OR`) | ||
:type joining_operator: :class:`str` | ||
""" | ||
|
||
# Ensure each side is in a list for consistency for string conversion | ||
if not isinstance(lhs, list): | ||
lhs = [lhs] | ||
if not isinstance(rhs, list): | ||
rhs = [rhs] | ||
|
||
self.lhs = lhs | ||
self.rhs = rhs | ||
self.joining_operator = joining_operator | ||
|
||
def __str__(self): | ||
""" | ||
Join the condition on the left with the one on the right with the boolean | ||
operator | ||
""" | ||
boolean_algebra_list = [self.lhs, self.rhs] | ||
try: | ||
boolean_algebra_list.remove([None]) | ||
except ValueError: | ||
# If neither side contains `None`, we should continue as normal | ||
pass | ||
|
||
# If either side contains a list of WHERE filter objects, flatten the conditions | ||
conditions = [str(m) for n in (i for i in boolean_algebra_list) for m in n] | ||
operator = f" {self.joining_operator} " | ||
|
||
return f"({operator.join(conditions)})" | ||
|
||
def __repr__(self): | ||
return ( | ||
f"LHS: {repr(self.lhs)}, RHS: {repr(self.rhs)}, Operator:" | ||
f" {repr(self.joining_operator)}" | ||
) |
Oops, something went wrong.