Skip to content

Commit

Permalink
TH2-5027 - move expand message to impl (#79)
Browse files Browse the repository at this point in the history
* Release 2.0.3.0 (#76)

* expand_message moved into LwdpMessageFieldsResolver

* Update package_info

* Update pypi-publish.yml (#77)

* Fix release notes chronology
  • Loading branch information
xHacka authored Aug 9, 2023
1 parent 5540bf6 commit a6bcacf
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 5 deletions.
1 change: 0 additions & 1 deletion .github/workflows/pypi-publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ jobs:
- name: Build package
run: |
python setup.py sdist
- name: Publish distribution to PyPI
uses: pypa/gh-action-pypi-publish@master
with:
Expand Down
14 changes: 10 additions & 4 deletions release_notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@
anymore.
Use BrokenEvent and BrokenMessage objects instead.

# v2.0.3.0

## Features

1. [TH2-5027] `expand_message` added to LwdpMessageFieldsResolver.

# v2.1.0.0

## User impact and migration instructions
Expand All @@ -88,9 +94,9 @@

## Improvements

1. [TH2-4922] GetMessageAliases command now takes optional start_timestamp and end_timestamp arguements and returns TH2 Data object instead of a list.
2. [TH2-4923] GetMessageGroups command now takes optional start_timestamp and end_timestamp arguements and returns TH2 Data object instead of a list.


1. [TH2-4922] GetMessageAliases command now takes optional start_timestamp and end_timestamp arguments and returns TH2 Data object instead of a list.
2. [TH2-4923] GetMessageGroups command now takes optional start_timestamp and end_timestamp arguments and returns TH2 Data object instead of a list.

## BugFixes

1. [TH2-4925] Fix BrokenEvent and BrokenMessage.
43 changes: 43 additions & 0 deletions th2_data_services/data_source/lwdp/resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,46 @@ def get_attached_event_ids(message):
@staticmethod
def get_fields(message):
return message[http_message_struct.BODY]["fields"]

@staticmethod
def expand_message(message):
"""Extract compounded message into list of individual messages.
Args:
message: Th2Message
Returns:
Iterable[Th2Message]
"""
if "/" not in LwdpMessageFieldsResolver.get_type(message):
return [message]
result = []
fields = LwdpMessageFieldsResolver.get_body(message)["fields"]
for field in fields:
msg_index = len(result)
msg_type = field
if "-" in field:
msg_type = msg_type[: msg_type.index("-")]
# TODO: Remove or keep this line?
# m_index = int(k[k.index("-") + 1:])

new_msg = {}
new_msg.update(message)
new_msg[http_message_struct.MESSAGE_TYPE] = msg_type
new_msg[http_message_struct.BODY] = {}
new_msg[http_message_struct.BODY]["metadata"] = {}
new_msg[http_message_struct.BODY]["metadata"].update(
LwdpMessageFieldsResolver.get_body(message)["metadata"]
)
new_msg[http_message_struct.BODY]["metadata"]["id"] = {}
new_msg[http_message_struct.BODY]["metadata"]["id"].update(
LwdpMessageFieldsResolver.get_body(message)["metadata"]["id"]
)
new_msg[http_message_struct.BODY]["metadata"][http_message_struct.MESSAGE_TYPE] = msg_type
new_msg[http_message_struct.BODY]["metadata"]["id"][http_message_struct.SUBSEQUENCE] = [
LwdpMessageFieldsResolver.get_body(message)["metadata"]["id"][http_message_struct.SUBSEQUENCE][
msg_index
]
]
new_msg[http_message_struct.BODY]["fields"] = fields[field]["messageValue"]["fields"]
result.append(new_msg)

return result

0 comments on commit a6bcacf

Please sign in to comment.