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