1 # Copyright (C) 2022 Wind River Systems, Inc.
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
7 # http://www.apache.org/licenses/LICENSE-2.0
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.
16 from typing import List, Set, Tuple
17 from o2ims.domain import alarm_obj as obj
20 class AlarmEventRecordRepository(abc.ABC):
22 self.seen = set() # type: Set[obj.AlarmEventRecord]
24 def add(self, alarm_event_record: obj.AlarmEventRecord):
25 self._add(alarm_event_record)
26 self.seen.add(alarm_event_record)
28 def get(self, alarm_event_record_id) -> obj.AlarmEventRecord:
29 alarm_event_record = self._get(alarm_event_record_id)
30 if alarm_event_record:
31 self.seen.add(alarm_event_record)
32 return alarm_event_record
34 def list(self, **kwargs) -> List[obj.AlarmEventRecord]:
35 return self._list(*[], **kwargs)[1]
37 def list_with_count(self, *args, **kwargs) -> \
38 Tuple[int, List[obj.AlarmEventRecord]]:
39 return self._list(*args, **kwargs)
41 def update(self, alarm_event_record: obj.AlarmEventRecord):
42 self._update(alarm_event_record)
44 def delete(self, alarm_event_record_id):
45 self._delete(alarm_event_record_id)
48 def _add(self, alarm_event_record: obj.AlarmEventRecord):
49 raise NotImplementedError
52 def _get(self, alarm_event_record_id) -> obj.AlarmEventRecord:
53 raise NotImplementedError
56 def _list(self, **kwargs) -> Tuple[int, List[obj.AlarmEventRecord]]:
57 raise NotImplementedError
60 def _update(self, alarm_event_record: obj.AlarmEventRecord):
61 raise NotImplementedError
64 def _delete(self, alarm_event_record_id):
65 raise NotImplementedError
68 class AlarmDefinitionRepository(abc.ABC):
70 self.seen = set() # type: Set[obj.AlarmDefinition]
72 def add(self, definition: obj.AlarmDefinition):
74 self.seen.add(definition)
76 def get(self, definition_id) -> obj.AlarmDefinition:
77 definition = self._get(definition_id)
79 self.seen.add(definition)
82 def list(self) -> List[obj.AlarmDefinition]:
85 def update(self, definition: obj.AlarmDefinition):
86 self._update(definition)
88 def delete(self, definition_id):
89 self._delete(definition_id)
92 def _add(self, definition: obj.AlarmDefinition):
93 raise NotImplementedError
96 def _get(self, definition_id) -> obj.AlarmDefinition:
97 raise NotImplementedError
100 def _list(self, **kwargs) -> List[obj.AlarmDefinition]:
101 raise NotImplementedError
104 def _update(self, definition: obj.AlarmDefinition):
105 raise NotImplementedError
108 def _delete(self, definition_id):
109 raise NotImplementedError
112 class AlarmDictionaryRepository(abc.ABC):
114 self.seen = set() # type: Set[obj.AlarmDictionary]
116 def add(self, dictionary: obj.AlarmDictionary):
117 self._add(dictionary)
118 self.seen.add(dictionary)
120 def get(self, dictionary_id) -> obj.AlarmDictionary:
121 dictionary = self._get(dictionary_id)
123 self.seen.add(dictionary)
126 def list(self) -> List[obj.AlarmDictionary]:
129 def update(self, dictionary: obj.AlarmDictionary):
130 self._update(dictionary)
132 def delete(self, dictionary_id):
133 self._delete(dictionary_id)
136 def _add(self, dictionary: obj.AlarmDictionary):
137 raise NotImplementedError
140 def _get(self, dictionary_id) -> obj.AlarmDictionary:
141 raise NotImplementedError
144 def _list(self, **kwargs) -> List[obj.AlarmDictionary]:
145 raise NotImplementedError
148 def _delete(self, dictionary_id):
149 raise NotImplementedError
152 class AlarmSubscriptionRepository(abc.ABC):
154 self.seen = set() # type: Set[obj.AlarmSubscription]
156 def add(self, subscription: obj.AlarmSubscription):
157 self._add(subscription)
158 self.seen.add(subscription)
160 def get(self, subscription_id) -> obj.AlarmSubscription:
161 subscription = self._get(subscription_id)
163 self.seen.add(subscription)
166 def list(self, **kwargs) -> List[obj.AlarmSubscription]:
167 return self._list(*[], **kwargs)[1]
169 def list_with_count(self, *args, **kwargs) -> \
170 Tuple[int, List[obj.AlarmSubscription]]:
171 return self._list(*args, **kwargs)
173 def update(self, subscription: obj.AlarmSubscription):
174 self._update(subscription)
176 def delete(self, subscription_id):
177 self._delete(subscription_id)
180 def _add(self, subscription: obj.AlarmSubscription):
181 raise NotImplementedError
184 def _get(self, subscription_id) -> obj.AlarmSubscription:
185 raise NotImplementedError
188 def _list(self, **kwargs) -> Tuple[int, List[obj.AlarmSubscription]]:
189 raise NotImplementedError
192 def _update(self, subscription: obj.AlarmSubscription):
193 raise NotImplementedError
196 def _delete(self, subscription_id):
197 raise NotImplementedError
200 class AlarmProbableCauseRepository(abc.ABC):
202 self.seen = set() # type: Set[obj.ProbableCause]
204 def add(self, probable_cause: obj.ProbableCause):
205 self._add(probable_cause)
206 self.seen.add(probable_cause)
208 def get(self, probable_cause_id) -> obj.ProbableCause:
209 probable_cause = self._get(probable_cause_id)
211 self.seen.add(probable_cause)
212 return probable_cause
214 def list(self) -> List[obj.ProbableCause]:
217 def update(self, probable_cause: obj.ProbableCause):
218 self._update(probable_cause)
220 def delete(self, probable_cause_id):
221 self._delete(probable_cause_id)
224 def _add(self, probable_cause: obj.ProbableCause):
225 raise NotImplementedError
228 def _get(self, probable_cause_id) -> obj.ProbableCause:
229 raise NotImplementedError
232 def _list(self, **kwargs) -> List[obj.ProbableCause]:
233 raise NotImplementedError
236 def _update(self, probable_cause: obj.ProbableCause):
237 raise NotImplementedError
240 def _delete(self, probable_cause_id):
241 raise NotImplementedError