6
6
*/
7
7
package org .gridsuite .shortcircuit .server .service ;
8
8
9
- import com .powsybl .ws .commons .LogUtils ;
10
-
11
9
import com .fasterxml .jackson .databind .ObjectMapper ;
10
+ import com .powsybl .ws .commons .LogUtils ;
12
11
import org .gridsuite .shortcircuit .server .dto .*;
13
12
import org .gridsuite .shortcircuit .server .entities .*;
14
13
import org .gridsuite .shortcircuit .server .repositories .ShortCircuitAnalysisResultRepository ;
15
- import org .gridsuite .shortcircuit .server .utils .FeederResultSpecifications ;
14
+ import org .slf4j .Logger ;
15
+ import org .slf4j .LoggerFactory ;
16
16
import org .springframework .beans .factory .annotation .Autowired ;
17
17
import org .springframework .data .domain .Page ;
18
18
import org .springframework .data .domain .Pageable ;
19
- import org .springframework .data .jpa .domain .Specification ;
20
19
import org .springframework .stereotype .Service ;
21
- import org .slf4j .Logger ;
22
- import org .slf4j .LoggerFactory ;
23
20
import org .springframework .transaction .annotation .Transactional ;
24
21
25
22
import java .util .*;
@@ -65,10 +62,10 @@ private static ShortCircuitAnalysisResult fromEntity(ShortCircuitAnalysisResultE
65
62
List <FaultResult > faultResults = new ArrayList <>();
66
63
switch (mode ) {
67
64
case BASIC , FULL :
68
- faultResults = resultEntity .getFaultResults ().stream ().map (fr -> fromEntity (fr , mode )).collect ( Collectors . toList () );
65
+ faultResults = resultEntity .getFaultResults ().stream ().map (fr -> fromEntity (fr , mode )).toList ();
69
66
break ;
70
67
case WITH_LIMIT_VIOLATIONS :
71
- faultResults = resultEntity .getFaultResults ().stream ().filter (fr -> !fr .getLimitViolations ().isEmpty ()).map (fr -> fromEntity (fr , mode )).collect ( Collectors . toList () );
68
+ faultResults = resultEntity .getFaultResults ().stream ().filter (fr -> !fr .getLimitViolations ().isEmpty ()).map (fr -> fromEntity (fr , mode )).toList ();
72
69
break ;
73
70
case NONE :
74
71
default :
@@ -87,8 +84,8 @@ private static FaultResult fromEntity(FaultResultEntity faultResultEntity, Fault
87
84
List <FeederResult > feederResults = new ArrayList <>();
88
85
if (mode != FaultResultsMode .BASIC ) {
89
86
// if we enter here, by calling the getters, the limit violations and feeder results will be loaded even if we don't want to in some mode
90
- limitViolations = faultResultEntity .getLimitViolations ().stream ().map (lv -> fromEntity ( lv )). collect ( Collectors . toList () );
91
- feederResults = faultResultEntity .getFeederResults ().stream ().map (fr -> fromEntity ( fr )). collect ( Collectors . toList () );
87
+ limitViolations = faultResultEntity .getLimitViolations ().stream ().map (ShortCircuitService :: fromEntity ). toList ();
88
+ feederResults = faultResultEntity .getFeederResults ().stream ().map (ShortCircuitService :: fromEntity ). toList ();
92
89
}
93
90
return new FaultResult (fault , current , positiveMagnitude , shortCircuitPower , limitViolations , feederResults , shortCircuitLimits );
94
91
}
@@ -136,39 +133,40 @@ public ShortCircuitAnalysisResult getResult(UUID resultUuid, FaultResultsMode mo
136
133
ShortCircuitAnalysisResultEntity sortedResult = sortByElementId (result .get ());
137
134
138
135
ShortCircuitAnalysisResult res = fromEntity (sortedResult , mode );
139
- LOGGER .info ("Get ShortCircuit Results {} in {}ms" , resultUuid , TimeUnit .NANOSECONDS .toMillis (System .nanoTime () - startTime .get ()));
136
+ if (LOGGER .isInfoEnabled ()) {
137
+ LOGGER .info ("Get ShortCircuit Results {} in {}ms" , resultUuid , TimeUnit .NANOSECONDS .toMillis (System .nanoTime () - startTime .get ()));
138
+ }
140
139
return res ;
141
140
}
142
141
return null ;
143
142
}
144
143
145
144
@ Transactional (readOnly = true )
146
- public Page <FaultResult > getFaultResultsPage (UUID resultUuid , FaultResultsMode mode , Pageable pageable ) {
145
+ public Page <FaultResult > getFaultResultsPage (UUID resultUuid , FaultResultsMode mode , List < ResourceFilter > resourceFilters , Pageable pageable ) {
147
146
AtomicReference <Long > startTime = new AtomicReference <>();
148
147
startTime .set (System .nanoTime ());
149
148
Optional <ShortCircuitAnalysisResultEntity > result ;
150
149
// get without faultResults : FaultResultsM.NONE
151
150
result = resultRepository .find (resultUuid );
152
151
if (result .isPresent ()) {
153
- Optional < Page <FaultResultEntity >> faultResultEntitiesPage = Optional .empty ();
152
+ Page <FaultResultEntity > faultResultEntitiesPage = Page .empty ();
154
153
switch (mode ) {
155
154
case BASIC , FULL :
156
- faultResultEntitiesPage = resultRepository .findFaultResultsPage (result .get (), pageable , mode );
155
+ faultResultEntitiesPage = resultRepository .findFaultResultsPage (result .get (), resourceFilters , pageable , mode );
157
156
break ;
158
157
case WITH_LIMIT_VIOLATIONS :
159
- faultResultEntitiesPage = resultRepository .findFaultResultsWithLimitViolationsPage (result .get (), pageable );
158
+ faultResultEntitiesPage = resultRepository .findFaultResultsWithLimitViolationsPage (result .get (), resourceFilters , pageable );
160
159
break ;
161
160
case NONE :
162
161
default :
163
162
break ;
164
163
}
165
- if ( faultResultEntitiesPage .isPresent ()) {
166
- Page < FaultResult > faultResultsPage = faultResultEntitiesPage . get (). map ( fr -> fromEntity ( fr , mode ));
164
+ Page < FaultResult > faultResultsPage = faultResultEntitiesPage .map ( fr -> fromEntity ( fr , mode ));
165
+ if ( LOGGER . isInfoEnabled ()) {
167
166
LOGGER .info ("Get ShortCircuit Results {} in {}ms" , resultUuid , TimeUnit .NANOSECONDS .toMillis (System .nanoTime () - startTime .get ()));
168
- String pageableStr = LogUtils .sanitizeParam (pageable .toString ());
169
- LOGGER .info ("pageable = {}" , pageableStr );
170
- return faultResultsPage ;
167
+ LOGGER .info ("pageable = {}" , LogUtils .sanitizeParam (pageable .toString ()));
171
168
}
169
+ return faultResultsPage ;
172
170
}
173
171
return null ;
174
172
}
@@ -179,12 +177,12 @@ public Page<FeederResult> getFeederResultsPage(UUID resultUuid, List<ResourceFil
179
177
startTime .set (System .nanoTime ());
180
178
Optional <ShortCircuitAnalysisResultEntity > result = resultRepository .find (resultUuid );
181
179
if (result .isPresent ()) {
182
- Specification <FeederResultEntity > specification = FeederResultSpecifications . buildSpecification (result .get (). getResultUuid () , resourceFilters );
183
- Page <FeederResultEntity > feederResultEntitiesPage = resultRepository . findFeederResultsPage ( specification , pageable );
184
- Page < FeederResult > feederResultsPage = feederResultEntitiesPage . map ( fr -> fromEntity ( fr ));
185
- LOGGER .info ("Get ShortCircuit Results {} in {}ms" , resultUuid , TimeUnit .NANOSECONDS .toMillis (System .nanoTime () - startTime .get ()));
186
- String pageableStr = LogUtils .sanitizeParam (pageable .toString ());
187
- LOGGER . info ( "pageable = {}" , pageableStr );
180
+ Page <FeederResultEntity > feederResultEntitiesPage = resultRepository . findFeederResultsPage (result .get (), resourceFilters , pageable );
181
+ Page <FeederResult > feederResultsPage = feederResultEntitiesPage . map ( ShortCircuitService :: fromEntity );
182
+ if ( LOGGER . isInfoEnabled ()) {
183
+ LOGGER .info ("Get ShortCircuit Results {} in {}ms" , resultUuid , TimeUnit .NANOSECONDS .toMillis (System .nanoTime () - startTime .get ()));
184
+ LOGGER . info ( "pageable = {}" , LogUtils .sanitizeParam (pageable .toString () ));
185
+ }
188
186
return feederResultsPage ;
189
187
}
190
188
return null ;
0 commit comments