from typing import List
from lxml import etree, objectify
from q2_sdk.models.cores.mappers.update_demographic_info import (
BaseUpdateDemographicInfoMapper,
)
from q2_sdk.models.cores.queries.base_query import BaseQuery
from .. import data_helpers
[docs]
class UpdateDemographicInfoMapper(BaseUpdateDemographicInfoMapper):
[docs]
@staticmethod
def parse_returned_queries(list_of_queries: List[BaseQuery]) -> bool:
"""Returns True if all queries were successful, False if there was an error"""
response_successes = []
# Updating phone and address give the same response, so we can just loop through
# All messages and see if the response text is 'OK'
# If not, there was a problem and we return False
for query in list_of_queries:
response = data_helpers.cleanse_itc_strings(query.raw_core_response)
success: bool = False
error: str | None = None
try:
root = objectify.fromstring(response)
success: bool = root.RESPONSE.text == "OK"
if not success:
error = root.RESPONSE.FAILED_MESSAGE.text
except etree.XMLSyntaxError:
success = False
error = response
if success:
response_successes.append(True)
else:
query.logger.error("Core Failure: {}".format(error))
response_successes.append(False)
return all(response_successes)