Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

patron_transaction: create new resource json and mapping. #716

Merged
merged 1 commit into from
Jan 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions rero_ils/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
from .modules.notifications.api import Notification
from .modules.organisations.api import Organisation
from .modules.organisations.permissions import can_update_organisations_factory
from .modules.patron_transactions.api import PatronTransaction
from .modules.patron_types.api import PatronType
from .modules.patrons.api import Patron
from .modules.patrons.permissions import can_delete_patron_factory, \
Expand Down Expand Up @@ -521,6 +522,39 @@ def _(x):
update_permission_factory_imp=can_update_patron_factory,
delete_permission_factory_imp=can_delete_patron_factory,
),
pttr=dict(
pid_type='pttr',
pid_minter='patron_transaction_id',
pid_fetcher='patron_transaction_id',
search_class=RecordsSearch,
search_index='patron_transactions',
search_type=None,
indexer_class=IlsRecordIndexer,
record_serializers={
'application/json': (
'rero_ils.modules.serializers:json_v1_response'
)
},
search_serializers={
'application/json': (
'rero_ils.modules.serializers:json_v1_search'
)
},
record_loaders={
'application/json': lambda: PatronTransaction(request.get_json()),
},
record_class='rero_ils.modules.patron_transactions.api:PatronTransaction',
list_route='/patron_transactions/',
item_route='/patron_transactions/<pid(pttr, record_class="rero_ils.modules.patron_transactions.api:PatronTransaction"):pid_value>',
default_media_type='application/json',
max_result_window=10000,
search_factory_imp='rero_ils.query:search_factory',
read_permission_factory_imp=allow_all,
list_permission_factory_imp=allow_all,
create_permission_factory_imp=deny_all,
update_permission_factory_imp=deny_all,
delete_permission_factory_imp=deny_all,
),
ptty=dict(
pid_type='ptty',
pid_minter='patron_type_id',
Expand Down Expand Up @@ -1236,6 +1270,7 @@ def _(x):
'budg': '/budgets/budget-v0.0.1.json',
'acor': '/acq_orders/acq_order-v0.0.1.json',
'acol': '/acq_order_lines/acq_order_line-v0.0.1.json',
'pttr': '/patron_transactions/patron_transaction-v0.0.1.json',
}

# Login Configuration
Expand Down
18 changes: 18 additions & 0 deletions rero_ils/modules/patron_transactions/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# -*- coding: utf-8 -*-
#
# RERO ILS
# Copyright (C) 2019 RERO
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, version 3 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

"""Patron Transaction Records."""
56 changes: 56 additions & 0 deletions rero_ils/modules/patron_transactions/api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# -*- coding: utf-8 -*-
#
# RERO ILS
# Copyright (C) 2019 RERO
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, version 3 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

"""API for manipulating patron transactions."""

from functools import partial

from .models import PatronTransactionIdentifier
from ..api import IlsRecord, IlsRecordsSearch
from ..fetchers import id_fetcher
from ..minters import id_minter
from ..providers import Provider

# provider
PatronTransactionProvider = type(
'PatronTransactionProvider',
(Provider,),
dict(identifier=PatronTransactionIdentifier, pid_type='pttr')
)
# minter
patron_transaction_id_minter = partial(
id_minter, provider=PatronTransactionProvider)
# fetcher
patron_transaction_id_fetcher = partial(
id_fetcher, provider=PatronTransactionProvider)


class PatronTransactionsSearch(IlsRecordsSearch):
"""Patron Transactions Search."""

class Meta:
"""Search only on patron transaction index."""

index = 'patron_transactions'


class PatronTransaction(IlsRecord):
"""Patron Transaction class."""

minter = patron_transaction_id_minter
fetcher = patron_transaction_id_fetcher
provider = PatronTransactionProvider
38 changes: 38 additions & 0 deletions rero_ils/modules/patron_transactions/jsonresolver.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# -*- coding: utf-8 -*-
#
# RERO ILS
# Copyright (C) 2019 RERO
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, version 3 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

