AuthenticateResponse.fromXML constructor

AuthenticateResponse.fromXML(
  1. String xmlSTR
)

Implementation

factory AuthenticateResponse.fromXML(String xmlSTR) {
  final document = XmlDocument.parse(xmlSTR);

  String messageID = document.rootElement.attributes
      .firstWhere((p0) => p0.name.toString() == "messageID")
      .value;
  String result = document.rootElement.childElements.first.attributes
      .firstWhere((p0) => p0.name.toString() == "result")
      .value;
  String deviceToken = document.rootElement.childElements.first.attributes
      .firstWhere((p0) => p0.name.toString() == "deviceToken")
      .value;

  XmlElement? platformParameterElement =
      document.findAllElements("platformParameter").first;
  XmlElement? applicationParameterElement =
      document.findAllElements("applicationParameter").first;
  XmlElement? deviceListElement =
      document.findAllElements("deviceList").first;
  List<XmlElement> devicesElements =
      deviceListElement.findElements("device").toList();



  PlatformParameter platformParameter =
      PlatformParameter.fromXML(platformParameterElement.toXmlString());
  ApplicationParameter applicationParameter =
      ApplicationParameter.fromXML(applicationParameterElement.toXmlString());
  List<Device> deviceList =
      devicesElements.where((element) =>
          element.attributes.any((a) =>
          a.name.toString() == 'deviceParameterType' &&
              [
                "bcDeviceParameter",
                "beDeviceParameter",
                "bgDeviceParameter",
                "bpDeviceParameter",
                "btDeviceParameter",
                "ddDeviceParameter",
                "msDeviceParameter",
                "ocDeviceParameter",
                "prDeviceParameter",
                "ziDeviceParameter",
                "zlDeviceParameter",
              ].contains(a.value.toString()))
      ).map((e) => Device.fromXML(e.toXmlString())).toList();

  PlatformDevices platformDevices = PlatformDevices(
      bcDevices: deviceList
          .where((element) => element.getType == DeviceType.bc)
          .map((e) => BcDevice.fromDevice(e))
          .toList(),
    beDevices: deviceList
        .where((element) => element.getType == DeviceType.be)
        .map((e) => BeDevice.fromDevice(e))
        .toList(),
    bgDevices: deviceList
        .where((element) => element.getType == DeviceType.bg)
        .map((e) => BgDevice.fromDevice(e))
        .toList(),
    bpDevices: deviceList
        .where((element) => element.getType == DeviceType.bp)
        .map((e) => BpDevice.fromDevice(e))
        .toList(),
    btDevices: deviceList
        .where((element) => element.getType == DeviceType.bt)
        .map((e) => BtDevice.fromDevice(e))
        .toList(),
    ddDevices:  deviceList
        .where((element) => element.getType == DeviceType.dd)
        .map((e) => DdDevice.fromDevice(e))
        .toList(),
      msDevices: deviceList
          .where((element) => element.getType == DeviceType.ms)
          .map((e) => MsDevice.fromDevice(e))
          .toList(),
      ocDevices: deviceList
          .where((element) => element.getType == DeviceType.oc)
          .map((e) => OcDevice.fromDevice(e))
          .toList(),
      prDevices: deviceList
          .where((element) => element.getType == DeviceType.pr)
          .map((e) => PrDevice.fromDevice(e))
          .toList(),
      ziDevices: deviceList
          .where((element) => element.getType == DeviceType.zi)
          .map((e) => ZiDevice.fromDevice(e))
          .toList(),
      zlDevices: deviceList
          .where((element) => element.getType == DeviceType.zl)
          .map((e) => ZlDevice.fromDevice(e))
          .toList(),
  );

  return AuthenticateResponse(
      result: result,
      deviceToken: deviceToken,
      platformParameter: platformParameter,
      applicationParameter: applicationParameter,
      deviceList: deviceList,
      messageId: int.parse(messageID),
      platformDevices: platformDevices);
}