-
Notifications
You must be signed in to change notification settings - Fork 424
/
Copy pathdqw_endpoint.py
60 lines (45 loc) · 2.36 KB
/
dqw_endpoint.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
import logging
from .endpoint import Endpoint
from .exceptions import MissingRequiredFieldError
from tableauserverclient.server import RequestFactory
from tableauserverclient.models import DQWItem
from tableauserverclient.helpers.logging import logger
class _DataQualityWarningEndpoint(Endpoint):
def __init__(self, parent_srv, resource_type):
super(_DataQualityWarningEndpoint, self).__init__(parent_srv)
self.resource_type = resource_type
@property
def baseurl(self):
return "{0}/sites/{1}/dataQualityWarnings/{2}".format(
self.parent_srv.baseurl, self.parent_srv.site_id, self.resource_type
)
def add(self, resource, warning):
url = "{baseurl}/{content_luid}".format(baseurl=self.baseurl, content_luid=resource.id)
add_req = RequestFactory.DQW.add_req(warning)
response = self.post_request(url, add_req)
warnings = DQWItem.from_response(response.content, self.parent_srv.namespace)
logger.info("Added dqw for resource {0}".format(resource.id))
return warnings
def update(self, resource, warning):
url = "{baseurl}/{content_luid}".format(baseurl=self.baseurl, content_luid=resource.id)
add_req = RequestFactory.DQW.update_req(warning)
response = self.put_request(url, add_req)
warnings = DQWItem.from_response(response.content, self.parent_srv.namespace)
logger.info("Added dqw for resource {0}".format(resource.id))
return warnings
def clear(self, resource):
url = "{baseurl}/{content_luid}".format(baseurl=self.baseurl, content_luid=resource.id)
return self.delete_request(url)
def populate(self, item):
if not item.id:
error = "Server item is missing ID. Item must be retrieved from server first."
raise MissingRequiredFieldError(error)
def dqw_fetcher():
return self._get_data_quality_warnings(item)
item._set_data_quality_warnings(dqw_fetcher)
logger.info("Populated permissions for item (ID: {0})".format(item.id))
def _get_data_quality_warnings(self, item, req_options=None):
url = "{baseurl}/{content_luid}".format(baseurl=self.baseurl, content_luid=item.id)
server_response = self.get_request(url, req_options)
dqws = DQWItem.from_response(server_response.content, self.parent_srv.namespace)
return dqws