-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathvirtual_table_header_model.py
More file actions
117 lines (100 loc) · 4.07 KB
/
virtual_table_header_model.py
File metadata and controls
117 lines (100 loc) · 4.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# The MIT License (MIT)
#
# Copyright (C) 2024 - Ericsson
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
"""Virtual table header model file."""
import json
COLUMN_ID_KEY = "id"
COLUMN_NAME_KEY = "name"
COLUMN_DESCRIPTION_KEY = "description"
COLUMN_TYPE_KEY = "type"
class VirtualTableHeaderModel:
'''
Virtual table header model that will be returned by the server
'''
def __init__(self, params):
# Array of columns in the virtual table
self.columns = []
if params is not None:
for column in params:
# Create a new virtual table header column model
self.columns.append(VirtualTableHeaderColumnModel(column))
def print(self):
'''
Print the virtual table header model
'''
print("Virtual Table Columns:")
for column in self.columns:
column.print()
def to_json(self):
return json.dumps(self, cls=VirtualTableHeaderModelEncoder, indent=4)
class VirtualTableHeaderModelEncoder(json.JSONEncoder):
def default(self, obj):
if isinstance(obj, VirtualTableHeaderModel):
# result = {}
# result['model'] = [ VirtualTableHeaderColumnModelEncoder().default(column) for column in obj.columns ]
return [ VirtualTableHeaderColumnModelEncoder().default(column) for column in obj.columns ]
return super().default(obj)
class VirtualTableHeaderColumnModel:
'''
Virtual table header column model that will be returned by the server
'''
def __init__(self, params):
# Column ID
self.id = None
if COLUMN_ID_KEY in params:
self.id = params.get(COLUMN_ID_KEY)
del params[COLUMN_ID_KEY]
# Column name
self.name = None
if COLUMN_NAME_KEY in params:
self.name = params.get(COLUMN_NAME_KEY)
del params[COLUMN_NAME_KEY]
# Column description
self.description = None
if COLUMN_DESCRIPTION_KEY in params:
self.description = params.get(COLUMN_DESCRIPTION_KEY)
del params[COLUMN_DESCRIPTION_KEY]
# Column type
self.type = None
if COLUMN_TYPE_KEY in params:
self.type = params.get(COLUMN_TYPE_KEY)
del params[COLUMN_TYPE_KEY]
def print(self):
'''
Print the virtual table header column model
'''
print(" id: " + str(self.id))
print(" name: " + str(self.name))
print(" description: " + str(self.description))
print(" type: " + str(self.type))
print("-" * 50)
def to_json(self):
return json.dumps(self, cls=VirtualTableHeaderColumnModelEncoder, indent=4)
class VirtualTableHeaderColumnModelEncoder(json.JSONEncoder):
def default(self, obj):
if isinstance(obj, VirtualTableHeaderColumnModel):
result = {}
result[COLUMN_ID_KEY] = obj.id
result[COLUMN_NAME_KEY] = obj.name
result[COLUMN_DESCRIPTION_KEY] = obj.description
result[COLUMN_TYPE_KEY] = obj.type
return result
return super().default(obj)