1use serde_json::{Map, Value};
23
24#[derive(Clone, Copy, Debug, PartialEq, Eq)]
26pub enum NotificationSeverity {
27 Information,
29 Warning,
31}
32
33impl NotificationSeverity {
34 pub fn as_str(self) -> &'static str {
36 match self {
37 NotificationSeverity::Information => "INFORMATION",
38 NotificationSeverity::Warning => "WARNING",
39 }
40 }
41}
42
43impl std::fmt::Display for NotificationSeverity {
44 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
45 f.write_str(self.as_str())
46 }
47}
48
49#[derive(Clone, Copy, Debug, PartialEq, Eq)]
51pub enum NotificationCategory {
52 Performance,
54 Unrecognized,
56 Deprecation,
58 Schema,
60 Hint,
62}
63
64impl NotificationCategory {
65 pub fn as_str(self) -> &'static str {
67 match self {
68 NotificationCategory::Performance => "PERFORMANCE",
69 NotificationCategory::Unrecognized => "UNRECOGNIZED",
70 NotificationCategory::Deprecation => "DEPRECATION",
71 NotificationCategory::Schema => "SCHEMA",
72 NotificationCategory::Hint => "HINT",
73 }
74 }
75}
76
77impl std::fmt::Display for NotificationCategory {
78 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
79 f.write_str(self.as_str())
80 }
81}
82
83#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
88pub enum NotificationKind {
89 CartesianProduct,
91 UnboundedVariableLengthPattern,
93 AllNodesScan,
95 LabelDisjunctionScan,
98 MissingIndex,
100 EagerAggregation,
102 EstimationMiss,
104 UnknownLabelWarning,
106 UnknownRelationshipTypeWarning,
108 UnknownPropertyKeyWarning,
110 DeprecatedFunction,
112 DeprecatedProcedure,
114 CallSubqueryWithoutScope,
116 MergeSelfReference,
118 AmbiguousSubclauseReference,
121 ComplexSubclauseReference,
124 CreateSelfReference,
127 SubqueryVariableShadowing,
129 DynamicProperty,
132 UnsatisfiableRelationshipTypeExpression,
134 RepeatedRelationshipVariable,
136 SearchIdentifierShadowingVariable,
138 ExhaustiveShortestPath,
140 SchemaIndexOrConstraintAlreadyExists,
143 SchemaIndexOrConstraintDoesNotExist,
146 SchemaVectorIndexDimensionsNotSpecified,
148 HintedIndexNotFound,
150 JoinHintUnfulfillable,
152 RedundantOptionalProcedure,
154 RedundantOptionalSubquery,
156}
157
158struct NotificationRow {
162 code: &'static str,
163 gql_status: &'static str,
164 severity: NotificationSeverity,
165 category: NotificationCategory,
166 title: &'static str,
167 remedy: &'static str,
168 plan_warning: bool,
172 occurrence_scoped: bool,
179}
180
181const CARTESIAN_PRODUCT_ROW: NotificationRow = NotificationRow {
187 code: "Neo.ClientNotification.Statement.CartesianProduct",
188 gql_status: "03N90",
189 severity: NotificationSeverity::Information,
190 category: NotificationCategory::Performance,
191 title: "Cartesian product",
192 remedy: "Give the patterns a join anchor: reuse a node variable across them, or add a \
193 pattern that relates their endpoints; otherwise run them as separate queries.",
194 plan_warning: true,
195 occurrence_scoped: true,
196};
197
198const UNBOUNDED_VARIABLE_LENGTH_PATTERN_ROW: NotificationRow = NotificationRow {
199 code: "Neo.ClientNotification.Statement.UnboundedVariableLengthPattern",
200 gql_status: "03N91",
201 severity: NotificationSeverity::Information,
202 category: NotificationCategory::Performance,
203 title: "Unbounded variable-length pattern",
204 remedy: "Bound the expansion (`[:R*1..5]`) where arbitrary length is not required, or add \
205 a selective endpoint/label predicate and a `LIMIT`.",
206 plan_warning: false,
207 occurrence_scoped: true,
208};
209
210const ALL_NODES_SCAN_ROW: NotificationRow = NotificationRow {
211 code: "Relate.Notification.Statement.AllNodesScan",
212 gql_status: "03C90",
213 severity: NotificationSeverity::Information,
214 category: NotificationCategory::Performance,
215 title: "All nodes scan",
216 remedy: "Name the label the scan intends (`MATCH (n:<Label>)`); on the index's label the \
217 scan becomes an index-backed lookup.",
218 plan_warning: true,
219 occurrence_scoped: false,
220};
221
222const LABEL_DISJUNCTION_SCAN_ROW: NotificationRow = NotificationRow {
223 code: "Relate.Notification.Statement.LabelDisjunctionScan",
224 gql_status: "03C94",
225 severity: NotificationSeverity::Information,
226 category: NotificationCategory::Performance,
227 title: "Label disjunction scan",
228 remedy: "Create a range index on each disjunct label's filtered property: the disjunction \
229 then serves as per-label keyed lookups instead of per-label scans.",
230 plan_warning: true,
231 occurrence_scoped: false,
232};
233
234const MISSING_INDEX_ROW: NotificationRow = NotificationRow {
235 code: "Relate.Notification.Statement.MissingIndex",
236 gql_status: "03C91",
237 severity: NotificationSeverity::Information,
238 category: NotificationCategory::Performance,
239 title: "Missing index",
240 remedy: "`CREATE INDEX relate_Person__email FOR (n:Person) ON (n.email)` — the exact \
241 runnable statement, with the name derived deterministically from label and \
242 property.",
243 plan_warning: false,
244 occurrence_scoped: false,
245};
246
247const EAGER_AGGREGATION_ROW: NotificationRow = NotificationRow {
248 code: "Relate.Notification.Statement.EagerAggregation",
249 gql_status: "03C92",
250 severity: NotificationSeverity::Information,
251 category: NotificationCategory::Performance,
252 title: "Eager aggregation",
253 remedy: "Reduce the rows reaching the aggregation with a selective label/property \
254 predicate or a `LIMIT` before it; profile again to confirm the buffered input \
255 shrank.",
256 plan_warning: false,
257 occurrence_scoped: false,
258};
259
260const ESTIMATION_MISS_ROW: NotificationRow = NotificationRow {
261 code: "Relate.Notification.Statement.EstimationMiss",
262 gql_status: "03C93",
263 severity: NotificationSeverity::Information,
264 category: NotificationCategory::Performance,
265 title: "Estimation miss",
266 remedy: "Rework the operator's input so the estimate can see the filter (add the \
267 selective predicate at the scan, or reorder the join); the estimate is a planner \
268 assumption, not a runtime fact.",
269 plan_warning: true,
270 occurrence_scoped: false,
271};
272
273const UNKNOWN_LABEL_WARNING_ROW: NotificationRow = NotificationRow {
274 code: "Neo.ClientNotification.Statement.UnknownLabelWarning",
275 gql_status: "01N50",
276 severity: NotificationSeverity::Warning,
277 category: NotificationCategory::Unrecognized,
278 title: "Unknown label",
279 remedy: "Check the spelling; the label exists after the first write that creates it, and \
280 no index or constraint uses the unknown name.",
281 plan_warning: false,
282 occurrence_scoped: false,
283};
284
285const UNKNOWN_RELATIONSHIP_TYPE_WARNING_ROW: NotificationRow = NotificationRow {
286 code: "Neo.ClientNotification.Statement.UnknownRelationshipTypeWarning",
287 gql_status: "01N51",
288 severity: NotificationSeverity::Warning,
289 category: NotificationCategory::Unrecognized,
290 title: "Unknown relationship type",
291 remedy: "Check the spelling; the type exists after the first write that creates it.",
292 plan_warning: false,
293 occurrence_scoped: false,
294};
295
296const UNKNOWN_PROPERTY_KEY_WARNING_ROW: NotificationRow = NotificationRow {
297 code: "Neo.ClientNotification.Statement.UnknownPropertyKeyWarning",
298 gql_status: "01N52",
299 severity: NotificationSeverity::Warning,
300 category: NotificationCategory::Unrecognized,
301 title: "Unknown property key",
302 remedy: "Check the spelling; the key exists after the first write that sets it.",
303 plan_warning: false,
304 occurrence_scoped: false,
305};
306
307const DEPRECATED_FUNCTION_ROW: NotificationRow = NotificationRow {
308 code: "Neo.ClientNotification.Statement.FeatureDeprecationWarning",
309 gql_status: "01N01",
310 severity: NotificationSeverity::Warning,
311 category: NotificationCategory::Deprecation,
312 title: "Deprecated function",
313 remedy: "Replace the call with the catalog's `deprecated_by` (`id(n)` → `elementId(n)`).",
314 plan_warning: false,
315 occurrence_scoped: true,
316};
317
318const DEPRECATED_PROCEDURE_ROW: NotificationRow = NotificationRow {
319 code: "Neo.ClientNotification.Statement.FeatureDeprecationWarning",
320 gql_status: "01N01",
321 severity: NotificationSeverity::Warning,
322 category: NotificationCategory::Deprecation,
323 title: "Deprecated procedure",
324 remedy: "Use the registry's `deprecated_by` replacement instead; the replacement is the \
325 remedy.",
326 plan_warning: false,
327 occurrence_scoped: true,
328};
329
330const CALL_SUBQUERY_WITHOUT_SCOPE_ROW: NotificationRow = NotificationRow {
331 code: "Neo.ClientNotification.Statement.FeatureDeprecationWarning",
332 gql_status: "01N00",
333 severity: NotificationSeverity::Warning,
334 category: NotificationCategory::Deprecation,
335 title: "CALL subquery without scope",
336 remedy: "Add the scope clause the body imports: `CALL (n) { … }`, or `CALL () { … }` when \
337 it imports nothing.",
338 plan_warning: false,
339 occurrence_scoped: true,
340};
341
342const MERGE_SELF_REFERENCE_ROW: NotificationRow = NotificationRow {
343 code: "Neo.ClientNotification.Statement.FeatureDeprecationWarning",
344 gql_status: "01N00",
345 severity: NotificationSeverity::Warning,
346 category: NotificationCategory::Deprecation,
347 title: "Merge self-reference",
348 remedy: "Compute the property into a separate variable before the MERGE, or set it \
349 with ON CREATE SET after the merge.",
350 plan_warning: false,
351 occurrence_scoped: true,
352};
353
354const AMBIGUOUS_SUBCLAUSE_REFERENCE_ROW: NotificationRow = NotificationRow {
355 code: "Neo.ClientNotification.Statement.FeatureDeprecationWarning",
356 gql_status: "01N01",
357 severity: NotificationSeverity::Warning,
358 category: NotificationCategory::Deprecation,
359 title: "Deprecated ambiguous subclause reference",
360 remedy: "Reference the projection item by an alias, or use the `GROUP BY` clause.",
361 plan_warning: false,
362 occurrence_scoped: true,
363};
364
365const COMPLEX_SUBCLAUSE_REFERENCE_ROW: NotificationRow = NotificationRow {
366 code: "Neo.ClientNotification.Statement.FeatureDeprecationWarning",
367 gql_status: "01N01",
368 severity: NotificationSeverity::Warning,
369 category: NotificationCategory::Deprecation,
370 title: "Deprecated complex subclause reference",
371 remedy: "Reference the projection item expression by an alias.",
372 plan_warning: false,
373 occurrence_scoped: true,
374};
375
376const CREATE_SELF_REFERENCE_ROW: NotificationRow = NotificationRow {
377 code: "Neo.ClientNotification.Statement.FeatureDeprecationWarning",
378 gql_status: "01N00",
379 severity: NotificationSeverity::Warning,
380 category: NotificationCategory::Deprecation,
381 title: "Create self-reference",
382 remedy: "Create the entity in a separate `CREATE` clause before referencing it, or set \
383 the property afterwards.",
384 plan_warning: false,
385 occurrence_scoped: true,
386};
387
388const SUBQUERY_VARIABLE_SHADOWING_ROW: NotificationRow = NotificationRow {
389 code: "Neo.ClientNotification.Statement.SubqueryVariableShadowing",
390 gql_status: "03N60",
391 severity: NotificationSeverity::Information,
392 category: NotificationCategory::Unrecognized,
393 title: "Subquery variable shadowing",
394 remedy: "Import the outer variable with `CALL (name) { … }`, or rename the inner one.",
395 plan_warning: false,
396 occurrence_scoped: true,
397};
398
399const DYNAMIC_PROPERTY_ROW: NotificationRow = NotificationRow {
400 code: "Neo.ClientNotification.Statement.DynamicProperty",
401 gql_status: "03N95",
402 severity: NotificationSeverity::Information,
403 category: NotificationCategory::Performance,
404 title: "Queries using dynamic properties will use neither index seeks nor \
405 index scans for those properties",
406 remedy: "Use a static property so index lookups stay possible.",
407 plan_warning: false,
408 occurrence_scoped: false,
409};
410
411const HINTED_INDEX_NOT_FOUND_ROW: NotificationRow = NotificationRow {
412 code: "Neo.ClientNotification.Schema.HintedIndexNotFound",
413 gql_status: "01N31",
414 severity: NotificationSeverity::Warning,
415 category: NotificationCategory::Hint,
416 title: "The request (directly or indirectly) referred to an index that \
417 does not exist.",
418 remedy: "Create the index, or drop the hint.",
419 plan_warning: false,
420 occurrence_scoped: true,
421};
422
423const JOIN_HINT_UNFULFILLABLE_ROW: NotificationRow = NotificationRow {
424 code: "Neo.ClientNotification.Statement.JoinHintUnfulfillableWarning",
425 gql_status: "01N30",
426 severity: NotificationSeverity::Warning,
427 category: NotificationCategory::Hint,
428 title: "The database was unable to plan a hinted join.",
429 remedy: "Try a different join key or restructure the query.",
430 plan_warning: false,
431 occurrence_scoped: true,
432};
433
434const UNSATISFIABLE_RELATIONSHIP_TYPE_EXPRESSION_ROW: NotificationRow = NotificationRow {
435 code: "Neo.ClientNotification.Statement.UnsatisfiableRelationshipTypeExpression",
436 gql_status: "01N61",
437 severity: NotificationSeverity::Warning,
438 category: NotificationCategory::Unrecognized,
439 title: "Unsatisfiable relationship type expression",
440 remedy: "Request one type or a disjunction of types; a relationship has exactly one type.",
441 plan_warning: false,
442 occurrence_scoped: true,
443};
444
445const REPEATED_RELATIONSHIP_VARIABLE_ROW: NotificationRow = NotificationRow {
446 code: "Neo.ClientNotification.Statement.RepeatedRelationshipVariable",
447 gql_status: "01N63",
448 severity: NotificationSeverity::Warning,
449 category: NotificationCategory::Unrecognized,
450 title: "Repeated relationship pattern variable",
451 remedy: "Use a distinct variable per relationship position; a relationship cannot be \
452 traversed twice in one pattern.",
453 plan_warning: false,
454 occurrence_scoped: true,
455};
456
457const SEARCH_IDENTIFIER_SHADOWING_VARIABLE_ROW: NotificationRow = NotificationRow {
458 code: "Neo.ClientNotification.Statement.IdentifierShadowingVariable",
459 gql_status: "03N63",
460 severity: NotificationSeverity::Information,
461 category: NotificationCategory::Unrecognized,
462 title: "Identifier shadowing variable",
463 remedy: "Rename the index or the variable; the index name is taken literally.",
464 plan_warning: false,
465 occurrence_scoped: true,
466};
467
468const EXHAUSTIVE_SHORTEST_PATH_ROW: NotificationRow = NotificationRow {
469 code: "Neo.ClientNotification.Statement.ExhaustiveShortestPath",
470 gql_status: "03N92",
471 severity: NotificationSeverity::Information,
472 category: NotificationCategory::Performance,
473 title: "Exhaustive shortest path",
474 remedy: "Separate the existential predicate from the `MATCH` with `WITH` where possible.",
475 plan_warning: false,
476 occurrence_scoped: true,
477};
478
479const INDEX_OR_CONSTRAINT_ALREADY_EXISTS_ROW: NotificationRow = NotificationRow {
480 code: "Neo.ClientNotification.Schema.IndexOrConstraintAlreadyExists",
481 gql_status: "00NA0",
482 severity: NotificationSeverity::Information,
483 category: NotificationCategory::Schema,
484 title: "Index or constraint already exists",
485 remedy: "Drop the existing index or constraint first, or use a different name or schema.",
486 plan_warning: false,
487 occurrence_scoped: false,
488};
489
490const INDEX_OR_CONSTRAINT_DOES_NOT_EXIST_ROW: NotificationRow = NotificationRow {
491 code: "Neo.ClientNotification.Schema.IndexOrConstraintDoesNotExist",
492 gql_status: "00NA1",
493 severity: NotificationSeverity::Information,
494 category: NotificationCategory::Schema,
495 title: "Index or constraint does not exist",
496 remedy: "Check the name; `IF EXISTS` makes a missing index or constraint a no-op.",
497 plan_warning: false,
498 occurrence_scoped: false,
499};
500
501const VECTOR_INDEX_DIMENSIONS_NOT_SPECIFIED_ROW: NotificationRow = NotificationRow {
502 code: "Neo.ClientNotification.Schema.VectorIndexDimensionsNotSpecified",
503 gql_status: "00NA2",
504 severity: NotificationSeverity::Information,
505 category: NotificationCategory::Schema,
506 title: "Vector index dimensions not specified",
507 remedy: "Set `vector.dimensions` in `OPTIONS { indexConfig: { … } }` when creating the index.",
508 plan_warning: false,
509 occurrence_scoped: false,
510};
511
512const REDUNDANT_OPTIONAL_PROCEDURE_ROW: NotificationRow = NotificationRow {
513 code: "Neo.ClientNotification.Statement.RedundantOptionalProcedure",
514 gql_status: "03N61",
515 severity: NotificationSeverity::Information,
516 category: NotificationCategory::Performance,
517 title: "Redundant optional procedure",
518 remedy: "Drop `OPTIONAL`: the procedure declares no return columns, so the call yields \
519 the same single row either way.",
520 plan_warning: false,
521 occurrence_scoped: true,
522};
523
524const REDUNDANT_OPTIONAL_SUBQUERY_ROW: NotificationRow = NotificationRow {
525 code: "Neo.ClientNotification.Statement.RedundantOptionalSubquery",
526 gql_status: "03N62",
527 severity: NotificationSeverity::Information,
528 category: NotificationCategory::Performance,
529 title: "Redundant optional subquery",
530 remedy: "Drop `OPTIONAL`: the subquery projects no columns, so the call yields the same \
531 single row either way.",
532 plan_warning: false,
533 occurrence_scoped: true,
534};
535
536impl NotificationKind {
537 fn row(self) -> &'static NotificationRow {
542 match self {
543 NotificationKind::CartesianProduct => &CARTESIAN_PRODUCT_ROW,
544 NotificationKind::UnboundedVariableLengthPattern => {
545 &UNBOUNDED_VARIABLE_LENGTH_PATTERN_ROW
546 }
547 NotificationKind::AllNodesScan => &ALL_NODES_SCAN_ROW,
548 NotificationKind::LabelDisjunctionScan => &LABEL_DISJUNCTION_SCAN_ROW,
549 NotificationKind::MissingIndex => &MISSING_INDEX_ROW,
550 NotificationKind::EagerAggregation => &EAGER_AGGREGATION_ROW,
551 NotificationKind::EstimationMiss => &ESTIMATION_MISS_ROW,
552 NotificationKind::UnknownLabelWarning => &UNKNOWN_LABEL_WARNING_ROW,
553 NotificationKind::UnknownRelationshipTypeWarning => {
554 &UNKNOWN_RELATIONSHIP_TYPE_WARNING_ROW
555 }
556 NotificationKind::UnknownPropertyKeyWarning => &UNKNOWN_PROPERTY_KEY_WARNING_ROW,
557 NotificationKind::DeprecatedFunction => &DEPRECATED_FUNCTION_ROW,
558 NotificationKind::DeprecatedProcedure => &DEPRECATED_PROCEDURE_ROW,
559 NotificationKind::CallSubqueryWithoutScope => &CALL_SUBQUERY_WITHOUT_SCOPE_ROW,
560 NotificationKind::MergeSelfReference => &MERGE_SELF_REFERENCE_ROW,
561 NotificationKind::AmbiguousSubclauseReference => &AMBIGUOUS_SUBCLAUSE_REFERENCE_ROW,
562 NotificationKind::ComplexSubclauseReference => &COMPLEX_SUBCLAUSE_REFERENCE_ROW,
563 NotificationKind::CreateSelfReference => &CREATE_SELF_REFERENCE_ROW,
564 NotificationKind::SubqueryVariableShadowing => &SUBQUERY_VARIABLE_SHADOWING_ROW,
565 NotificationKind::DynamicProperty => &DYNAMIC_PROPERTY_ROW,
566 NotificationKind::UnsatisfiableRelationshipTypeExpression => {
567 &UNSATISFIABLE_RELATIONSHIP_TYPE_EXPRESSION_ROW
568 }
569 NotificationKind::RepeatedRelationshipVariable => &REPEATED_RELATIONSHIP_VARIABLE_ROW,
570 NotificationKind::SearchIdentifierShadowingVariable => {
571 &SEARCH_IDENTIFIER_SHADOWING_VARIABLE_ROW
572 }
573 NotificationKind::ExhaustiveShortestPath => &EXHAUSTIVE_SHORTEST_PATH_ROW,
574 NotificationKind::RedundantOptionalProcedure => &REDUNDANT_OPTIONAL_PROCEDURE_ROW,
575 NotificationKind::RedundantOptionalSubquery => &REDUNDANT_OPTIONAL_SUBQUERY_ROW,
576 NotificationKind::SchemaIndexOrConstraintAlreadyExists => {
577 &INDEX_OR_CONSTRAINT_ALREADY_EXISTS_ROW
578 }
579 NotificationKind::SchemaIndexOrConstraintDoesNotExist => {
580 &INDEX_OR_CONSTRAINT_DOES_NOT_EXIST_ROW
581 }
582 NotificationKind::SchemaVectorIndexDimensionsNotSpecified => {
583 &VECTOR_INDEX_DIMENSIONS_NOT_SPECIFIED_ROW
584 }
585 NotificationKind::HintedIndexNotFound => &HINTED_INDEX_NOT_FOUND_ROW,
586 NotificationKind::JoinHintUnfulfillable => &JOIN_HINT_UNFULFILLABLE_ROW,
587 }
588 }
589
590 pub fn dedups_identical(self) -> bool {
597 !self.row().occurrence_scoped
598 }
599
600 pub fn is_plan_warning(self) -> bool {
609 self.row().plan_warning
610 }
611
612 pub fn code(self) -> &'static str {
615 self.row().code
616 }
617
618 pub fn gql_status(self) -> &'static str {
620 self.row().gql_status
621 }
622
623 pub fn severity(self) -> NotificationSeverity {
625 self.row().severity
626 }
627
628 pub fn category(self) -> NotificationCategory {
630 self.row().category
631 }
632
633 pub fn title(self) -> &'static str {
636 self.row().title
637 }
638
639 pub fn remedy(self) -> &'static str {
642 self.row().remedy
643 }
644}
645
646#[derive(Clone, Debug, PartialEq, Eq)]
658pub struct Notification {
659 kind: NotificationKind,
660 description: String,
661 remedy: Option<String>,
662 operator_id: Option<usize>,
663}
664
665impl Notification {
666 pub fn new(kind: NotificationKind, description: impl Into<String>) -> Self {
670 Notification {
671 kind,
672 description: description.into(),
673 remedy: None,
674 operator_id: None,
675 }
676 }
677
678 pub fn with_operator_id(mut self, operator_id: usize) -> Self {
681 self.operator_id = Some(operator_id);
682 self
683 }
684
685 pub fn with_remedy(mut self, remedy: impl Into<String>) -> Self {
688 self.remedy = Some(remedy.into());
689 self
690 }
691
692 pub fn kind(&self) -> NotificationKind {
694 self.kind
695 }
696
697 pub fn description(&self) -> &str {
700 &self.description
701 }
702
703 pub fn code(&self) -> &'static str {
705 self.kind.code()
706 }
707
708 pub fn gql_status(&self) -> &'static str {
710 self.kind.gql_status()
711 }
712
713 pub fn title(&self) -> &'static str {
715 self.kind.title()
716 }
717
718 pub fn severity(&self) -> NotificationSeverity {
720 self.kind.severity()
721 }
722
723 pub fn category(&self) -> NotificationCategory {
725 self.kind.category()
726 }
727
728 pub fn remedy(&self) -> &str {
732 self.remedy.as_deref().unwrap_or_else(|| self.kind.remedy())
733 }
734
735 pub fn operator_id(&self) -> Option<usize> {
737 self.operator_id
738 }
739}
740
741pub mod notification_keys {
745 pub const CODE: &str = "code";
747 pub const GQL_STATUS: &str = "gql_status";
749 pub const SEVERITY: &str = "severity";
751 pub const CATEGORY: &str = "category";
753 pub const TITLE: &str = "title";
755 pub const DESCRIPTION: &str = "description";
757 pub const REMEDY: &str = "remedy";
759 pub const OPERATOR_ID: &str = "operator_id";
761 pub const NOTIFICATIONS: &str = "notifications";
763}
764
765pub(crate) fn notification_fields(notification: &Notification) -> Map<String, Value> {
774 let mut obj = Map::new();
775 obj.insert(
776 notification_keys::CODE.into(),
777 Value::String(notification.code().into()),
778 );
779 obj.insert(
780 notification_keys::GQL_STATUS.into(),
781 Value::String(notification.gql_status().into()),
782 );
783 obj.insert(
784 notification_keys::SEVERITY.into(),
785 Value::String(notification.severity().as_str().into()),
786 );
787 obj.insert(
788 notification_keys::CATEGORY.into(),
789 Value::String(notification.category().as_str().into()),
790 );
791 obj.insert(
792 notification_keys::TITLE.into(),
793 Value::String(notification.title().into()),
794 );
795 obj.insert(
796 notification_keys::DESCRIPTION.into(),
797 Value::String(notification.description().into()),
798 );
799 obj.insert(
800 notification_keys::REMEDY.into(),
801 Value::String(notification.remedy().into()),
802 );
803 obj
804}
805
806pub fn notification_to_wire_json(notification: &Notification) -> Value {
810 let mut obj = notification_fields(notification);
811 if let Some(operator_id) = notification.operator_id() {
812 obj.insert(
813 notification_keys::OPERATOR_ID.into(),
814 Value::from(operator_id),
815 );
816 }
817 Value::Object(obj)
818}
819
820pub fn notifications_to_wire_json(notifications: &[Notification]) -> Value {
823 Value::Array(
824 notifications
825 .iter()
826 .map(notification_to_wire_json)
827 .collect(),
828 )
829}
830
831pub fn notification_to_neo4j_entries(notification: &Notification) -> Vec<(&'static str, String)> {
839 vec![
840 (notification_keys::CODE, notification.code().to_string()),
841 (notification_keys::TITLE, notification.title().to_string()),
842 (
843 notification_keys::DESCRIPTION,
844 format!(
845 "{} (remedy: {})",
846 notification.description(),
847 notification.remedy()
848 ),
849 ),
850 (
851 notification_keys::SEVERITY,
852 notification.severity().as_str().to_string(),
853 ),
854 (
855 notification_keys::CATEGORY,
856 notification.category().as_str().to_string(),
857 ),
858 ]
859}
860
861pub fn notification_to_neo4j_json(notification: &Notification) -> Value {
871 let obj: Map<String, Value> = notification_to_neo4j_entries(notification)
872 .into_iter()
873 .map(|(key, value)| (key.to_owned(), Value::String(value)))
874 .collect();
875 Value::Object(obj)
876}
877
878#[cfg(test)]
879#[path = "notification_wire/tests.rs"]
880mod tests;