1
1
import xml .etree .ElementTree as ET
2
2
from .exceptions import UnpopulatedPropertyError
3
- from .property_decorators import property_not_nullable , property_is_boolean
3
+ from .property_decorators import property_not_empty , property_not_nullable , property_is_boolean , property_is_set
4
4
from .tag_item import TagItem
5
5
from ..datetime_helpers import parse_datetime
6
<
8000
code>6 import copy
7
7
8
8
9
9
class DatasourceItem (object ):
10
10
def __init__ (self , project_id , name = None ):
11
+ self ._certified = None
12
+ self ._certification_note = None
13
+ self ._connected_workbooks_count = None
11
14
self ._connections = None
12
15
self ._content_url = None
13
16
self ._created_at = None
17
+ self ._database_name = None
14
18
self ._datasource_type = None
19
+ self ._description = None
20
+ self ._encrypt_extracts = None
21
+ self ._favorites_total = None
15
22
self ._id = None
16
23
self ._initial_tags = set ()
24
+ self ._has_alert = None
25
+ self ._has_extracts = None
26
+ self ._name = name
27
+ self ._owner_id = None
28
+ self ._owner_name = None
17
29
self ._project_name = None
30
+ self ._published = None
31
+ self ._server_name = None
32
+ self ._size = None
33
+ self ._tags = set ()
18
34
self ._updated_at = None
19
- self ._certified = None
20
- self ._certification_note = None
21
- self .name = name
22
- self .owner_id = None
35
+ self ._use_remote_query_agent = None
36
+ self ._webpage_url = None
37
+
23
38
self .project_id = project_id
24
- self .tags = set ()
39
+
40
+ @property
41
+ def certified (self ):
42
+ return self ._certified
43
+
44
+ @certified .setter
45
+ @property_not_nullable
46
+ @property_is_boolean
47
+ def certified (self , value ):
48
+ self ._certified = value
49
+
50
+ @property
51
+ def certification_note (self ):
52
+ return self ._certification_note
53
+
54
+ @certification_note .setter
55
+ def certification_note (self , value ):
56
+ self ._certification_note = value
57
+
58
+ @property
59
+ def connected_workbooks_count (self ):
60
+ return self ._connected_workbooks_count
25
61
26
62
@property
27
63
def connections (self ):
@@ -39,32 +75,67 @@ def created_at(self):
39
75
return self ._created_at
40
76
41
77
@property
42
- def certified (self ):
43
- return self ._certified
78
+ def database_name (self ):
79
+ return self ._database_name
44
80
45
- @certified .setter
46
- @property_not_nullable
47
- @property_is_boolean
48
- def certified (self , value ):
49
- self ._certified = value
81
+ @property
82
+ def datasource_type (self ):
83
+ return self ._datasource_type
50
84
51
85
@property
52
- def certification_note (self ):
53
- return self ._certification_note
86
+ def description (self ):
87
+ return self ._description
54
88
55
- @certification_note .setter
56
- def certification_note (self , value ):
57
- self ._certification_note = value
89
+ @property
90
+ def encrypt_extracts (self ):
91
+ return self ._encrypt_extracts
92
+
93
+ @property
94
+ def favorites_total (self ):
95
+ return self ._favorites_total
58
96
59
97
@property
60
98
def id (self ):
61
99
return self ._id
62
100
101
+ @property
102
+ def has_alert (self ):
103
+ return self ._has_alert
104
+
105
+ @property
106
+ def has_extracts (self ):
107
+ return self ._has_extracts
108
+
109
+ @property
110
+ def name (self ):
111
+ return self ._name
112
+
113
+ @name .setter
114
+ @property_not_empty
115
+ @property_not_nullable
116
+ def name (self , value ):
117
+ self ._name = value
118
+
119
+ @property
120
+ def owner_id (self ):
121
+ return self ._owner_id
122
+
123
+ @owner_id .setter
124
+ @property_not_empty
125
+ @property_not_nullable
126
+ def owner_id (self , value ):
127
+ self ._owner_id = value
128
+
129
+ @property
130
+ def owner_name (self ):
131
+ return self ._owner_name
132
+
63
133
@property
64
134
def project_id (self ):
65
135
return self ._project_id
66
136
67
137
@project_id .setter
138
+ @property_not_empty
68
139
@property_not_nullable
69
140
def project_id (self , value ):
70
141
self ._project_id = value
@@ -74,52 +145,104 @@ def project_name(self):
74
145
return self ._project_name
75
146
76
147
@property
77
- def datasource_type (self ):
78
- return self ._datasource_type
148
+ def published (self ):
149
+ return self ._published
150
+
151
+ @property
152
+ def server_name (self ):
153
+ return self ._server_name
154
+
155
+ @property
156
+ def size (self ):
157
+ return self ._size
158
+
159
+ @property
160
+ def tags (self ):
161
+ return self ._tags
162
+
163
+ @tags .setter
164
+ @property_is_set
165
+ def tags (self , value ):
166
+ self ._tags = value
79
167
80
168
@property
81
169
def updated_at (self ):
82
170
return self ._updated_at
83
171
84
- def _set_connections (self , connections ):
85
- self ._connections = connections
172
+ @property
173
+ def use_remote_query_agent (self ):
174
+ return self ._use_remote_query_agent
86
175
87
- def _parse_common_elements (self , datasource_xml , ns ):
176
+ @property
177
+ def webpage_url (self ):
178
+ return self ._webpage_url
179
+
180
+ def _parse_updated_elements (self , datasource_xml , ns ):
88
181
if not isinstance (datasource_xml , ET .Element ):
89
182
datasource_xml = ET .fromstring (datasource_xml ).find ('.//t:datasource' , namespaces = ns )
90
183
if datasource_xml is not None :
91
- ( _ , _ , _ , _ , _ , updated_at , _ , project_id , project_name , owner_id ,
92
- certified , certification_note ) = self ._parse_element ( datasource_xml , ns )
93
- self . _set_values ( None , None , None , None , None , updated_at , None , project_id ,
94
- project_name , owner_id , certified , certification_note )
184
+ datasource_fields = self . _parse_element ( datasource_xml , ns )
185
+ self ._set_values ( datasource_fields )
186
+ if not self . _certified :
187
+ self . _certification_note = None
95
188
return self
96
189
97
- def _set_values (self , id , name , datasource_type , content_url , created_at ,
98
- updated_at , tags , project_id , project_name , owner_id , certified , certification_note ):
99
- if id is not None :
100
- self ._id = id
101
- if name :
102
- self .name = name
103
- if datasource_type :
104
- self ._datasource_type = datasource_type
105
- if content_url :
106
- self ._content_url = content_url
107
- if created_at :
108
- self ._created_at = created_at
109
- if updated_at :
110
- self ._updated_at = updated_at
111
- if tags :
112
- self .tags = tags
113
- self ._initial_tags = copy .copy (tags )
114
- if project_id :
115
- self .project_id = project_id
116
- if project_name :
117
- self ._project_name = project_name
118
- if owner_id :
119
- self .owner_id = owner_id
120
- if certification_note :
121
- self .certification_note = certification_note
122
- self .certified = certified # Always True/False, not conditional
190
+ def _set_values (self , datasource_fields ):
191
+ if 'isCertified' in datasource_fields :
192
+ self ._certified = string_to_bool (datasource_fields ['isCertified' ])
193
+ if 'certificationNote' in datasource_fields :
194
+ self ._certification_note = datasource_fields ['certificationNote' ]
195
+ if 'connectedWorkbooksCount' in datasource_fields :
196
+ self ._connected_workbooks_count = int (datasource_fields ['connectedWorkbooksCount' ])
197
+ if 'contentUrl' in datasource_fields :
198
+ self ._content_url = datasource_fields ['contentUrl' ]
199
+ if 'createdAt' in datasource_fields :
200
+ self ._created_at = parse_datetime (datasource_fields ['createdAt' ])
201
+ if 'databaseName' in datasource_fields :
202
+ self ._database_name = datasource_fields ['databaseName' ]
203
+ if 'type' in datasource_fields :
204
+ self ._datasource_type = datasource_fields ['type' ]
205
+ if 'description' in datasource_fields :
206
+ self ._description = datasource_fields ['description' ]
207
+ if 'encryptExtracts' in datasource_fields :
208
+ self ._encrypt_extracts = string_to_bool (datasource_fields ['encryptExtracts' ])
209
+ if 'favoritesTotal' in datasource_fields :
210
+ self ._favorites_total = int (datasource_fields ['favoritesTotal' ])
211
+ if 'id' in datasource_fields :
212
+ self ._id = datasource_fields ['id' ]
213
+ if 'hasAlert' in datasource_fields :
214
+ self ._has_alert = string_to_bool (datasource_fields ['hasAlert' ])
215
+ if 'hasExtracts' in datasource_fields :
216
+ self ._has_extracts = string_to_bool (datasource_fields ['hasExtracts' ])
217
+ if 'name' in datasource_fields :
218
+ self ._name = datasource_fields ['name' ]
219
+ if 'isPublished' in datasource_fields :
220
+ self ._published = string_to_bool (datasource_fields ['isPublished' ])
221
+ if 'serverName' in datasource_fields :
222
+ self ._server_name = datasource_fields ['serverName' ]
223
+ if 'size' in datasource_fields :
224
+ self ._size = int (datasource_fields ['size' ])
225
+ if 'tags' in datasource_fields :
226
+ self ._tags = datasource_fields ['tags' ]
227
+ self ._initial_tags = copy .copy (self ._tags )
228
+ if 'updatedAt' in datasource_fields :
229
+ self ._updated_at = parse_datetime (datasource_fields ['updatedAt' ])
230
+ if 'useRemoteQueryAgent' in datasource_fields :
231
+ self ._use_remote_query_agent = string_to_bool (datasource_fields ['useRemoteQueryAgent' ])
232
+ if 'webpageUrl' in datasource_fields :
233
+ self ._webpage_url = datasource_fields ['webpageUrl' ]
234
+ if 'owner' in datasource_fields :
235
+ owner_fields = datasource_fields ['owner' ]
236
+ if 'id' in owner_fields :
237
+ self ._owner_id = owner_fields ['id' ]
238
+ if 'name' in owner_fields :
239
+ self ._owner_name = owner_fields ['name' ]
240
+ if 'project' in datasource_fields :
241
+ project_fields = datasource_fields ['project' ]
242
+ if 'id' in project_fields :
243
+ self ._project_id = project_fields ['id' ]
244
+ if 'name' in project_fields :
245
+ self ._project_name = project_fields ['name' ]
123
246
124
247
@classmethod
125
248
def from_response (cls , resp , ns ):
@@ -128,42 +251,34 @@ def from_response(cls, resp, ns):
128
251
all_datasource_xml = parsed_response .findall ('.//t:datasource' , namespaces = ns )
129
252
130
253
for datasource_xml in all_datasource_xml :
131
- (id_ , name , datasource_type , content_url , created_at , updated_at ,
132
- tags , project_id , project_name , owner_id ,
133
- certified , certification_note ) = cls ._parse_element (datasource_xml , ns )
134
- datasource_item = cls (project_id )
135
- datasource_item ._set_values (id_ , name , datasource_type , content_url , created_at , updated_at ,
136
- tags , None , project_name , owner_id , certified , certification_note )
254
+ datasource_fields = cls ._parse_element (datasource_xml , ns )
255
+ datasource_item = cls (datasource_fields ['project' ]['id' ])
256
+ datasource_item ._set_values (datasource_fields )
137
257
all_datasource_items .append (datasource_item )
138
258
return all_datasource_items
139
259
140
260
@staticmethod
141
261
def _parse_element (datasource_xml , ns ):
142
- id_ = datasource_xml .get ('id' , None )
143
- name = datasource_xml .get ('name' , None )
144
- datasource_type = datasource_xml .get ('type' , None )
145
- content_url = datasource_xml .get ('contentUrl' , None )
146
- created_at = parse_datetime (datasource_xml .get ('createdAt' , None ))
147
- updated_at = parse_datetime (datasource_xml .get ('updatedAt' , None ))
148
- certification_note = datasource_xml .get ('certificationNote' , None )
149
- certified = str (datasource_xml .get ('isCertified' , None )).lower () == 'true'
150
-
151
- tags = None
262
+ datasource_fields = datasource_xml .attrib
263
+ owner_elem = datasource_xml .find ('.//t:owner' , namespaces = ns )
264
+ project_elem = datasource_xml .find ('.//t:project' , namespaces = ns )
152
265
tags_elem = datasource_xml .find ('.//t:tags' , namespaces = ns )
266
+
267
+ if owner_elem is not None :
268
+ owner_fields = owner_elem .attrib
269
+ datasource_fields ['owner' ] = owner_fields
270
+
271
+ if project_elem is not None :
272
+ project_fields = project_elem .attrib
273
+ datasource_fields ['project' ] = project_fields
274
+
153
275
if tags_elem is not None :
154
276
tags = TagItem .from_xml_element (tags_elem , ns )
277
+ datasource_fields ['tags' ] = tags
155
278
156
- project_id = None
157
- project_name = None
158
- project_elem = datasource_xml .find ('.//t:project' , namespaces = ns )
159
- if project_elem is not None :
160
- project_id = project_elem .get ('id' , None )
161
- project_name = project_elem .get ('name' , None )
279
+ return datasource_fields
162
280
163
- owner_id = None
164
- owner_elem = datasource_xml .find ('.//t:owner' , namespaces = ns )
165
- if owner_elem is not None :
166
- owner_id = owner_elem .get ('id' , None )
167
281
168
- return (id_ , name , datasource_type , content_url , created_at , updated_at , tags , project_id ,
169
- project_name , owner_id , certified , certification_note )
282
+ # Used to convert string represented boolean to a boolean type
283
+ def string_to_bool (s ):
284
+ return s .lower () == 'true'
0 commit comments