|
10 | 10 |
|
11 | 11 | from enum import Enum |
12 | 12 | from functools import partial |
| 13 | +from werkzeug.utils import cached_property |
13 | 14 |
|
14 | 15 | from invenio_records.dumpers import SearchDumper |
15 | 16 | from invenio_records.systemfields import ConstantField, DictField, ModelField |
16 | 17 | from invenio_records_resources.records.api import Record |
17 | 18 | from invenio_records_resources.records.systemfields import IndexField |
18 | 19 |
|
19 | 20 | from ..customizations import RequestState as State |
20 | | -from .dumpers import CalculatedFieldDumperExt, GrantTokensDumperExt |
| 21 | +from .dumpers import ( |
| 22 | + CalculatedFieldDumperExt, |
| 23 | + GrantTokensDumperExt, |
| 24 | + ParentChildDumperExt, |
| 25 | +) |
21 | 26 | from .models import RequestEventModel, RequestMetadata |
22 | 27 | from .systemfields import ( |
23 | 28 | EntityReferenceField, |
@@ -51,6 +56,13 @@ class RequestEvent(Record): |
51 | 56 |
|
52 | 57 | model_cls = RequestEventModel |
53 | 58 |
|
| 59 | + dumper = SearchDumper( |
| 60 | + extensions=[ |
| 61 | + ParentChildDumperExt(), |
| 62 | + ] |
| 63 | + ) |
| 64 | + """Search dumper with parent-child relationship extension.""" |
| 65 | + |
54 | 66 | # Systemfields |
55 | 67 | metadata = None |
56 | 68 |
|
@@ -83,6 +95,22 @@ class RequestEvent(Record): |
83 | 95 | created_by = EntityReferenceField("created_by", check_referenced) |
84 | 96 | """Who created the event.""" |
85 | 97 |
|
| 98 | + parent_id = DictField("parent_id") |
| 99 | + """The parent event ID for parent-child relationships.""" |
| 100 | + |
| 101 | + parent_child = DictField("parent_child") |
| 102 | + """OpenSearch join relationship for parent-child queries.""" |
| 103 | + |
| 104 | + def pre_commit(self): |
| 105 | + """Hook called before committing the record. |
| 106 | +
|
| 107 | + Validates that children are allowed for this event type. |
| 108 | + """ |
| 109 | + from .validators import validate_children_allowed |
| 110 | + |
| 111 | + validate_children_allowed(self) |
| 112 | + super().pre_commit() |
| 113 | + |
86 | 114 |
|
87 | 115 | class Request(Record): |
88 | 116 | """A generic request record.""" |
|
0 commit comments