oarepo-runtime 1.10.2__py3-none-any.whl → 2.0.0.dev3__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.
Files changed (171) hide show
  1. oarepo_runtime/__init__.py +24 -0
  2. oarepo_runtime/api.py +111 -0
  3. oarepo_runtime/cli/__init__.py +10 -21
  4. oarepo_runtime/cli/search.py +34 -0
  5. oarepo_runtime/config.py +86 -13
  6. oarepo_runtime/ext.py +64 -82
  7. oarepo_runtime/proxies.py +21 -5
  8. oarepo_runtime/records/__init__.py +11 -50
  9. oarepo_runtime/records/drafts.py +24 -18
  10. oarepo_runtime/records/mapping.py +84 -0
  11. oarepo_runtime/records/pid_providers.py +43 -7
  12. oarepo_runtime/records/systemfields/__init__.py +15 -33
  13. oarepo_runtime/records/systemfields/mapping.py +41 -24
  14. oarepo_runtime/records/systemfields/publication_status.py +59 -0
  15. oarepo_runtime/services/__init__.py +12 -0
  16. oarepo_runtime/services/config/__init__.py +15 -21
  17. oarepo_runtime/services/config/link_conditions.py +69 -75
  18. oarepo_runtime/services/config/permissions.py +62 -0
  19. oarepo_runtime/services/records/__init__.py +14 -1
  20. oarepo_runtime/services/records/links.py +21 -11
  21. oarepo_runtime/services/records/mapping.py +42 -0
  22. oarepo_runtime/services/results.py +98 -109
  23. oarepo_runtime/services/schema/__init__.py +12 -44
  24. oarepo_runtime/services/schema/i18n.py +47 -22
  25. oarepo_runtime/services/schema/i18n_ui.py +61 -24
  26. {oarepo_runtime-1.10.2.dist-info → oarepo_runtime-2.0.0.dev3.dist-info}/METADATA +9 -21
  27. oarepo_runtime-2.0.0.dev3.dist-info/RECORD +30 -0
  28. {oarepo_runtime-1.10.2.dist-info → oarepo_runtime-2.0.0.dev3.dist-info}/WHEEL +1 -2
  29. oarepo_runtime-2.0.0.dev3.dist-info/entry_points.txt +5 -0
  30. oarepo_runtime/cli/assets.py +0 -145
  31. oarepo_runtime/cli/base.py +0 -25
  32. oarepo_runtime/cli/cf.py +0 -15
  33. oarepo_runtime/cli/check.py +0 -167
  34. oarepo_runtime/cli/configuration.py +0 -51
  35. oarepo_runtime/cli/fixtures.py +0 -167
  36. oarepo_runtime/cli/index.py +0 -272
  37. oarepo_runtime/cli/permissions/__init__.py +0 -6
  38. oarepo_runtime/cli/permissions/base.py +0 -26
  39. oarepo_runtime/cli/permissions/evaluate.py +0 -63
  40. oarepo_runtime/cli/permissions/list.py +0 -239
  41. oarepo_runtime/cli/permissions/search.py +0 -121
  42. oarepo_runtime/cli/validate.py +0 -150
  43. oarepo_runtime/datastreams/__init__.py +0 -38
  44. oarepo_runtime/datastreams/asynchronous.py +0 -247
  45. oarepo_runtime/datastreams/catalogue.py +0 -150
  46. oarepo_runtime/datastreams/datastreams.py +0 -152
  47. oarepo_runtime/datastreams/errors.py +0 -54
  48. oarepo_runtime/datastreams/ext.py +0 -41
  49. oarepo_runtime/datastreams/fixtures.py +0 -265
  50. oarepo_runtime/datastreams/json.py +0 -4
  51. oarepo_runtime/datastreams/readers/__init__.py +0 -39
  52. oarepo_runtime/datastreams/readers/attachments.py +0 -51
  53. oarepo_runtime/datastreams/readers/excel.py +0 -123
  54. oarepo_runtime/datastreams/readers/json.py +0 -27
  55. oarepo_runtime/datastreams/readers/service.py +0 -54
  56. oarepo_runtime/datastreams/readers/yaml.py +0 -14
  57. oarepo_runtime/datastreams/semi_asynchronous.py +0 -91
  58. oarepo_runtime/datastreams/synchronous.py +0 -70
  59. oarepo_runtime/datastreams/transformers.py +0 -18
  60. oarepo_runtime/datastreams/types.py +0 -323
  61. oarepo_runtime/datastreams/utils.py +0 -131
  62. oarepo_runtime/datastreams/writers/__init__.py +0 -21
  63. oarepo_runtime/datastreams/writers/attachments_file.py +0 -92
  64. oarepo_runtime/datastreams/writers/attachments_service.py +0 -118
  65. oarepo_runtime/datastreams/writers/publish.py +0 -70
  66. oarepo_runtime/datastreams/writers/service.py +0 -175
  67. oarepo_runtime/datastreams/writers/utils.py +0 -30
  68. oarepo_runtime/datastreams/writers/validation_errors.py +0 -20
  69. oarepo_runtime/datastreams/writers/yaml.py +0 -56
  70. oarepo_runtime/ext_config.py +0 -67
  71. oarepo_runtime/i18n/__init__.py +0 -3
  72. oarepo_runtime/info/__init__.py +0 -0
  73. oarepo_runtime/info/check.py +0 -95
  74. oarepo_runtime/info/permissions/__init__.py +0 -0
  75. oarepo_runtime/info/permissions/debug.py +0 -191
  76. oarepo_runtime/info/views.py +0 -586
  77. oarepo_runtime/profile.py +0 -60
  78. oarepo_runtime/records/dumpers/__init__.py +0 -8
  79. oarepo_runtime/records/dumpers/edtf_interval.py +0 -38
  80. oarepo_runtime/records/dumpers/multilingual_dumper.py +0 -34
  81. oarepo_runtime/records/entity_resolvers/__init__.py +0 -13
  82. oarepo_runtime/records/entity_resolvers/proxies.py +0 -57
  83. oarepo_runtime/records/mappings/__init__.py +0 -0
  84. oarepo_runtime/records/mappings/rdm_parent_mapping.json +0 -483
  85. oarepo_runtime/records/owners/__init__.py +0 -3
  86. oarepo_runtime/records/owners/registry.py +0 -22
  87. oarepo_runtime/records/relations/__init__.py +0 -22
  88. oarepo_runtime/records/relations/base.py +0 -296
  89. oarepo_runtime/records/relations/internal.py +0 -46
  90. oarepo_runtime/records/relations/lookup.py +0 -28
  91. oarepo_runtime/records/relations/pid_relation.py +0 -102
  92. oarepo_runtime/records/systemfields/featured_file.py +0 -45
  93. oarepo_runtime/records/systemfields/has_draftcheck.py +0 -47
  94. oarepo_runtime/records/systemfields/icu.py +0 -371
  95. oarepo_runtime/records/systemfields/owner.py +0 -115
  96. oarepo_runtime/records/systemfields/record_status.py +0 -35
  97. oarepo_runtime/records/systemfields/selectors.py +0 -98
  98. oarepo_runtime/records/systemfields/synthetic.py +0 -130
  99. oarepo_runtime/resources/__init__.py +0 -4
  100. oarepo_runtime/resources/config.py +0 -12
  101. oarepo_runtime/resources/file_resource.py +0 -15
  102. oarepo_runtime/resources/json_serializer.py +0 -27
  103. oarepo_runtime/resources/localized_ui_json_serializer.py +0 -54
  104. oarepo_runtime/resources/resource.py +0 -53
  105. oarepo_runtime/resources/responses.py +0 -20
  106. oarepo_runtime/services/components.py +0 -429
  107. oarepo_runtime/services/config/draft_link.py +0 -23
  108. oarepo_runtime/services/config/permissions_presets.py +0 -174
  109. oarepo_runtime/services/config/service.py +0 -117
  110. oarepo_runtime/services/custom_fields/__init__.py +0 -80
  111. oarepo_runtime/services/custom_fields/mappings.py +0 -188
  112. oarepo_runtime/services/entity/__init__.py +0 -0
  113. oarepo_runtime/services/entity/config.py +0 -14
  114. oarepo_runtime/services/entity/schema.py +0 -9
  115. oarepo_runtime/services/entity/service.py +0 -48
  116. oarepo_runtime/services/expansions/__init__.py +0 -0
  117. oarepo_runtime/services/expansions/expandable_fields.py +0 -21
  118. oarepo_runtime/services/expansions/service.py +0 -4
  119. oarepo_runtime/services/facets/__init__.py +0 -33
  120. oarepo_runtime/services/facets/base.py +0 -12
  121. oarepo_runtime/services/facets/date.py +0 -72
  122. oarepo_runtime/services/facets/enum.py +0 -11
  123. oarepo_runtime/services/facets/facet_groups_names.py +0 -17
  124. oarepo_runtime/services/facets/max_facet.py +0 -13
  125. oarepo_runtime/services/facets/multilingual_facet.py +0 -33
  126. oarepo_runtime/services/facets/nested_facet.py +0 -32
  127. oarepo_runtime/services/facets/params.py +0 -192
  128. oarepo_runtime/services/facets/year_histogram.py +0 -200
  129. oarepo_runtime/services/files/__init__.py +0 -8
  130. oarepo_runtime/services/files/components.py +0 -62
  131. oarepo_runtime/services/files/service.py +0 -16
  132. oarepo_runtime/services/generators.py +0 -10
  133. oarepo_runtime/services/permissions/__init__.py +0 -3
  134. oarepo_runtime/services/permissions/generators.py +0 -103
  135. oarepo_runtime/services/relations/__init__.py +0 -0
  136. oarepo_runtime/services/relations/components.py +0 -15
  137. oarepo_runtime/services/relations/errors.py +0 -18
  138. oarepo_runtime/services/relations/mapping.py +0 -38
  139. oarepo_runtime/services/schema/cf.py +0 -13
  140. oarepo_runtime/services/schema/i18n_validation.py +0 -7
  141. oarepo_runtime/services/schema/marshmallow.py +0 -44
  142. oarepo_runtime/services/schema/marshmallow_to_json_schema.py +0 -72
  143. oarepo_runtime/services/schema/oneofschema.py +0 -192
  144. oarepo_runtime/services/schema/polymorphic.py +0 -21
  145. oarepo_runtime/services/schema/rdm.py +0 -75
  146. oarepo_runtime/services/schema/rdm_ui.py +0 -156
  147. oarepo_runtime/services/schema/ui.py +0 -251
  148. oarepo_runtime/services/schema/validation.py +0 -70
  149. oarepo_runtime/services/search.py +0 -282
  150. oarepo_runtime/services/service.py +0 -61
  151. oarepo_runtime/tasks.py +0 -6
  152. oarepo_runtime/translations/cs/LC_MESSAGES/messages.mo +0 -0
  153. oarepo_runtime/translations/cs/LC_MESSAGES/messages.po +0 -85
  154. oarepo_runtime/translations/default_translations.py +0 -6
  155. oarepo_runtime/translations/en/LC_MESSAGES/messages.mo +0 -0
  156. oarepo_runtime/translations/en/LC_MESSAGES/messages.po +0 -89
  157. oarepo_runtime/translations/messages.pot +0 -91
  158. oarepo_runtime/uow.py +0 -146
  159. oarepo_runtime/utils/__init__.py +0 -0
  160. oarepo_runtime/utils/functools.py +0 -37
  161. oarepo_runtime/utils/identity_utils.py +0 -35
  162. oarepo_runtime/utils/index.py +0 -11
  163. oarepo_runtime/utils/path.py +0 -97
  164. oarepo_runtime-1.10.2.dist-info/RECORD +0 -163
  165. oarepo_runtime-1.10.2.dist-info/entry_points.txt +0 -16
  166. oarepo_runtime-1.10.2.dist-info/top_level.txt +0 -2
  167. tests/marshmallow_to_json/__init__.py +0 -0
  168. tests/marshmallow_to_json/test_datacite_ui_schema.py +0 -1410
  169. tests/marshmallow_to_json/test_simple_schema.py +0 -52
  170. tests/pkg_data/__init__.py +0 -0
  171. {oarepo_runtime-1.10.2.dist-info → oarepo_runtime-2.0.0.dev3.dist-info}/licenses/LICENSE +0 -0
