9
9
import com .fasterxml .jackson .databind .ObjectMapper ;
10
10
import com .powsybl .network .store .client .NetworkStoreService ;
11
11
12
+ import com .powsybl .ws .commons .computation .dto .GlobalFilter ;
12
13
import com .powsybl .ws .commons .computation .service .AbstractComputationService ;
13
14
import com .powsybl .ws .commons .computation .service .NotificationService ;
14
15
import com .powsybl .ws .commons .computation .service .UuidGeneratorService ;
16
+ import com .powsybl .ws .commons .computation .utils .FilterUtils ;
17
+ import org .apache .commons .collections4 .CollectionUtils ;
15
18
import org .gridsuite .voltageinit .server .dto .BusVoltage ;
16
19
import org .gridsuite .voltageinit .server .dto .ReactiveSlack ;
17
20
import org .gridsuite .voltageinit .server .dto .VoltageInitResult ;
18
21
import org .gridsuite .voltageinit .server .dto .VoltageInitStatus ;
19
22
import org .gridsuite .voltageinit .server .entities .VoltageInitResultEntity ;
23
+ import org .gridsuite .voltageinit .server .service .parameters .FilterService ;
20
24
import org .springframework .beans .factory .annotation .Autowired ;
21
25
import org .springframework .context .annotation .ComponentScan ;
22
26
import org .springframework .stereotype .Service ;
@@ -36,13 +40,17 @@ public class VoltageInitService extends AbstractComputationService<VoltageInitRu
36
40
@ Autowired
37
41
NetworkModificationService networkModificationService ;
38
42
43
+ private final FilterService filterService ;
44
+
39
45
public VoltageInitService (NotificationService notificationService ,
40
46
NetworkModificationService networkModificationService ,
41
47
UuidGeneratorService uuidGeneratorService ,
42
48
VoltageInitResultService resultService ,
49
+ FilterService filterService ,
43
50
ObjectMapper objectMapper ) {
44
51
super (notificationService , resultService , objectMapper , uuidGeneratorService , null );
45
52
this .networkModificationService = Objects .requireNonNull (networkModificationService );
53
+ this .filterService = Objects .requireNonNull (filterService );
46
54
}
47
55
48
56
@ Override
@@ -63,20 +71,32 @@ public List<String> getProviders() {
63
71
}
64
72
65
73
@ Transactional (readOnly = true )
66
- public VoltageInitResult getResult (UUID resultUuid ) {
74
+ public VoltageInitResult getResult (UUID resultUuid , String stringGlobalFilters , UUID networkUuid , String variantId ) {
67
75
Optional <VoltageInitResultEntity > result = resultService .find (resultUuid );
68
- return result .map (VoltageInitService ::fromEntity ).orElse (null );
76
+
77
+ List <String > voltageLevelIds ;
78
+ // get global filters
79
+ GlobalFilter globalFilter = FilterUtils .fromStringGlobalFiltersToDTO (stringGlobalFilters , objectMapper );
80
+ if (globalFilter != null ) {
81
+ voltageLevelIds = filterService .getResourceFilters (networkUuid , variantId , globalFilter );
82
+ } else {
83
+ voltageLevelIds = null ;
84
+ }
85
+
86
+ return result .map (entity -> VoltageInitService .fromEntity (entity , voltageLevelIds )).orElse (null );
69
87
}
70
88
71
- private static VoltageInitResult fromEntity (VoltageInitResultEntity resultEntity ) {
89
+ private static VoltageInitResult fromEntity (VoltageInitResultEntity resultEntity , List < String > voltageLevelIds ) {
72
90
LinkedHashMap <String , String > sortedIndicators = resultEntity .getIndicators ().entrySet ()
73
91
.stream ()
74
92
.sorted (Map .Entry .comparingByKey (String .CASE_INSENSITIVE_ORDER ))
75
93
.collect (Collectors .toMap (Map .Entry ::getKey , Map .Entry ::getValue , (collisionValue1 , collisionValue2 ) -> collisionValue1 , LinkedHashMap ::new ));
76
94
List <ReactiveSlack > reactiveSlacks = resultEntity .getReactiveSlacks ().stream ()
77
- .map (slack -> new ReactiveSlack (slack .getBusId (), slack .getSlack ()))
95
+ .filter (slack -> CollectionUtils .isEmpty (voltageLevelIds ) || voltageLevelIds .contains (slack .getVoltageLevelId ()))
96
+ .map (slack -> new ReactiveSlack (slack .getVoltageLevelId (), slack .getBusId (), slack .getSlack ()))
78
97
.toList ();
79
98
List <BusVoltage > busVoltages = resultEntity .getBusVoltages ().stream ()
99
+ .filter (bv -> CollectionUtils .isEmpty (voltageLevelIds ) || voltageLevelIds .contains (bv .getVoltageLevelId ()))
80
100
.map (bv -> new BusVoltage (bv .getVoltageLevelId (), bv .getBusId (), bv .getV (), bv .getAngle ()))
81
101
.toList ();
82
102
return new VoltageInitResult (resultEntity .getResultUuid (), resultEntity .getWriteTimeStamp (), sortedIndicators ,
0 commit comments