c9ef6c2420e695a7a09adce731e72c79cf4b1d59
[pti/o2.git] / o2ims / domain / stx_repo.py
1 # Copyright (C) 2021 Wind River Systems, Inc.\r
2 #\r
3 #  Licensed under the Apache License, Version 2.0 (the "License");\r
4 #  you may not use this file except in compliance with the License.\r
5 #  You may obtain a copy of the License at\r
6 #\r
7 #      http://www.apache.org/licenses/LICENSE-2.0\r
8 #\r
9 #  Unless required by applicable law or agreed to in writing, software\r
10 #  distributed under the License is distributed on an "AS IS" BASIS,\r
11 #  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
12 #  See the License for the specific language governing permissions and\r
13 #  limitations under the License.\r
14 \r
15 import abc\r
16 from typing import List, Set\r
17 from o2ims.domain.stx_object import StxGenericModel\r
18 from o2ims.domain.resource_type import ResourceTypeEnum\r
19 \r
20 \r
21 class StxObjectRepository(abc.ABC):\r
22     def __init__(self):\r
23         self.seen = set()  # type: Set[StxGenericModel]\r
24 \r
25     def add(self, stx_obj: StxGenericModel):\r
26         self._add(stx_obj)\r
27         self.seen.add(stx_obj)\r
28 \r
29     def get(self, stx_obj_id) -> StxGenericModel:\r
30         stx_obj = self._get(stx_obj_id)\r
31         if stx_obj:\r
32             self.seen.add(stx_obj)\r
33         return stx_obj\r
34 \r
35     def list(self, type: ResourceTypeEnum) -> List[StxGenericModel]:\r
36         return self._list(type)\r
37 \r
38     def update(self, stx_obj: StxGenericModel):\r
39         self._update(stx_obj)\r
40         self.seen.add(stx_obj)\r
41 \r
42     # def update_fields(self, stx_obj_id: str, updatefields: dict):\r
43     #     self._update(stx_obj_id, updatefields)\r
44 \r
45     @abc.abstractmethod\r
46     def _add(self, stx_obj: StxGenericModel):\r
47         raise NotImplementedError\r
48 \r
49     @abc.abstractmethod\r
50     def _get(self, stx_obj_id) -> StxGenericModel:\r
51         raise NotImplementedError\r
52 \r
53     @abc.abstractmethod\r
54     def _update(self, stx_obj: StxGenericModel):\r
55         raise NotImplementedError\r
56 \r
57     @abc.abstractmethod\r
58     def _list(self, type: ResourceTypeEnum):\r
59         raise NotImplementedError\r