Barebones notif works. Doing nothing with warnings at the moment. Not sure what I can do exept log the things
This commit is contained in:
@@ -8,6 +8,7 @@ handshaking functionality with configurable supported actions and capabilities.
|
|||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
from zoneinfo import ZoneInfo
|
||||||
import difflib
|
import difflib
|
||||||
import json
|
import json
|
||||||
import inspect
|
import inspect
|
||||||
@@ -20,7 +21,7 @@ from enum import Enum, IntEnum
|
|||||||
from alpine_bits_python.alpine_bits_helpers import PhoneTechType, create_xml_from_db
|
from alpine_bits_python.alpine_bits_helpers import PhoneTechType, create_xml_from_db
|
||||||
|
|
||||||
|
|
||||||
from .generated.alpinebits import OtaPingRq, OtaPingRs, WarningStatus, OtaReadRq
|
from .generated.alpinebits import OtaNotifReportRq, OtaNotifReportRs, OtaPingRq, OtaPingRs, WarningStatus, OtaReadRq
|
||||||
from xsdata_pydantic.bindings import XmlSerializer
|
from xsdata_pydantic.bindings import XmlSerializer
|
||||||
from xsdata.formats.dataclass.serializers.config import SerializerConfig
|
from xsdata.formats.dataclass.serializers.config import SerializerConfig
|
||||||
from abc import ABC, abstractmethod
|
from abc import ABC, abstractmethod
|
||||||
@@ -556,26 +557,74 @@ class NotifReportReadAction(AlpineBitsAction):
|
|||||||
action: str,
|
action: str,
|
||||||
request_xml: str,
|
request_xml: str,
|
||||||
version: Version,
|
version: Version,
|
||||||
|
client_info: AlpineBitsClientInfo,
|
||||||
dbsession=None,
|
dbsession=None,
|
||||||
username=None,
|
server_capabilities=None,
|
||||||
password=None,
|
|
||||||
) -> AlpineBitsResponse:
|
) -> AlpineBitsResponse:
|
||||||
"""Handle read requests."""
|
"""Handle read requests."""
|
||||||
|
|
||||||
return AlpineBitsResponse(
|
notif_report = XmlParser().from_string(request_xml, OtaNotifReportRq)
|
||||||
f"Error: Action {action} not implemented", HttpStatusCode.BAD_REQUEST
|
|
||||||
|
# we can't check hotel auth here, because this action does not contain hotel info
|
||||||
|
|
||||||
|
warnings = notif_report.warnings
|
||||||
|
notif_report_details = notif_report.notif_details
|
||||||
|
|
||||||
|
success_message = OtaNotifReportRs(
|
||||||
|
version="7.000", success=""
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if client_info.client_id is None:
|
||||||
|
return AlpineBitsResponse(
|
||||||
|
"ERROR:no valid client id provided", HttpStatusCode.BAD_REQUEST
|
||||||
|
)
|
||||||
|
|
||||||
class GuestRequestsAction(AlpineBitsAction):
|
config = SerializerConfig(
|
||||||
"""Unimplemented action - will not appear in capabilities."""
|
pretty_print=True, xml_declaration=True, encoding="UTF-8"
|
||||||
|
)
|
||||||
|
serializer = XmlSerializer(config=config)
|
||||||
|
response_xml = serializer.render(
|
||||||
|
success_message, ns_map={None: "http://www.opentravel.org/OTA/2003/05"}
|
||||||
|
)
|
||||||
|
|
||||||
def __init__(self):
|
if warnings is None and notif_report_details is None:
|
||||||
self.name = AlpineBitsActionName.OTA_HOTEL_RES_NOTIF_GUEST_REQUESTS
|
return AlpineBitsResponse(
|
||||||
self.version = Version.V2024_10
|
response_xml, HttpStatusCode.OK
|
||||||
|
) # Nothing to process
|
||||||
|
elif notif_report_details is not None and notif_report_details.hotel_notif_report is None:
|
||||||
|
return AlpineBitsResponse(
|
||||||
|
response_xml, HttpStatusCode.OK
|
||||||
|
) # Nothing to process
|
||||||
|
else:
|
||||||
|
|
||||||
# Note: This class doesn't override the handle method, so it won't be discovered
|
if dbsession is None:
|
||||||
|
return AlpineBitsResponse(
|
||||||
|
"Error: Something went wrong", HttpStatusCode.INTERNAL_SERVER_ERROR
|
||||||
|
)
|
||||||
|
|
||||||
|
timestamp = datetime.now(ZoneInfo("UTC"))
|
||||||
|
for entry in notif_report_details.hotel_notif_report.hotel_reservations.hotel_reservation: # type: ignore
|
||||||
|
|
||||||
|
unique_id = entry.unique_id.id
|
||||||
|
acked_request = AckedRequest(
|
||||||
|
unique_id=unique_id, client_id=client_info.client_id, timestamp=timestamp
|
||||||
|
)
|
||||||
|
dbsession.add(acked_request)
|
||||||
|
|
||||||
|
await dbsession.commit()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
return AlpineBitsResponse(
|
||||||
|
response_xml, HttpStatusCode.OK
|
||||||
|
)
|
||||||
|
|
||||||
class AlpineBitsServer:
|
class AlpineBitsServer:
|
||||||
"""
|
"""
|
||||||
|
|||||||
Reference in New Issue
Block a user