|
| 1 | +# Utility Guide: Notify Criteria Parser |
| 2 | +**Source:** [`utils/notify_criteria_parser.py`](../../utils/notify_criteria_parser.py) |
| 3 | + |
| 4 | +The Notify Criteria Parser is a lightweight utility that extracts structured values from compact Notify message criteria strings. It is used by selection builders to support Notify filter logic—like `"S1 - new"` or `"S1 (S1w) - sending"` — by parsing these inputs into cleanly separated parts: `message type`, `message code (optional)`, and `status`. |
| 5 | + |
| 6 | +## Table of Contents |
| 7 | + |
| 8 | +- [Utility Guide: Notify Criteria Parser](#utility-guide-notify-criteria-parser) |
| 9 | + - [Table of Contents](#table-of-contents) |
| 10 | + - [Overview](#overview) |
| 11 | + - [Using the Parser](#using-the-parser) |
| 12 | + - [Expected Input Formats](#expected-input-formats) |
| 13 | + - [Example Usage](#example-usage) |
| 14 | + - [Output Structure](#output-structure) |
| 15 | + - [Edge Case: none](#edge-case-none) |
| 16 | + - [Error Handling](#error-handling) |
| 17 | + - [Integration Points](#integration-points) |
| 18 | + |
| 19 | +--- |
| 20 | + |
| 21 | +## Overview |
| 22 | + |
| 23 | +Notify message filters are written as short text descriptions like "S1 - new" or "S1 (S1w) - sending". |
| 24 | +The parser splits them into meaningful parts so that the system knows what message type to look for, whether there's a specific message code, and the message's status (like "new", "sending", etc). This parser breaks those strings into usable components for SQL query builders. |
| 25 | + |
| 26 | +- `"S1 - new"` |
| 27 | +- `"S1 (S1w) - sending"` |
| 28 | +- `"none"` |
| 29 | + |
| 30 | +--- |
| 31 | + |
| 32 | +## Using the Parser |
| 33 | + |
| 34 | +Import the parser function and give it a string like "S1 (S1w) - sending", and it gives you back each piece of information separately, like the message type, the code (if there is one), and the status. |
| 35 | + |
| 36 | +```python |
| 37 | +from utils.notify_criteria_parser import parse_notify_criteria |
| 38 | + |
| 39 | +parts = parse_notify_criteria("S1 (S1w) - sending") |
| 40 | +``` |
| 41 | + |
| 42 | +## Expected Input Formats |
| 43 | +The parser supports the following input patterns: |
| 44 | + |
| 45 | +| Format | Meaning | |
| 46 | +| ------------------------- | ---------------------------------------------- | |
| 47 | +| `Type - status` | e.g. `"S1 - new"` | |
| 48 | +| `Type (Code) - status` | e.g. `"S1 (S1w) - sending"` | |
| 49 | +| `none` (case-insensitive) | Special case meaning “no message should exist” | |
| 50 | + |
| 51 | +## Example Usage |
| 52 | +Here are a few examples of what the parser returns. Think of it like splitting a sentence into parts so each part can be used in a database search: |
| 53 | + |
| 54 | +```python |
| 55 | +parse_notify_criteria("S2 (X9) - failed") |
| 56 | +# ➜ {'type': 'S2', 'code': 'X9', 'status': 'failed'} |
| 57 | + |
| 58 | +parse_notify_criteria("S1 - new") |
| 59 | +# ➜ {'type': 'S1', 'code': None, 'status': 'new'} |
| 60 | + |
| 61 | +parse_notify_criteria("None") |
| 62 | +# ➜ {'status': 'none'} |
| 63 | +``` |
| 64 | + |
| 65 | +## Output Structure |
| 66 | +The returned value is a dictionary containing: |
| 67 | + |
| 68 | +```python |
| 69 | +{ |
| 70 | + "type": str, # the main message group (like S1 or M1) |
| 71 | + "code": Optional[str], # the specific version (optional) |
| 72 | + "status": str # the message’s progress, such as "new", "sending", or "none" |
| 73 | +} |
| 74 | +``` |
| 75 | +## Edge Case: none |
| 76 | +If someone enters `none` as the criteria, it means "we're looking for subjects who do not have a matching message." The parser handles this specially, and the SQL builder will write `NOT EXISTS` logic behind the scenes to exclude those cases, so the parser returns: |
| 77 | + |
| 78 | +```python |
| 79 | +{'status': 'none'} |
| 80 | +``` |
| 81 | +This signals `NOT EXISTS` logic for Notify message filtering. |
| 82 | + |
| 83 | +## Error Handling |
| 84 | +If the input doesn’t match an expected pattern, the parser raises: |
| 85 | + |
| 86 | +```python |
| 87 | +ValueError("Invalid Notify criteria format: 'your_input'") |
| 88 | +``` |
| 89 | +e.g. If a tester or user types something like `S1 - banana` or forgets the - status bit, the parser will throw an error. This helps catch typos or unsupported formats early. |
| 90 | + |
| 91 | +## Integration Points |
| 92 | +These are the parts of the system that use the parser to decide whether to include or exclude Notify messages from a search: |
| 93 | +`SubjectSelectionQueryBuilder._add_criteria_notify_queued_message_status()` – for messages currently in the system |
| 94 | + |
| 95 | +`SubjectSelectionQueryBuilder._add_criteria_notify_archived_message_status()` – for messages already sent or stored |
| 96 | + |
| 97 | +You can also reuse it in any other part of the system that needs to interpret Notify message filters. |
0 commit comments