oarepo-runtime 1.5.116__py3-none-any.whl → 1.5.118__py3-none-any.whl
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_runtime/cli/index.py +7 -7
- oarepo_runtime/datastreams/json.py +3 -3
- oarepo_runtime/datastreams/writers/publish.py +32 -22
- oarepo_runtime/datastreams/writers/service.py +62 -9
- oarepo_runtime/services/permissions/generators.py +7 -6
- {oarepo_runtime-1.5.116.dist-info → oarepo_runtime-1.5.118.dist-info}/METADATA +1 -1
- {oarepo_runtime-1.5.116.dist-info → oarepo_runtime-1.5.118.dist-info}/RECORD +11 -11
- {oarepo_runtime-1.5.116.dist-info → oarepo_runtime-1.5.118.dist-info}/LICENSE +0 -0
- {oarepo_runtime-1.5.116.dist-info → oarepo_runtime-1.5.118.dist-info}/WHEEL +0 -0
- {oarepo_runtime-1.5.116.dist-info → oarepo_runtime-1.5.118.dist-info}/entry_points.txt +0 -0
- {oarepo_runtime-1.5.116.dist-info → oarepo_runtime-1.5.118.dist-info}/top_level.txt +0 -0
oarepo_runtime/cli/index.py
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
import sys
|
2
|
+
import traceback
|
2
3
|
from io import StringIO
|
3
4
|
|
4
5
|
import click
|
@@ -7,7 +8,6 @@ from flask.cli import with_appcontext
|
|
7
8
|
from invenio_db import db
|
8
9
|
from invenio_records_resources.proxies import current_service_registry
|
9
10
|
from invenio_search.proxies import current_search
|
10
|
-
import traceback
|
11
11
|
from werkzeug.utils import ImportStringError, import_string
|
12
12
|
|
13
13
|
try:
|
@@ -157,7 +157,7 @@ def reindex(model, bulk_size, verbose):
|
|
157
157
|
count += len(bulk) // 2
|
158
158
|
for index_item_result in index_result["items"]:
|
159
159
|
result = index_item_result["index"]
|
160
|
-
if result["status"]
|
160
|
+
if result["status"] not in (200, 201):
|
161
161
|
errors += 1
|
162
162
|
click.secho(
|
163
163
|
f"Error indexing record with id {result['_id']}",
|
@@ -245,11 +245,9 @@ def users_record_generator(model_class):
|
|
245
245
|
except Exception as e:
|
246
246
|
click.secho(f"Could not index {model_class}: {e}", fg="red", file=sys.stderr)
|
247
247
|
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
'groups'
|
252
|
-
]
|
248
|
+
|
249
|
+
priorities = ["vocabular", "users", "groups"]
|
250
|
+
|
253
251
|
|
254
252
|
def sort_services(services):
|
255
253
|
def idx(x):
|
@@ -257,7 +255,9 @@ def sort_services(services):
|
|
257
255
|
if p in x:
|
258
256
|
return idx, x
|
259
257
|
return len(priorities), x
|
258
|
+
|
260
259
|
services.sort(key=idx)
|
261
260
|
return services
|
262
261
|
|
262
|
+
|
263
263
|
RECORD_GENERATORS = {"users": users_record_generator}
|
@@ -1,4 +1,4 @@
|
|
1
|
-
from typing import
|
1
|
+
from typing import Union
|
2
2
|
|
3
|
-
JSON = Union[str, int, float, bool, None,
|
4
|
-
JSONObject =
|
3
|
+
JSON = Union[str, int, float, bool, None, dict[str, "JSON"], list["JSON"]]
|
4
|
+
JSONObject = dict[str, "JSON"]
|
@@ -8,7 +8,13 @@ from oarepo_runtime.datastreams.writers.utils import record_invenio_exceptions
|
|
8
8
|
|
9
9
|
class PublishWriter(BaseWriter):
|
10
10
|
def __init__(
|
11
|
-
self,
|
11
|
+
self,
|
12
|
+
*,
|
13
|
+
service,
|
14
|
+
request_name="publish_draft",
|
15
|
+
identity=None,
|
16
|
+
direct_call=False,
|
17
|
+
**kwargs
|
12
18
|
):
|
13
19
|
if isinstance(service, str):
|
14
20
|
service = current_service_registry.get(service)
|
@@ -16,6 +22,7 @@ class PublishWriter(BaseWriter):
|
|
16
22
|
self._service = service
|
17
23
|
self._identity = identity or system_identity
|
18
24
|
self._request_name = request_name
|
25
|
+
self._direct_call = direct_call
|
19
26
|
|
20
27
|
def write(self, batch: StreamBatch) -> StreamBatch:
|
21
28
|
for entry in batch.ok_entries:
|
@@ -26,24 +33,27 @@ class PublishWriter(BaseWriter):
|
|
26
33
|
self._write_entry(entry)
|
27
34
|
|
28
35
|
def _write_entry(self, entry: StreamEntry):
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
36
|
+
if self._direct_call:
|
37
|
+
self._service.publish(self._identity, entry.id)
|
38
|
+
else:
|
39
|
+
from invenio_requests.proxies import (
|
40
|
+
current_requests_service as current_invenio_requests_service,
|
41
|
+
)
|
42
|
+
from oarepo_requests.proxies import current_oarepo_requests_service
|
43
|
+
|
44
|
+
draft = self._service.read_draft(self._identity, entry.id)
|
45
|
+
request = current_oarepo_requests_service.create(
|
46
|
+
identity=self._identity,
|
47
|
+
data=None,
|
48
|
+
request_type=self._request_name,
|
49
|
+
topic=draft._record,
|
50
|
+
)
|
51
|
+
|
52
|
+
submit_result = current_invenio_requests_service.execute_action(
|
53
|
+
self._identity, request.id, "submit"
|
54
|
+
)
|
55
|
+
accept_result = current_invenio_requests_service.execute_action(
|
56
|
+
self._identity, request.id, "accept"
|
57
|
+
)
|
58
|
+
|
59
|
+
self._service.read(self._identity, draft["id"])
|
@@ -4,7 +4,7 @@ from invenio_records_resources.proxies import current_service_registry
|
|
4
4
|
from invenio_records_resources.services.uow import UnitOfWork
|
5
5
|
|
6
6
|
from ...uow import BulkUnitOfWork
|
7
|
-
from ..types import StreamBatch, StreamEntry
|
7
|
+
from ..types import StreamBatch, StreamEntry, StreamEntryError
|
8
8
|
from . import BaseWriter
|
9
9
|
from .utils import record_invenio_exceptions
|
10
10
|
|
@@ -38,10 +38,26 @@ class ServiceWriter(BaseWriter):
|
|
38
38
|
self._update = update
|
39
39
|
|
40
40
|
def _resolve(self, id_):
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
41
|
+
if hasattr(self._service, "read_draft"):
|
42
|
+
try:
|
43
|
+
# try to read the draft first
|
44
|
+
return self._service.read_draft(self._identity, id_)
|
45
|
+
except PIDDoesNotExistError:
|
46
|
+
pass
|
47
|
+
try:
|
48
|
+
# if the draft does not exist, read the published record
|
49
|
+
# and create a draft for it
|
50
|
+
rec = self._service.read(self._identity, id_)
|
51
|
+
return self._service.edit(self._identity, id_)
|
52
|
+
except PIDDoesNotExistError:
|
53
|
+
pass
|
54
|
+
|
55
|
+
else:
|
56
|
+
try:
|
57
|
+
return self._service.read(self._identity, id_)
|
58
|
+
except PIDDoesNotExistError:
|
59
|
+
pass
|
60
|
+
return None
|
45
61
|
|
46
62
|
def _get_stream_entry_id(self, entry: StreamEntry):
|
47
63
|
return entry.id
|
@@ -92,6 +108,16 @@ class ServiceWriter(BaseWriter):
|
|
92
108
|
stream_entry.id = repository_entry.id
|
93
109
|
|
94
110
|
stream_entry.context["revision_id"] = repository_entry._record.revision_id
|
111
|
+
if repository_entry.errors:
|
112
|
+
for err in repository_entry.errors:
|
113
|
+
field = err.get("field")
|
114
|
+
messages = err.get("messages")
|
115
|
+
for message in messages:
|
116
|
+
stream_entry.errors.append(
|
117
|
+
StreamEntryError(
|
118
|
+
code="validation", message=message, location=field
|
119
|
+
)
|
120
|
+
)
|
95
121
|
|
96
122
|
def try_update(self, entry_id, entry, **service_kwargs):
|
97
123
|
current = self._resolve(entry_id)
|
@@ -99,9 +125,15 @@ class ServiceWriter(BaseWriter):
|
|
99
125
|
updated = dict(current.to_dict(), **entry)
|
100
126
|
# might raise exception here but that's ok - we know that the entry
|
101
127
|
# exists in db as it was _resolved
|
102
|
-
|
103
|
-
|
104
|
-
|
128
|
+
if hasattr(self._service, "update_draft"):
|
129
|
+
# try to update draft first
|
130
|
+
return self._service.update_draft(
|
131
|
+
self._identity, entry_id, updated, **service_kwargs
|
132
|
+
)
|
133
|
+
else:
|
134
|
+
return self._service.update(
|
135
|
+
self._identity, entry_id, updated, **service_kwargs
|
136
|
+
)
|
105
137
|
|
106
138
|
def _delete_entry(self, stream_entry: StreamEntry, uow=None):
|
107
139
|
entry_id = self._get_stream_entry_id(stream_entry)
|
@@ -110,4 +142,25 @@ class ServiceWriter(BaseWriter):
|
|
110
142
|
service_kwargs = {}
|
111
143
|
if uow:
|
112
144
|
service_kwargs["uow"] = uow
|
113
|
-
|
145
|
+
deletion_exceptions = []
|
146
|
+
deletion_tries = 0
|
147
|
+
|
148
|
+
# if the service has drafts, try to delete it first
|
149
|
+
if hasattr(self._service, "delete_draft"):
|
150
|
+
# delete draft
|
151
|
+
deletion_tries += 1
|
152
|
+
try:
|
153
|
+
self._service.delete_draft(self._identity, entry_id, **service_kwargs)
|
154
|
+
except Exception as e:
|
155
|
+
deletion_exceptions.append(e)
|
156
|
+
|
157
|
+
# delete the record if it was published
|
158
|
+
deletion_tries += 1
|
159
|
+
try:
|
160
|
+
self._service.delete(self._identity, entry_id, **service_kwargs)
|
161
|
+
except Exception as e:
|
162
|
+
deletion_exceptions.append(e)
|
163
|
+
|
164
|
+
if len(deletion_exceptions) == deletion_tries:
|
165
|
+
# all deletion attempts failed
|
166
|
+
raise deletion_exceptions[-1]
|
@@ -38,6 +38,7 @@ class RecordOwners(Generator):
|
|
38
38
|
return dsl.Q("terms", **{"parent.access.owned_by.user": users})
|
39
39
|
else:
|
40
40
|
return dsl.Q("terms", **{"parent.owners.user": users})
|
41
|
+
return dsl.Q("match_none")
|
41
42
|
|
42
43
|
|
43
44
|
class UserWithRole(Generator):
|
@@ -59,12 +60,12 @@ class UserWithRole(Generator):
|
|
59
60
|
class IfDraftType(ConditionalGenerator):
|
60
61
|
def __init__(
|
61
62
|
self,
|
62
|
-
draft_types:
|
63
|
-
Literal["initial"] | Literal["metadata"] | Literal["new_version"]
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
63
|
+
draft_types: (
|
64
|
+
list[Literal["initial"] | Literal["metadata"] | Literal["new_version"]]
|
65
|
+
| Literal["initial"]
|
66
|
+
| Literal["metadata"]
|
67
|
+
| Literal["new_version"]
|
68
|
+
),
|
68
69
|
then_=None,
|
69
70
|
else_=None,
|
70
71
|
):
|
@@ -12,7 +12,7 @@ oarepo_runtime/cli/cf.py,sha256=W0JEJK2JqKubQw8qtZJxohmADDRUBode4JZAqYLDGvc,339
|
|
12
12
|
oarepo_runtime/cli/check.py,sha256=sCe2PeokSHvNOXHFZ8YHF8NMhsu5nYjyuZuvXHJ6X18,5092
|
13
13
|
oarepo_runtime/cli/configuration.py,sha256=M_19zrS0vo-7uHi047a3i4rQsK6pmp4QS0IEBAxMLZ0,2039
|
14
14
|
oarepo_runtime/cli/fixtures.py,sha256=l6zHpz1adjotrbFy_wcN2TOL8x20i-1jbQmaoEEo-UU,5419
|
15
|
-
oarepo_runtime/cli/index.py,sha256=
|
15
|
+
oarepo_runtime/cli/index.py,sha256=9Dqbe1dVrz-TcZkXCGYe4qm4sVxJRWnTzzr9OEaIko8,8686
|
16
16
|
oarepo_runtime/cli/validate.py,sha256=HpSvHQCGHlrdgdpKix9cIlzlBoJEiT1vACZdMnOUGEY,2827
|
17
17
|
oarepo_runtime/cli/permissions/__init__.py,sha256=2qufYdUoCb9kG7Zy0gKNW5lpRyqbVQSNsf7shLwrThM,198
|
18
18
|
oarepo_runtime/cli/permissions/base.py,sha256=USzA5LNFPpR7tvM_uan70GI7oO6FrGlHzODU_Z4Tl6c,744
|
@@ -26,7 +26,7 @@ oarepo_runtime/datastreams/datastreams.py,sha256=N9XXwIaBTADkPhE-XG6uotMwd-8Kn0v
|
|
26
26
|
oarepo_runtime/datastreams/errors.py,sha256=WyZLU53EdFJTLv6K2ooM_M6ISjLS-U1dDw6B7guOLSc,1540
|
27
27
|
oarepo_runtime/datastreams/ext.py,sha256=ivugdVMCqwugK-5SeX14a-dMq6VaTt7DM2wFU357tR4,1406
|
28
28
|
oarepo_runtime/datastreams/fixtures.py,sha256=LTzRLoS3hkdP7a7wX3fCNWplaxh0DQQjxGto3p1_Luk,8691
|
29
|
-
oarepo_runtime/datastreams/json.py,sha256=
|
29
|
+
oarepo_runtime/datastreams/json.py,sha256=OkIkGKUawtYoGelyS5V92DVk7Ei7SlkMMny2Ue2dDWc,132
|
30
30
|
oarepo_runtime/datastreams/semi_asynchronous.py,sha256=kNc6BBnV6oFoY9kHgf5l8fd1wibRfI0dwyzLtu4fmUA,2940
|
31
31
|
oarepo_runtime/datastreams/synchronous.py,sha256=t5lfnMkLqy3jK5zMl-nIuA0HlMPiHGjwCqZ8XQP-3GM,2595
|
32
32
|
oarepo_runtime/datastreams/transformers.py,sha256=q5KzHPl2kJg7HP1BtKJ7F_UMqg_7L1ZGDX0O7s8D6UI,521
|
@@ -41,8 +41,8 @@ oarepo_runtime/datastreams/readers/yaml.py,sha256=U4nyJQ8ocM_ohp-eUN1RjVoNzYV9z7
|
|
41
41
|
oarepo_runtime/datastreams/writers/__init__.py,sha256=PWufWNrixFhXv5wSv3_pzmrimroqVB2DVgTxVtY5FCg,526
|
42
42
|
oarepo_runtime/datastreams/writers/attachments_file.py,sha256=kV_IPAWawJ9PX-IfoncmLQXpdTbzRMsJie8uKX1vNp0,3161
|
43
43
|
oarepo_runtime/datastreams/writers/attachments_service.py,sha256=g_tbjUA3YnTE5gP21zlG2kIxneZsn0q95EVjlxB8s1M,4152
|
44
|
-
oarepo_runtime/datastreams/writers/publish.py,sha256=
|
45
|
-
oarepo_runtime/datastreams/writers/service.py,sha256=
|
44
|
+
oarepo_runtime/datastreams/writers/publish.py,sha256=Fq2GJ6-We_CMzft_kegQYt7bEYCN-2knMCX_B8Z6McI,2078
|
45
|
+
oarepo_runtime/datastreams/writers/service.py,sha256=GUnXVuRlJaBo19s7oeSG-vpFenah-NTursrX08UP-B4,6010
|
46
46
|
oarepo_runtime/datastreams/writers/utils.py,sha256=Lk_ZLNeXTLuFEn04lw1-6bJ7duG6kwA8X4wf9c_GiL4,1067
|
47
47
|
oarepo_runtime/datastreams/writers/validation_errors.py,sha256=wOCXdniR6so_4ExpdFYYgBRyENp7_6kVFZM2L-Hy3G8,661
|
48
48
|
oarepo_runtime/datastreams/writers/yaml.py,sha256=XchUJHQ58E2Mfgs8elImXbL38jFtI8Hfoye6yaR0gKI,1482
|
@@ -115,7 +115,7 @@ oarepo_runtime/services/files/__init__.py,sha256=K8MStrEQf_BUhvzhwPTF93Hkhwrd1dt
|
|
115
115
|
oarepo_runtime/services/files/components.py,sha256=x6Wd-vvkqTqB1phj2a6h42DNQksN8PuR2XKaOGoNHfw,2400
|
116
116
|
oarepo_runtime/services/files/service.py,sha256=8DH0Pefr9kilM2JnOb-UYsnqerE8Z1Mu4p6DOJ4j_ZU,608
|
117
117
|
oarepo_runtime/services/permissions/__init__.py,sha256=33zqKGgRQmRfNZI8kAhue1bFoT1deYiVVNinP8Bvv0I,123
|
118
|
-
oarepo_runtime/services/permissions/generators.py,sha256=
|
118
|
+
oarepo_runtime/services/permissions/generators.py,sha256=XjirYTCk2dNZTf5wrRdKaCxYNj9GVYBPiMPR0pkt_Eo,3337
|
119
119
|
oarepo_runtime/services/records/__init__.py,sha256=hIoa2fx1AkDr6c-MgY561U2oN9LFeUCtfbVnetpBUOg,78
|
120
120
|
oarepo_runtime/services/records/links.py,sha256=gVe-_hGkLtX7pd6sS6jTbRIhBby2FTn9PXyYPy3yxzs,737
|
121
121
|
oarepo_runtime/services/relations/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
@@ -148,9 +148,9 @@ tests/marshmallow_to_json/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJW
|
|
148
148
|
tests/marshmallow_to_json/test_datacite_ui_schema.py,sha256=82iLj8nW45lZOUewpWbLX3mpSkpa9lxo-vK-Qtv_1bU,48552
|
149
149
|
tests/marshmallow_to_json/test_simple_schema.py,sha256=izZN9p0v6kovtSZ6AdxBYmK_c6ZOti2_z_wPT_zXIr0,1500
|
150
150
|
tests/pkg_data/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
151
|
-
oarepo_runtime-1.5.
|
152
|
-
oarepo_runtime-1.5.
|
153
|
-
oarepo_runtime-1.5.
|
154
|
-
oarepo_runtime-1.5.
|
155
|
-
oarepo_runtime-1.5.
|
156
|
-
oarepo_runtime-1.5.
|
151
|
+
oarepo_runtime-1.5.118.dist-info/LICENSE,sha256=h2uWz0OaB3EN-J1ImdGJZzc7yvfQjvHVYdUhQ-H7ypY,1064
|
152
|
+
oarepo_runtime-1.5.118.dist-info/METADATA,sha256=F9CQ65sKMqAO61j9a623e4aFTgYO708b3lClSUAahA0,4721
|
153
|
+
oarepo_runtime-1.5.118.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
|
154
|
+
oarepo_runtime-1.5.118.dist-info/entry_points.txt,sha256=k7O5LZUOGsVeSpB7ulU0txBUNp1CVQG7Q7TJIVTPbzU,491
|
155
|
+
oarepo_runtime-1.5.118.dist-info/top_level.txt,sha256=bHhlkT1_RQC4IkfTQCqA3iN4KCB6cSFQlsXpQMSP-bE,21
|
156
|
+
oarepo_runtime-1.5.118.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|