Skip to content

Commit 3cd971e

Browse files
PR feedback
1 parent 32af648 commit 3cd971e

File tree

9 files changed

+71
-48
lines changed

9 files changed

+71
-48
lines changed

docs/schemas/events/metadatamanager/MetadataStateChange.schema.json

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"$schema": "http://json-schema.org/draft-04/schema#",
3-
"$id": "https://raw.githubusercontent.com/umccr/orcabus/main/docs/schemas/events/workflowmanager/WorkflowRunStateChange.schema.json",
3+
"$id": "https://raw.githubusercontent.com/umccr/orcabus/main/docs/schemas/events/metadatamanager/MetadataStateChange.schema.json",
44
"description": "EventBridge custom event schema for orcabus.metadatamanager@MetadataStateChange",
55
"title": "AWSEvent",
66
"type": "object",
@@ -55,9 +55,7 @@
5555
"model": {
5656
"type": "string",
5757
"enum": [
58-
"LIBRARY",
59-
"SPECIMEN",
60-
"SUBJECT"
58+
"LIBRARY"
6159
]
6260
},
6361
"action": {

docs/schemas/events/metadatamanager/example/MSC__example1.json

+8-9
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,20 @@
88
"region": "ap-southeast-2",
99
"resources": [],
1010
"detail": {
11-
"model": "LIBRARY",
1211
"action": "CREATE",
13-
"refId": "lib.01FZ7N3XK1GZ5V9P8Z4H7J5S9F",
12+
"model": "LIBRARY",
13+
"refId": "lib.01J8GMF3XCHW9CV8ZFS8F1P1RF",
1414
"data": {
15-
"orcabus_id": "lib.01FZ7N3XK1GZ5V9P8Z4H7J5S9F",
16-
"library_id": "L00001",
15+
"orcabusId": "lib.01J8GMF3XCHW9CV8ZFS8F1P1RF",
16+
"libraryId": "L10001",
1717
"phenotype": "normal",
18-
"workflow": "control",
18+
"workflow": "research",
1919
"quality": "good",
2020
"type": "WTS",
2121
"assay": "ctTSO",
22-
"coverage": 75,
23-
"project_owner": "UMCCR",
24-
"project_name": "Alpha",
25-
"specimen": "spc.01FZ7N3XK1GZ5V9P8Z4H7J5S9F"
22+
"coverage": 120.0,
23+
"sample": "smp.01J8GMF3WD6TD5Y491EEBARYBE",
24+
"subject": "sbj.01J8GMF3VZRGYQG1GYDJC6E9MV"
2625
}
2726
}
2827
}

docs/schemas/events/metadatamanager/example/MSC__example2.json

+13-8
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,20 @@
88
"region": "ap-southeast-2",
99
"resources": [],
1010
"detail": {
11-
"model": "SPECIMEN",
12-
"action": "CREATE",
13-
"refId": "spc.01FZ7N3XK1GZ5V9P8Z4H7J5S9F",
11+
"action": "DELETE",
12+
"model": "LIBRARY",
13+
"refId": "lib.01J8GNBB7YK8RCVFGXSBV4ZKST",
1414
"data": {
15-
"orcabus_id": "spc.01H5S9FNZH3KX5SSGK8BWPSFST",
16-
"lab_specimen_id": "PRJ10001",
17-
"external_specimen_id": "EXT_PRJ10001",
18-
"source": "blood",
19-
"subject": "sbj.01H5S9FNZH3KX5SSGK8BWPSFST"
15+
"orcabusId": "lib.01J8GNBB7YK8RCVFGXSBV4ZKST",
16+
"libraryId": "L10001",
17+
"phenotype": "normal",
18+
"workflow": "research",
19+
"quality": "poor",
20+
"type": "WTS",
21+
"assay": "ctTSO",
22+
"coverage": 120.0,
23+
"sample": "smp.01J8GNBB67HGG3G17QA5QP98TE",
24+
"subject": "sbj.01J8GNBB59GR0KMTNR0BT3F31V"
2025
}
2126
}
2227
}

lib/workload/stateless/stacks/metadata-manager/README.md

+8-7
Original file line numberDiff line numberDiff line change
@@ -80,17 +80,18 @@ Example of the event emitted.
8080
"detail": {
8181
"action": "CREATE",
8282
"model": "LIBRARY",
83-
"ref_id": "lib.123",
83+
"refId": "lib.01J8GMF3XCHW9CV8ZFS8F1P1RF",
8484
"data": {
85-
"orcabus_id": "lib.123",
86-
"phenotype": "tumor",
85+
"orcabusId": "lib.01J8GMF3XCHW9CV8ZFS8F1P1RF",
86+
"libraryId": "L10001",
87+
"phenotype": "normal",
8788
"workflow": "research",
8889
"quality": "good",
89-
"type": "ctTSO",
90+
"type": "WTS",
9091
"assay": "ctTSO",
91-
"coverage": 75.0,
92-
"sample": "smp.123",
93-
"subject": "sbj.123",
92+
"coverage": 120.0,
93+
"sample": "smp.01J8GMF3WD6TD5Y491EEBARYBE",
94+
"subject": "sbj.01J8GMF3VZRGYQG1GYDJC6E9MV"
9495
}
9596
}
9697
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
2+
3+
def to_camel_case_key_dict(data: dict) -> dict:
4+
"""
5+
Convert dictionary keys from snake_case to camelCase.
6+
"""
7+
def snake_to_camel(word):
8+
components = word.split('_')
9+
# We capitalize the first letter of each component except the first one
10+
# with the 'title' method and join them together.
11+
return components[0] + ''.join(x.title() for x in components[1:])
12+
13+
new_data = {}
14+
for key, value in data.items():
15+
new_key = snake_to_camel(key)
16+
new_data[new_key] = value
17+
return new_data

