Store the event field from CAP XML broadcasts

We don’t store everything that comes in the CAP XML when someone creates
a broadcast via the API.

One thing we do store is `<identifier>` (in a column called `reference`)
which is a unique (to the external system) identifier for the broadcast.
We show this in the front end instead of the template name, because
broadcasts created from the API don’t use templates.

However this ID isn’t very friendly – the Environment Agency just supply
a UUID.

The Environment Agency also populate the `<event>` field with some human
readable text, for example:
> 013 Issue Severe Flood Warning EA

(013 is an area code which will be meaningful to the Flood Warning
Service team)

We should show this in the UI instead of the reference. The first step
towards this is storing it in the database and returning it in the REST
endpoints.

Later we can have the admin app prefer `cap_event` over `reference`,
where `cap_event` is present.

We can’t backfill this data because we don’t keep a copy of the original
XML.

Seems like `<event>` is a mandatory property of `<info>`, so we don’t
need to worry about the field being missing (`<info>` is optional in
CAP but we require it because it contains stuff like the areas which
we need in order to send out the broadcast`).

***

https://www.pivotaltracker.com/story/show/176927060
This commit is contained in:
Chris Hill-Scott
2021-10-18 11:42:18 +01:00
parent d703251b13
commit 54bcf618da
8 changed files with 58 additions and 2 deletions

View File

@@ -1119,7 +1119,8 @@ def create_broadcast_message(
starts_at=None,
finishes_at=None,
areas=None,
stubbed=False
stubbed=False,
cap_event=None,
):
if template:
service = template.service
@@ -1148,7 +1149,8 @@ def create_broadcast_message(
created_by_id=created_by.id if created_by else service.created_by_id,
areas=areas or {'ids': [], 'simple_polygons': []},
content=content,
stubbed=stubbed
stubbed=stubbed,
cap_event=cap_event,
)
db.session.add(broadcast_message)
db.session.commit()