-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
patron_transaction: create new resource json and mapping.
Co-Authored-by: Aly Badr <[email protected]> Co-Authored-by: Renaud Michotte <[email protected]>
- Loading branch information
Showing
11 changed files
with
457 additions
and
4 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
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,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/>. | ||
|
||
"""PatronTransaction Records.""" |
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,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): | ||
"""PatronTransactionsSearch.""" | ||
|
||
class Meta: | ||
"""Search only on patron_transaction index.""" | ||
|
||
index = 'patron_transactions' | ||
|
||
|
||
class PatronTransaction(IlsRecord): | ||
"""PatronTransaction class.""" | ||
|
||
minter = patron_transaction_id_minter | ||
fetcher = patron_transaction_id_fetcher | ||
provider = PatronTransactionProvider |
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,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/>. | ||
|
||
"""PatronTransaction 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
20
rero_ils/modules/patron_transactions/jsonschemas/__init__.py
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,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 |
135 changes: 135 additions & 0 deletions
135
...odules/patron_transactions/jsonschemas/patron_transactions/patron_transaction-v0.0.1.json
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,135 @@ | ||
{ | ||
"$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", | ||
"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": "other", | ||
"value": "other" | ||
} | ||
] | ||
} | ||
}, | ||
"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/.*?$" | ||
} | ||
} | ||
} | ||
} | ||
} |
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,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
20
rero_ils/modules/patron_transactions/mappings/v6/__init__.py
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,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 |
Oops, something went wrong.