oarepo-runtime 1.5.110__py3-none-any.whl → 1.5.112__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/datastreams/writers/publish.py +49 -0
- oarepo_runtime/ext_config.py +2 -0
- oarepo_runtime/records/relations/__init__.py +4 -1
- oarepo_runtime/records/relations/base.py +26 -0
- oarepo_runtime/records/relations/pid_relation.py +18 -2
- {oarepo_runtime-1.5.110.dist-info → oarepo_runtime-1.5.112.dist-info}/METADATA +1 -1
- {oarepo_runtime-1.5.110.dist-info → oarepo_runtime-1.5.112.dist-info}/RECORD +11 -10
- {oarepo_runtime-1.5.110.dist-info → oarepo_runtime-1.5.112.dist-info}/LICENSE +0 -0
- {oarepo_runtime-1.5.110.dist-info → oarepo_runtime-1.5.112.dist-info}/WHEEL +0 -0
- {oarepo_runtime-1.5.110.dist-info → oarepo_runtime-1.5.112.dist-info}/entry_points.txt +0 -0
- {oarepo_runtime-1.5.110.dist-info → oarepo_runtime-1.5.112.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,49 @@
|
|
1
|
+
from invenio_access.permissions import system_identity
|
2
|
+
from invenio_records_resources.proxies import current_service_registry
|
3
|
+
|
4
|
+
from oarepo_runtime.datastreams.types import StreamBatch, StreamEntry
|
5
|
+
from oarepo_runtime.datastreams.writers import BaseWriter
|
6
|
+
from oarepo_runtime.datastreams.writers.utils import record_invenio_exceptions
|
7
|
+
|
8
|
+
|
9
|
+
class PublishWriter(BaseWriter):
|
10
|
+
def __init__(
|
11
|
+
self, *, service, request_name="publish_draft", identity=None, **kwargs
|
12
|
+
):
|
13
|
+
if isinstance(service, str):
|
14
|
+
service = current_service_registry.get(service)
|
15
|
+
|
16
|
+
self._service = service
|
17
|
+
self._identity = identity or system_identity
|
18
|
+
self._request_name = request_name
|
19
|
+
|
20
|
+
def write(self, batch: StreamBatch) -> StreamBatch:
|
21
|
+
for entry in batch.ok_entries:
|
22
|
+
if entry.deleted:
|
23
|
+
continue
|
24
|
+
|
25
|
+
with record_invenio_exceptions(entry):
|
26
|
+
self._write_entry(entry)
|
27
|
+
|
28
|
+
def _write_entry(self, entry: StreamEntry):
|
29
|
+
from invenio_requests.proxies import (
|
30
|
+
current_requests_service as current_invenio_requests_service,
|
31
|
+
)
|
32
|
+
from oarepo_requests.proxies import current_oarepo_requests_service
|
33
|
+
|
34
|
+
draft = self._service.read_draft(self._identity, entry.id)
|
35
|
+
request = current_oarepo_requests_service.create(
|
36
|
+
identity=self._identity,
|
37
|
+
data=None,
|
38
|
+
request_type=self._request_name,
|
39
|
+
topic=draft._record,
|
40
|
+
)
|
41
|
+
|
42
|
+
submit_result = current_invenio_requests_service.execute_action(
|
43
|
+
self._identity, request.id, "submit"
|
44
|
+
)
|
45
|
+
accept_result = current_invenio_requests_service.execute_action(
|
46
|
+
self._identity, request.id, "accept"
|
47
|
+
)
|
48
|
+
|
49
|
+
self._service.read(self._identity, draft["id"])
|
oarepo_runtime/ext_config.py
CHANGED
@@ -9,6 +9,7 @@ from oarepo_runtime.datastreams.writers.attachments_file import AttachmentsFileW
|
|
9
9
|
from oarepo_runtime.datastreams.writers.attachments_service import (
|
10
10
|
AttachmentsServiceWriter,
|
11
11
|
)
|
12
|
+
from oarepo_runtime.datastreams.writers.publish import PublishWriter
|
12
13
|
from oarepo_runtime.datastreams.writers.service import ServiceWriter
|
13
14
|
from oarepo_runtime.datastreams.writers.yaml import YamlWriter
|
14
15
|
from oarepo_runtime.records.entity_resolvers import UserResolver
|
@@ -50,6 +51,7 @@ DATASTREAMS_WRITERS = {
|
|
50
51
|
"attachments_service": AttachmentsServiceWriter,
|
51
52
|
"yaml": YamlWriter,
|
52
53
|
"attachments_file": AttachmentsFileWriter,
|
54
|
+
"publish": PublishWriter,
|
53
55
|
}
|
54
56
|
|
55
57
|
DATASTREAMS_TRANSFORMERS = {}
|
@@ -4,9 +4,10 @@ from .base import (
|
|
4
4
|
Relation,
|
5
5
|
RelationResult,
|
6
6
|
RelationsField,
|
7
|
+
UnstrictRelationResult
|
7
8
|
)
|
8
9
|
from .internal import InternalRelation
|
9
|
-
from .pid_relation import PIDRelation
|
10
|
+
from .pid_relation import PIDRelation, UnstrictPIDRelation
|
10
11
|
|
11
12
|
__all__ = (
|
12
13
|
"Relation",
|
@@ -16,4 +17,6 @@ __all__ = (
|
|
16
17
|
"RelationsField",
|
17
18
|
"InternalRelation",
|
18
19
|
"PIDRelation",
|
20
|
+
"UnstrictPIDRelation",
|
21
|
+
"UnstrictRelationResult"
|
19
22
|
)
|
@@ -173,6 +173,32 @@ class RelationResult:
|
|
173
173
|
|
174
174
|
def resolve(self, id_):
|
175
175
|
raise NotImplementedError("Please implement this method in your subclass")
|
176
|
+
class UnstrictRelationResult(RelationResult):
|
177
|
+
|
178
|
+
def _resolve_lookup_result(self, relation):
|
179
|
+
if not isinstance(relation.value, dict):
|
180
|
+
raise InvalidRelationValue(
|
181
|
+
f"Value at path {relation.path} must be dict, found {relation.value}"
|
182
|
+
)
|
183
|
+
relation_id = self._lookup_id(relation)
|
184
|
+
resolved_object = self.resolve(relation_id, relation.value)
|
185
|
+
if not resolved_object:
|
186
|
+
raise InvalidRelationValue(f"Could not resolve relation id {relation_id}.")
|
187
|
+
return resolved_object
|
188
|
+
|
189
|
+
def _dereference_one(self, relation: LookupResult):
|
190
|
+
"""Dereference a single object into a dict."""
|
191
|
+
if not self._needs_update_relation_value(relation):
|
192
|
+
return
|
193
|
+
|
194
|
+
data = relation.value
|
195
|
+
obj = self._resolve_lookup_result(relation)
|
196
|
+
if type(obj) is not dict:
|
197
|
+
self._get_dereferenced_value(data, obj, relation)
|
198
|
+
|
199
|
+
return data
|
200
|
+
|
201
|
+
|
176
202
|
|
177
203
|
|
178
204
|
class Relation:
|
@@ -1,12 +1,13 @@
|
|
1
1
|
from invenio_db import db
|
2
2
|
|
3
3
|
from oarepo_runtime.services.relations.errors import InvalidRelationError
|
4
|
+
from sqlalchemy.exc import NoResultFound
|
4
5
|
|
5
|
-
from .base import Relation, RelationResult
|
6
|
+
from .base import Relation, RelationResult, UnstrictRelationResult
|
6
7
|
from .lookup import LookupResult
|
7
8
|
|
8
9
|
class PIDRelationResult(RelationResult):
|
9
|
-
def resolve(self, id_):
|
10
|
+
def resolve(self, id_, data = None):
|
10
11
|
"""Resolve the value using the record class."""
|
11
12
|
# TODO: handle permissions here !!!!!!
|
12
13
|
try:
|
@@ -65,6 +66,15 @@ class PIDRelationResult(RelationResult):
|
|
65
66
|
def _add_version_info(self, data, relation: LookupResult, resolved_object):
|
66
67
|
data["@v"] = f"{resolved_object.id}::{resolved_object.revision_id}"
|
67
68
|
|
69
|
+
class UnstrictPIDRelationResult(PIDRelationResult, UnstrictRelationResult):
|
70
|
+
|
71
|
+
def resolve(self, id_, data):
|
72
|
+
try:
|
73
|
+
return super().resolve(id_, data)
|
74
|
+
except InvalidRelationError as e:
|
75
|
+
if isinstance(e.__cause__, NoResultFound):
|
76
|
+
return data
|
77
|
+
raise
|
68
78
|
|
69
79
|
class PIDRelation(Relation):
|
70
80
|
result_cls = PIDRelationResult
|
@@ -73,6 +83,12 @@ class PIDRelation(Relation):
|
|
73
83
|
super().__init__(key=key, **kwargs)
|
74
84
|
self.pid_field = pid_field
|
75
85
|
|
86
|
+
class UnstrictPIDRelation(Relation):
|
87
|
+
result_cls = UnstrictPIDRelationResult
|
88
|
+
|
89
|
+
def __init__(self, key=None, pid_field=None, **kwargs):
|
90
|
+
super().__init__(key=key, **kwargs)
|
91
|
+
self.pid_field = pid_field
|
76
92
|
|
77
93
|
class MetadataRelationResult(PIDRelationResult):
|
78
94
|
def _dereference_one(self, relation: LookupResult):
|
@@ -1,6 +1,6 @@
|
|
1
1
|
oarepo_runtime/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
2
2
|
oarepo_runtime/ext.py,sha256=6w6bpTpNjjj3txgVu0nfpmPa9CnDS6Zl6U2DCNs9Usc,2565
|
3
|
-
oarepo_runtime/ext_config.py,sha256=
|
3
|
+
oarepo_runtime/ext_config.py,sha256=ERpi6uJqDE6OpqebB_vuusmoB3xaAziuKeGVxVI5Q-w,2155
|
4
4
|
oarepo_runtime/profile.py,sha256=QzrQoZncjoN74ZZnpkEKakNk08KCzBU7m6y42RN8AMY,1637
|
5
5
|
oarepo_runtime/proxies.py,sha256=NN_WNj1xuKc-OveoZmzvTFlUonNjSmLIGsv_JUcHGls,285
|
6
6
|
oarepo_runtime/tasks.py,sha256=AciXN1fUq6tzfzNSICh1S6XoHGWiuH76bUqXyzTsOPU,140
|
@@ -41,6 +41,7 @@ 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=rU1HgIR2OO1CyA_QBe1MGHiZmcfKthrLYYlw6Laj9Gk,1795
|
44
45
|
oarepo_runtime/datastreams/writers/service.py,sha256=PvCxYASDxOqT6iyL6cjw0aH41LaC1vwob4W3vnE9XmA,3920
|
45
46
|
oarepo_runtime/datastreams/writers/utils.py,sha256=Lk_ZLNeXTLuFEn04lw1-6bJ7duG6kwA8X4wf9c_GiL4,1067
|
46
47
|
oarepo_runtime/datastreams/writers/validation_errors.py,sha256=wOCXdniR6so_4ExpdFYYgBRyENp7_6kVFZM2L-Hy3G8,661
|
@@ -61,11 +62,11 @@ oarepo_runtime/records/mappings/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm
|
|
61
62
|
oarepo_runtime/records/mappings/rdm_parent_mapping.json,sha256=9yRjlGs8-TZZiKN9MtAzNhRzYq9AEJFY9E80FN0wYoM,647
|
62
63
|
oarepo_runtime/records/owners/__init__.py,sha256=R4hudCBqLRRzgCnkEjXIL7hSp068z-s6YOwYSkWyuaw,93
|
63
64
|
oarepo_runtime/records/owners/registry.py,sha256=fYgBuW5nBKn6pyz2OBgfNlynk64_yhQ9J7FzPk8QU1U,795
|
64
|
-
oarepo_runtime/records/relations/__init__.py,sha256=
|
65
|
-
oarepo_runtime/records/relations/base.py,sha256=
|
65
|
+
oarepo_runtime/records/relations/__init__.py,sha256=Zn7JeQrd5f1doWl5IpbNSpO8m8hm1m-oljAW-7WHn-k,477
|
66
|
+
oarepo_runtime/records/relations/base.py,sha256=gTXvyxdkKZ_khdoqvShE2mIbPDU91Bf9beTxHwQtyFk,9925
|
66
67
|
oarepo_runtime/records/relations/internal.py,sha256=OTp8iJqyl80sWDk0Q0AK42l6UsxZDABspVU_GwWza9o,1556
|
67
68
|
oarepo_runtime/records/relations/lookup.py,sha256=wi3jPfOedazOmhOMrgu50PUETc1jfSdpmjK0wvOFsEM,848
|
68
|
-
oarepo_runtime/records/relations/pid_relation.py,sha256=
|
69
|
+
oarepo_runtime/records/relations/pid_relation.py,sha256=eojw5uIo5zXmJGge_bj6Wj2njCRY5S4o4B_h_HFyaDY,3901
|
69
70
|
oarepo_runtime/records/systemfields/__init__.py,sha256=LL1R64RUakA_4r0IkTq9MtwqD5eV-AQaj5u96zkWa74,533
|
70
71
|
oarepo_runtime/records/systemfields/featured_file.py,sha256=MbSaYR130_o5S9gEOblnChq-PVK4xGPGpSCrzwG3cwc,1720
|
71
72
|
oarepo_runtime/records/systemfields/has_draftcheck.py,sha256=4JkMEefPLpqtPtlTgK3UT0KzTRgyw5_Qtkss2qcz5xk,1643
|
@@ -146,9 +147,9 @@ tests/marshmallow_to_json/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJW
|
|
146
147
|
tests/marshmallow_to_json/test_datacite_ui_schema.py,sha256=82iLj8nW45lZOUewpWbLX3mpSkpa9lxo-vK-Qtv_1bU,48552
|
147
148
|
tests/marshmallow_to_json/test_simple_schema.py,sha256=izZN9p0v6kovtSZ6AdxBYmK_c6ZOti2_z_wPT_zXIr0,1500
|
148
149
|
tests/pkg_data/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
149
|
-
oarepo_runtime-1.5.
|
150
|
-
oarepo_runtime-1.5.
|
151
|
-
oarepo_runtime-1.5.
|
152
|
-
oarepo_runtime-1.5.
|
153
|
-
oarepo_runtime-1.5.
|
154
|
-
oarepo_runtime-1.5.
|
150
|
+
oarepo_runtime-1.5.112.dist-info/LICENSE,sha256=h2uWz0OaB3EN-J1ImdGJZzc7yvfQjvHVYdUhQ-H7ypY,1064
|
151
|
+
oarepo_runtime-1.5.112.dist-info/METADATA,sha256=FIFAT3sYW6SKrJBMWejDRJ-HemcYYvZq4ZrPesVGShg,4721
|
152
|
+
oarepo_runtime-1.5.112.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
|
153
|
+
oarepo_runtime-1.5.112.dist-info/entry_points.txt,sha256=k7O5LZUOGsVeSpB7ulU0txBUNp1CVQG7Q7TJIVTPbzU,491
|
154
|
+
oarepo_runtime-1.5.112.dist-info/top_level.txt,sha256=bHhlkT1_RQC4IkfTQCqA3iN4KCB6cSFQlsXpQMSP-bE,21
|
155
|
+
oarepo_runtime-1.5.112.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|