Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated parent mapping #239

Merged
merged 2 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file.
39 changes: 39 additions & 0 deletions oarepo_runtime/records/mappings/rdm_parent_mapping.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
}
}
}
}
24 changes: 21 additions & 3 deletions oarepo_runtime/services/custom_fields/mappings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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",
Expand All @@ -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(
Expand All @@ -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(
Expand All @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Loading