Skip to content

Commit

Permalink
search: remove ES6 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
kpsherva committed Jan 10, 2024
1 parent 5471737 commit a564467
Show file tree
Hide file tree
Showing 10 changed files with 15 additions and 45 deletions.
2 changes: 1 addition & 1 deletion docker-services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ services:
- "15672:15672"
- "5672:5672"
search:
image: opensearchproject/opensearch:2.5.0
image: opensearchproject/opensearch:2.11.1
environment:
- bootstrap.memory_lock=true
- "OPENSEARCH_JAVA_OPTS=-Xms512m -Xmx512m"
Expand Down
11 changes: 3 additions & 8 deletions invenio_app_ils/circulation/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
from invenio_db import db
from invenio_pidstore.models import PIDStatus
from invenio_pidstore.providers.recordid_v2 import RecordIdProviderV2
from invenio_search.engine import uses_es7

from invenio_app_ils.circulation.search import (
get_all_expiring_or_overdue_loans_by_patron_pid,
Expand All @@ -44,8 +43,6 @@
from invenio_app_ils.minters import pid_minter
from invenio_app_ils.proxies import current_app_ils

lt_es7 = not uses_es7

# override default `invenio-circulation` minters to use the base32 PIDs
# CIRCULATION_LOAN_PID_TYPE is already defined in `invenio-circulation`
ILS_CIRCULATION_LOAN_MINTER = "ilsloanid"
Expand Down Expand Up @@ -93,7 +90,7 @@ def patron_has_request_on_document(patron_pid, document_pid):
patron_pid=patron_pid, document_pid=document_pid, filter_states=states
)
search_result = search.execute()
total = search_result.hits.total if lt_es7 else search_result.hits.total.value
total = search_result.hits.total.value
if total > 0:
return search_result.hits[0]
else:
Expand All @@ -110,7 +107,7 @@ def patron_has_active_loan_or_request_on_document(patron_pid, document_pid):
patron_pid=patron_pid, document_pid=document_pid, filter_states=states
)
search_result = search.execute()
total = search_result.hits.total if lt_es7 else search_result.hits.total.value
total = search_result.hits.total.value
if total > 0:
return search_result.hits[0]
else:
Expand Down Expand Up @@ -170,9 +167,7 @@ def patron_has_active_loan_on_item(patron_pid, item_pid):
filter_states=current_app.config["CIRCULATION_STATES_LOAN_ACTIVE"],
)
search_result = search.execute()
return (
search_result.hits.total > 0 if lt_es7 else search_result.hits.total.value > 0
)
return search_result.hits.total.value > 0


