33import co .elastic .clients .elasticsearch .ElasticsearchClient ;
44import co .elastic .clients .elasticsearch ._types .ElasticsearchVersionInfo ;
55import co .elastic .clients .elasticsearch .core .InfoResponse ;
6-
76import com .fasterxml .jackson .core .JsonProcessingException ;
87import com .fasterxml .jackson .databind .ObjectMapper ;
8+ import io .swagger .v3 .oas .annotations .Operation ;
9+ import io .swagger .v3 .oas .annotations .Parameter ;
10+ import io .swagger .v3 .oas .annotations .Parameters ;
11+ import io .swagger .v3 .oas .annotations .media .Schema ;
12+ import io .swagger .v3 .oas .annotations .tags .Tag ;
913import org .phoebus .alarm .logging .AlarmLoggingService ;
1014import org .phoebus .alarm .logging .ElasticClientHelper ;
1115import org .springframework .beans .factory .annotation .Value ;
1822import org .springframework .web .bind .annotation .RestController ;
1923import org .springframework .web .server .ResponseStatusException ;
2024
25+ import javax .servlet .http .HttpServletResponse ;
2126import java .io .IOException ;
2227import java .util .HashMap ;
2328import java .util .LinkedHashMap ;
2631import java .util .logging .Level ;
2732import java .util .logging .Logger ;
2833
29- import io .swagger .v3 .oas .annotations .Operation ;
30- import io .swagger .v3 .oas .annotations .tags .Tag ;
31- import io .swagger .v3 .oas .annotations .media .Schema ;
32- import io .swagger .v3 .oas .annotations .Parameter ;
33- import io .swagger .v3 .oas .annotations .Parameters ;
34-
3534/**
3635 * A REST service for querying the alarm message history
3736 *
@@ -85,16 +84,16 @@ public String info() {
8584
8685 @ Operation (summary = "Search alarms" )
8786 @ Parameters ({
88- @ Parameter (name = "pv" , description = "PV name" , schema = @ Schema (type = "string" ), required = false , example = "*" ),
89- @ Parameter (name = "severity" , description = "Alarm severity" , schema = @ Schema (type = "string" ), required = false , example = "*" ),
90- @ Parameter (name = "message" , description = "Alarm message" , schema = @ Schema (type = "string" ), required = false , example = "*" ),
91- @ Parameter (name = "current_severity" , description = "PV severity" , schema = @ Schema (type = "string" ), required = false , example = "*" ),
92- @ Parameter (name = "current_message" , description = "PV message" , schema = @ Schema (type = "string" ), required = false , example = "*" ),
93- @ Parameter (name = "user" , description = "User" , schema = @ Schema (type = "string" ), required = false , example = "*" ),
94- @ Parameter (name = "host" , description = "Host" , schema = @ Schema (type = "string" ), required = false , example = "*" ),
95- @ Parameter (name = "command" , description = "Command" , schema = @ Schema (type = "string" ), required = false , example = "*" ),
96- @ Parameter (name = "start" , description = "Start time" , schema = @ Schema (type = "string" ), required = false , example = "2024-06-12" ),
97- @ Parameter (name = "end" , description = "End time" , schema = @ Schema (type = "string" ), required = false , example = "2024-06-14" ),
87+ @ Parameter (name = "pv" , description = "PV name" , schema = @ Schema (type = "string" ), required = false , example = "*" ),
88+ @ Parameter (name = "severity" , description = "Alarm severity" , schema = @ Schema (type = "string" ), required = false , example = "*" ),
89+ @ Parameter (name = "message" , description = "Alarm message" , schema = @ Schema (type = "string" ), required = false , example = "*" ),
90+ @ Parameter (name = "current_severity" , description = "PV severity" , schema = @ Schema (type = "string" ), required = false , example = "*" ),
91+ @ Parameter (name = "current_message" , description = "PV message" , schema = @ Schema (type = "string" ), required = false , example = "*" ),
92+ @ Parameter (name = "user" , description = "User" , schema = @ Schema (type = "string" ), required = false , example = "*" ),
93+ @ Parameter (name = "host" , description = "Host" , schema = @ Schema (type = "string" ), required = false , example = "*" ),
94+ @ Parameter (name = "command" , description = "Command" , schema = @ Schema (type = "string" ), required = false , example = "*" ),
95+ @ Parameter (name = "start" , description = "Start time" , schema = @ Schema (type = "string" ), required = false , example = "2024-06-12" ),
96+ @ Parameter (name = "end" , description = "End time" , schema = @ Schema (type = "string" ), required = false , example = "2024-06-14" ),
9897 })
9998 @ RequestMapping (value = "/search/alarm" , method = RequestMethod .GET )
10099 public List <AlarmLogMessage > search (@ Parameter (hidden = true ) @ RequestParam Map <String , String > allRequestParams ) {
@@ -114,18 +113,29 @@ public List<AlarmLogMessage> searchPv(@Parameter(description = "PV name") @PathV
114113 @ Operation (summary = "Search alarm config" )
115114 @ Schema (name = "config" , example = "/Accelerator/compteur" , required = true )
116115 @ Parameters ({
117- @ Parameter (name = "config" , description = "Config path" , schema = @ Schema (type = "string" ), required = false , example = "/Accelerator/pvname" ),
116+ @ Parameter (name = "config" , description = "Config path" , schema = @ Schema (type = "string" ), required = false , example = "/Accelerator/pvname" ),
118117 })
119118 @ RequestMapping (value = "/search/alarm/config" , method = RequestMethod .GET )
120119 public List <AlarmLogMessage > searchConfig (@ Parameter (hidden = true ) @ RequestParam Map <String , String > allRequestParams ) {
121- if (allRequestParams == null ||
120+ if (allRequestParams == null ||
122121 allRequestParams .isEmpty () ||
123122 !allRequestParams .containsKey ("config" ) ||
124- allRequestParams .get ("config" ).isEmpty ()){
123+ allRequestParams .get ("config" ).isEmpty ()) {
125124 throw new ResponseStatusException (HttpStatus .BAD_REQUEST );
126125 }
127126 List <AlarmLogMessage > result = AlarmLogSearchUtil .searchConfig (ElasticClientHelper .getInstance ().getClient (), allRequestParams );
128127 return result ;
129128 }
130129
130+ /**
131+ * Handles the /swagger-ui URL: redirects to /swagger-ui/index.html to avoid 500 response.
132+ *
133+ * @param response The {@link HttpServletResponse} to configure with a redirect (301).
134+ */
135+ @ GetMapping ("/swagger-ui" )
136+ public void api (HttpServletResponse response ) {
137+ response .setStatus (HttpServletResponse .SC_MOVED_PERMANENTLY );
138+ response .addHeader ("Location" , "/swagger-ui/index.html" );
139+ }
140+
131141}
0 commit comments