16
16
*/
17
17
package org .neo4j .driver .internal .summary ;
18
18
19
+ import static org .neo4j .driver .internal .value .NullValue .NULL ;
20
+
19
21
import java .util .Arrays ;
20
- import java .util .Map ;
21
- import java .util .Objects ;
22
22
import java .util .Optional ;
23
+ import java .util .function .Function ;
23
24
import org .neo4j .driver .NotificationCategory ;
24
25
import org .neo4j .driver .NotificationClassification ;
25
26
import org .neo4j .driver .NotificationSeverity ;
26
27
import org .neo4j .driver .Value ;
28
+ import org .neo4j .driver .internal .InternalNotificationSeverity ;
27
29
import org .neo4j .driver .summary .InputPosition ;
28
30
import org .neo4j .driver .summary .Notification ;
29
31
30
- public class InternalNotification extends InternalGqlStatusObject implements Notification {
32
+ public class InternalNotification implements Notification {
31
33
public static Optional <NotificationCategory > valueOf (String value ) {
32
34
return Arrays .stream (NotificationClassification .values ())
33
35
.filter (type -> type .toString ().equals (value ))
@@ -45,57 +47,73 @@ public static Optional<NotificationCategory> valueOf(String value) {
45
47
});
46
48
}
47
49
50
+ public static final Function <Value , Notification > VALUE_TO_NOTIFICATION = value -> {
51
+ var code = value .get ("code" ).asString ();
52
+ var title = value .get ("title" ).asString ();
53
+ var description = value .get ("description" ).asString ();
54
+ var rawSeverityLevel =
55
+ value .containsKey ("severity" ) ? value .get ("severity" ).asString () : null ;
56
+ var severityLevel =
57
+ InternalNotificationSeverity .valueOf (rawSeverityLevel ).orElse (null );
58
+ var rawCategory = value .containsKey ("category" ) ? value .get ("category" ).asString () : null ;
59
+ var category = valueOf (rawCategory ).orElse (null );
60
+
61
+ var posValue = value .get ("position" );
62
+ InputPosition position = null ;
63
+ if (posValue != NULL ) {
64
+ position = new InternalInputPosition (
65
+ posValue .get ("offset" ).asInt (),
66
+ posValue .get ("line" ).asInt (),
67
+ posValue .get ("column" ).asInt ());
68
+ }
69
+
70
+ return new InternalNotification (
71
+ code , title , description , severityLevel , rawSeverityLevel , category , rawCategory , position );
72
+ };
73
+
48
74
private final String code ;
49
75
private final String title ;
50
76
private final String description ;
51
77
private final NotificationSeverity severityLevel ;
52
78
private final String rawSeverityLevel ;
53
- private final NotificationClassification classification ;
54
- private final String rawClassification ;
79
+ private final NotificationCategory category ;
80
+ private final String rawCategory ;
55
81
private final InputPosition position ;
56
82
57
83
public InternalNotification (
58
- String gqlStatus ,
59
- String statusDescription ,
60
- Map <String , Value > diagnosticRecord ,
61
84
String code ,
62
85
String title ,
63
86
String description ,
64
87
NotificationSeverity severityLevel ,
65
88
String rawSeverityLevel ,
66
- NotificationClassification classification ,
67
- String rawClassification ,
89
+ NotificationCategory category ,
90
+ String rawCategory ,
68
91
InputPosition position ) {
69
- super (gqlStatus , statusDescription , diagnosticRecord );
70
- this .code = Objects .requireNonNull (code );
92
+ this .code = code ;
71
93
this .title = title ;
72
94
this .description = description ;
73
95
this .severityLevel = severityLevel ;
74
96
this .rawSeverityLevel = rawSeverityLevel ;
75
- this .classification = classification ;
76
- this .rawClassification = rawClassification ;
97
+ this .category = category ;
98
+ this .rawCategory = rawCategory ;
77
99
this .position = position ;
78
100
}
79
101
80
- @ SuppressWarnings ({"deprecation" , "RedundantSuppression" })
81
102
@ Override
82
103
public String code () {
83
104
return code ;
84
105
}
85
106
86
- @ SuppressWarnings ({"deprecation" , "RedundantSuppression" })
87
107
@ Override
88
108
public String title () {
89
109
return title ;
90
110
}
91
111
92
- @ SuppressWarnings ({"deprecation" , "RedundantSuppression" })
93
112
@ Override
94
113
public String description () {
95
114
return description ;
96
115
}
97
116
98
- @ SuppressWarnings ({"deprecation" , "RedundantSuppression" })
99
117
@ Override
100
118
public InputPosition position () {
101
119
return position ;
@@ -111,62 +129,21 @@ public Optional<String> rawSeverityLevel() {
111
129
return Optional .ofNullable (rawSeverityLevel );
112
130
}
113
131
114
- @ Override
115
- public Optional <NotificationClassification > classification () {
116
- return Optional .ofNullable (classification );
117
- }
118
-
119
- @ Override
120
- public Optional <String > rawClassification () {
121
- return Optional .ofNullable (rawClassification );
122
- }
123
-
124
132
@ Override
125
133
public Optional <NotificationCategory > category () {
126
- return Optional .ofNullable (classification );
134
+ return Optional .ofNullable (category );
127
135
}
128
136
129
137
@ Override
130
138
public Optional <String > rawCategory () {
131
- return Optional .ofNullable (rawClassification );
132
- }
133
-
134
- @ Override
135
- public boolean equals (Object o ) {
136
- if (this == o ) return true ;
137
- if (o == null || getClass () != o .getClass ()) return false ;
138
- if (!super .equals (o )) return false ;
139
- var that = (InternalNotification ) o ;
140
- return Objects .equals (code , that .code )
141
- && Objects .equals (title , that .title )
142
- && Objects .equals (description , that .description )
143
- && Objects .equals (severityLevel , that .severityLevel )
144
- && Objects .equals (rawSeverityLevel , that .rawSeverityLevel )
145
- && classification == that .classification
146
- && Objects .equals (rawClassification , that .rawClassification )
147
- && Objects .equals (position , that .position );
148
- }
149
-
150
- @ Override
151
- public int hashCode () {
152
- return Objects .hash (
153
- super .hashCode (),
154
- code ,
155
- title ,
156
- description ,
157
- severityLevel ,
158
- rawSeverityLevel ,
159
- classification ,
160
- rawClassification ,
161
- position );
139
+ return Optional .ofNullable (rawCategory );
162
140
}
163
141
164
142
@ Override
165
143
public String toString () {
166
144
var info = "code=" + code + ", title=" + title + ", description=" + description + ", severityLevel="
167
- + severityLevel + ", rawSeverityLevel=" + rawSeverityLevel + ", classification=" + classification
168
- + ", rawClassification="
169
- + rawClassification ;
145
+ + severityLevel + ", rawSeverityLevel=" + rawSeverityLevel + ", category=" + category + ", rawCategory="
146
+ + rawCategory ;
170
147
return position == null ? info : info + ", position={" + position + "}" ;
171
148
}
172
149
}
0 commit comments