def checkout_loan(
Expand Down
12 changes: 2 additions & 10 deletions invenio_app_ils/documents/jsonresolvers/document_circulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
"""Resolve the circulation status referenced in the Document."""

import jsonresolver
from invenio_search.engine import uses_es7
from werkzeug.routing import Rule

from invenio_app_ils.circulation.search import (
Expand All @@ -19,9 +18,6 @@
from invenio_app_ils.ill.api import BORROWING_REQUEST_PID_TYPE
from invenio_app_ils.items.search import get_items_aggregated_by_statuses

lt_es7 = not uses_es7


# Note: there must be only one resolver per file,
# otherwise only the last one is registered

Expand Down Expand Up @@ -62,7 +58,7 @@ def circulation_resolver(document_pid):
items_for_reference_count = 0
item_statuses = get_items_aggregated_by_statuses(document_pid)
item_result = item_statuses.execute()
items_count = item_result.hits.total if lt_es7 else item_result.hits.total.value
items_count = item_result.hits.total.value
for bucket in item_result.aggregations.statuses.buckets:
if bucket["key"] not in "CAN_CIRCULATE":
unavailable_items_count += bucket["doc_count"]
Expand Down Expand Up @@ -106,11 +102,7 @@ def circulation_resolver(document_pid):
next_available_loans = (
get_loan_next_available_date(document_pid).execute().hits
)
total = (
next_available_loans.total
if lt_es7
else next_available_loans.total.value
)
total = next_available_loans.total.value
if total > 0:
next_date = next_available_loans[0].end_date
circulation["next_available_date"] = next_date
Expand Down
2 changes: 1 addition & 1 deletion invenio_app_ils/patrons/anonymization.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from copy import deepcopy

from flask import current_app
from invenio_accounts.models import SessionActivity, User, userrole, LoginInformation
from invenio_accounts.models import LoginInformation, SessionActivity, User, userrole
from invenio_circulation.proxies import current_circulation
from invenio_db import db
from invenio_oauthclient.models import RemoteAccount, RemoteToken, UserIdentity
Expand Down
3 changes: 0 additions & 3 deletions invenio_app_ils/patrons/indexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
from invenio_circulation.search.api import search_by_patron_pid
from invenio_db import db
from invenio_indexer.api import RecordIndexer
from invenio_search.engine import uses_es7

from invenio_app_ils.acquisition.api import ORDER_PID_TYPE
from invenio_app_ils.acquisition.proxies import current_ils_acq
Expand All @@ -28,8 +27,6 @@
from invenio_app_ils.patrons.api import PATRON_PID_TYPE
from invenio_app_ils.proxies import current_app_ils

lt_es7 = not uses_es7


def get_loans(patron_pid):
"""Get referenced loans."""
Expand Down
9 changes: 1 addition & 8 deletions invenio_app_ils/patrons/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,12 @@
from flask import Blueprint, current_app
from flask_login import current_user
from invenio_circulation.search.api import search_by_patron_item_or_document
from invenio_search.engine import uses_es7
from webargs import fields
from webargs.flaskparser import use_kwargs

from invenio_app_ils.circulation.search import get_loans_aggregated_by_states
from invenio_app_ils.permissions import need_permissions

lt_es7 = not uses_es7


def get_user_loan_information_blueprint(_):
"""Add patron views to the blueprint."""
Expand Down Expand Up @@ -79,11 +76,7 @@ def retrieve_user_loans_information(patron_pid, document_pid):

search = search.sort({"end_date": {"order": "desc"}})
search_result = search.execute()
has_past_loans = (
search_result.hits.total > 0
if lt_es7
else search_result.hits.total.value > 0
)
has_past_loans = search_result.hits.total.value > 0
if has_past_loans:
last_loan = search_result.hits[0]
user_information["last_loan"] = last_loan["end_date"]
Expand Down
3 changes: 0 additions & 3 deletions invenio_app_ils/vocabularies/indexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@
"""Vocabulary indexer APIs."""

from invenio_indexer.api import RecordIndexer
from invenio_search.engine import uses_es7

lt_es7 = not uses_es7


class VocabularyIndexer(RecordIndexer):
Expand Down
5 changes: 1 addition & 4 deletions invenio_app_ils/vocabularies/jsonresolvers/licenses.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,11 @@
from urllib.parse import unquote_plus

import jsonresolver
from invenio_search.engine import uses_es7
from werkzeug.routing import Rule

from invenio_app_ils.proxies import current_app_ils
from invenio_app_ils.vocabularies.api import VOCABULARY_TYPE_LICENSE

lt_es7 = not uses_es7

# Note: there must be only one resolver per file,
# otherwise only the last one is registered

Expand All @@ -39,7 +36,7 @@ def license_resolver(license_id):
type=VOCABULARY_TYPE_LICENSE, key=unquote_plus(_id)
)
search_result = search.execute()
total = search_result.hits.total if lt_es7 else search_result.hits.total.value
total = search_result.hits.total.value

_license = dict()
if total == 1:
Expand Down
7 changes: 3 additions & 4 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -69,19 +69,18 @@ install_requires =
# needed to have namedtuple json serialized as dict
simplejson>=3.8.1,<4.0.0
pluggy>=0.13.1,<1.0.0
# breaking changes in version 4
jsonschema>=4.3.0,<5.0.0
# Version 2.1.0 removes `TimedJSONWebSignatureSerializer`
itsdangerous>=1.1,<2.1
# Version 2.1.0 removes `werkzeug.security.safe_str_cmp`
Werkzeug>=2.2.0,<2.3.0
# sqlalchemy needs upgrades in invenio core to unpin
SQLAlchemy>=1.3.0,<2.0.0
# Pinned due to before_first_request deprecation https://flask.palletsprojects.com/en/2.2.x/api/#flask.Flask.before_first_request
Flask>=2.2.0,<2.3.0
Werkzeug>=2.2.0,<2.3.0

[options.extras_require]
tests =
pytest-black>=0.3.0,<0.3.10
pytest-black>=0.3.0
mock>=2.0.0
pytest-invenio>=2.0.0,<3.0.0
docker-services-cli>=0.6.0
Expand Down
6 changes: 3 additions & 3 deletions tests/api/document_requests/test_notifications_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ def filter_document_request_messages(record, action, **kwargs):
# remove footer
app_with_notifs.config["ILS_NOTIFICATIONS_TEMPLATES"] = {}
# set filtering on the document requests
app_with_notifs.config["ILS_NOTIFICATIONS_FILTER_DOCUMENT_REQUEST"] = (
filter_document_request_messages
)
app_with_notifs.config[
"ILS_NOTIFICATIONS_FILTER_DOCUMENT_REQUEST"
] = filter_document_request_messages

send_document_request_notification(
document_request, action="decline", msg_extra_ctx={}
Expand Down

0 comments on commit a564467

Please sign in to comment.