package com.toedter.chatty.server.boot.rest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.io.InputStream;
import java.util.Properties;

import static org.springframework.hateoas.mvc.ControllerLinkBuilder.linkTo;
import static org.springframework.hateoas.mvc.ControllerLinkBuilder.methodOn;

@Controller
public class BuildInfoController {
    private static Logger logger = LoggerFactory.getLogger(BuildInfoController.class);
    
    @RequestMapping("/chatty/api/buildinfo")
    @ResponseBody
    public HttpEntity<BuildInfo> buildInfo() {
        String version = "?";
        String timeStamp = "?";

        Properties prop = new Properties();

        try {
            ClassLoader loader = Thread.currentThread().getContextClassLoader();
            InputStream stream = loader.getResourceAsStream("/build-info.properties");
            if(stream != null) {
                prop.load(stream);

                version = prop.getProperty("version", "??");
                timeStamp = prop.getProperty("timestamp", "??");
            }

        } catch (Exception e) {
            logger.error(e.getMessage());
        }

        BuildInfo buildInfo = new BuildInfo(version, timeStamp);
        buildInfo.add(linkTo(methodOn(BuildInfoController.class).buildInfo()).withSelfRel());

        return new ResponseEntity<>(buildInfo, HttpStatus.OK);
    }
}
@@ -155,16 +155,78 @@
 .Value;%0A
+import org.springframework.context.annotation.PropertySource;%0A
 import o
@@ -753,16 +753,71 @@
 troller%0A
+@PropertySource(%7B %22classpath:build-info.properties%22 %7D)%0A
 public c
@@ -934,130 +934,47 @@
 s);%0A
-    
 %0A    @
-RequestMapping(%22/chatty/api/buildinfo%22)%0A    @ResponseBody%0A    public HttpEntity%3CBuildInfo%3E buildInfo() %7B%0A       
+Value( %22$%7Bversion%7D%22 )%0A    private
  Str
@@ -1000,558 +1000,183 @@
     
-    String 
+@Value( %22$%7B
 time
-S
+s
 tamp
- = %22?%22;%0A%0A        Properties prop = new Properties();%0A%0A        try %7B%0A            ClassLoader loader = Thread.currentThread().getContextClassLoader()
+%7D%22 )%0A    private String timeStamp = %22?%22
 ;%0A    
- 
-   
+%0A
     
-InputStream stream = loader.getResourceAsStream(%22
+@RequestMapping(%22/chatty/api
 /build
--
 info
-.properties
 %22)
-;
 %0A    
-        if(stream != null) %7B%0A                prop.load(stream);%0A%0A                version = prop.getProperty(%22version%22, %22??%22);%0A                timeStamp = prop.getProperty(%22timestamp%22, %22??%22);%0A            %7D%0A%0A        %7D catch (Exception e) %7B%0A            logger.error(e.getMessage());%0A        %7D%0A
+@ResponseBody%0A    public HttpEntity%3CBuildInfo%3E buildInfo() %7B
 %0A   

build info now using PropertySource