"""Patron Transaction resolver."""

import jsonresolver
from flask import current_app
from invenio_pidstore.models import PersistentIdentifier, PIDStatus


@jsonresolver.route('/api/patron_transactions/<pid>', host='ils.rero.ch')
def patron_transaction_resolver(pid):
"""Resolver for patron transaction record."""
persistent_id = PersistentIdentifier.get('pttr', pid)
if persistent_id.status == PIDStatus.REGISTERED:
return dict(pid=persistent_id.pid_value)
current_app.logger.error(
'record resolver error: /api/patron_transactions/{pid} \
{persistent_id}'.format(
pid=pid,
persistent_id=persistent_id
)
)
raise Exception('unable to resolve')
20 changes: 20 additions & 0 deletions rero_ils/modules/patron_transactions/jsonschemas/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
#
# RERO ILS
# Copyright (C) 2019 RERO
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, version 3 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

"""JSON schemas."""

from __future__ import absolute_import, print_function
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"title": "Patron Transaction",
"description": "JSON schema for Patron Transaction.",
"additionalProperties": false,
"required": [
"$schema",
"pid",
"creation_date",
"status",
"type",
"patron"
],
"properties": {
"$schema": {
"title": "Schema",
"description": "Schema to validate Patron Transaction records against.",
"type": "string",
"minLength": 9,
"default": "https://ils.rero.ch/schema/patron_transactions/patron_transaction-v0.0.1.json"
},
"pid": {
"title": "Patron Transaction ID",
"type": "string",
"minLength": 1
},
"creation_date": {
"type": "string",
"format": "date-time",
"title": "Patron Transaction creation date"
},
"note": {
"title": "Patron Transaction Note",
"description": "Additional informations about patron transaction",
"type": "string",
"minLength": 3
},
"status": {
"title": "Status",
"type": "string",
"enum": [
"open",
"closed"
],
"default": "open",
"form": {
"options": [
{
"label": "open",
"value": "open"
},
{
"label": "closed",
"value": "closed"
}
]
}
},
"type": {
"title": "Patron Transaction Type",
"type": "string",
"enum": [
"overdue",
"photocopy",
"subscription",
"lost",
"damaged",
"Interlibrary loan",
"other"
],
"default": "overdue",
"form": {
"options": [
{
"label": "overdue",
"value": "overdue"
},
{
"label": "photocopy",
"value": "photocopy"
},
{
"label": "subscription",
"value": "subscription"
},
{
"label": "lost",
"value": "lost"
},
{
"label": "damaged",
"value": "damaged"
},
{
"label": "Interlibrary loan",
"value": "Interlibrary loan"
},
{
"label": "other",
"value": "other"
}
]
}
},
BadrAly marked this conversation as resolved.
Show resolved Hide resolved
"patron": {
"title": "Patron",
"type": "object",
"properties": {
"$ref": {
"title": "Patron URI",
"type": "string",
"pattern": "^https://ils.rero.ch/api/patrons/.*?$"
}
}
},
"loan": {
"title": "Loan",
"type": "object",
"properties": {
"$ref": {
"title": "Loan URI",
"type": "string",
"pattern": "^https://ils.rero.ch/api/loans/.*?$"
}
}
},
"notification": {
"title": "Notification",
"type": "object",
"properties": {
"$ref": {
"title": "Notification URI",
"type": "string",
"pattern": "^https://ils.rero.ch/api/notifications/.*?$"
}
}
}
}
}
20 changes: 20 additions & 0 deletions rero_ils/modules/patron_transactions/mappings/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
#
# RERO ILS
# Copyright (C) 2019 RERO
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, version 3 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

"""Elasticsearch mappings."""

from __future__ import absolute_import, print_function
20 changes: 20 additions & 0 deletions rero_ils/modules/patron_transactions/mappings/v6/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
#
# RERO ILS
# Copyright (C) 2019 RERO
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, version 3 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

"""Elasticsearch mappings."""

from __future__ import absolute_import, print_function
Loading