diff --git a/oarepo_runtime/records/mappings/__init__.py b/oarepo_runtime/records/mappings/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/oarepo_runtime/records/mappings/rdm_parent_mapping.json b/oarepo_runtime/records/mappings/rdm_parent_mapping.json new file mode 100644 index 0000000..0656466 --- /dev/null +++ b/oarepo_runtime/records/mappings/rdm_parent_mapping.json @@ -0,0 +1,39 @@ +{ + "is_verified": { + "type": "boolean" + }, + "access": { + "properties": { + "owned_by": { + "properties": { + "user": { + "type": "keyword" + } + } + }, + "grants": { + "properties": { + "subject": { + "type": "keyword" + }, + "id": { + "type": "keyword" + }, + "level": { + "type": "keyword" + } + } + }, + "grant_tokens": { + "type": "keyword" + }, + "links": { + "properties": { + "id": { + "type": "keyword" + } + } + } + } + } +} \ No newline at end of file diff --git a/oarepo_runtime/services/custom_fields/mappings.py b/oarepo_runtime/services/custom_fields/mappings.py index 4dbdd00..f063121 100644 --- a/oarepo_runtime/services/custom_fields/mappings.py +++ b/oarepo_runtime/services/custom_fields/mappings.py @@ -13,8 +13,12 @@ from invenio_search.engine import dsl, search from invenio_search.utils import build_alias_name +from deepmerge import always_merger from oarepo_runtime.records.systemfields.mapping import MappingSystemFieldMixin +import json +import os +from pathlib import Path class Mapping(InvenioMapping): @classmethod @@ -116,6 +120,16 @@ def prepare_cf_index(record_class, config, path=[]): def prepare_parent_mapping(parent_class, config): if not parent_class: return + + script_dir = str(Path(__file__).resolve().parent) + path_parts = script_dir.split('/') + path_parts = path_parts[:-2] + base_path = '/'.join(path_parts) + mapping_path = f"{base_path}/records/mappings/rdm_parent_mapping.json" + + with open(mapping_path, 'r') as f: + rdm_parent = json.load(f) + parent_mapping = { "parent": { "type": "object", @@ -142,7 +156,11 @@ def prepare_parent_mapping(parent_class, config): }, } } - + parent_mapping_merged = always_merger.merge(parent_mapping, { + "parent": { + "properties": rdm_parent + } + }) # upload mapping try: record_index = dsl.Index( @@ -151,7 +169,7 @@ def prepare_parent_mapping(parent_class, config): ), using=current_search_client, ) - update_index(record_index, {}, parent_mapping) + update_index(record_index, {}, parent_mapping_merged) if hasattr(config, "draft_cls"): draft_index = dsl.Index( @@ -160,7 +178,7 @@ def prepare_parent_mapping(parent_class, config): ), using=current_search_client, ) - update_index(draft_index, {}, parent_mapping) + update_index(record_index, {}, parent_mapping_merged) except search.RequestError as e: click.secho("An error occurred while creating parent mapping.", fg="red") diff --git a/setup.cfg b/setup.cfg index aa6a935..12c1c4a 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = oarepo-runtime -version = 1.5.81 +version = 1.5.82 description = A set of runtime extensions of Invenio repository authors = Alzbeta Pokorna readme = README.md