Skip to content

store_session

MLTE custom list store interface implementation

CustomListEntryMapper

Bases: ResourceMapper

An interface for mapping CRUD actions to custom list entries.

Source code in mlte/store/custom_list/store_session.py
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
class CustomListEntryMapper(ResourceMapper):
    """An interface for mapping CRUD actions to custom list entries."""

    def create(
        self,
        new_custom_list_entry: CustomListEntryModel,
        custom_list_name: Optional[CustomListName] = None,
    ) -> CustomListEntryModel:
        raise NotImplementedError(ResourceMapper.NOT_IMPLEMENTED_ERROR_MSG)

    def edit(
        self,
        updated_custom_list_entry: CustomListEntryModel,
        custom_list_name: Optional[CustomListName] = None,
    ) -> CustomListEntryModel:
        raise NotImplementedError(ResourceMapper.NOT_IMPLEMENTED_ERROR_MSG)

    def read(
        self,
        custom_list_entry_name: str,
        custom_list_name: Optional[CustomListName] = None,
    ) -> CustomListEntryModel:
        raise NotImplementedError(ResourceMapper.NOT_IMPLEMENTED_ERROR_MSG)

    def list(
        self,
        custom_list_name: Optional[CustomListName] = None,
    ) -> List[str]:
        raise NotImplementedError(ResourceMapper.NOT_IMPLEMENTED_ERROR_MSG)

    def delete(
        self,
        custom_list_entry_name: str,
        custom_list_name: Optional[CustomListName] = None,
    ) -> CustomListEntryModel:
        raise NotImplementedError(ResourceMapper.NOT_IMPLEMENTED_ERROR_MSG)

    def _ensure_parent_exists(
        self, parent: str, list_name: Optional[CustomListName]
    ) -> None:
        if list_name in CustomListParentMappings.parent_mappings.keys():
            if parent not in self.list(
                CustomListName(
                    CustomListParentMappings.parent_mappings[list_name]
                )
            ):
                raise errors.ErrorNotFound(
                    f"Parent {parent} does not exist in list {CustomListParentMappings.parent_mappings[list_name]}"
                )
        elif parent != "":
            raise errors.InternalError(
                "Parent specified for item in list with no parent list."
            )

    def _delete_children(
        self, list_name: Optional[CustomListName], entry_name: str
    ) -> None:
        """Cascades delete to children of a parent."""
        child_list_name = CustomListParentMappings.get_child_list_name(
            list_name
        )
        if child_list_name:
            for child_entry_name in self.list(CustomListName(child_list_name)):
                child_entry = self.read(child_entry_name, child_list_name)
                if child_entry.parent == entry_name:
                    self.delete(child_entry_name, child_list_name)

CustomListStoreSession

Bases: StoreSession

The base class for all implementations of the MLTE custom list store session.

Source code in mlte/store/custom_list/store_session.py
20
21
22
23
24
class CustomListStoreSession(StoreSession):
    """The base class for all implementations of the MLTE custom list store session."""

    custom_list_entry_mapper: CustomListEntryMapper
    """Mapper for the custom list entry resource."""

custom_list_entry_mapper instance-attribute

Mapper for the custom list entry resource.

ManagedCustomListSession

Bases: ManagedSession

A simple context manager for store sessions.

Source code in mlte/store/custom_list/store_session.py
27
28
29
30
31
class ManagedCustomListSession(ManagedSession):
    """A simple context manager for store sessions."""

    def __enter__(self) -> CustomListStoreSession:
        return cast(CustomListStoreSession, self.session)