|
21 | 21 | */ |
22 | 22 | package com.iemr.admin.controller.version; |
23 | 23 |
|
24 | | -import java.io.BufferedReader; |
25 | | -import java.io.IOException; |
26 | | -import java.io.InputStream; |
27 | | -import java.io.InputStreamReader; |
| 24 | +import java.util.Map; |
28 | 25 |
|
29 | 26 | import org.slf4j.Logger; |
30 | 27 | import org.slf4j.LoggerFactory; |
31 | | - |
32 | | -import org.springframework.web.bind.annotation.RequestMapping; |
33 | | -import org.springframework.web.bind.annotation.RequestMethod; |
| 28 | +import org.springframework.beans.factory.annotation.Autowired; |
| 29 | +import org.springframework.http.MediaType; |
| 30 | +import org.springframework.web.bind.annotation.GetMapping; |
34 | 31 | import org.springframework.web.bind.annotation.RestController; |
35 | 32 |
|
36 | | -import com.iemr.admin.utils.response.OutputResponse; |
| 33 | +import com.iemr.admin.service.version.VersionService; |
37 | 34 |
|
38 | 35 | import io.swagger.v3.oas.annotations.Operation; |
39 | 36 |
|
40 | | - |
41 | 37 | @RestController |
42 | 38 | public class VersionController { |
43 | 39 |
|
44 | | - private Logger logger = LoggerFactory.getLogger(this.getClass().getSimpleName()); |
45 | | - |
46 | | - @Operation(summary = "Version information") |
47 | | - @RequestMapping(value = "/version", method = { RequestMethod.GET }) |
48 | | - public String versionInformation() { |
49 | | - OutputResponse output = new OutputResponse(); |
50 | | - try { |
51 | | - logger.info("version Controller Start"); |
52 | | - output.setResponse(readGitProperties()); |
53 | | - } catch (Exception e) { |
54 | | - output.setError(e); |
55 | | - } |
56 | | - |
57 | | - logger.info("version Controller End"); |
58 | | - return output.toString(); |
59 | | - } |
60 | | - |
61 | | - private String readGitProperties() throws Exception { |
62 | | - ClassLoader classLoader = getClass().getClassLoader(); |
63 | | - InputStream inputStream = classLoader.getResourceAsStream("git.properties"); |
| 40 | + private static final Logger logger = LoggerFactory.getLogger(VersionController.class); |
64 | 41 |
|
65 | | - return readFromInputStream(inputStream); |
66 | | - } |
| 42 | + @Autowired |
| 43 | + private VersionService versionService; |
67 | 44 |
|
68 | | - private String readFromInputStream(InputStream inputStream) throws IOException { |
69 | | - StringBuilder resultStringBuilder = new StringBuilder(); |
70 | | - try (BufferedReader br = new BufferedReader(new InputStreamReader(inputStream))) { |
71 | | - String line; |
72 | | - while ((line = br.readLine()) != null) { |
73 | | - resultStringBuilder.append(line).append("\n"); |
74 | | - } |
75 | | - } |
76 | | - return resultStringBuilder.toString(); |
77 | | - } |
| 45 | + @Operation(summary = "Version information") |
| 46 | + @GetMapping(value = "/version", produces = MediaType.APPLICATION_JSON_VALUE) |
| 47 | + public Map<String, String> versionInformation() { |
| 48 | + logger.info("version Controller Start"); |
| 49 | + Map<String, String> versionInfo = versionService.getVersionInfo(); |
| 50 | + logger.info("version Controller End"); |
| 51 | + return versionInfo; |
| 52 | + } |
78 | 53 | } |
0 commit comments