From d430adf2be401d45aa0b3840e464f2ed69798ac1 Mon Sep 17 00:00:00 2001 From: Thorsten Vitt <thorsten.vitt@uni-wuerzburg.de> Date: Thu, 26 Sep 2013 13:15:27 +0200 Subject: [PATCH] Added version / configuration info page --- .../services/aggregator/ITextGridRep.java | 5 ++ .../aggregator/TextGridRepProvider.java | 7 ++- .../textgrid/services/aggregator/Version.java | 57 +++++++++++++++++++ src/main/webapp/WEB-INF/beans.xml | 8 +++ 4 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 src/main/java/info/textgrid/services/aggregator/Version.java diff --git a/src/main/java/info/textgrid/services/aggregator/ITextGridRep.java b/src/main/java/info/textgrid/services/aggregator/ITextGridRep.java index 0a97b99..370487e 100644 --- a/src/main/java/info/textgrid/services/aggregator/ITextGridRep.java +++ b/src/main/java/info/textgrid/services/aggregator/ITextGridRep.java @@ -12,6 +12,7 @@ import java.io.IOException; import java.io.InputStream; import java.net.URI; +import java.util.Map; import javax.ws.rs.WebApplicationException; @@ -42,4 +43,8 @@ public interface TGOSupplier<T> extends InputSupplier<T> { public String getCRUDRestEndpoint(); + String getCONF_ENDPOINT(); + + Map<String, String> getConfig(); + } \ No newline at end of file diff --git a/src/main/java/info/textgrid/services/aggregator/TextGridRepProvider.java b/src/main/java/info/textgrid/services/aggregator/TextGridRepProvider.java index 35aa87c..67c637c 100644 --- a/src/main/java/info/textgrid/services/aggregator/TextGridRepProvider.java +++ b/src/main/java/info/textgrid/services/aggregator/TextGridRepProvider.java @@ -38,6 +38,7 @@ public class TextGridRepProvider implements ITextGridRep { private SearchClient publicSearchClient; private String CONF_ENDPOINT = "https://www.textgridlab.org/1.0/confserv"; + @Override public String getCONF_ENDPOINT() { return CONF_ENDPOINT; } @@ -50,6 +51,10 @@ public void setCONF_ENDPOINT(final String cONF_ENDPOINT) { @Override public String getConfValue(final String key) throws WebApplicationException { + return getConfig().get(key); + } + + public Map<String, String> getConfig() { if (config == null) { try { confservClient = new ConfservClient(CONF_ENDPOINT); @@ -62,7 +67,7 @@ public String getConfValue(final String key) throws WebApplicationException { throw new WebApplicationException(e); } } - return config.get(key); + return config; } @Override diff --git a/src/main/java/info/textgrid/services/aggregator/Version.java b/src/main/java/info/textgrid/services/aggregator/Version.java new file mode 100644 index 0000000..745d07d --- /dev/null +++ b/src/main/java/info/textgrid/services/aggregator/Version.java @@ -0,0 +1,57 @@ +package info.textgrid.services.aggregator; + +import java.io.IOException; +import java.io.OutputStream; +import java.io.PrintStream; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.WebApplicationException; +import javax.ws.rs.core.StreamingOutput; + +import com.google.common.base.Joiner; + +@Path("/version") +public class Version { + + + private final ITextGridRep repository; + private final String version; + + public Version(final ITextGridRep repository, final String version) { + this.repository = repository; + this.version = version; + } + + @GET + // @Path("/") + @Produces("text/html") + public StreamingOutput get() { + return new StreamingOutput() { + + @Override + public void write(final OutputStream outputStream) + throws IOException, + WebApplicationException { + final PrintStream out = new PrintStream(outputStream, true); + out.println("<!DOCTYPE html><html><head><meta charset='utf-8'/><title>Aggregator Version Report</title></head><body>"); + out.printf("<h1>TextGrid Aggregator Version %s</h1>\n", version); + out.printf("<p>TextGridRep Configuration Endpoint: <a href='%1$s'>%1$s</a></p>\n\n", + repository.getCONF_ENDPOINT()); + out.print("<h3>Repository Configuration:</h3>\n<table><tr><td>"); + out.print(Joiner.on("</td></tr>\n<tr><td>").withKeyValueSeparator("</td><td>") + .join(repository.getConfig())); + out.println("</td></tr></table>"); + out.printf("<p>Using TG-crud version: <strong>%s</strong>\n", repository + .getCRUDService().getVersion()); + + out.println("</body></html>"); + out.close(); + outputStream.close(); + } + }; + } + + +} diff --git a/src/main/webapp/WEB-INF/beans.xml b/src/main/webapp/WEB-INF/beans.xml index 13ed357..482504a 100644 --- a/src/main/webapp/WEB-INF/beans.xml +++ b/src/main/webapp/WEB-INF/beans.xml @@ -44,6 +44,10 @@ http://cxf.apache.org/schemas/jaxrs.xsd"> <bean class="info.textgrid.services.aggregator.zip.ZIP" scope="singleton"> <constructor-arg ref="stable-repo"/> </bean> + <bean class="info.textgrid.services.aggregator.Version" scope="singleton"> + <constructor-arg ref="stable-repo"/> + <constructor-arg name="version" value="${project.version}" /> + </bean> </jaxrs:serviceBeans> <jaxrs:providers> <!-- bean class="org.codehaus.jackson.jaxrs.JacksonJsonProvider"/--> @@ -70,6 +74,10 @@ http://cxf.apache.org/schemas/jaxrs.xsd"> <bean class="info.textgrid.services.aggregator.zip.ZIP" scope="singleton"> <constructor-arg ref="dev-repo" /> </bean> + <bean class="info.textgrid.services.aggregator.Version" scope="singleton"> + <constructor-arg ref="dev-repo"/> + <constructor-arg name="version" value="${project.version}" /> + </bean> </jaxrs:serviceBeans> <jaxrs:providers> <!-- bean class="org.codehaus.jackson.jaxrs.JacksonJsonProvider"/ --> -- GitLab