-
Notifications
You must be signed in to change notification settings - Fork 421
/
dqw_item.py
141 lines (108 loc) · 3.63 KB
/
dqw_item.py
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
from defusedxml.ElementTree import fromstring
from tableauserverclient.datetime_helpers import parse_datetime
class DQWItem(object):
class WarningType:
WARNING = "WARNING"
DEPRECATED = "DEPRECATED"
STALE = "STALE"
SENSITIVE_DATA = "SENSITIVE_DATA"
MAINTENANCE = "MAINTENANCE"
def __init__(self, warning_type="WARNING", message=None, active=True, severe=False):
self._id = None
# content related
self._content_id = None
self._content_type = None
# DQW related
self.warning_type = warning_type
self.message = message
self.active = active
self.severe = severe
self._created_at = None
self._updated_at = None
# owner
self._owner_display_name = None
self._owner_id = None
@property
def id(self):
return self._id
@property
def content_id(self):
return self._content_id
@property
def content_type(self):
return self._content_type
@property
def owner_display_name(self):
return self._owner_display_name
@property
def owner_id(self):
return self._owner_id
@property
def warning_type(self):
return self._warning_type
@warning_type.setter
def warning_type(self, value):
self._warning_type = value
@property
def message(self):
return self._message
@message.setter
def message(self, value):
self._message = value
@property
def active(self):
return self._active
@active.setter
def active(self, value):
self._active = value
@property
def severe(self):
return self._severe
@severe.setter
def severe(self, value):
self._severe = value
@property
def created_at(self):
return self._created_at
@created_at.setter
def created_at(self, value):
self._created_at = value
@property
def updated_at(self):
return self._updated_at
@updated_at.setter
def updated_at(self, value):
self._updated_at = value
@classmethod
def from_response(cls, resp, ns):
return cls.from_xml_element(fromstring(resp), ns)
@classmethod
def from_xml_element(cls, parsed_response, ns):
all_dqws = []
dqw_elem_list = parsed_response.findall(".//t:dataQualityWarning", namespaces=ns)
for dqw_elem in dqw_elem_list:
dqw = DQWItem()
dqw._id = dqw_elem.get("id", None)
dqw._owner_display_name = dqw_elem.get("userDisplayName", None)
dqw._content_id = dqw_elem.get("contentId", None)
dqw._content_type = dqw_elem.get("contentType", None)
dqw.message = dqw_elem.get("message", None)
dqw.warning_type = dqw_elem.get("type", None)
is_active = dqw_elem.get("isActive", None)
if is_active is not None:
dqw._active = string_to_bool(is_active)
is_severe = dqw_elem.get("isSevere", None)
if is_severe is not None:
dqw._severe = string_to_bool(is_severe)
dqw._created_at = parse_datetime(dqw_elem.get("createdAt", None))
dqw._updated_at = parse_datetime(dqw_elem.get("updatedAt", None))
owner_id = None
owner_tag = dqw_elem.find(".//t:owner", namespaces=ns)
if owner_tag is not None:
owner_id = owner_tag.get("id", None)
dqw._owner_id = owner_id
all_dqws.append(dqw)
return all_dqws
# Used to convert string represented boolean to a boolean type
def string_to_bool(s):
return s.lower() == "true"