@@ -51,43 +51,93 @@ def _should_process_record(self, record: dict) -> bool:
51
51
52
52
return True
53
53
54
+ @staticmethod
55
+ def _required_fields () -> list :
56
+ """
57
+ Returns a list of fields required for to make a StovaEvent a Data Hub Event.
58
+ Any fields listed here but not provided by Stova will be rejected from ingestion.
59
+
60
+ :return: Required fields to save a StovaEvent.
61
+ """
62
+ return [
63
+ 'id' ,
64
+ 'name' ,
65
+ 'location_address1' ,
66
+ 'location_city' ,
67
+ ]
68
+
69
+ @staticmethod
70
+ def _convert_fields_from_null_to_blank (values : dict ) -> dict :
71
+ """
72
+ Coverts values from the stova record which could be null into empty strings for saving
73
+ as a Data Hub event.
74
+
75
+ :param values: A single Stova Event record from an S3 bucket.
76
+ :return: A single Stova Event record with null/None values replaced with empty strings.
77
+ """
78
+ fields_required_as_blank = [
79
+ 'location_address2' ,
80
+ 'location_address3' ,
81
+ 'location_state' ,
82
+ 'location_postcode' ,
83
+ 'description' ,
84
+ ]
85
+
86
+ for field in fields_required_as_blank :
87
+ if values [field ] is None :
88
+ values [field ] = ''
89
+
90
+ return values
91
+
54
92
def _process_record (self , record : dict ) -> None :
55
93
"""Saves an event from Stova from the S3 bucket into a `StovaEvent`"""
56
94
stova_event_id = record .get ('id' )
95
+
96
+ required_fields = self ._required_fields ()
97
+ for field in required_fields :
98
+ if record [field ] is None or record [field ] == '' :
99
+ logger .info (
100
+ f'Stova Event with id { stova_event_id } does not have required field { field } . '
101
+ 'This stova event will not be processed into Data Hub.' ,
102
+ )
103
+ return
104
+
105
+ cleaned_record = self ._convert_fields_from_null_to_blank (record )
106
+
57
107
values = {
58
- 'stova_event_id' : record .get ('id' ),
59
- 'url' : record .get ('url' , '' ),
60
- 'city' : record .get ('city' , '' ),
61
- 'code' : record .get ('code' , '' ),
62
- 'name' : record .get ('name' , '' ),
63
- 'state' : record .get ('state' , '' ),
64
- 'country' : record .get ('country' , '' ),
65
- 'max_reg' : record .get ('max_reg' ),
66
- 'end_date' : record .get ('end_date' ),
67
- 'timezone' : record .get ('timezone' , '' ),
68
- 'folder_id' : record .get ('folder_id' ),
69
- 'live_date' : record .get ('live_date' ),
70
- 'close_date' : record .get ('close_date' ),
71
- 'created_by' : record .get ('created_by' , '' ),
72
- 'price_type' : record .get ('price_type' , '' ),
73
- 'start_date' : record .get ('start_date' ),
74
- 'description' : record .get ('description' , '' ),
75
- 'modified_by' : record .get ('modified_by' , '' ),
76
- 'contact_info' : record .get ('contact_info' , '' ),
77
- 'created_date' : record .get ('created_date' ),
78
- 'location_city' : record .get ('location_city' , '' ),
79
- 'location_name' : record .get ('location_name' , '' ),
80
- 'modified_date' : record .get ('modified_date' ),
81
- 'client_contact' : record .get ('client_contact' , '' ),
82
- 'location_state' : record .get ('location_state' , '' ),
83
- 'default_language' : record .get ('default_language' , '' ),
84
- 'location_country' : record .get ('location_country' , '' ),
85
- 'approval_required' : record .get ('approval_required' ),
86
- 'location_address1' : record .get ('location_address1' , '' ),
87
- 'location_address2' : record .get ('location_address2' , '' ),
88
- 'location_address3' : record .get ('location_address3' , '' ),
89
- 'location_postcode' : record .get ('location_postcode' , '' ),
90
- 'standard_currency' : record .get ('standard_currency' , '' ),
108
+ 'stova_event_id' : cleaned_record .get ('id' ),
109
+ 'url' : cleaned_record .get ('url' , '' ),
110
+ 'city' : cleaned_record .get ('city' , '' ),
111
+ 'code' : cleaned_record .get ('code' , '' ),
112
+ 'name' : cleaned_record .get ('name' , '' ),
113
+ 'state' : cleaned_record .get ('state' , '' ),
114
+ 'country' : cleaned_record .get ('country' , '' ),
115
+ 'max_reg' : cleaned_record .get ('max_reg' ),
116
+ 'end_date' : cleaned_record .get ('end_date' ),
117
+ 'timezone' : cleaned_record .get ('timezone' , '' ),
118
+ 'folder_id' : cleaned_record .get ('folder_id' ),
119
+ 'live_date' : cleaned_record .get ('live_date' ),
120
+ 'close_date' : cleaned_record .get ('close_date' ),
121
+ 'created_by' : cleaned_record .get ('created_by' , '' ),
122
+ 'price_type' : cleaned_record .get ('price_type' , '' ),
123
+ 'start_date' : cleaned_record .get ('start_date' ),
124
+ 'description' : cleaned_record .get ('description' , '' ),
125
+ 'modified_by' : cleaned_record .get ('modified_by' , '' ),
126
+ 'contact_info' : cleaned_record .get ('contact_info' , '' ),
127
+ 'created_date' : cleaned_record .get ('created_date' ),
128
+ 'location_city' : cleaned_record .get ('location_city' , '' ),
129
+ 'location_name' : cleaned_record .get ('location_name' , '' ),
130
+ 'modified_date' : cleaned_record .get ('modified_date' ),
131
+ 'client_contact' : cleaned_record .get ('client_contact' , '' ),
132
+ 'location_state' : cleaned_record .get ('location_state' , '' ),
133
+ 'default_language' : cleaned_record .get ('default_language' , '' ),
134
+ 'location_country' : cleaned_record .get ('location_country' , '' ),
135
+ 'approval_required' : cleaned_record .get ('approval_required' ),
136
+ 'location_address1' : cleaned_record .get ('location_address1' , '' ),
137
+ 'location_address2' : cleaned_record .get ('location_address2' , '' ),
138
+ 'location_address3' : cleaned_record .get ('location_address3' , '' ),
139
+ 'location_postcode' : cleaned_record .get ('location_postcode' , '' ),
140
+ 'standard_currency' : cleaned_record .get ('standard_currency' , '' ),
91
141
}
92
142
93
143
try :
0 commit comments