24
24
import org .gridsuite .actions .server .entities .*;
25
25
import org .gridsuite .actions .server .repositories .FormContingencyListRepository ;
26
26
import org .gridsuite .actions .server .repositories .IdBasedContingencyListRepository ;
27
- import org .gridsuite .actions .server .repositories .ScriptContingencyListRepository ;
28
27
import org .gridsuite .actions .server .utils .ContingencyListType ;
29
28
import org .springframework .context .annotation .ComponentScan ;
30
29
import org .springframework .dao .EmptyResultDataAccessException ;
46
45
@ Service
47
46
public class ContingencyListService {
48
47
49
- private final ScriptContingencyListRepository scriptContingencyListRepository ;
50
-
51
48
private final FormContingencyListRepository formContingencyListRepository ;
52
49
53
50
private final IdBasedContingencyListRepository idBasedContingencyListRepository ;
@@ -56,43 +53,29 @@ public class ContingencyListService {
56
53
57
54
private final NotificationService notificationService ;
58
55
59
- private final FormToGroovyScript formToScript = new FormToGroovyScript ();
60
-
61
- public ContingencyListService (ScriptContingencyListRepository scriptContingencyListRepository ,
62
- FormContingencyListRepository formContingencyListRepository ,
56
+ public ContingencyListService (FormContingencyListRepository formContingencyListRepository ,
63
57
IdBasedContingencyListRepository idBasedContingencyListRepository ,
64
58
NetworkStoreService networkStoreService ,
65
59
NotificationService notificationService ) {
66
- this .scriptContingencyListRepository = scriptContingencyListRepository ;
67
60
this .formContingencyListRepository = formContingencyListRepository ;
68
61
this .idBasedContingencyListRepository = idBasedContingencyListRepository ;
69
62
this .networkStoreService = networkStoreService ;
70
63
this .notificationService = notificationService ;
71
64
}
72
65
73
- private static ScriptContingencyList fromScriptContingencyListEntity (ScriptContingencyListEntity entity ) {
74
- return new ScriptContingencyList (entity .getId (), entity .getModificationDate (), entity .getScript () != null ? entity .getScript () : "" );
75
- }
76
-
77
66
private static FormContingencyList fromFormContingencyListEntity (FormContingencyListEntity entity ) {
78
67
return new FormContingencyList (entity .getId (), entity .getModificationDate (), entity .getEquipmentType (), NumericalFilterEntity .convert (entity .getNominalVoltage ()), NumericalFilterEntity .convert (entity .getNominalVoltage1 ()), NumericalFilterEntity .convert (entity .getNominalVoltage2 ()),
79
68
entity .getCountries () == null ? entity .getCountries () : Set .copyOf (entity .getCountries ()),
80
69
entity .getCountries1 () == null ? entity .getCountries1 () : Set .copyOf (entity .getCountries1 ()),
81
70
entity .getCountries2 () == null ? entity .getCountries2 () : Set .copyOf (entity .getCountries2 ()));
82
71
}
83
72
84
- List <PersistentContingencyList > getScriptContingencyLists () {
85
- return scriptContingencyListRepository .findAll ().stream ().map (ContingencyListService ::fromScriptContingencyListEntity ).collect (Collectors .toList ());
86
- }
87
-
88
73
ContingencyListMetadata fromContingencyListEntity (AbstractContingencyEntity entity , ContingencyListType type ) {
89
74
return new ContingencyListMetadataImpl (entity .getId (), type , entity .getModificationDate ());
90
75
}
91
76
92
77
List <ContingencyListMetadata > getContingencyListsMetadata () {
93
78
return Stream .of (
94
- scriptContingencyListRepository .findAll ().stream ().map (scriptContingencyListEntity ->
95
- fromContingencyListEntity (scriptContingencyListEntity , ContingencyListType .SCRIPT )),
96
79
formContingencyListRepository .findAll ().stream ().map (formContingencyListEntity ->
97
80
fromContingencyListEntity (formContingencyListEntity , ContingencyListType .FORM )),
98
81
idBasedContingencyListRepository .findAll ().stream ().map (idBasedContingencyListEntity ->
@@ -102,8 +85,6 @@ List<ContingencyListMetadata> getContingencyListsMetadata() {
102
85
103
86
List <ContingencyListMetadata > getContingencyListsMetadata (List <UUID > ids ) {
104
87
return Stream .of (
105
- scriptContingencyListRepository .findAllById (ids ).stream ().map (scriptContingencyListEntity ->
106
- fromContingencyListEntity (scriptContingencyListEntity , ContingencyListType .SCRIPT )),
107
88
formContingencyListRepository .findAllById (ids ).stream ().map (formContingencyListEntity ->
108
89
fromContingencyListEntity (formContingencyListEntity , ContingencyListType .FORM )),
109
90
idBasedContingencyListRepository .findAllById (ids ).stream ().map (idBasedContingencyListEntity ->
@@ -116,11 +97,6 @@ public List<PersistentContingencyList> getFormContingencyLists() {
116
97
return formContingencyListRepository .findAllWithCountries ().stream ().map (ContingencyListService ::fromFormContingencyListEntity ).collect (Collectors .toList ());
117
98
}
118
99
119
- Optional <PersistentContingencyList > getScriptContingencyList (UUID id ) {
120
- Objects .requireNonNull (id );
121
- return scriptContingencyListRepository .findById (id ).map (ContingencyListService ::fromScriptContingencyListEntity );
122
- }
123
-
124
100
private Optional <FormContingencyListEntity > doGetFormContingencyListWithPreFetchedCountries (UUID name ) {
125
101
return formContingencyListRepository .findById (name ).map (entity -> {
126
102
@ SuppressWarnings ("unused" )
@@ -203,8 +179,7 @@ private PersistentContingencyList findContingencyList(UUID id, Network network)
203
179
204
180
private Optional <PersistentContingencyList > getAnyContingencyList (UUID id , Network network ) {
205
181
return doGetFormContingencyList (id )
206
- .or (() -> doGetIdBasedContingencyList (id , network ))
207
- .or (() -> getScriptContingencyList (id ));
182
+ .or (() -> doGetIdBasedContingencyList (id , network ));
208
183
}
209
184
210
185
private List <ContingencyInfos > evaluateContingencyList (PersistentContingencyList persistentContingencyList , Network network ) {
@@ -266,27 +241,6 @@ private Network getNetworkFromUuid(UUID networkUuid, String variantId) {
266
241
return network ;
267
242
}
268
243
269
- ScriptContingencyList createScriptContingencyList (UUID id , ScriptContingencyList script ) {
270
- ScriptContingencyListEntity entity = new ScriptContingencyListEntity (script );
271
- entity .setId (id == null ? UUID .randomUUID () : id );
272
- return fromScriptContingencyListEntity (scriptContingencyListRepository .save (entity ));
273
- }
274
-
275
- Optional <UUID > duplicateScriptContingencyList (UUID sourceListId ) {
276
- Optional <ScriptContingencyList > scriptContingencyList = getScriptContingencyList (sourceListId ).map (s -> createScriptContingencyList (null , (ScriptContingencyList ) s ));
277
- if (!scriptContingencyList .isPresent ()) {
278
- throw createNotFoundException (sourceListId .toString (), "Script contingency list" );
279
- } else {
280
- return Optional .of (scriptContingencyList .get ().getId ());
281
- }
282
- }
283
-
284
- @ Transactional
285
- public void modifyScriptContingencyList (UUID id , ScriptContingencyList script , String userId ) {
286
- scriptContingencyListRepository .save (scriptContingencyListRepository .getReferenceById (id ).update (script ));
287
- notificationService .emitElementUpdated (id , userId );
288
- }
289
-
290
244
@ Transactional
291
245
public FormContingencyList createFormContingencyList (UUID id , FormContingencyList formContingencyList ) {
292
246
return doCreateFormContingencyList (id , formContingencyList );
@@ -338,49 +292,11 @@ public void deleteContingencyList(UUID id) throws EmptyResultDataAccessException
338
292
// if there is no form contingency list by this Id, deleted count == 0
339
293
if (formContingencyListRepository .deleteFormContingencyListEntityById (id ) == 0 ) {
340
294
if (idBasedContingencyListRepository .deleteIdBasedContingencyListEntityById (id ) == 0 ) {
341
- if (scriptContingencyListRepository .deleteScriptContingencyListById (id ) == 0 ) {
342
- throw new EmptyResultDataAccessException ("No element found" , 1 );
343
- }
295
+ throw new EmptyResultDataAccessException ("No element found" , 1 );
344
296
}
345
297
}
346
298
}
347
299
348
- private String generateGroovyScriptFromForm (FormContingencyList formContingencyList ) {
349
- return formToScript .generateGroovyScriptFromForm (formContingencyList );
350
- }
351
-
352
- @ Transactional
353
- public ScriptContingencyList replaceFormContingencyListWithScript (UUID id , String userId ) {
354
- Objects .requireNonNull (id );
355
- Optional <FormContingencyListEntity > formContingencyList = doGetFormContingencyListWithPreFetchedCountries (id );
356
- ScriptContingencyList result = formContingencyList .map (entity -> {
357
- String script = generateGroovyScriptFromForm (fromFormContingencyListEntity (entity ));
358
- var scriptContingencyListEntity = new ScriptContingencyListEntity (new ScriptContingencyList (id , null , script ));
359
- scriptContingencyListEntity .setId (id );
360
- var res = fromScriptContingencyListEntity (scriptContingencyListRepository .save (scriptContingencyListEntity ));
361
- formContingencyListRepository .deleteById (id );
362
- return res ;
363
- }).orElseThrow (() -> {
364
- throw new ResponseStatusException (HttpStatus .NOT_FOUND , "Contingency list " + id + " not found" );
365
- });
366
- notificationService .emitElementUpdated (id , userId );
367
- return result ;
368
- }
369
-
370
- @ Transactional
371
- public ScriptContingencyList newScriptFromFormContingencyList (UUID id , UUID newId ) {
372
- Objects .requireNonNull (id );
373
- Optional <FormContingencyListEntity > formContingencyList = doGetFormContingencyListWithPreFetchedCountries (id );
374
- return formContingencyList .map (entity -> {
375
- String script = generateGroovyScriptFromForm (fromFormContingencyListEntity (entity ));
376
- ScriptContingencyListEntity scriptEntity = new ScriptContingencyListEntity (new ScriptContingencyList (script ));
377
- scriptEntity .setId (newId == null ? UUID .randomUUID () : newId );
378
- return fromScriptContingencyListEntity (scriptContingencyListRepository .save (scriptEntity ));
379
- }).orElseThrow (() -> {
380
- throw new ResponseStatusException (HttpStatus .NOT_FOUND , "Contingency list " + id + " not found" );
381
- });
382
- }
383
-
384
300
private static IdBasedContingencyList fromIdBasedContingencyListEntity (IdBasedContingencyListEntity entity , Network network ) {
385
301
List <NetworkElementIdentifier > listOfNetworkElementIdentifierList = new ArrayList <>();
386
302
Map <String , Set <String >> notFoundElements = new HashMap <>();
0 commit comments