Skip to content

Commit

Permalink
Updated parent mapping (#239)
Browse files Browse the repository at this point in the history
* rdm parent mapping

* rdm parent mapping

---------

Co-authored-by: Alzbeta Pokorna <[email protected]>
Alzpeta and Alzbeta Pokorna authored Dec 11, 2024
1 parent 3b6eb65 commit a8122e8
Showing 4 changed files with 61 additions and 4 deletions.
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
@@ -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")
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

0 comments on commit a8122e8

Please sign in to comment.