-
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.
notifications: create resource data model and api
* Adds notification schema, mappings and required objects * Integrate invenio-records 1.2.1 to have a separate table by resource Signed-off-by: Aly Badr <aly.badr@rero.ch>
- Loading branch information
Aly Badr
committed
Jun 5, 2019
1 parent
b72f68c
commit 1e8dde0
Showing
26 changed files
with
1,332 additions
and
84 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
Large diffs are not rendered by default.
Oops, something went wrong.
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
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 -*- | ||
# | ||
# This file is part of RERO ILS. | ||
# Copyright (C) 2017 RERO. | ||
# | ||
# RERO ILS is free software; you can redistribute it | ||
# and/or modify it under the terms of the GNU General Public License as | ||
# published by the Free Software Foundation; either version 2 of the | ||
# License, or (at your option) any later version. | ||
# | ||
# RERO ILS 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 | ||
# General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with RERO ILS; if not, write to the | ||
# Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, | ||
# MA 02111-1307, USA. | ||
# | ||
# In applying this license, RERO does not | ||
# waive the privileges and immunities granted to it by virtue of its status | ||
# as an Intergovernmental Organization or submit itself to any jurisdiction. | ||
|
||
"""Item resolver.""" | ||
|
||
|
||
import jsonresolver | ||
from invenio_pidstore.models import PersistentIdentifier, PIDStatus | ||
|
||
|
||
@jsonresolver.route('/api/items/<pid>', host='ils.rero.ch') | ||
def item_resolver(pid): | ||
"""Item resolver.""" | ||
persistent_id = PersistentIdentifier.get('item', pid) | ||
if persistent_id.status == PIDStatus.REGISTERED: | ||
return dict(pid=persistent_id.pid_value) | ||
raise Exception('unable to resolve') |
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,25 @@ | ||
# -*- coding: utf-8 -*- | ||
# | ||
# This file is part of RERO ILS. | ||
# Copyright (C) 2018 RERO. | ||
# | ||
# RERO ILS is free software; you can redistribute it | ||
# and/or modify it under the terms of the GNU General Public License as | ||
# published by the Free Software Foundation; either version 2 of the | ||
# License, or (at your option) any later version. | ||
# | ||
# RERO ILS 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 | ||
# General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with RERO ILS; if not, write to the | ||
# Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, | ||
# MA 02111-1307, USA. | ||
# | ||
# In applying this license, RERO does not | ||
# waive the privileges and immunities granted to it by virtue of its status | ||
# as an Intergovernmental Organization or submit itself to any jurisdiction. | ||
|
||
"""Notifications 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,75 @@ | ||
# -*- coding: utf-8 -*- | ||
# | ||
# This file is part of RERO ILS. | ||
# Copyright (C) 2018 RERO. | ||
# | ||
# RERO ILS is free software; you can redistribute it | ||
# and/or modify it under the terms of the GNU General Public License as | ||
# published by the Free Software Foundation; either version 2 of the | ||
# License, or (at your option) any later version. | ||
# | ||
# RERO ILS 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 | ||
# General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with RERO ILS; if not, write to the | ||
# Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, | ||
# MA 02111-1307, USA. | ||
# | ||
# In applying this license, RERO does not | ||
# waive the privileges and immunities granted to it by virtue of its status | ||
# as an Intergovernmental Organization or submit itself to any jurisdiction. | ||
|
||
"""API for manipulating Notifications.""" | ||
|
||
from __future__ import absolute_import, print_function | ||
|
||
from functools import partial | ||
|
||
from elasticsearch_dsl import Q | ||
from invenio_search.api import RecordsSearch | ||
|
||
from .models import NotificationIdentifier, NotificationMetadata | ||
from ..api import IlsRecord | ||
from ..fetchers import id_fetcher | ||
from ..locations.api import Location | ||
from ..minters import id_minter | ||
from ..providers import Provider | ||
|
||
# notif provider | ||
NotificationProvider = type( | ||
'NotificationProvider', | ||
(Provider,), | ||
dict(identifier=NotificationIdentifier, pid_type='notif') | ||
) | ||
# notif minter | ||
notification_id_minter = partial(id_minter, provider=NotificationProvider) | ||
# notif fetcher | ||
notification_id_fetcher = partial(id_fetcher, provider=NotificationProvider) | ||
|
||
|
||
class NotificationsSearch(RecordsSearch): | ||
"""RecordsSearch for Notifications.""" | ||
|
||
class Meta: | ||
"""Search only on Notifications index.""" | ||
|
||
index = 'notifications' | ||
|
||
|
||
class Notification(IlsRecord): | ||
"""Notifications class.""" | ||
|
||
minter = notification_id_minter | ||
fetcher = notification_id_fetcher | ||
provider = NotificationProvider | ||
model_cls = NotificationMetadata | ||
|
||
@property | ||
def organisation_pid(self): | ||
"""Get organisation pid for notification.""" | ||
location_pid = self.replace_refs()['transaction_location']['pid'] | ||
location = Location.get_record_by_pid(location_pid) | ||
return location.organisation_pid |
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,25 @@ | ||
# -*- coding: utf-8 -*- | ||
# | ||
# This file is part of Invenio. | ||
# Copyright (C) 2018 RERO. | ||
# | ||
# Invenio is free software; you can redistribute it | ||
# and/or modify it under the terms of the GNU General Public License as | ||
# published by the Free Software Foundation; either version 2 of the | ||
# License, or (at your option) any later version. | ||
# | ||
# Invenio 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 | ||
# General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with Invenio; if not, write to the | ||
# Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, | ||
# MA 02111-1307, USA. | ||
# | ||
# In applying this license, RERO does not | ||
# waive the privileges and immunities granted to it by virtue of its status | ||
# as an Intergovernmental Organization or submit itself to any jurisdiction. | ||
|
||
"""Notifications JSON schemas.""" |
97 changes: 97 additions & 0 deletions
97
rero_ils/modules/notifications/jsonschemas/notifications/notification-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,97 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-04/schema#", | ||
"type": "object", | ||
"title": "Notification", | ||
"description": "JSON schema for notifications.", | ||
"additionalProperties": true, | ||
"required": [ | ||
"$schema", | ||
"pid", | ||
"notification_type", | ||
"patron", | ||
"transaction_location" | ||
], | ||
"properties": { | ||
"$schema": { | ||
"title": "Schema", | ||
"description": "Schema to validate notifications records against.", | ||
"type": "string", | ||
"minLength": 9, | ||
"default": "https://ils.rero.ch/schema/notifications/notification-v0.0.1.json" | ||
}, | ||
"pid": { | ||
"title": "Notification ID", | ||
"type": "string", | ||
"minLength": 1 | ||
}, | ||
"notification_date": { | ||
"type": "string", | ||
"format": "date-time", | ||
"title": "Notification creation date" | ||
}, | ||
"patron": { | ||
"title": "Patron", | ||
"type": "object", | ||
"properties": { | ||
"$ref": { | ||
"title": "Patron URI", | ||
"type": "string", | ||
"pattern": "^https://ils.rero.ch/api/patrons/.*?$" | ||
} | ||
} | ||
}, | ||
"item": { | ||
"title": "Item", | ||
"type": "object", | ||
"properties": { | ||
"$ref": { | ||
"title": "Item URI", | ||
"type": "string", | ||
"pattern": "^https://ils.rero.ch/api/items/.*?$" | ||
} | ||
} | ||
}, | ||
"due_date": { | ||
"type": "string", | ||
"format": "date-time", | ||
"title": "Checkout/renewal due date" | ||
}, | ||
"reminder_counter": { | ||
"type": "integer", | ||
"title": "Current reminder count" | ||
}, | ||
"transaction_location": { | ||
"title": "Transaction location", | ||
"type": "object", | ||
"properties": { | ||
"$ref": { | ||
"title": "Transaction location URI", | ||
"type": "string", | ||
"pattern": "^https://ils.rero.ch/api/locations/.*?$" | ||
} | ||
} | ||
}, | ||
"pickup_library": { | ||
"title": "Pickup library", | ||
"type": "object", | ||
"properties": { | ||
"$ref": { | ||
"title": "Pickup library URI", | ||
"type": "string", | ||
"pattern": "^https://ils.rero.ch/api/libaries/.*?$" | ||
} | ||
} | ||
}, | ||
"notification_type": { | ||
"title": "Notification type", | ||
"description": "The type of the notification.", | ||
"type": "string", | ||
"enum": [ | ||
"due_soon", | ||
"overdue", | ||
"availability", | ||
"recall" | ||
] | ||
} | ||
} | ||
} |
Oops, something went wrong.