Create an init version of a network viewer
[oam.git] / code / network-generator / model / python / o_ran_object.py
1 # Copyright 2023 highstreet technologies GmbH
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 #!/usr/bin/python
16
17 """
18 An abstract Class for O-RAN Objects
19 """
20 from abc import ABC, abstractmethod
21 from typing import Dict
22
23 from model.python.top import ITop, Top
24 from model.python.type_definitions import (
25     AddressType,
26 )
27 from model.python.geo_location import GeoLocation
28
29
30 # Define the "IORanObject" interface
31 class IORanObject(ITop):
32     def __init__(
33         self,
34         address: AddressType = None,
35         geoLocation: GeoLocation = None,
36         url: str = None,
37         **kwargs
38     ):
39         super().__init__(**kwargs)
40         self.address = address
41         self.geoLocation = geoLocation
42         self.url = url
43
44
45 # Define an abstract O-RAN Object class
46 class ORanObject(Top, IORanObject):
47     def __init__(self, of: IORanObject = None, **kwargs):
48         super().__init__(**kwargs)
49         self.address = of["address"] if of and "address" in of else None
50         self.geoLocation = (
51             of["geoLocation"] if of and "geoLocation" in of else GeoLocation()
52         )
53         self.url = of["url"] if of and "url" in of else self.id
54
55     @property
56     def address(self):
57         return self._address
58
59     @address.setter
60     def address(self, value):
61         self._address = value
62
63     @property
64     def geoLocation(self):
65         return self._geographicalLocation
66
67     @geoLocation.setter
68     def geoLocation(self, value):
69         self._geographicalLocation = value
70
71     @property
72     def url(self):
73         return self._url
74
75     @url.setter
76     def url(self, value):
77         self._url = value
78
79     def json(self):
80         result :Dict = super().json()
81         result['address'] = self.address
82         result['geoLocation'] = self.geoLocation.json()
83         result['url'] = self.url
84         return result
85
86     def __str__(self):
87         return str(self.json())
88     
89     @abstractmethod
90     def toTopology(self):
91         pass
92
93     @abstractmethod
94     def toKml(self):
95         pass
96
97     @abstractmethod
98     def toSvg(self):
99         pass