1818import java .util .UUID ;
1919
2020import org .gridsuite .study .server .dto .ComputationType ;
21- import org .springframework .beans .factory .annotation .Value ;
21+ import org .gridsuite .study .server .elasticsearch .EquipmentInfosService ;
22+ import org .springframework .data .elasticsearch .client .ClientConfiguration ;
2223import org .springframework .http .MediaType ;
2324import org .springframework .http .ResponseEntity ;
2425import org .springframework .web .bind .annotation .*;
3132@ Tag (name = "Study server - Supervision" )
3233public class SupervisionController {
3334
34- // Simple solution to get index name (with the prefix by environment).
35- // Maybe use the Spring boot actuator or other solution ?
36- // Keep indexName in sync with the annotation @Document in EquipmentInfos and TombstonedEquipmentInfos
37- @ Value ("#{@environment.getProperty('powsybl-ws.elasticsearch.index.prefix')}equipments" )
38- public String indexNameEquipments ;
39- @ Value ("#{@environment.getProperty('powsybl-ws.elasticsearch.index.prefix')}tombstoned-equipments" )
40- public String indexNameTombstonedEquipments ;
41-
42- @ Value ("#{@environment.getProperty('spring.data.elasticsearch.host')}" + ":" + "#{@environment.getProperty('spring.data.elasticsearch.port')}" )
43- public String elasticSerachHost ;
44-
4535 private final SupervisionService supervisionService ;
4636
4737 private final StudyService studyService ;
4838
49- public SupervisionController (SupervisionService supervisionService , StudyService studyService ) {
39+ private final EquipmentInfosService equipmentInfosService ;
40+
41+ private final ClientConfiguration elasticsearchClientConfiguration ;
42+
43+ public SupervisionController (SupervisionService supervisionService , StudyService studyService , EquipmentInfosService equipmentInfosService , ClientConfiguration elasticsearchClientConfiguration ) {
5044 this .supervisionService = supervisionService ;
5145 this .studyService = studyService ;
46+ this .equipmentInfosService = equipmentInfosService ;
47+ this .elasticsearchClientConfiguration = elasticsearchClientConfiguration ;
5248 }
5349
5450 @ DeleteMapping (value = "/computation/results" )
@@ -63,42 +59,45 @@ public ResponseEntity<Integer> deleteComputationResults(@Parameter(description =
6359 @ Operation (summary = "get the elasticsearch address" )
6460 @ ApiResponses (value = {@ ApiResponse (responseCode = "200" , description = "the elasticsearch address" )})
6561 public ResponseEntity <String > getElasticsearchHost () {
66- return ResponseEntity .ok ().contentType (MediaType .APPLICATION_JSON ).body (elasticSerachHost );
62+ String host = elasticsearchClientConfiguration .getEndpoints ().get (0 ).getHostName ()
63+ + ":"
64+ + elasticsearchClientConfiguration .getEndpoints ().get (0 ).getPort ();
65+ return ResponseEntity .ok ().contentType (MediaType .TEXT_PLAIN ).body (host );
6766 }
6867
69- @ GetMapping (value = "/indexed- equipments- index-name" )
68+ @ GetMapping (value = "/equipments/ index-name" )
7069 @ Operation (summary = "get the indexed equipments index name" )
7170 @ ApiResponses (value = {@ ApiResponse (responseCode = "200" , description = "Indexed equipments index name" )})
7271 public ResponseEntity <String > getIndexedEquipmentsIndexName () {
73- return ResponseEntity .ok ().contentType (MediaType .APPLICATION_JSON ).body (indexNameEquipments );
72+ return ResponseEntity .ok ().contentType (MediaType .TEXT_PLAIN ).body (equipmentInfosService . getEquipmentsIndexName () );
7473 }
7574
76- @ GetMapping (value = "/indexed- tombstoned-equipments- index-name" )
75+ @ GetMapping (value = "/tombstoned-equipments/ index-name" )
7776 @ Operation (summary = "get the indexed tombstoned equipments index name" )
7877 @ ApiResponses (value = {@ ApiResponse (responseCode = "200" , description = "Indexed tombstoned equipments index name" )})
7978 public ResponseEntity <String > getIndexedTombstonedEquipmentsIndexName () {
80- return ResponseEntity .ok ().contentType (MediaType .APPLICATION_JSON ).body (indexNameTombstonedEquipments );
79+ return ResponseEntity .ok ().contentType (MediaType .TEXT_PLAIN ).body (equipmentInfosService . getTombstonedEquipmentsIndexName () );
8180 }
8281
83- @ GetMapping (value = "/indexed- equipments-count" )
82+ @ GetMapping (value = "/equipments/indexation -count" )
8483 @ Operation (summary = "get indexed equipments count for all studies" )
8584 @ ApiResponses (value = {@ ApiResponse (responseCode = "200" , description = "Indexed equipments count" )})
86- public ResponseEntity <Long > getIndexedEquipmentsCount () {
87- return ResponseEntity .ok ().contentType (MediaType .APPLICATION_JSON ).body (supervisionService .getIndexedEquipmentsCount ());
85+ public ResponseEntity <String > getIndexedEquipmentsCount () {
86+ return ResponseEntity .ok ().contentType (MediaType .TEXT_PLAIN ).body (Long . toString ( supervisionService .getIndexedEquipmentsCount () ));
8887 }
8988
90- @ GetMapping (value = "/indexed- tombstoned-equipments-count" )
89+ @ GetMapping (value = "/tombstoned-equipments/indexation -count" )
9190 @ Operation (summary = "get indexed tombstoned equipments count for all studies" )
9291 @ ApiResponses (value = {@ ApiResponse (responseCode = "200" , description = "Tombstoned equipments count" )})
93- public ResponseEntity <Long > getIndexedTombstonedEquipmentsCount () {
94- return ResponseEntity .ok ().contentType (MediaType .APPLICATION_JSON ).body (supervisionService .getIndexedTombstonedEquipmentsCount ());
92+ public ResponseEntity <String > getIndexedTombstonedEquipmentsCount () {
93+ return ResponseEntity .ok ().contentType (MediaType .TEXT_PLAIN ).body (Long . toString ( supervisionService .getIndexedTombstonedEquipmentsCount () ));
9594 }
9695
97- @ DeleteMapping (value = "/studies/{studyUuid}/indexed- equipments" )
96+ @ DeleteMapping (value = "/studies/{studyUuid}/equipments/indexation " )
9897 @ Operation (summary = "delete indexed equipments and tombstoned equipments for the given study" )
9998 @ ApiResponses (value = {@ ApiResponse (responseCode = "200" , description = "all indexed equipments and tombstoned equipments for the given study have been deleted" )})
100- public ResponseEntity <Long > deleteStudyIndexedEquipmentsAndTombstoned (@ PathVariable ("studyUuid" ) UUID studyUuid ) {
101- return ResponseEntity .ok ().contentType (MediaType .APPLICATION_JSON ).body (supervisionService .deleteStudyIndexedEquipmentsAndTombstoned (studyUuid ));
99+ public ResponseEntity <String > deleteStudyIndexedEquipmentsAndTombstoned (@ PathVariable ("studyUuid" ) UUID studyUuid ) {
100+ return ResponseEntity .ok ().contentType (MediaType .TEXT_PLAIN ).body (Long . toString ( supervisionService .deleteStudyIndexedEquipmentsAndTombstoned (studyUuid ) ));
102101 }
103102
104103 @ GetMapping (value = "/orphan_indexed_network_uuids" )
0 commit comments