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.QueueInfoException;
27  import info.mikethomas.jfold.unit.Unit;
28  
29  import io.swagger.v3.oas.annotations.Operation;
30  import io.swagger.v3.oas.annotations.media.ArraySchema;
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.RequestMapping;
42  import org.springframework.web.bind.annotation.RequestMethod;
43  import org.springframework.web.bind.annotation.ResponseBody;
44  import org.springframework.web.bind.annotation.ResponseStatus;
45  import org.springframework.web.bind.annotation.RestController;
46  
47  import java.util.List;
48  
49  /**
50   * REST Web Service.
51   *
52   * @author Michael Thomas (mikepthomas@outlook.com)
53   * @version $Id: $Id
54   */
55  @RestController("queue-info")
56  @Tag(name = "Queue Info", description = "Get work unit queue information.")
57  public class QueueInfoResource {
58  
59      @Autowired
60      private Connection connection;
61  
62      /**
63       * Retrieves representation of an instance of
64       * info.mikethomas.fahservices.service.QueueInfoResource.
65       *
66       * @return an instance of java.lang.String
67       * @throws info.mikethomas.jfold.exceptions.QueueInfoException if any.
68       */
69      @Operation(summary = "queue-info", description = "Get List of work unit queue information.", responses = {
70              @ApiResponse(responseCode = "200", description = "OK", content = {
71                      @Content(array = @ArraySchema(schema = @Schema(implementation = Unit.class)))
72              })
73      })
74      @RequestMapping(
75              value = "/queue-info",
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<List<Unit>> getQueueInfo() throws QueueInfoException {
84          return new ResponseEntity<>(connection.queueInfo(), HttpStatus.OK);
85      }
86  
87      /**
88       * <p>handleException.</p>
89       *
90       * @param ex a {@link java.lang.Exception} object
91       * @return a {@link org.springframework.http.ResponseEntity} object
92       */
93      @ExceptionHandler(QueueInfoException.class)
94      @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
95      public ResponseEntity<Exception> handleException(Exception ex) {
96          return new ResponseEntity<>(ex, HttpStatus.INTERNAL_SERVER_ERROR);
97      }
98  }