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}
153
154struct NotificationRow {
158 code: &'static str,
159 gql_status: &'static str,
160 severity: NotificationSeverity,
161 category: NotificationCategory,
162 title: &'static str,
163 remedy: &'static str,
164 plan_warning: bool,
168 occurrence_scoped: bool,
175}
176
177const CARTESIAN_PRODUCT_ROW: NotificationRow = NotificationRow {
183 code: "Neo.ClientNotification.Statement.CartesianProduct",
184 gql_status: "03N90",
185 severity: NotificationSeverity::Information,
186 category: NotificationCategory::Performance,
187 title: "Cartesian product",
188 remedy: "Give the patterns a join anchor: reuse a node variable across them, or add a \
189 pattern that relates their endpoints; otherwise run them as separate queries.",
190 plan_warning: true,
191 occurrence_scoped: true,
192};
193
194const UNBOUNDED_VARIABLE_LENGTH_PATTERN_ROW: NotificationRow = NotificationRow {
195 code: "Neo.ClientNotification.Statement.UnboundedVariableLengthPattern",
196 gql_status: "03N91",
197 severity: NotificationSeverity::Information,
198 category: NotificationCategory::Performance,
199 title: "Unbounded variable-length pattern",
200 remedy: "Bound the expansion (`[:R*1..5]`) where arbitrary length is not required, or add \
201 a selective endpoint/label predicate and a `LIMIT`.",
202 plan_warning: false,
203 occurrence_scoped: true,
204};
205
206const ALL_NODES_SCAN_ROW: NotificationRow = NotificationRow {
207 code: "Relate.Notification.Statement.AllNodesScan",
208 gql_status: "03C90",
209 severity: NotificationSeverity::Information,
210 category: NotificationCategory::Performance,
211 title: "All nodes scan",
212 remedy: "Name the label the scan intends (`MATCH (n:<Label>)`); on the index's label the \
213 scan becomes an index-backed lookup.",
214 plan_warning: true,
215 occurrence_scoped: false,
216};
217
218const LABEL_DISJUNCTION_SCAN_ROW: NotificationRow = NotificationRow {
219 code: "Relate.Notification.Statement.LabelDisjunctionScan",
220 gql_status: "03C94",
221 severity: NotificationSeverity::Information,
222 category: NotificationCategory::Performance,
223 title: "Label disjunction scan",
224 remedy: "Create a range index on each disjunct label's filtered property: the disjunction \
225 then serves as per-label keyed lookups instead of per-label scans.",
226 plan_warning: true,
227 occurrence_scoped: false,
228};
229
230const MISSING_INDEX_ROW: NotificationRow = NotificationRow {
231 code: "Relate.Notification.Statement.MissingIndex",
232 gql_status: "03C91",
233 severity: NotificationSeverity::Information,
234 category: NotificationCategory::Performance,
235 title: "Missing index",
236 remedy: "`CREATE INDEX relate_Person__email FOR (n:Person) ON (n.email)` — the exact \
237 runnable statement, with the name derived deterministically from label and \
238 property.",
239 plan_warning: false,
240 occurrence_scoped: false,
241};
242
243const EAGER_AGGREGATION_ROW: NotificationRow = NotificationRow {
244 code: "Relate.Notification.Statement.EagerAggregation",
245 gql_status: "03C92",
246 severity: NotificationSeverity::Information,
247 category: NotificationCategory::Performance,
248 title: "Eager aggregation",
249 remedy: "Reduce the rows reaching the aggregation with a selective label/property \
250 predicate or a `LIMIT` before it; profile again to confirm the buffered input \
251 shrank.",
252 plan_warning: false,
253 occurrence_scoped: false,
254};
255
256const ESTIMATION_MISS_ROW: NotificationRow = NotificationRow {
257 code: "Relate.Notification.Statement.EstimationMiss",
258 gql_status: "03C93",
259 severity: NotificationSeverity::Information,
260 category: NotificationCategory::Performance,
261 title: "Estimation miss",
262 remedy: "Rework the operator's input so the estimate can see the filter (add the \
263 selective predicate at the scan, or reorder the join); the estimate is a planner \
264 assumption, not a runtime fact.",
265 plan_warning: true,
266 occurrence_scoped: false,
267};
268
269const UNKNOWN_LABEL_WARNING_ROW: NotificationRow = NotificationRow {
270 code: "Neo.ClientNotification.Statement.UnknownLabelWarning",
271 gql_status: "01N50",
272 severity: NotificationSeverity::Warning,
273 category: NotificationCategory::Unrecognized,
274 title: "Unknown label",
275 remedy: "Check the spelling; the label exists after the first write that creates it, and \
276 no index or constraint uses the unknown name.",
277 plan_warning: false,
278 occurrence_scoped: false,
279};
280
281const UNKNOWN_RELATIONSHIP_TYPE_WARNING_ROW: NotificationRow = NotificationRow {
282 code: "Neo.ClientNotification.Statement.UnknownRelationshipTypeWarning",
283 gql_status: "01N51",
284 severity: NotificationSeverity::Warning,
285 category: NotificationCategory::Unrecognized,
286 title: "Unknown relationship type",
287 remedy: "Check the spelling; the type exists after the first write that creates it.",
288 plan_warning: false,
289 occurrence_scoped: false,
290};
291
292const UNKNOWN_PROPERTY_KEY_WARNING_ROW: NotificationRow = NotificationRow {
293 code: "Neo.ClientNotification.Statement.UnknownPropertyKeyWarning",
294 gql_status: "01N52",
295 severity: NotificationSeverity::Warning,
296 category: NotificationCategory::Unrecognized,
297 title: "Unknown property key",
298 remedy: "Check the spelling; the key exists after the first write that sets it.",
299 plan_warning: false,
300 occurrence_scoped: false,
301};
302
303const DEPRECATED_FUNCTION_ROW: NotificationRow = NotificationRow {
304 code: "Neo.ClientNotification.Statement.FeatureDeprecationWarning",
305 gql_status: "01N01",
306 severity: NotificationSeverity::Warning,
307 category: NotificationCategory::Deprecation,
308 title: "Deprecated function",
309 remedy: "Replace the call with the catalog's `deprecated_by` (`id(n)` → `elementId(n)`).",
310 plan_warning: false,
311 occurrence_scoped: true,
312};
313
314const DEPRECATED_PROCEDURE_ROW: NotificationRow = NotificationRow {
315 code: "Neo.ClientNotification.Statement.FeatureDeprecationWarning",
316 gql_status: "01N01",
317 severity: NotificationSeverity::Warning,
318 category: NotificationCategory::Deprecation,
319 title: "Deprecated procedure",
320 remedy: "Use the registry's `deprecated_by` replacement instead; the replacement is the \
321 remedy.",
322 plan_warning: false,
323 occurrence_scoped: true,
324};
325
326const CALL_SUBQUERY_WITHOUT_SCOPE_ROW: NotificationRow = NotificationRow {
327 code: "Neo.ClientNotification.Statement.FeatureDeprecationWarning",
328 gql_status: "01N00",
329 severity: NotificationSeverity::Warning,
330 category: NotificationCategory::Deprecation,
331 title: "CALL subquery without scope",
332 remedy: "Add the scope clause the body imports: `CALL (n) { … }`, or `CALL () { … }` when \
333 it imports nothing.",
334 plan_warning: false,
335 occurrence_scoped: true,
336};
337
338const MERGE_SELF_REFERENCE_ROW: NotificationRow = NotificationRow {
339 code: "Neo.ClientNotification.Statement.FeatureDeprecationWarning",
340 gql_status: "01N00",
341 severity: NotificationSeverity::Warning,
342 category: NotificationCategory::Deprecation,
343 title: "Merge self-reference",
344 remedy: "Compute the property into a separate variable before the MERGE, or set it \
345 with ON CREATE SET after the merge.",
346 plan_warning: false,
347 occurrence_scoped: true,
348};
349
350const AMBIGUOUS_SUBCLAUSE_REFERENCE_ROW: NotificationRow = NotificationRow {
351 code: "Neo.ClientNotification.Statement.FeatureDeprecationWarning",
352 gql_status: "01N01",
353 severity: NotificationSeverity::Warning,
354 category: NotificationCategory::Deprecation,
355 title: "Deprecated ambiguous subclause reference",
356 remedy: "Reference the projection item by an alias, or use the `GROUP BY` clause.",
357 plan_warning: false,
358 occurrence_scoped: true,
359};
360
361const COMPLEX_SUBCLAUSE_REFERENCE_ROW: NotificationRow = NotificationRow {
362 code: "Neo.ClientNotification.Statement.FeatureDeprecationWarning",
363 gql_status: "01N01",
364 severity: NotificationSeverity::Warning,
365 category: NotificationCategory::Deprecation,
366 title: "Deprecated complex subclause reference",
367 remedy: "Reference the projection item expression by an alias.",
368 plan_warning: false,
369 occurrence_scoped: true,
370};
371
372const CREATE_SELF_REFERENCE_ROW: NotificationRow = NotificationRow {
373 code: "Neo.ClientNotification.Statement.FeatureDeprecationWarning",
374 gql_status: "01N00",
375 severity: NotificationSeverity::Warning,
376 category: NotificationCategory::Deprecation,
377 title: "Create self-reference",
378 remedy: "Create the entity in a separate `CREATE` clause before referencing it, or set \
379 the property afterwards.",
380 plan_warning: false,
381 occurrence_scoped: true,
382};
383
384const SUBQUERY_VARIABLE_SHADOWING_ROW: NotificationRow = NotificationRow {
385 code: "Neo.ClientNotification.Statement.SubqueryVariableShadowing",
386 gql_status: "03N60",
387 severity: NotificationSeverity::Information,
388 category: NotificationCategory::Unrecognized,
389 title: "Subquery variable shadowing",
390 remedy: "Import the outer variable with `CALL (name) { … }`, or rename the inner one.",
391 plan_warning: false,
392 occurrence_scoped: true,
393};
394
395const DYNAMIC_PROPERTY_ROW: NotificationRow = NotificationRow {
396 code: "Neo.ClientNotification.Statement.DynamicProperty",
397 gql_status: "03N95",
398 severity: NotificationSeverity::Information,
399 category: NotificationCategory::Performance,
400 title: "Queries using dynamic properties will use neither index seeks nor \
401 index scans for those properties",
402 remedy: "Use a static property so index lookups stay possible.",
403 plan_warning: false,
404 occurrence_scoped: false,
405};
406
407const HINTED_INDEX_NOT_FOUND_ROW: NotificationRow = NotificationRow {
408 code: "Neo.ClientNotification.Schema.HintedIndexNotFound",
409 gql_status: "01N31",
410 severity: NotificationSeverity::Warning,
411 category: NotificationCategory::Hint,
412 title: "The request (directly or indirectly) referred to an index that \
413 does not exist.",
414 remedy: "Create the index, or drop the hint.",
415 plan_warning: false,
416 occurrence_scoped: true,
417};
418
419const JOIN_HINT_UNFULFILLABLE_ROW: NotificationRow = NotificationRow {
420 code: "Neo.ClientNotification.Statement.JoinHintUnfulfillableWarning",
421 gql_status: "01N30",
422 severity: NotificationSeverity::Warning,
423 category: NotificationCategory::Hint,
424 title: "The database was unable to plan a hinted join.",
425 remedy: "Try a different join key or restructure the query.",
426 plan_warning: false,
427 occurrence_scoped: true,
428};
429
430const UNSATISFIABLE_RELATIONSHIP_TYPE_EXPRESSION_ROW: NotificationRow = NotificationRow {
431 code: "Neo.ClientNotification.Statement.UnsatisfiableRelationshipTypeExpression",
432 gql_status: "01N61",
433 severity: NotificationSeverity::Warning,
434 category: NotificationCategory::Unrecognized,
435 title: "Unsatisfiable relationship type expression",
436 remedy: "Request one type or a disjunction of types; a relationship has exactly one type.",
437 plan_warning: false,
438 occurrence_scoped: true,
439};
440
441const REPEATED_RELATIONSHIP_VARIABLE_ROW: NotificationRow = NotificationRow {
442 code: "Neo.ClientNotification.Statement.RepeatedRelationshipVariable",
443 gql_status: "01N63",
444 severity: NotificationSeverity::Warning,
445 category: NotificationCategory::Unrecognized,
446 title: "Repeated relationship pattern variable",
447 remedy: "Use a distinct variable per relationship position; a relationship cannot be \
448 traversed twice in one pattern.",
449 plan_warning: false,
450 occurrence_scoped: true,
451};
452
453const SEARCH_IDENTIFIER_SHADOWING_VARIABLE_ROW: NotificationRow = NotificationRow {
454 code: "Neo.ClientNotification.Statement.IdentifierShadowingVariable",
455 gql_status: "03N63",
456 severity: NotificationSeverity::Information,
457 category: NotificationCategory::Unrecognized,
458 title: "Identifier shadowing variable",
459 remedy: "Rename the index or the variable; the index name is taken literally.",
460 plan_warning: false,
461 occurrence_scoped: true,
462};
463
464const EXHAUSTIVE_SHORTEST_PATH_ROW: NotificationRow = NotificationRow {
465 code: "Neo.ClientNotification.Statement.ExhaustiveShortestPath",
466 gql_status: "03N92",
467 severity: NotificationSeverity::Information,
468 category: NotificationCategory::Performance,
469 title: "Exhaustive shortest path",
470 remedy: "Separate the existential predicate from the `MATCH` with `WITH` where possible.",
471 plan_warning: false,
472 occurrence_scoped: true,
473};
474
475const INDEX_OR_CONSTRAINT_ALREADY_EXISTS_ROW: NotificationRow = NotificationRow {
476 code: "Neo.ClientNotification.Schema.IndexOrConstraintAlreadyExists",
477 gql_status: "00NA0",
478 severity: NotificationSeverity::Information,
479 category: NotificationCategory::Schema,
480 title: "Index or constraint already exists",
481 remedy: "Drop the existing index or constraint first, or use a different name or schema.",
482 plan_warning: false,
483 occurrence_scoped: false,
484};
485
486const INDEX_OR_CONSTRAINT_DOES_NOT_EXIST_ROW: NotificationRow = NotificationRow {
487 code: "Neo.ClientNotification.Schema.IndexOrConstraintDoesNotExist",
488 gql_status: "00NA1",
489 severity: NotificationSeverity::Information,
490 category: NotificationCategory::Schema,
491 title: "Index or constraint does not exist",
492 remedy: "Check the name; `IF EXISTS` makes a missing index or constraint a no-op.",
493 plan_warning: false,
494 occurrence_scoped: false,
495};
496
497const VECTOR_INDEX_DIMENSIONS_NOT_SPECIFIED_ROW: NotificationRow = NotificationRow {
498 code: "Neo.ClientNotification.Schema.VectorIndexDimensionsNotSpecified",
499 gql_status: "00NA2",
500 severity: NotificationSeverity::Information,
501 category: NotificationCategory::Schema,
502 title: "Vector index dimensions not specified",
503 remedy: "Set `vector.dimensions` in `OPTIONS { indexConfig: { … } }` when creating the index.",
504 plan_warning: false,
505 occurrence_scoped: false,
506};
507
508impl NotificationKind {
509 fn row(self) -> &'static NotificationRow {
514 match self {
515 NotificationKind::CartesianProduct => &CARTESIAN_PRODUCT_ROW,
516 NotificationKind::UnboundedVariableLengthPattern => {
517 &UNBOUNDED_VARIABLE_LENGTH_PATTERN_ROW
518 }
519 NotificationKind::AllNodesScan => &ALL_NODES_SCAN_ROW,
520 NotificationKind::LabelDisjunctionScan => &LABEL_DISJUNCTION_SCAN_ROW,
521 NotificationKind::MissingIndex => &MISSING_INDEX_ROW,
522 NotificationKind::EagerAggregation => &EAGER_AGGREGATION_ROW,
523 NotificationKind::EstimationMiss => &ESTIMATION_MISS_ROW,
524 NotificationKind::UnknownLabelWarning => &UNKNOWN_LABEL_WARNING_ROW,
525 NotificationKind::UnknownRelationshipTypeWarning => {
526 &UNKNOWN_RELATIONSHIP_TYPE_WARNING_ROW
527 }
528 NotificationKind::UnknownPropertyKeyWarning => &UNKNOWN_PROPERTY_KEY_WARNING_ROW,
529 NotificationKind::DeprecatedFunction => &DEPRECATED_FUNCTION_ROW,
530 NotificationKind::DeprecatedProcedure => &DEPRECATED_PROCEDURE_ROW,
531 NotificationKind::CallSubqueryWithoutScope => &CALL_SUBQUERY_WITHOUT_SCOPE_ROW,
532 NotificationKind::MergeSelfReference => &MERGE_SELF_REFERENCE_ROW,
533 NotificationKind::AmbiguousSubclauseReference => &AMBIGUOUS_SUBCLAUSE_REFERENCE_ROW,
534 NotificationKind::ComplexSubclauseReference => &COMPLEX_SUBCLAUSE_REFERENCE_ROW,
535 NotificationKind::CreateSelfReference => &CREATE_SELF_REFERENCE_ROW,
536 NotificationKind::SubqueryVariableShadowing => &SUBQUERY_VARIABLE_SHADOWING_ROW,
537 NotificationKind::DynamicProperty => &DYNAMIC_PROPERTY_ROW,
538 NotificationKind::UnsatisfiableRelationshipTypeExpression => {
539 &UNSATISFIABLE_RELATIONSHIP_TYPE_EXPRESSION_ROW
540 }
541 NotificationKind::RepeatedRelationshipVariable => &REPEATED_RELATIONSHIP_VARIABLE_ROW,
542 NotificationKind::SearchIdentifierShadowingVariable => {
543 &SEARCH_IDENTIFIER_SHADOWING_VARIABLE_ROW
544 }
545 NotificationKind::ExhaustiveShortestPath => &EXHAUSTIVE_SHORTEST_PATH_ROW,
546 NotificationKind::SchemaIndexOrConstraintAlreadyExists => {
547 &INDEX_OR_CONSTRAINT_ALREADY_EXISTS_ROW
548 }
549 NotificationKind::SchemaIndexOrConstraintDoesNotExist => {
550 &INDEX_OR_CONSTRAINT_DOES_NOT_EXIST_ROW
551 }
552 NotificationKind::SchemaVectorIndexDimensionsNotSpecified => {
553 &VECTOR_INDEX_DIMENSIONS_NOT_SPECIFIED_ROW
554 }
555 NotificationKind::HintedIndexNotFound => &HINTED_INDEX_NOT_FOUND_ROW,
556 NotificationKind::JoinHintUnfulfillable => &JOIN_HINT_UNFULFILLABLE_ROW,
557 }
558 }
559
560 pub fn dedups_identical(self) -> bool {
567 !self.row().occurrence_scoped
568 }
569
570 pub fn is_plan_warning(self) -> bool {
579 self.row().plan_warning
580 }
581
582 pub fn code(self) -> &'static str {
585 self.row().code
586 }
587
588 pub fn gql_status(self) -> &'static str {
590 self.row().gql_status
591 }
592
593 pub fn severity(self) -> NotificationSeverity {
595 self.row().severity
596 }
597
598 pub fn category(self) -> NotificationCategory {
600 self.row().category
601 }
602
603 pub fn title(self) -> &'static str {
606 self.row().title
607 }
608
609 pub fn remedy(self) -> &'static str {
612 self.row().remedy
613 }
614}
615
616#[derive(Clone, Debug, PartialEq, Eq)]
628pub struct Notification {
629 kind: NotificationKind,
630 description: String,
631 remedy: Option<String>,
632 operator_id: Option<usize>,
633}
634
635impl Notification {
636 pub fn new(kind: NotificationKind, description: impl Into<String>) -> Self {
640 Notification {
641 kind,
642 description: description.into(),
643 remedy: None,
644 operator_id: None,
645 }
646 }
647
648 pub fn with_operator_id(mut self, operator_id: usize) -> Self {
651 self.operator_id = Some(operator_id);
652 self
653 }
654
655 pub fn with_remedy(mut self, remedy: impl Into<String>) -> Self {
658 self.remedy = Some(remedy.into());
659 self
660 }
661
662 pub fn kind(&self) -> NotificationKind {
664 self.kind
665 }
666
667 pub fn description(&self) -> &str {
670 &self.description
671 }
672
673 pub fn code(&self) -> &'static str {
675 self.kind.code()
676 }
677
678 pub fn gql_status(&self) -> &'static str {
680 self.kind.gql_status()
681 }
682
683 pub fn title(&self) -> &'static str {
685 self.kind.title()
686 }
687
688 pub fn severity(&self) -> NotificationSeverity {
690 self.kind.severity()
691 }
692
693 pub fn category(&self) -> NotificationCategory {
695 self.kind.category()
696 }
697
698 pub fn remedy(&self) -> &str {
702 self.remedy.as_deref().unwrap_or_else(|| self.kind.remedy())
703 }
704
705 pub fn operator_id(&self) -> Option<usize> {
707 self.operator_id
708 }
709}
710
711pub mod notification_keys {
715 pub const CODE: &str = "code";
717 pub const GQL_STATUS: &str = "gql_status";
719 pub const SEVERITY: &str = "severity";
721 pub const CATEGORY: &str = "category";
723 pub const TITLE: &str = "title";
725 pub const DESCRIPTION: &str = "description";
727 pub const REMEDY: &str = "remedy";
729 pub const OPERATOR_ID: &str = "operator_id";
731 pub const NOTIFICATIONS: &str = "notifications";
733}
734
735pub(crate) fn notification_fields(notification: &Notification) -> Map<String, Value> {
744 let mut obj = Map::new();
745 obj.insert(
746 notification_keys::CODE.into(),
747 Value::String(notification.code().into()),
748 );
749 obj.insert(
750 notification_keys::GQL_STATUS.into(),
751 Value::String(notification.gql_status().into()),
752 );
753 obj.insert(
754 notification_keys::SEVERITY.into(),
755 Value::String(notification.severity().as_str().into()),
756 );
757 obj.insert(
758 notification_keys::CATEGORY.into(),
759 Value::String(notification.category().as_str().into()),
760 );
761 obj.insert(
762 notification_keys::TITLE.into(),
763 Value::String(notification.title().into()),
764 );
765 obj.insert(
766 notification_keys::DESCRIPTION.into(),
767 Value::String(notification.description().into()),
768 );
769 obj.insert(
770 notification_keys::REMEDY.into(),
771 Value::String(notification.remedy().into()),
772 );
773 obj
774}
775
776pub fn notification_to_wire_json(notification: &Notification) -> Value {
780 let mut obj = notification_fields(notification);
781 if let Some(operator_id) = notification.operator_id() {
782 obj.insert(
783 notification_keys::OPERATOR_ID.into(),
784 Value::from(operator_id),
785 );
786 }
787 Value::Object(obj)
788}
789
790pub fn notifications_to_wire_json(notifications: &[Notification]) -> Value {
793 Value::Array(
794 notifications
795 .iter()
796 .map(notification_to_wire_json)
797 .collect(),
798 )
799}
800
801pub fn notification_to_neo4j_entries(notification: &Notification) -> Vec<(&'static str, String)> {
809 vec![
810 (notification_keys::CODE, notification.code().to_string()),
811 (notification_keys::TITLE, notification.title().to_string()),
812 (
813 notification_keys::DESCRIPTION,
814 format!(
815 "{} (remedy: {})",
816 notification.description(),
817 notification.remedy()
818 ),
819 ),
820 (
821 notification_keys::SEVERITY,
822 notification.severity().as_str().to_string(),
823 ),
824 (
825 notification_keys::CATEGORY,
826 notification.category().as_str().to_string(),
827 ),
828 ]
829}
830
831pub fn notification_to_neo4j_json(notification: &Notification) -> Value {
841 let obj: Map<String, Value> = notification_to_neo4j_entries(notification)
842 .into_iter()
843 .map(|(key, value)| (key.to_owned(), Value::String(value)))
844 .collect();
845 Value::Object(obj)
846}
847
848#[cfg(test)]
849#[path = "notification_wire/tests.rs"]
850mod tests;