Skip to content

Commit 4308652

Browse files
authored
Add supervision controller to get results count (#79)
Signed-off-by: Hugo Marcellin <[email protected]>
1 parent d558bc4 commit 4308652

File tree

3 files changed

+108
-0
lines changed

3 files changed

+108
-0
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/**
2+
* Copyright (c) 2023, RTE (http://www.rte-france.com)
3+
* This Source Code Form is subject to the terms of the Mozilla Public
4+
* License, v. 2.0. If a copy of the MPL was not distributed with this
5+
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
6+
*/
7+
package org.gridsuite.securityanalysis.server;
8+
9+
import io.swagger.v3.oas.annotations.Operation;
10+
import io.swagger.v3.oas.annotations.responses.ApiResponse;
11+
import io.swagger.v3.oas.annotations.responses.ApiResponses;
12+
import io.swagger.v3.oas.annotations.tags.Tag;
13+
import org.gridsuite.securityanalysis.server.service.SupervisionService;
14+
import org.springframework.http.MediaType;
15+
import org.springframework.http.ResponseEntity;
16+
import org.springframework.web.bind.annotation.GetMapping;
17+
import org.springframework.web.bind.annotation.RequestMapping;
18+
import org.springframework.web.bind.annotation.RestController;
19+
20+
/**
21+
* @author Hugo Marcellin <hugo.marcelin at rte-france.com>
22+
*/
23+
@RestController
24+
@RequestMapping(value = "/" + SecurityAnalysisApi.API_VERSION + "/supervision")
25+
@Tag(name = "Security analysis server - Supervision")
26+
public class SupervisionController {
27+
private final SupervisionService supervisionService;
28+
29+
public SupervisionController(SupervisionService supervisionService) {
30+
this.supervisionService = supervisionService;
31+
}
32+
33+
@GetMapping(value = "/results-count")
34+
@Operation(summary = "Get results count")
35+
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "The count of all results")})
36+
public ResponseEntity<Integer> getResultsCount() {
37+
return ResponseEntity.ok().contentType(MediaType.APPLICATION_JSON).body(supervisionService.getResultsCount());
38+
}
39+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/**
2+
* Copyright (c) 2023, RTE (http://www.rte-france.com)
3+
* This Source Code Form is subject to the terms of the Mozilla Public
4+
* License, v. 2.0. If a copy of the MPL was not distributed with this
5+
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
6+
*/
7+
package org.gridsuite.securityanalysis.server.service;
8+
9+
import org.gridsuite.securityanalysis.server.repositories.GlobalStatusRepository;
10+
import org.springframework.stereotype.Service;
11+
12+
/**
13+
* @author Hugo Marcellin <hugo.marcelin at rte-france.com>
14+
*/
15+
@Service
16+
public class SupervisionService {
17+
private final GlobalStatusRepository globalStatusRepository;
18+
19+
public SupervisionService(GlobalStatusRepository globalStatusRepository) {
20+
this.globalStatusRepository = globalStatusRepository;
21+
}
22+
23+
public Integer getResultsCount() {
24+
return (int) globalStatusRepository.count();
25+
}
26+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/**
2+
* Copyright (c) 2023, RTE (http://www.rte-france.com)
3+
* This Source Code Form is subject to the terms of the Mozilla Public
4+
* License, v. 2.0. If a copy of the MPL was not distributed with this
5+
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
6+
*/
7+
package org.gridsuite.securityanalysis.server;
8+
9+
import org.junit.Test;
10+
import org.junit.runner.RunWith;
11+
import org.springframework.beans.factory.annotation.Autowired;
12+
import org.springframework.boot.test.autoconfigure.web.reactive.AutoConfigureWebTestClient;
13+
import org.springframework.boot.test.context.SpringBootTest;
14+
import org.springframework.test.context.junit4.SpringRunner;
15+
import org.springframework.test.web.reactive.server.EntityExchangeResult;
16+
import org.springframework.test.web.reactive.server.WebTestClient;
17+
import static org.junit.Assert.assertEquals;
18+
19+
/**
20+
* @author Hugo Marcellin <hugo.marcelin at rte-france.com>
21+
*/
22+
@RunWith(SpringRunner.class)
23+
@AutoConfigureWebTestClient
24+
@SpringBootTest
25+
public class SupervisionControllerTest {
26+
27+
@Autowired
28+
private WebTestClient webTestClient;
29+
30+
@Test
31+
public void testResultCount() {
32+
//get the result timeline uuid of the calculation
33+
EntityExchangeResult<Integer> entityExchangeResult = webTestClient.get()
34+
.uri("/v1/supervision/results-count")
35+
.exchange()
36+
.expectStatus().isOk()
37+
.expectBody(Integer.class).returnResult();
38+
39+
int resultCount = entityExchangeResult.getResponseBody();
40+
assertEquals(0, resultCount);
41+
42+
}
43+
}

0 commit comments

Comments
 (0)