diff --git a/lib/model/classycat_classify.py b/lib/model/classycat_classify.py index 1e63e69..cb5b28d 100644 --- a/lib/model/classycat_classify.py +++ b/lib/model/classycat_classify.py @@ -238,11 +238,28 @@ def validate_input(cls, data: Dict) -> None: """ Validate input data. Must be implemented by all child "Model" classes. """ - pass + if "schema_id" not in data["parameters"] or data["parameters"]["schema_id"] == "": + raise PrestoBaseException("schema_id is required as input to classify", 422) + + if "items" not in data["parameters"] or len(data["parameters"]["items"]) == 0: + raise PrestoBaseException("items are required as input to classify", 422) + + for item in data["parameters"]["items"]: + if "id" not in item or item["id"] == "": + raise PrestoBaseException("id is required for each item", 422) + if "text" not in item or item["text"] == "": + raise PrestoBaseException("text is required for each item", 422) @classmethod def parse_input_message(cls, data: Dict) -> Any: """ - Validate input data. Must be implemented by all child "Model" classes. + Parse input into appropriate response instances. """ - return None \ No newline at end of file + event_type = data['parameters']['event_type'] + result_data = data.get('result', {}) + + if event_type == 'classify': + return ClassyCatBatchClassificationResponse(**result_data) + else: + logger.error(f"Unknown event type {event_type}") + raise PrestoBaseException(f"Unknown event type {event_type}", 422) \ No newline at end of file diff --git a/lib/model/classycat_schema_create.py b/lib/model/classycat_schema_create.py index d8dc009..f04994d 100644 --- a/lib/model/classycat_schema_create.py +++ b/lib/model/classycat_schema_create.py @@ -274,8 +274,7 @@ def parse_input_message(cls, data: Dict) -> Any: result_data = data.get('result', {}) if event_type == 'schema_create': - result_instance = ClassyCatSchemaResponse(**result_data) + return ClassyCatSchemaResponse(**result_data) else: + logger.error(f"Unknown event type {event_type}") raise PrestoBaseException(f"Unknown event type {event_type}", 422) - - return result_instance diff --git a/lib/model/classycat_schema_lookup.py b/lib/model/classycat_schema_lookup.py index b7d8cc9..23f6b36 100644 --- a/lib/model/classycat_schema_lookup.py +++ b/lib/model/classycat_schema_lookup.py @@ -95,8 +95,7 @@ def parse_input_message(cls, data: Dict) -> Any: result_data = data.get('result', {}) if event_type == 'schema_lookup': - result_instance = ClassyCatSchemaResponse(**result_data) + return ClassyCatSchemaResponse(**result_data) else: + logger.error(f"Unknown event type {event_type}") raise PrestoBaseException(f"Unknown event type {event_type}", 422) - - return result_instance