diff --git a/ds-caselaw-ingester/lambda_function.py b/ds-caselaw-ingester/lambda_function.py index 0d5ab49..5043223 100644 --- a/ds-caselaw-ingester/lambda_function.py +++ b/ds-caselaw-ingester/lambda_function.py @@ -95,6 +95,9 @@ def save_s3_response(self, sqs_client, s3_client): return filename + def validate(self): + return + class V2Message(Message): def is_v1(self): @@ -120,6 +123,14 @@ def save_s3_response(self, sqs_client, s3_client): print(f"tar.gz saved locally as {filename}") return filename + def validate(self): + message_type = self.message["properties"]["messageType"] + if ( + message_type + != "uk.gov.nationalarchives.da.messages.request.courtdocument.parse.RequestCourtDocumentParse" + ): + raise WrongMessageTypeError(f"Received message with type: {message_type}") + class ReportableException(Exception): def __init__(self, *args, **kwargs): @@ -127,6 +138,10 @@ def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) +class WrongMessageTypeError(ReportableException): + pass + + class S3HTTPError(ReportableException): pass @@ -413,6 +428,8 @@ def unpublish_updated_judgment(uri): def handler(event, context): message = Message.from_event(event) + message.validate() + consignment_reference = message.get_consignment_reference() print(f"Ingester Start: Consignment reference {consignment_reference}") print(f"Received Message: {message.message}") diff --git a/ds-caselaw-ingester/tests.py b/ds-caselaw-ingester/tests.py index a0161bb..9b702eb 100644 --- a/ds-caselaw-ingester/tests.py +++ b/ds-caselaw-ingester/tests.py @@ -25,8 +25,7 @@ v2_message_raw = """ { "properties": { - "messageType": - "uk.gov.nationalarchives.tre.messages.judgmentpackage.available.JudgmentPackageAvailable", + "messageType": "uk.gov.nationalarchives.da.messages.request.courtdocument.parse.RequestCourtDocumentParse", "timestamp": "2023-05-15T09:14:53.791409Z", "function": "staging-tre-judgment-packer-lambda", "producer": "TRE",