oarepo-doi 1.0.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- oarepo_doi-1.0.2/LICENSE +21 -0
- oarepo_doi-1.0.2/MANIFEST.in +3 -0
- oarepo_doi-1.0.2/PKG-INFO +12 -0
- oarepo_doi-1.0.2/README.md +1 -0
- oarepo_doi-1.0.2/oarepo_doi/__init__.py +0 -0
- oarepo_doi-1.0.2/oarepo_doi/__pycache__/__init__.cpython-310.pyc +0 -0
- oarepo_doi-1.0.2/oarepo_doi/__pycache__/api.cpython-310.pyc +0 -0
- oarepo_doi-1.0.2/oarepo_doi/__pycache__/ext.cpython-310.pyc +0 -0
- oarepo_doi-1.0.2/oarepo_doi/actions/__init__.py +0 -0
- oarepo_doi-1.0.2/oarepo_doi/actions/__pycache__/__init__.cpython-310.pyc +0 -0
- oarepo_doi-1.0.2/oarepo_doi/actions/__pycache__/doi.cpython-310.pyc +0 -0
- oarepo_doi-1.0.2/oarepo_doi/actions/doi.py +74 -0
- oarepo_doi-1.0.2/oarepo_doi/api.py +59 -0
- oarepo_doi-1.0.2/oarepo_doi/ext.py +20 -0
- oarepo_doi-1.0.2/oarepo_doi/services/__init__.py +0 -0
- oarepo_doi-1.0.2/oarepo_doi/services/components/__init__.py +57 -0
- oarepo_doi-1.0.2/oarepo_doi/types/__init__.py +0 -0
- oarepo_doi-1.0.2/oarepo_doi/types/__pycache__/__init__.cpython-310.pyc +0 -0
- oarepo_doi-1.0.2/oarepo_doi/types/__pycache__/doi.cpython-310.pyc +0 -0
- oarepo_doi-1.0.2/oarepo_doi/types/doi.py +28 -0
- oarepo_doi-1.0.2/oarepo_doi.egg-info/PKG-INFO +12 -0
- oarepo_doi-1.0.2/oarepo_doi.egg-info/SOURCES.txt +28 -0
- oarepo_doi-1.0.2/oarepo_doi.egg-info/dependency_links.txt +1 -0
- oarepo_doi-1.0.2/oarepo_doi.egg-info/entry_points.txt +9 -0
- oarepo_doi-1.0.2/oarepo_doi.egg-info/requires.txt +6 -0
- oarepo_doi-1.0.2/oarepo_doi.egg-info/top_level.txt +2 -0
- oarepo_doi-1.0.2/pyproject.toml +3 -0
- oarepo_doi-1.0.2/setup.cfg +40 -0
- oarepo_doi-1.0.2/setup.py +3 -0
oarepo_doi-1.0.2/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (C) 2021 CESNET.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
6
|
+
this software and associated documentation files (the "Software"), to deal in
|
|
7
|
+
the Software without restriction, including without limitation the rights to
|
|
8
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
|
9
|
+
of the Software, and to permit persons to whom the Software is furnished to do
|
|
10
|
+
so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: oarepo-doi
|
|
3
|
+
Version: 1.0.2
|
|
4
|
+
Description-Content-Type: text/markdown
|
|
5
|
+
License-File: LICENSE
|
|
6
|
+
Requires-Dist: invenio-requests
|
|
7
|
+
Requires-Dist: oarepo-requests
|
|
8
|
+
Provides-Extra: tests
|
|
9
|
+
Requires-Dist: oarepo-model-builder-tests; extra == "tests"
|
|
10
|
+
Requires-Dist: oarepo-requests; extra == "tests"
|
|
11
|
+
|
|
12
|
+
# OARepo DOI
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# OARepo DOI
|
|
File without changes
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
File without changes
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
from invenio_requests.customizations import actions
|
|
2
|
+
from flask import current_app
|
|
3
|
+
from oarepo_doi.api import create_doi, edit_doi
|
|
4
|
+
|
|
5
|
+
class CreateDoiAction(actions.CreateAction):
|
|
6
|
+
log_event = True
|
|
7
|
+
|
|
8
|
+
def __init__(self, *args, **kwargs):
|
|
9
|
+
super().__init__(*args, **kwargs)
|
|
10
|
+
|
|
11
|
+
self.mode = current_app.config.get("DATACITE_MODE")
|
|
12
|
+
self.url = current_app.config.get("DATACITE_URL")
|
|
13
|
+
self.mapping = current_app.config.get("DATACITE_MAPPING")
|
|
14
|
+
|
|
15
|
+
self.username = None
|
|
16
|
+
self.password = None
|
|
17
|
+
self.prefix = None
|
|
18
|
+
|
|
19
|
+
def credentials(self, community):
|
|
20
|
+
credentials_def = current_app.config.get("DATACITE_CREDENTIALS")
|
|
21
|
+
|
|
22
|
+
community_credentials = getattr(credentials_def, community, None)
|
|
23
|
+
if community_credentials is None and "DATACITE_CREDENTIALS_DEFAULT" in current_app.config:
|
|
24
|
+
community_credentials = current_app.config.get("DATACITE_CREDENTIALS_DEFAULT")
|
|
25
|
+
self.username = community_credentials["username"]
|
|
26
|
+
self.password = community_credentials["password"]
|
|
27
|
+
self.prefix = community_credentials["prefix"]
|
|
28
|
+
|
|
29
|
+
def execute(self, identity, uow, *args, **kwargs):
|
|
30
|
+
|
|
31
|
+
topic = self.request.topic.resolve()
|
|
32
|
+
self.credentials(topic['parent']['communities']['default'])
|
|
33
|
+
|
|
34
|
+
if topic.is_draft:
|
|
35
|
+
create_doi(self, topic, topic["metadata"], None)
|
|
36
|
+
else:
|
|
37
|
+
create_doi(self, topic, topic["metadata"], "publish")
|
|
38
|
+
super().execute(identity, uow)
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
class EditDoiAction(actions.AcceptAction):
|
|
42
|
+
log_event = True
|
|
43
|
+
|
|
44
|
+
def __init__(self, *args, **kwargs):
|
|
45
|
+
super().__init__(*args, **kwargs)
|
|
46
|
+
|
|
47
|
+
self.mode = current_app.config.get("DATACITE_MODE")
|
|
48
|
+
self.url = current_app.config.get("DATACITE_URL")
|
|
49
|
+
self.mapping = current_app.config.get("DATACITE_MAPPING")
|
|
50
|
+
|
|
51
|
+
self.username = None
|
|
52
|
+
self.password = None
|
|
53
|
+
self.prefix = None
|
|
54
|
+
|
|
55
|
+
def credentials(self, community):
|
|
56
|
+
credentials_def = current_app.config.get("DATACITE_CREDENTIALS")
|
|
57
|
+
|
|
58
|
+
community_credentials = getattr(credentials_def, community, None)
|
|
59
|
+
if community_credentials is None and "DATACITE_CREDENTIALS_DEFAULT" in current_app.config:
|
|
60
|
+
community_credentials = current_app.config.get("DATACITE_CREDENTIALS_DEFAULT")
|
|
61
|
+
self.username = community_credentials["username"]
|
|
62
|
+
self.password = community_credentials["password"]
|
|
63
|
+
self.prefix = community_credentials["prefix"]
|
|
64
|
+
|
|
65
|
+
def execute(self, identity, uow, *args, **kwargs):
|
|
66
|
+
|
|
67
|
+
topic = self.request.topic.resolve()
|
|
68
|
+
self.credentials(topic['parent']['communities']['default'])
|
|
69
|
+
if topic.is_draft:
|
|
70
|
+
edit_doi(self, topic, None)
|
|
71
|
+
else:
|
|
72
|
+
edit_doi(self, topic, "publish")
|
|
73
|
+
|
|
74
|
+
super().execute(identity, uow)
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import requests
|
|
2
|
+
import json
|
|
3
|
+
from invenio_base.utils import obj_or_import_string
|
|
4
|
+
from flask import current_app
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def create_doi(service, record, data, event = None ):
|
|
8
|
+
""" if event = None, doi will be created as a draft."""
|
|
9
|
+
|
|
10
|
+
mapping = obj_or_import_string(service.mapping[record.schema])()
|
|
11
|
+
errors = mapping.metadata_check(data)
|
|
12
|
+
if len(errors) > 0 and event:
|
|
13
|
+
return #todo: dois can not be published with missing mandatory values
|
|
14
|
+
|
|
15
|
+
request_metadata = mapping.create_datacite_payload(data)
|
|
16
|
+
|
|
17
|
+
if event:
|
|
18
|
+
request_metadata["data"]["attributes"]["event"] = event
|
|
19
|
+
|
|
20
|
+
request_metadata["data"]["attributes"]["prefix"] = service.prefix
|
|
21
|
+
|
|
22
|
+
request = requests.post(url=service.url, json=request_metadata, headers={'Content-type': 'application/vnd.api+json'},
|
|
23
|
+
auth=(service.username, service.password)
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
if request.status_code != 201:
|
|
27
|
+
raise requests.ConnectionError("Expected status code 201, but got {}".format(request.status_code))
|
|
28
|
+
|
|
29
|
+
content = request.content.decode('utf-8')
|
|
30
|
+
json_content = json.loads(content)
|
|
31
|
+
doi_value = json_content['data']['id']
|
|
32
|
+
mapping.add_doi(record, data, doi_value)
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def edit_doi(service, record, event = None):
|
|
36
|
+
""" edit existing draft """
|
|
37
|
+
|
|
38
|
+
mapping = obj_or_import_string(service.mapping[record.schema])()
|
|
39
|
+
errors = mapping.metadata_check(record)
|
|
40
|
+
if len(errors) > 0 and event:
|
|
41
|
+
return #todo: dois can not be published with missing mandatory values
|
|
42
|
+
doi_value = mapping.get_doi(record)
|
|
43
|
+
if doi_value:
|
|
44
|
+
if not service.url.endswith('/'):
|
|
45
|
+
url = service.url + '/'
|
|
46
|
+
else:
|
|
47
|
+
url = service.url
|
|
48
|
+
url = url + doi_value.replace("/", "%2F")
|
|
49
|
+
|
|
50
|
+
request_metadata = mapping.create_datacite_payload(record)
|
|
51
|
+
if event:
|
|
52
|
+
request_metadata["data"]["attributes"]["event"] = event
|
|
53
|
+
|
|
54
|
+
request = requests.put(url=url, json=request_metadata, headers={'Content-type': 'application/vnd.api+json'},
|
|
55
|
+
auth=(service.username, service.password))
|
|
56
|
+
|
|
57
|
+
if request.status_code != 200:
|
|
58
|
+
raise requests.ConnectionError("Expected status code 200, but got {}".format(request.status_code))
|
|
59
|
+
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
|
|
2
|
+
class OARepoDOI(object):
|
|
3
|
+
"""OARepo DOI extension."""
|
|
4
|
+
|
|
5
|
+
def __init__(self, app=None):
|
|
6
|
+
"""Extension initialization."""
|
|
7
|
+
if app:
|
|
8
|
+
self.init_app(app)
|
|
9
|
+
|
|
10
|
+
def init_app(self, app):
|
|
11
|
+
"""Flask application initialization."""
|
|
12
|
+
self.init_config(app)
|
|
13
|
+
app.extensions["oarepo-doi"] = self
|
|
14
|
+
|
|
15
|
+
def init_config(self, app):
|
|
16
|
+
"""Initialize configuration."""
|
|
17
|
+
if "DATACITE_URL" not in app.config:
|
|
18
|
+
app.config["DATACITE_URL"] = 'https://api.datacite.org/dois'
|
|
19
|
+
if "DATACITE_MODE" not in app.config:
|
|
20
|
+
app.config["DATACITE_MODE"] = "ON_EVENT"
|
|
File without changes
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import json
|
|
2
|
+
import requests
|
|
3
|
+
from invenio_records_resources.services.records.components import ServiceComponent
|
|
4
|
+
from flask import current_app
|
|
5
|
+
from invenio_base.utils import obj_or_import_string
|
|
6
|
+
|
|
7
|
+
from oarepo_doi.api import create_doi, edit_doi
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class DoiComponent(ServiceComponent):
|
|
11
|
+
|
|
12
|
+
def __init__(self, *args, **kwargs):
|
|
13
|
+
super().__init__(*args, **kwargs)
|
|
14
|
+
|
|
15
|
+
self.mode = current_app.config.get("DATACITE_MODE")
|
|
16
|
+
self.url = current_app.config.get("DATACITE_URL")
|
|
17
|
+
self.mapping = current_app.config.get("DATACITE_MAPPING")
|
|
18
|
+
|
|
19
|
+
self.username = None
|
|
20
|
+
self.password = None
|
|
21
|
+
self.prefix = None
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def credentials(self, community):
|
|
26
|
+
credentials_def = current_app.config.get("DATACITE_CREDENTIALS")
|
|
27
|
+
|
|
28
|
+
community_credentials = getattr(credentials_def, community, None)
|
|
29
|
+
if community_credentials is None and "DATACITE_CREDENTIALS_DEFAULT" in current_app.config:
|
|
30
|
+
community_credentials = current_app.config.get("DATACITE_CREDENTIALS_DEFAULT")
|
|
31
|
+
self.username = community_credentials["username"]
|
|
32
|
+
self.password = community_credentials["password"]
|
|
33
|
+
self.prefix = community_credentials["prefix"]
|
|
34
|
+
|
|
35
|
+
def create(self, identity, data=None, record=None, **kwargs):
|
|
36
|
+
|
|
37
|
+
if self.mode == "AUTOMATIC_DRAFT":
|
|
38
|
+
self.credentials(data['parent']['communities']['default'])
|
|
39
|
+
create_doi(self, record,data, None)
|
|
40
|
+
|
|
41
|
+
def update_draft(self, identity, data=None, record=None, **kwargs):
|
|
42
|
+
if self.mode == "AUTOMATIC_DRAFT":
|
|
43
|
+
self.credentials(data['parent']['communities']['default'])
|
|
44
|
+
edit_doi(self, record)
|
|
45
|
+
|
|
46
|
+
def update(self, identity, data=None, record=None, **kwargs):
|
|
47
|
+
if self.mode == "AUTOMATIC_DRAFT" or self.mode == "AUTOMATIC":
|
|
48
|
+
self.credentials(data['parent']['communities']['default'])
|
|
49
|
+
edit_doi(self, record)
|
|
50
|
+
|
|
51
|
+
def publish(self, identity, data=None, record=None, **kwargs):
|
|
52
|
+
if self.mode == "AUTOMATIC":
|
|
53
|
+
self.credentials(data['parent']['communities']['default'])
|
|
54
|
+
create_doi(self, record, data, "publish")
|
|
55
|
+
if self.mode == "AUTOMATIC_DRAFT":
|
|
56
|
+
self.credentials(data['parent']['communities']['default'])
|
|
57
|
+
edit_doi(self, record, "publish")
|
|
File without changes
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
from invenio_requests.customizations import RequestType
|
|
2
|
+
from oarepo_runtime.i18n import lazy_gettext as _
|
|
3
|
+
from ..actions.doi import CreateDoiAction, EditDoiAction
|
|
4
|
+
from oarepo_requests.types.ref_types import ModelRefTypes
|
|
5
|
+
|
|
6
|
+
class CreateDoiRequestType(RequestType):
|
|
7
|
+
type_id = "create_doi"
|
|
8
|
+
name = _("create_doi")
|
|
9
|
+
|
|
10
|
+
available_actions = {
|
|
11
|
+
**RequestType.available_actions,
|
|
12
|
+
"accept": CreateDoiAction,
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
receiver_can_be_none = True
|
|
16
|
+
allowed_topic_ref_types = ModelRefTypes(published=True, draft=True)
|
|
17
|
+
|
|
18
|
+
class EditDoiRequestType(RequestType):
|
|
19
|
+
type_id = "edit_doi"
|
|
20
|
+
name = _("edit_doi")
|
|
21
|
+
|
|
22
|
+
available_actions = {
|
|
23
|
+
**RequestType.available_actions,
|
|
24
|
+
"accept": EditDoiAction,
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
receiver_can_be_none = True
|
|
28
|
+
allowed_topic_ref_types = ModelRefTypes(published=True, draft=True)
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: oarepo-doi
|
|
3
|
+
Version: 1.0.2
|
|
4
|
+
Description-Content-Type: text/markdown
|
|
5
|
+
License-File: LICENSE
|
|
6
|
+
Requires-Dist: invenio-requests
|
|
7
|
+
Requires-Dist: oarepo-requests
|
|
8
|
+
Provides-Extra: tests
|
|
9
|
+
Requires-Dist: oarepo-model-builder-tests; extra == "tests"
|
|
10
|
+
Requires-Dist: oarepo-requests; extra == "tests"
|
|
11
|
+
|
|
12
|
+
# OARepo DOI
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
MANIFEST.in
|
|
3
|
+
README.md
|
|
4
|
+
pyproject.toml
|
|
5
|
+
setup.cfg
|
|
6
|
+
setup.py
|
|
7
|
+
oarepo_doi/__init__.py
|
|
8
|
+
oarepo_doi/api.py
|
|
9
|
+
oarepo_doi/ext.py
|
|
10
|
+
oarepo_doi.egg-info/PKG-INFO
|
|
11
|
+
oarepo_doi.egg-info/SOURCES.txt
|
|
12
|
+
oarepo_doi.egg-info/dependency_links.txt
|
|
13
|
+
oarepo_doi.egg-info/entry_points.txt
|
|
14
|
+
oarepo_doi.egg-info/requires.txt
|
|
15
|
+
oarepo_doi.egg-info/top_level.txt
|
|
16
|
+
oarepo_doi/__pycache__/__init__.cpython-310.pyc
|
|
17
|
+
oarepo_doi/__pycache__/api.cpython-310.pyc
|
|
18
|
+
oarepo_doi/__pycache__/ext.cpython-310.pyc
|
|
19
|
+
oarepo_doi/actions/__init__.py
|
|
20
|
+
oarepo_doi/actions/doi.py
|
|
21
|
+
oarepo_doi/actions/__pycache__/__init__.cpython-310.pyc
|
|
22
|
+
oarepo_doi/actions/__pycache__/doi.cpython-310.pyc
|
|
23
|
+
oarepo_doi/services/__init__.py
|
|
24
|
+
oarepo_doi/services/components/__init__.py
|
|
25
|
+
oarepo_doi/types/__init__.py
|
|
26
|
+
oarepo_doi/types/doi.py
|
|
27
|
+
oarepo_doi/types/__pycache__/__init__.cpython-310.pyc
|
|
28
|
+
oarepo_doi/types/__pycache__/doi.cpython-310.pyc
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
[invenio_base.api_apps]
|
|
2
|
+
oarepodoi = oarepo_doi.ext:OARepoDOI
|
|
3
|
+
|
|
4
|
+
[invenio_base.apps]
|
|
5
|
+
oarepo_doi = oarepo_doi.ext:OARepoDOI
|
|
6
|
+
|
|
7
|
+
[invenio_requests.types]
|
|
8
|
+
create-doi-request = oarepo_doi.types.doi:CreateDoiRequestType
|
|
9
|
+
edit-doi-request = oarepo_doi.types.doi:EditDoiRequestType
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
[metadata]
|
|
2
|
+
name = oarepo-doi
|
|
3
|
+
version = 1.0.2
|
|
4
|
+
description =
|
|
5
|
+
authors = Alzbeta Pokorna <lili3@cesnet.cz>
|
|
6
|
+
readme = README.md
|
|
7
|
+
long_description = file:README.md
|
|
8
|
+
long_description_content_type = text/markdown
|
|
9
|
+
|
|
10
|
+
[options]
|
|
11
|
+
python = >=3.10
|
|
12
|
+
install_requires =
|
|
13
|
+
invenio-requests
|
|
14
|
+
oarepo-requests
|
|
15
|
+
packages = find:
|
|
16
|
+
|
|
17
|
+
[tool.setuptools.packages.find]
|
|
18
|
+
include = ['oarepo_requests.*']
|
|
19
|
+
|
|
20
|
+
[options.package_data]
|
|
21
|
+
* = *.json, *.rst, *.md, *.json5, *.jinja2
|
|
22
|
+
|
|
23
|
+
[options.extras_require]
|
|
24
|
+
tests =
|
|
25
|
+
oarepo-model-builder-tests
|
|
26
|
+
oarepo-requests
|
|
27
|
+
|
|
28
|
+
[options.entry_points]
|
|
29
|
+
invenio_base.apps =
|
|
30
|
+
oarepo_doi = oarepo_doi.ext:OARepoDOI
|
|
31
|
+
invenio_base.api_apps =
|
|
32
|
+
oarepodoi = oarepo_doi.ext:OARepoDOI
|
|
33
|
+
invenio_requests.types =
|
|
34
|
+
create-doi-request = oarepo_doi.types.doi:CreateDoiRequestType
|
|
35
|
+
edit-doi-request = oarepo_doi.types.doi:EditDoiRequestType
|
|
36
|
+
|
|
37
|
+
[egg_info]
|
|
38
|
+
tag_build =
|
|
39
|
+
tag_date = 0
|
|
40
|
+
|