@@ -1,130 +0,0 @@
1
- import logging
2
-
3
- from invenio_records.systemfields import SystemField
4
-
5
- from . import Selector
6
- from .mapping import MappingSystemFieldMixin
7
-
8
- log = logging.getLogger(__name__)
9
-
10
-
11
- class SyntheticSystemField(MappingSystemFieldMixin, SystemField):
12
- """
13
- A class that provides a synthetic system field, that is a system field that
14
- generates its content from what is already present inside the record.
15
-
16
- The field is not stored in the record, but is generated on the fly when
17
- the record is being indexed.
18
-
19
- Usage:
20
- 1. Check if any of the provided selectors (oarepo_runtime.records.systemfields.selectors)
21
- are usable for your use case. If not, create a subclass of Selector class.
22
- 2. Put this class onto the record. If you use oarepo-model-builder, add it to the model
23
- like:
24
- ```yaml
25
- record:
26
- record:
27
- imports:
28
- - oarepo_runtime.records.systemfields.SyntheticSystemField
29
- - oarepo_vocabularies.records.selectors.LevelSelector
30
- fields:
31
- faculty = SyntheticSystemField(selector=LevelSelector("metadata.thesis.degreeGrantors", level=1))
32
- department = SyntheticSystemField(selector=LevelSelector("metadata.thesis.degreeGrantors", level=2))
33
- defenseYear = |
34
- SyntheticSystemField(selector=PathSelector("metadata.thesis.dateDefended"),
35
- transformer=lambda x: x[:4]
36
- )
37
- ```
38
-
39
- 4. Add the extra fields to the mapping and facets. If using oarepo-model-builder, add it to the
40
- model like the following piece of code and compile the model:
41
- ```yaml
42
- record:
43
- properties:
44
- faculty:
45
- type: vocabulary
46
- vocabulary-type: institutions
47
- facets:
48
- facet-groups:
49
- - default
50
- label.cs: Fakulta
51
- label.en: Faculty
52
-
53
-
54
- department:
55
- type: vocabulary
56
- vocabulary-type: institutions
57
- facets:
58
- facet-groups:
59
- - default
60
- label.cs: Ústav
61
- label.en: Department
62
-
63
- defenseYear:
64
- type: integer
65
- facets:
66
- facet-groups:
67
- - default
68
- label.cs: Rok obhajoby
69
- label.en: Defense year
70
- ```
71
- """
72
-
73
- def __init__(
74
- self, selector: Selector = None, filter=None, map=None, key=None, **kwargs
75
- ):
76
- self.selector = selector
77
- self.map = map
78
- self.filter = filter
79
- super().__init__(key=key, **kwargs)
80
-
81
- def search_dump(self, data, record):
82
- dt = self._value(data)
83
- if dt:
84
- key = self.key.split(".")
85
- d = data
86
- for k in key[:-1]:
87
- d = d.setdefault(k, {})
88
- d[key[-1]] = dt
89
-
90
- def search_load(self, data, record_cls):
91
- def remove_key(d, key):
92
- if len(key) == 1:
93
- d.pop(key[0], None)
94
- else:
95
- if not isinstance(d, dict) or key[0] not in d:
96
- return
97
- remove_key(d[key[0]], key[1:])
98
- if not d[key[0]]:
99
- d.pop(key[0])
100
-
101
- remove_key(data, self.key.split("."))
102
-
103
- def __get__(self, record, owner=None):
104
- if record is None:
105
- return self
106
- return self._value(record)
107
-
108
- def _value(self, data):
109
- if self.selector:
110
- try:
111
- value = list(self.selector.select(data) or [])
112
- value = [x for x in value if x is not None]
113
- if self.filter:
114
- value = [x for x in value if self.filter(x)]
115
- if self.map:
116
- ret = []
117
- for x in value:
118
- mapped = self.map(x)
119
- if isinstance(mapped, list):
120
- ret.extend(mapped)
121
- elif mapped is not None:
122
- ret.append(mapped)
123
- value = ret
124
- return value
125
- except:
126
- log.exception(f"Error in selector {self.selector} for {self.key}")
127
- return []
128
- raise ValueError(
129
- "Please either provide a selector or subclass this class and implement a _value method"
130
- )
@@ -1,4 +0,0 @@
1
- from .file_resource import S3RedirectFileResource
2
- from .localized_ui_json_serializer import LocalizedUIJSONSerializer
3
-
4
- __all__ = ("LocalizedUIJSONSerializer", "S3RedirectFileResource")
@@ -1,12 +0,0 @@
1
- from invenio_rdm_records.resources.config import (
2
- RDMRecordResourceConfig,
3
- )
4
-
5
- class BaseRecordResourceConfig(RDMRecordResourceConfig):
6
- """Record resource configuration."""
7
-
8
- blueprint_name = None
9
- url_prefix = None
10
-
11
- routes = RDMRecordResourceConfig.routes
12
- routes["all-prefix"] = "/all"
@@ -1,15 +0,0 @@
1
- from invenio_records_resources.resources import FileResource
2
-
3
-
4
- class S3RedirectFileResource(FileResource):
5
- """
6
- A workaround for the fact that the file resource with S3 backend does not
7
- return HTTP 302 for pre-signed URLs.
8
- """
9
-
10
- def read_content(self):
11
- ret = super().read_content()
12
- if ret[0].status_code == 302:
13
- return ret[0], 302
14
- else:
15
- return ret
@@ -1,27 +0,0 @@
1
- from flask import url_for
2
- from flask_resources import JSONSerializer as FlaskJSONSerializer
3
- from invenio_records_resources.services import Service
4
-
5
-
6
- class JSONSerializer(FlaskJSONSerializer):
7
-
8
- def info(self, service:Service) -> dict:
9
- ret = {'description': "Invenio RDM JSON Serialization",
10
- 'name': "JSON Serialization"
11
- }
12
-
13
- schema_value = service.config.record_cls.schema.value
14
- if schema_value:
15
- ret['schema'] = schema_value
16
- if schema_value.startswith("local://"):
17
- schema_value = schema_value.replace("local://", "")
18
- ret['schema_url'] = url_for(
19
- "oarepo_runtime_info.schema",
20
- schema= schema_value,
21
- _external=True,
22
- )
23
- elif schema_value.startwith("http://") or schema_value.startwith("https://"):
24
- ret['schema_url'] = schema_value
25
-
26
-
27
- return ret
@@ -1,54 +0,0 @@
1
- import marshmallow
2
- from flask_resources import MarshmallowSerializer
3
-
4
- from oarepo_runtime.i18n import get_locale
5
-
6
-
7
- class LocalizedUIJSONSerializer(MarshmallowSerializer):
8
- def __init__(
9
- self,
10
- format_serializer_cls,
11
- object_schema_cls,
12
- list_schema_cls=None,
13
- schema_context=None,
14
- **serializer_options,
15
- ):
16
- # the constructor instantiates the object_schema_cls, which is too early
17
- # if the schema uses current_app (for example, for translations or custom fields)
18
- # so we pass an empty schema and replace it later
19
- super().__init__(
20
- format_serializer_cls=format_serializer_cls,
21
- object_schema_cls=marshmallow.Schema,
22
- list_schema_cls=marshmallow.Schema,
23
- schema_context=schema_context or {},
24
- **serializer_options,
25
- )
26
- # replace the object schema class
27
- self.object_schema_cls = object_schema_cls
28
- self.list_schema_cls = list_schema_cls
29
-
30
- def dump_obj(self, obj, *args, **kwargs):
31
- """Dump the object using object schema class."""
32
- ctx = {**self.schema_context, "locale": get_locale()}
33
- if "extra_context" in kwargs:
34
- ctx |= kwargs["extra_context"]
35
-
36
- return self.object_schema_cls(context=ctx).dump(obj)
37
-
38
- def dump_list(self, obj_list, *args, **kwargs):
39
- """Dump the list of objects."""
40
- ctx = {
41
- "object_schema_cls": self.object_schema_cls,
42
- }
43
- ctx.update(self.schema_context)
44
- ctx["locale"] = get_locale()
45
-
46
- if "extra_context" in kwargs:
47
- ctx |= kwargs["extra_context"]
48
-
49
- if self.list_schema_cls is None:
50
- return self.object_schema_cls(context=self.schema_context).dump(
51
- obj_list, many=True
52
- )
53
-
54
- return self.list_schema_cls(context=ctx).dump(obj_list)
@@ -1,53 +0,0 @@
1
- from flask import g
2
- from flask_resources import (
3
- resource_requestctx,
4
- response_handler,
5
- route,
6
- )
7
- from invenio_rdm_records.resources import RDMRecordResource
8
- from invenio_records_resources.resources.records.resource import (
9
- request_extra_args,
10
- request_search_args,
11
- request_view_args,
12
- )
13
- from invenio_records_resources.resources.records.utils import search_preference
14
-
15
- class BaseRecordResource(RDMRecordResource):
16
-
17
- def create_url_rules(self):
18
- """Create the URL rules for the record resource."""
19
-
20
- def p(route):
21
- """Prefix a route with the URL prefix."""
22
- return f"{self.config.url_prefix}{route}"
23
-
24
- def s(route):
25
- """Suffix a route with the URL prefix."""
26
- return f"{route}{self.config.url_prefix}"
27
-
28
- routes = self.config.routes
29
- url_rules = super(RDMRecordResource, self).create_url_rules()
30
- url_rules += [
31
- route("GET", s(routes["all-prefix"]), self.search_all_records),
32
- ]
33
-
34
- return url_rules
35
-
36
- @request_extra_args
37
- @request_search_args
38
- @request_view_args
39
- @response_handler(many=True)
40
- def search_all_records(self):
41
- """Perform a search over all records. Permission generators for search_all_records
42
- and read_all_records must be in place and must be used to filter the results so that
43
- no information is leaked.
44
-
45
- GET /all/records
46
- """
47
- hits = self.service.search_all_records(
48
- identity=g.identity,
49
- params=resource_requestctx.args,
50
- search_preference=search_preference(),
51
- expand=resource_requestctx.args.get("expand", False),
52
- )
53
- return hits.to_dict(), 200
@@ -1,20 +0,0 @@
1
- from flask_resources.responses import ResponseHandler
2
-
3
- class ExportableResponseHandler(ResponseHandler):
4
-
5
- def __init__(self, serializer, export_code, name, headers=None):
6
- """Constructor."""
7
- self.export_code = export_code
8
- self.name = name
9
- super().__init__(serializer, headers)
10
-
11
-
12
- class OAIExportableResponseHandler(ExportableResponseHandler):
13
-
14
- def __init__(self, serializer, export_code, name, oai_metadata_prefix, oai_schema, oai_namespace,
15
- headers=None):
16
- """Constructor."""
17
- self.oai_metadata_prefix = oai_metadata_prefix
18
- self.oai_schema = oai_schema
19
- self.oai_namespace = oai_namespace
20
- super().__init__(serializer, export_code, name, headers)