diff --git a/src/main/java/info/textgrid/services/aggregator/ITextGridRep.java b/src/main/java/info/textgrid/services/aggregator/ITextGridRep.java index 0a97b993e1167016cafd7e1e0bc948a3552d55a6..370487eff79bac1619eecd02df04875bccc4a600 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 35aa87c81abbfe69780696204997de9388680a63..67c637cc178803349d6d5feec38bbc455a0affb6 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 0000000000000000000000000000000000000000..745d07d01b70fe2482aff91bb5855488171f571e --- /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 13ed357ace7e9187800ddacf723aff4dc8914348..482504acd8d4480ccb9786727d2fe3aa625b05c1 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"/ -->