001 package com.khubla.pragmatach.plugin.adminapp;
002
003 import java.io.InputStream;
004 import java.util.Properties;
005
006 import com.khubla.pragmatach.framework.annotation.Controller;
007 import com.khubla.pragmatach.framework.annotation.Route;
008 import com.khubla.pragmatach.framework.annotation.View;
009 import com.khubla.pragmatach.framework.api.PragmatachException;
010 import com.khubla.pragmatach.framework.api.Response;
011
012 /**
013 * @author tome
014 */
015 @Controller(name = "pragmatachShowApplicationController")
016 @View(view = "pragmatach/admin/application.html")
017 public class ShowApplicationController extends SecuredAdminController {
018 /**
019 * application version from maven pom
020 */
021 private String applicationVersion;
022 /**
023 * build date from maven pom
024 */
025 private String buildDate;
026
027 private String findApplicationBuildDate() throws PragmatachException {
028 try {
029 InputStream is = null;
030 try {
031 is = ShowApplicationController.class
032 .getResourceAsStream("/version.properties");
033 if (null != is) {
034 final Properties properties = new Properties();
035 properties.load(is);
036 return properties.getProperty("maven.builddate");
037 }
038 return null;
039 } finally {
040 if (null != is) {
041 is.close();
042 }
043 }
044 } catch (final Exception e) {
045 throw new PragmatachException(
046 "Exception in findApplicationBuildDate", e);
047 }
048 }
049
050 private String findApplicationVersion() throws PragmatachException {
051 try {
052 InputStream is = null;
053 try {
054 is = ShowApplicationController.class
055 .getResourceAsStream("/version.properties");
056 if (null != is) {
057 final Properties properties = new Properties();
058 properties.load(is);
059 return properties.getProperty("maven.version");
060 }
061 return null;
062 } finally {
063 if (null != is) {
064 is.close();
065 }
066 }
067 } catch (final Exception e) {
068 throw new PragmatachException(
069 "Exception in findApplicationVersion", e);
070 }
071 }
072
073 public String getApplicationVersion() {
074 return applicationVersion;
075 }
076
077 public String getBuildDate() {
078 return buildDate;
079 }
080
081 @Route(uri = "/pragmatach/admin/application")
082 public Response render() throws PragmatachException {
083 applicationVersion = findApplicationVersion();
084 buildDate = findApplicationBuildDate();
085 return super.render();
086 }
087
088 public void setApplicationVersion(String applicationVersion) {
089 this.applicationVersion = applicationVersion;
090 }
091
092 public void setBuildDate(String buildDate) {
093 this.buildDate = buildDate;
094 }
095 }