import logging
from typing import List, NewType
from lxml import etree
from lxml.builder import E
from q2_cores.Corelation.queries import mock_responses
from q2_sdk.models.cores.queries.base_query import BaseQuery
AlertStr = NewType("AlertStr", str)
[docs]
class AlertDetailsQuery(BaseQuery):
"""Gets details about user alerts"""
def __init__(self, logger: logging.Logger, target_serials: List[str]):
self.target_serials: AlertStr = target_serials
super().__init__(logger)
[docs]
def build(self):
"""
Creates query to get details about user alerts
Example query:
.. code-block:: xml
<query xmlns="http://www.corelationinc.com/queryLanguage/v1.0">
<sequence>
<transaction>
<step>
<recordTree>
<tableName>ALERT_ENROLLMENT</tableName>
<targetSerial>5</targetSerial>
<includeRecordDetail option="Y"/>
<recordDetail>
<tableName>ALERT_ENROLLMENT</tableName>
</recordDetail>
<recordDetail>
<tableName>ALERT_ENROLLMENT_CONTACT</tableName>
</recordDetail>
</recordTree>
</step>
</transaction>
</sequence>
<sequence>
<transaction>
<step>
<recordTree>
<tableName>ALERT_ENROLLMENT</tableName>
<targetSerial>6</targetSerial>
<includeRecordDetail option="Y"/>
<recordDetail>
<tableName>ALERT_ENROLLMENT</tableName>
</recordDetail>
<recordDetail>
<tableName>ALERT_ENROLLMENT_CONTACT</tableName>
</recordDetail>
</recordTree>
</step>
</transaction>
</sequence>
</query>
"""
xml_str = etree.tostring(
E.query(
{"xmlns": "http://www.corelationinc.com/queryLanguage/v1.0"},
*[
E.sequence(
E.transaction(
E.step(
E.recordTree(
E.tableName("ALERT_ENROLLMENT"),
E.targetSerial(target_serial),
E.includeRecordDetail({"option": "Y"}),
E.recordDetail(E.tableName("ALERT_ENROLLMENT")),
E.recordDetail(
E.tableName("ALERT_ENROLLMENT_CONTACT")
),
)
)
)
)
for target_serial in self.target_serials
],
),
encoding="unicode",
)
return xml_str
[docs]
def mock_response(self):
return mock_responses.alert_details_response()