lib/workload/stateless/stacks/metadata-manager/proc/aws/event/event.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import os
22
import json
33
from typing import Literal
4+
5+
from app.serializers.utils import to_camel_case_key_dict
46
from .schema.orcabus_metadatamanager.metadatastatechange import Marshaller
57

68

@@ -14,11 +16,12 @@ def __init__(self,
1416
ref_id: str,
1517
data: dict) -> None:
1618
self.event_bus_name = os.getenv('EVENT_BUS_NAME', '')
19+
# Below must be in camelCase as what we agreed (and written in docs) in API level
1720
self.detail = json.dumps({
1821
"action": action,
1922
"model": model,
20-
"ref_id": ref_id,
21-
"data": Marshaller.marshall(data)
23+
"refId": ref_id,
24+
"data": Marshaller.marshall(to_camel_case_key_dict(data))
2225
})
2326

2427
def __str__(self):

lib/workload/stateless/stacks/metadata-manager/proc/service/tracking_sheet_srv.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ def persist_lab_metadata(df: pd.DataFrame, sheet_year: str):
8383
for lib in Library.objects.filter(library_id__startswith=library_prefix).exclude(
8484
library_id__in=df['library_id'].tolist()).iterator():
8585
stats['library']['delete_count'] += 1
86-
lib.delete()
8786
lib_dict = LibrarySerializer(lib).data
8887
event = MetadataStateChangeEvent(
8988
action='DELETE',
@@ -92,6 +91,7 @@ def persist_lab_metadata(df: pd.DataFrame, sheet_year: str):
9291
data=lib_dict
9392
)
9493
event_bus_entries.append(event.get_put_event_entry())
94+
lib.delete()
9595

9696
# this the where records are updated, inserted, linked based on library_id
9797
for record in df.to_dict('records'):

lib/workload/stateless/stacks/metadata-manager/proc/tests/test_tracking_sheet_srv.py

+16-16
Original file line numberDiff line numberDiff line change
@@ -320,9 +320,9 @@ def test_eb_put_event(self) -> None:
320320
mock_dispatch_events = MagicMock()
321321
libeb.dispatch_events = mock_dispatch_events
322322

323-
"""
324-
Test if event entries are in the correct format when CREATE new records
325-
"""
323+
# ####
324+
# Test if event entries are in the correct format when CREATE new records
325+
# ####
326326
metadata_pd = pd.json_normalize([RECORD_1])
327327
metadata_pd = sanitize_lab_metadata_df(metadata_pd)
328328
persist_lab_metadata(metadata_pd, SHEET_YEAR)
@@ -332,9 +332,9 @@ def test_eb_put_event(self) -> None:
332332
{
333333
"action": "CREATE",
334334
"model": "LIBRARY",
335-
"ref_id": "lib.ULID",
335+
"refId": "lib.ULID",
336336
"data": {
337-
"library_id": "L10001",
337+
"libraryId": "L10001",
338338
}
339339
}
340340
]
@@ -349,9 +349,9 @@ def test_eb_put_event(self) -> None:
349349
self.assertTrue(
350350
is_expected_event_in_output(self, expected=event, output=[json.loads(i.get('Detail')) for i in arg]))
351351

352-
"""
353-
Test if record are UPDATE and event entries are correct
354-
"""
352+
# ####
353+
# Test if record are UPDATE and event entries are correct
354+
# ####
355355
updated_record_1 = RECORD_1.copy()
356356
updated_record_1['Quality'] = 'poor'
357357
mock_dispatch_events.reset_mock()
@@ -364,9 +364,9 @@ def test_eb_put_event(self) -> None:
364364
{
365365
"action": "UPDATE",
366366
"model": "LIBRARY",
367-
"ref_id": "lib.ULID",
367+
"refId": "lib.ULID",
368368
"data": {
369-
"library_id": "L10001",
369+
"libraryId": "L10001",
370370
}
371371
},
372372
]
@@ -380,10 +380,9 @@ def test_eb_put_event(self) -> None:
380380
for event in expected_update_detail:
381381
self.assertTrue(
382382
is_expected_event_in_output(self, expected=event, output=[json.loads(i.get('Detail')) for i in arg]))
383-
384-
"""
385-
Test if the record are DELETE and event entries are correct
386-
"""
383+
# ####
384+
# Test if the record are DELETE and event entries are correct
385+
# ####
387386
mock_dispatch_events.reset_mock()
388387
empty_pd = metadata_pd.drop(0) # Remove the only one record data
389388
persist_lab_metadata(empty_pd, SHEET_YEAR)
@@ -393,12 +392,13 @@ def test_eb_put_event(self) -> None:
393392
{
394393
"action": "DELETE",
395394
"model": "LIBRARY",
396-
"ref_id": "lib.ULID",
395+
"refId": "lib.ULID",
397396
"data": {
398-
"library_id": "L10001",
397+
"libraryId": "L10001",
399398
}
400399
}
401400
]
401+
402402
for entry in arg:
403403
check_put_event_entries_format(self, entry)
404404
check_put_event_value(self, entry=entry, source="orcabus.metadatamanager",

lib/workload/stateless/stacks/metadata-manager/proc/tests/utils.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def is_subset_dict(subset_dict: dict, main_dict: dict):
3030
try:
3131
self.assertEqual(expected['action'], o['action'])
3232
self.assertEqual(expected['model'], o['model'])
33-
self.assertIn('ref_id', o)
33+
self.assertIn('refId', o)
3434

3535
# The expected is the bare minimum data, so we need to check if the expected data is a subset of the
3636
# actual data

0 commit comments

Comments
 (0)