Source code for q2_sdk.hq.hq_api.backoffice.GetReport

# This is an autogenerated file from the command "q2 generate_hq_api" and will be overwritten if run again


from typing import cast, Optional

from lxml import etree
from q2_sdk.core.q2_logging.logger import Q2LoggerType
from q2_sdk.hq.models.hq_credentials import BackOfficeHqCredentials
from q2_sdk.hq.models.hq_params.base import BaseParameter

from q2_sdk.hq.models.hq_params.backoffice import BackOfficeAuthenticatedParamsObj
from q2_sdk.hq.models.hq_request.backoffice import BackOfficeRequest
from q2_sdk.hq.models.backoffice_response import BackOfficeResponse


class object(BaseParameter):
    def __init__(
        self,
    ):
        pass

    def serialize_as_xml(self):
        root = etree.Element("object")
        return root

    def serialize_as_json(self):
        return {}


class Default(BaseParameter):
    def __init__(
        self,
        decimal: float,
        bool: bool,
        int: int,
        datetime: str,
        object: Optional[object] = None,
        string: Optional[str] = None,
    ):
        self.decimal = decimal
        self.bool = bool
        self.object = object
        self.int = int
        self.string = string
        self.datetime = datetime

    def serialize_as_xml(self):
        root = etree.Element("Default")
        sub_elem = etree.SubElement(root, "decimal")
        sub_elem.text = str(self.decimal)
        sub_elem = etree.SubElement(root, "bool")
        sub_elem.text = str(self.bool.real)
        if self.object is not None:
            for child in self.object:
                root.append(child.serialize_as_xml())
        sub_elem = etree.SubElement(root, "int")
        sub_elem.text = str(self.int)
        sub_elem = etree.SubElement(root, "string")
        sub_elem.text = str(self.string)
        sub_elem = etree.SubElement(root, "datetime")
        sub_elem.text = str(self.datetime)
        return root

    def serialize_as_json(self):
        return {
            "decimal": self.decimal,
            "bool": self.bool,
            "object": self.object,
            "int": self.int,
            "string": self.string,
            "datetime": self.datetime,
        }


