Skip to content

Commit

Permalink
remove isPublic field changes from bugfix/filters-on-ispublic-panos…
Browse files Browse the repository at this point in the history
…c-field-#308 #329
  • Loading branch information
VKTB committed Feb 14, 2022
1 parent 11d59e8 commit 8d0496d
Showing 1 changed file with 0 additions and 44 deletions.
44 changes: 0 additions & 44 deletions datagateway_api/src/search_api/query_filter_factory.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
from datetime import datetime, timezone
import logging

from dateutil.relativedelta import relativedelta

from datagateway_api.src.common.base_query_filter_factory import QueryFilterFactory
from datagateway_api.src.common.config import Config
from datagateway_api.src.common.exceptions import FilterError, SearchAPIError
from datagateway_api.src.search_api.filters import (
SearchAPIIncludeFilter,
Expand Down Expand Up @@ -300,14 +297,6 @@ def get_condition_values(conditions_dict):
"Bad Where filter: Invalid operator used with boolean value",
)

if field == "isPublic":
(
value,
operation,
) = SearchAPIQueryFilterFactory.convert_is_public_field_value_and_operation(
value, operation,
)

return field, value, operation

@staticmethod
Expand Down Expand Up @@ -344,36 +333,3 @@ def prefix_where_filter_field_with_entity_name(where_filters, entity_name):
)
if isinstance(where_filter, SearchAPIWhereFilter):
where_filter.field = f"{entity_name}.{where_filter.field}"

@staticmethod
def convert_is_public_field_value_and_operation(value, operation):
"""
The ICAT mappings for the isPublic PaNOSC fields are not direct and as a result
of this, we calculate whether data is public or not at the Search API level.
For example, in the case of ISIS, Dataset's isPublic field maps to Dataset's
createTime field in ICAT. We take this datetime value and determine whether it
is public or not by checking whether the datetime is more than 3 years ago or
not. The isPublic fields are of type boolean so any WHERE filter applied to
them will have a value that is boolean too. As a result of this, the value and
operation need to be converted to a format appropriate for the mapped ICAT
field. In the example above, if the filter asks for all Datasets whose isPublic
fields are set to True to be returned, then this method changes the WHERE
filter value to a three years ago datetime value and the operator to less than
so that all Datasets older than 3 years (which ISIS considers public) are
returned.
"""
value = not value if operation == "neq" else value
if value is True:
operation = "lt"
else:
operation = "gt"

current_datetime = datetime.now(timezone.utc)
rd = relativedelta(
years=Config.config.search_api.num_of_years_determining_public_data,
)
# The timezone part has a plus sign so replacing
# with a blank space to avoid issues
value = str(current_datetime - rd).replace("+", " ")

return value, operation

0 comments on commit 8d0496d

Please sign in to comment.