View Javadoc
1   package info.mikethomas.fahservices.service;
2   
3   /*
4    * #%L
5    * This file is part of FAHServices.
6    * %%
7    * Copyright (C) 2014 - 2024 Mike Thomas <mikepthomas@outlook.com>
8    * %%
9    * This program is free software: you can redistribute it and/or modify
10   * it under the terms of the GNU General Public License as
11   * published by the Free Software Foundation, either version 3 of the
12   * License, or (at your option) any later version.
13   *
14   * This program is distributed in the hope that it will be useful,
15   * but WITHOUT ANY WARRANTY; without even the implied warranty of
16   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17   * GNU General Public License for more details.
18   *
19   * You should have received a copy of the GNU General Public
20   * License along with this program.  If not, see
21   * <http://www.gnu.org/licenses/gpl-3.0.html>.
22   * #L%
23   */
24  
25  import info.mikethomas.jfold.Connection;
26  import info.mikethomas.jfold.exceptions.InfoException;
27  
28  import io.swagger.v3.oas.annotations.Operation;
29  import io.swagger.v3.oas.annotations.media.ArraySchema;
30  import io.swagger.v3.oas.annotations.media.Content;
31  import io.swagger.v3.oas.annotations.media.Schema;
32  import io.swagger.v3.oas.annotations.responses.ApiResponse;
33  import io.swagger.v3.oas.annotations.tags.Tag;
34  
35  import org.springframework.beans.factory.annotation.Autowired;
36  import org.springframework.http.HttpStatus;
37  import org.springframework.http.MediaType;
38  import org.springframework.http.ResponseEntity;
39  import org.springframework.web.bind.annotation.ExceptionHandler;
40  import org.springframework.web.bind.annotation.RequestMapping;
41  import org.springframework.web.bind.annotation.RequestMethod;
42  import org.springframework.web.bind.annotation.ResponseBody;
43  import org.springframework.web.bind.annotation.ResponseStatus;
44  import org.springframework.web.bind.annotation.RestController;
45  
46  import java.util.List;
47  
48  /**
49   * REST Web Service.
50   *
51   * @author Michael Thomas (mikepthomas@outlook.com)
52   * @version $Id: $Id
53   */
54  @RestController("info")
55  @Tag(name = "Info", description = "Print application information.")
56  public class InfoResource {
57  
58      @Autowired
59      private Connection connection;
60  
61      /**
62       * Retrieves representation of an instance of
63       * info.mikethomas.fahservices.service.InfoResource.
64       *
65       * @return an instance of java.lang.String
66       * @throws info.mikethomas.jfold.exceptions.InfoException if any.
67       */
68      @Operation(summary = "info", description = "Get Info.", responses = {
69              @ApiResponse(responseCode = "200", description = "OK", content = {
70                      @Content(array = @ArraySchema(schema = @Schema(implementation = String.class)))
71              })
72      })
73      @RequestMapping(
74              value = "/info",
75              method = RequestMethod.GET,
76              produces = {
77                      MediaType.APPLICATION_JSON_VALUE
78              })
79      @ResponseBody
80      public ResponseEntity<List> getInfo() throws InfoException {
81          return new ResponseEntity<>(connection.info(), HttpStatus.OK);
82      }
83  
84      /**
85       * <p>handleException.</p>
86       *
87       * @param ex a {@link java.lang.Exception} object
88       * @return a {@link org.springframework.http.ResponseEntity} object
89       */
90      @ExceptionHandler(InfoException.class)
91      @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
92      public ResponseEntity<Exception> handleException(Exception ex) {
93          return new ResponseEntity<>(ex, HttpStatus.INTERNAL_SERVER_ERROR);
94      }
95  }