Skip to content

Commit

Permalink
semifixed valueTypeID search
Browse files Browse the repository at this point in the history
  • Loading branch information
BernhardKoschicek committed Oct 2, 2024
1 parent 73f5de6 commit 8fe870b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 24 deletions.
14 changes: 12 additions & 2 deletions openatlas/api/endpoints/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,20 +99,30 @@ def set_search_param(self) -> None:
for category, value_list in search.items():
for values in value_list:
is_comparable= False
links = []
if check_if_date_search(category):
is_comparable = True
if category == 'valueTypeID':
is_comparable = True
for value in values["values"]:
links.append(Entity.get_links_of_entities(
value[0],
inverse=True))
self.search_param.append({
"search_values": get_search_values(
category,
values),
"logical_operator": values['logicalOperator'],
"operator": values['operator'],
"category": category,
"is_comparable": is_comparable})

"is_comparable": is_comparable,
"value_type_links":
flatten_list_and_remove_duplicates(links)})

# Todo: fix multiple valueTypeID searches, e.g.
# search={"valueTypeID":[{"operator":"equal","values":[(150412,34)],
# "logicalOperator":"or"}]}&search={"valueTypeID":[{"operator":"equal",
# "values":[(131994,13.5),(131997,3.7)],"logicalOperator":"or"}]}
def search_filter(self, entity: Entity) -> bool:
for param in self.search_param:
if not search_entity(entity, param):
Expand Down
33 changes: 11 additions & 22 deletions openatlas/api/resources/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from openatlas.api.resources.util import (
flatten_list_and_remove_duplicates, get_linked_entities_id_api)
from openatlas.models.entity import Entity
from openatlas.models.entity import Entity, Link


def get_search_values(
Expand All @@ -18,10 +18,8 @@ def get_search_values(
case "relationToID":
values = flatten_list_and_remove_duplicates(
[get_linked_entities_id_api(value) for value in values])
# case "valueTypeID":
# values = flatten_list_and_remove_duplicates(
# [search_for_value_type(value, parameter) for value in
# values])
case "valueTypeID":
values = [value[1] for value in values]
case _:
values = [
value.lower() if isinstance(value, str) else value
Expand All @@ -32,19 +30,13 @@ def get_search_values(



def search_entity(entity: Entity, param: dict[str, Any]) -> bool:
def search_entity(entity: Entity | Link, param: dict[str, Any]) -> bool:
entity_values = value_to_be_searched(entity, param)
operator_ = param['operator']
search_values = param['search_values']
logical_operator = param['logical_operator']
is_comparable = param['is_comparable']

# Problem is, that we get not only one value to compare.
# How compare multiple?
if param['category'] == 'valueTypeID':
search_values = [value[1] for value in search_values]
print(search_values)

if not entity_values and (operator_ == 'like' or is_comparable):
return False

Expand All @@ -63,7 +55,8 @@ def search_entity(entity: Entity, param: dict[str, Any]) -> bool:
bool_values.append(bool(not any(
item in entity_values for item in search_value)))
return all(bool_values)

if entity_values:
print(entity_values)
bool_ = False
match operator_:
case 'equal' if logical_operator == 'or':
Expand Down Expand Up @@ -107,7 +100,7 @@ def value_to_be_searched(
-> list[int | str | float] | Optional[datetime64] | Optional[float]:
value: list[int | str | float] | Optional[datetime64]| Optional[float] = []
match param['category']:
case "entityID" | "relationToID" | "valueTypeID":
case "entityID" | "relationToID":
value = [entity.id]
case "entityName":
value = [entity.name.lower()]
Expand All @@ -134,14 +127,10 @@ def value_to_be_searched(
case "endTo":
value = entity.end_to
case "valueTypeID":
links = Entity.get_links_of_entities(
param['values'][0],
inverse=True)
for link_ in links:
if link_.description:
value = [float(entity.description)] \
if param['operator'] in ['equal', 'notEqual'] \
else float(entity.description)
value = []
for link_ in param['value_type_links']:
if entity.id == link_.domain.id:
value.append(float(link_.description))
case _:
value = []
return value

0 comments on commit 8fe870b

Please sign in to comment.