1 package info.mikethomas.fahservices.service;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 import info.mikethomas.jfold.Connection;
26 import info.mikethomas.jfold.exceptions.SimulationInfoException;
27 import info.mikethomas.jfold.simulation.SimulationInfo;
28
29 import io.swagger.v3.oas.annotations.Operation;
30 import io.swagger.v3.oas.annotations.Parameter;
31 import io.swagger.v3.oas.annotations.media.Content;
32 import io.swagger.v3.oas.annotations.media.Schema;
33 import io.swagger.v3.oas.annotations.responses.ApiResponse;
34 import io.swagger.v3.oas.annotations.tags.Tag;
35
36 import org.springframework.beans.factory.annotation.Autowired;
37 import org.springframework.http.HttpStatus;
38 import org.springframework.http.MediaType;
39 import org.springframework.http.ResponseEntity;
40 import org.springframework.web.bind.annotation.ExceptionHandler;
41 import org.springframework.web.bind.annotation.PathVariable;
42 import org.springframework.web.bind.annotation.RequestMapping;
43 import org.springframework.web.bind.annotation.RequestMethod;
44 import org.springframework.web.bind.annotation.ResponseBody;
45 import org.springframework.web.bind.annotation.ResponseStatus;
46 import org.springframework.web.bind.annotation.RestController;
47
48
49
50
51
52
53
54 @RestController("simulation-info")
55 @Tag(name = "Simulation Info", description = "Get current simulation information.")
56 public class SimulationInfoResource {
57
58 @Autowired
59 private Connection connection;
60
61
62
63
64
65
66
67
68
69 @Operation(summary = "simulation-info {slot}", description = "Get current simulation information.", responses = {
70 @ApiResponse(responseCode = "200", description = "OK", content = {
71 @Content(schema = @Schema(implementation = SimulationInfo.class))
72 })
73 })
74 @RequestMapping(
75 value = "/simulation-info/{slot}",
76 method = RequestMethod.GET,
77 produces = {
78 MediaType.APPLICATION_JSON_VALUE,
79 MediaType.APPLICATION_XML_VALUE,
80 MediaType.TEXT_XML_VALUE
81 })
82 @ResponseBody
83 public ResponseEntity<SimulationInfo> getSimulationInfo(
84 @Parameter(description = "slot number", required = true)
85 @PathVariable("slot") final int slot) throws SimulationInfoException {
86 return new ResponseEntity<>(connection.simulationInfo(slot), HttpStatus.OK);
87 }
88
89
90
91
92
93
94
95 @ExceptionHandler(SimulationInfoException.class)
96 @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
97 public ResponseEntity<Exception> handleException(Exception ex) {
98 return new ResponseEntity<>(ex, HttpStatus.INTERNAL_SERVER_ERROR);
99 }
100 }