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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
class CustomListEntryMapper(ResourceMapper):
    """An interface for mapping CRUD actions to custom list entries."""

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

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

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

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

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

    def _check_valid_custom_list(
        self, list_name: Optional[CustomListName]
    ) -> CustomListName:
        """Checks if the custom lists exists within the store."""
        if (
            list_name is None
            or list_name not in CustomListName._value2member_map_.keys()
        ):
            raise errors.ErrorNotFound(
                f"CustomListName, {list_name}, does not exist or is None."
            )
        else:
            return list_name

    def _ensure_parent_exists(
        self, parent: Optional[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 is not None:
            raise errors.InternalError(
                "Parent specified for item in list with no parent list."
            )

    def _delete_children(
        self, entry_name: str, list_name: CustomListName
    ) -> 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)