[docs] class Default(BaseParameter): def __init__(self, default: Optional[list[Default]] = None): self.default = default
[docs] def serialize_as_xml(self): root = etree.Element("Default") if self.default is not None: for child in self.default: root.append(child.serialize_as_xml()) return root
[docs] def serialize_as_json(self): return [item.serialize_as_json() for item in self.default]
[docs] class object(BaseParameter): def __init__( self, ): pass
[docs] def serialize_as_xml(self): root = etree.Element("object") return root
[docs] def serialize_as_json(self): return {}
class Value(BaseParameter): def __init__( self, datetime: str, int: int, decimal: float, bool: bool, object: Optional[object] = None, string: Optional[str] = None, ): self.object = object self.string = string self.datetime = datetime self.int = int self.decimal = decimal self.bool = bool def serialize_as_xml(self): root = etree.Element("Value") if self.object is not None: for child in self.object: root.append(child.serialize_as_xml()) sub_elem = etree.SubElement(root, "string") sub_elem.text = str(self.string) sub_elem = etree.SubElement(root, "datetime") sub_elem.text = str(self.datetime) sub_elem = etree.SubElement(root, "int") sub_elem.text = str(self.int) sub_elem = etree.SubElement(root, "decimal") sub_elem.text = str(self.decimal) sub_elem = etree.SubElement(root, "bool") sub_elem.text = str(self.bool.real) return root def serialize_as_json(self): return { "object": self.object, "string": self.string, "datetime": self.datetime, "int": self.int, "decimal": self.decimal, "bool": self.bool, }
[docs] class Value(BaseParameter): def __init__(self, value: Optional[list[Value]] = None): self.value = value
[docs] def serialize_as_xml(self): root = etree.Element("Value") if self.value is not None: for child in self.value: root.append(child.serialize_as_xml()) return root
[docs] def serialize_as_json(self): return [item.serialize_as_json() for item in self.value]
class Parameter(BaseParameter): def __init__( self, value: Optional[list[Value]] = None, default: Optional[list[Default]] = None, ): self.value = value self.default = default def serialize_as_xml(self): root = etree.Element("Parameter") if self.value is not None: for child in self.value: root.append(child.serialize_as_xml()) if self.default is not None: for child in self.default: root.append(child.serialize_as_xml()) return root def serialize_as_json(self): return { "Value": self.value, "Default": self.default, }
[docs] class Parameter(BaseParameter): def __init__(self, parameter: Optional[list[Parameter]] = None): self.parameter = parameter
[docs] def serialize_as_xml(self): root = etree.Element("Parameter") if self.parameter is not None: for child in self.parameter: root.append(child.serialize_as_xml()) return root
[docs] def serialize_as_json(self): return [item.serialize_as_json() for item in self.parameter]
class Table(BaseParameter): def __init__(self, parameter: Optional[list[Parameter]] = None): self.parameter = parameter def serialize_as_xml(self): root = etree.Element("Table") if self.parameter is not None: for child in self.parameter: root.append(child.serialize_as_xml()) return root def serialize_as_json(self): return [item.serialize_as_json() for item in self.parameter]
[docs] class Table(BaseParameter): def __init__(self, table: Optional[list[Table]] = None): self.table = table
[docs] def serialize_as_xml(self): root = etree.Element("Table") if self.table is not None: for child in self.table: root.append(child.serialize_as_xml()) return root
[docs] def serialize_as_json(self): return [item.serialize_as_json() for item in self.table]
[docs] class Object(BaseParameter): def __init__( self, ): pass
[docs] def serialize_as_xml(self): root = etree.Element("Object") return root
[docs] def serialize_as_json(self): return {}
[docs] class AvailableFormats(BaseParameter): def __init__(self, object: Optional[list[Object]] = None): self.object = object
[docs] def serialize_as_xml(self): root = etree.Element("AvailableFormats") if self.object is not None: for child in self.object: root.append(child.serialize_as_xml()) return root
[docs] def serialize_as_json(self): return [item.serialize_as_json() for item in self.object]
class Parameters(BaseParameter): def __init__( self, available_formats: Optional[AvailableFormats] = None, table: Optional[list[Table]] = None, ): self.available_formats = available_formats self.table = table def serialize_as_xml(self): root = etree.Element("Parameters") if self.available_formats is not None: for child in self.available_formats: root.append(child.serialize_as_xml()) if self.table is not None: for child in self.table: root.append(child.serialize_as_xml()) return root def serialize_as_json(self): return { "AvailableFormats": self.available_formats, "Table": self.table, }
[docs] class Parameters(BaseParameter): def __init__(self, parameters: Optional[Parameters] = None): self.parameters = parameters
[docs] def serialize_as_xml(self): root = etree.Element("Parameters") if self.parameters is not None: for child in self.parameters: root.append(child.serialize_as_xml()) return root
[docs] def serialize_as_json(self): return [item.serialize_as_json() for item in self.parameters]
[docs] class ParamsObj(BackOfficeAuthenticatedParamsObj): """Parameters definition for GetReport""" def __init__( self, logger: Q2LoggerType, hq_credentials: BackOfficeHqCredentials, parameters: Optional[Parameters] = None, report_title: Optional[str] = None, ): """ :param logger: Reference to calling request's logger (self.logger in your extension) :param parameters: :param report_title: :param hq_credentials: Defaults to settings.HQ_CREDENTIALS """ super().__init__(logger, hq_credentials) self.request_params.update({ "Parameters": parameters, "ReportTitle": report_title, })
[docs] async def execute( params_obj: ParamsObj, use_json=False, **kwargs ) -> BackOfficeResponse: """ This is the default way to submit the request to HQ. In theory, both json and soap payloads are equally accepted by HQ, though several variables may affect that (HQ version, Q2SDK implementation bugs, etc). This should not affect anything about the way your code deals with the data. In fact, the only difference to consuming extensions is the logging. Basically, call this with default parameters unless you find a compelling reason not to. :param params_obj: Object containing everything necessary to call this HQ endpoint :param use_json: If True, will call HQ's .ashx (json) endpoint instead of .asmx (soap) """ request = BackOfficeRequest("GetReport", use_json=use_json, **kwargs) return cast(BackOfficeResponse, await request.execute(params_obj, **kwargs))
[docs] def build_json(params_obj: ParamsObj): return BackOfficeRequest.build_json(params_obj)
[docs] def build_soap(params_obj: ParamsObj): return BackOfficeRequest("GetReport", use_json=False).build_soap(params_obj)