823d0d5eca51edd27f9a0a340df7038e8a361244
[pti/o2.git] / o2ims / adapter / alarm_loader.py
1 # Copyright (C) 2022 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 from typing import List
16
17 from o2ims.domain import alarm_obj
18 from o2ims.domain.alarm_repo import AlarmDictionaryRepository
19 from o2common.helper import o2logging
20 logger = o2logging.get_logger(__name__)
21
22
23 class AlarmDictionaryConfigFileRepository(AlarmDictionaryRepository):
24     def __init__(self):
25         super().__init__()
26         self.dictionary = {}
27
28     def _add(self, alarm_dict: alarm_obj.AlarmDictionary):
29         self.dictionary[alarm_dict.entityType] = alarm_dict
30
31     def _get(self, alarm_entity_type) -> alarm_obj.AlarmDictionary:
32         return self.dictionary[alarm_entity_type]
33
34     def _list(self) -> List[alarm_obj.AlarmDictionary]:
35         return [alarm_dict for alarm_dict in self.dictionary.items()]
36
37     def _update(self, alarm_dict: alarm_obj.AlarmDictionary):
38         self.dictionary[alarm_dict.entityType] = alarm_dict
39
40     def _delete(self, alarm_entity_type):
41         if alarm_entity_type in self.dictionary.keys():
42             del self.dictionary[alarm_entity_type]