28
28
import org .springframework .stereotype .Service ;
29
29
import org .springframework .util .CollectionUtils ;
30
30
31
- import java .util .ArrayList ;
32
31
import java .util .Collections ;
33
32
import java .util .List ;
34
33
import java .util .Objects ;
@@ -116,11 +115,10 @@ protected CompletableFuture<SecurityAnalysisResult> getCompletableFuture(Securit
116
115
protected void preRun (SecurityAnalysisRunContext runContext ) {
117
116
LOGGER .info ("Run security analysis on contingency lists: {}" , runContext .getContingencyListNames ().stream ().map (LogUtils ::sanitizeParam ).toList ());
118
117
119
- // enrich context
120
118
List <ContingencyInfos > contingencies = observer .observe ("contingencies.fetch" , runContext ,
121
- () -> runContext .getContingencyListNames (). stream ()
122
- .map ( contingencyListName -> actionsService . getContingencyList ( contingencyListName , runContext . getNetworkUuid (), runContext . getVariantId ()) )
123
- .flatMap (List :: stream )
119
+ () -> runContext .getContingencyListNames ()
120
+ .stream ( )
121
+ .flatMap (contingencyListName -> actionsService . getContingencyList ( contingencyListName , runContext . getNetworkUuid (), runContext . getVariantId ()). stream () )
124
122
.toList ());
125
123
126
124
runContext .setContingencies (contingencies );
@@ -129,24 +127,8 @@ protected void preRun(SecurityAnalysisRunContext runContext) {
129
127
@ Override
130
128
protected void postRun (SecurityAnalysisRunContext runContext , AtomicReference <ReportNode > rootReportNode , SecurityAnalysisResult ignoredResult ) {
131
129
if (runContext .getReportInfos ().reportUuid () != null ) {
132
- List <ReportNode > notFoundElementReports = new ArrayList <>();
133
- runContext .getContingencies ().stream ()
134
- .filter (contingencyInfos -> !CollectionUtils .isEmpty (contingencyInfos .getNotFoundElements ()))
135
- .forEach (contingencyInfos -> {
136
- String elementsIds = String .join (", " , contingencyInfos .getNotFoundElements ());
137
- notFoundElementReports .add (ReportNode .newRootReportNode ()
138
- .withMessageTemplate ("contingencyElementNotFound_" + contingencyInfos .getId () + notFoundElementReports .size (),
139
- String .format ("Cannot find the following equipments %s in contingency %s" , elementsIds , contingencyInfos .getId ()))
140
- .withSeverity (TypedValue .WARN_SEVERITY )
141
- .build ());
142
- });
143
- if (!CollectionUtils .isEmpty (notFoundElementReports )) {
144
- ReportNode elementNotFoundSubReporter = runContext .getReportNode ().newReportNode ()
145
- .withMessageTemplate (runContext .getReportInfos ().reportUuid ().toString () + "notFoundElements" , "Elements not found" )
146
- .add ();
147
- notFoundElementReports .forEach (r -> elementNotFoundSubReporter .newReportNode ()
148
- .withMessageTemplate (r .getMessageKey (), r .getMessageTemplate ()).add ());
149
- }
130
+ logContingencyEquipmentsNotConnected (runContext );
131
+ logContingencyEquipmentsNotFound (runContext );
150
132
}
151
133
super .postRun (runContext , rootReportNode , ignoredResult );
152
134
}
@@ -177,4 +159,53 @@ public Consumer<Message<String>> consumeRun() {
177
159
public Consumer <Message <String >> consumeCancel () {
178
160
return super .consumeCancel ();
179
161
}
162
+
163
+ private static void logContingencyEquipmentsNotFound (SecurityAnalysisRunContext runContext ) {
164
+ List <ContingencyInfos > contingencyInfosList = runContext .getContingencies ().stream ()
165
+ .filter (contingencyInfos -> !CollectionUtils .isEmpty (contingencyInfos .getNotFoundElements ())).toList ();
166
+
167
+ if (contingencyInfosList .isEmpty ()) {
168
+ return ;
169
+ }
170
+
171
+ ReportNode elementsNotFoundSubReporter = runContext .getReportNode ().newReportNode ()
172
+ .withMessageTemplate ("notFoundEquipments" , "Equipments not found" )
173
+ .add ();
174
+
175
+ contingencyInfosList .forEach (contingencyInfos -> {
176
+ String elementsIds = String .join (", " , contingencyInfos .getNotFoundElements ());
177
+ elementsNotFoundSubReporter .newReportNode ()
178
+ .withMessageTemplate ("contingencyEquipmentNotFound" ,
179
+ "Cannot find the following equipments ${elementsIds} in contingency ${contingencyId}" )
180
+ .withUntypedValue ("elementsIds" , elementsIds )
181
+ .withUntypedValue ("contingencyId" , contingencyInfos .getId ())
182
+ .withSeverity (TypedValue .WARN_SEVERITY )
183
+ .add ();
184
+ });
185
+ }
186
+
187
+ private void logContingencyEquipmentsNotConnected (SecurityAnalysisRunContext runContext ) {
188
+ List <ContingencyInfos > contingencyInfosList = runContext .getContingencies ().stream ()
189
+ .filter (contingencyInfos -> !CollectionUtils .isEmpty (contingencyInfos .getNotConnectedElements ())).toList ();
190
+
191
+ if (contingencyInfosList .isEmpty ()) {
192
+ return ;
193
+ }
194
+
195
+ ReportNode elementsNotConnectedSubReporter = runContext .getReportNode ().newReportNode ()
196
+ .withMessageTemplate ("notConnectedEquipments" , "Equipments not connected" )
197
+ .add ();
198
+
199
+ contingencyInfosList .forEach (contingencyInfos -> {
200
+ String elementsIds = String .join (", " , contingencyInfos .getNotConnectedElements ());
201
+ elementsNotConnectedSubReporter .newReportNode ()
202
+ .withMessageTemplate ("contingencyEquipmentNotConnected" ,
203
+ "The following equipments ${elementsIds} in contingency ${contingencyId} are not connected" )
204
+ .withUntypedValue ("elementsIds" , elementsIds )
205
+ .withUntypedValue ("contingencyId" , contingencyInfos .getId ())
206
+ .withSeverity (TypedValue .WARN_SEVERITY )
207
+ .add ();
208
+ });
209
+ }
210
+
180
211
}
0 commit comments