Skip to content
Snippets Groups Projects
Commit a3519c6d authored by Thorsten Vitt's avatar Thorsten Vitt
Browse files

Reconfigured REST API to a single class per instance

parent c2b8aa5f
No related branches found
No related tags found
No related merge requests found
package info.textgrid.services.aggregator;
import info.textgrid.namespaces.middleware.tgcrud.services.tgcrudservice.AuthFault;
import info.textgrid.namespaces.middleware.tgcrud.services.tgcrudservice.IoFault;
import info.textgrid.namespaces.middleware.tgcrud.services.tgcrudservice.MetadataParseFault;
import info.textgrid.namespaces.middleware.tgcrud.services.tgcrudservice.ObjectNotFoundFault;
import info.textgrid.namespaces.middleware.tgcrud.services.tgcrudservice.ProtocolNotImplementedFault;
import info.textgrid.services.aggregator.epub.EPUBSerializer;
import info.textgrid.services.aggregator.html.HTMLWriter;
import info.textgrid.services.aggregator.teicorpus.TEICorpusExporter;
import info.textgrid.services.aggregator.zip.ZipResult;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.concurrent.ExecutionException;
import javax.servlet.ServletContext;
import javax.ws.rs.DefaultValue;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.Request;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.StreamingOutput;
import net.sf.saxon.s9api.SaxonApiException;
import org.apache.cxf.jaxrs.model.wadl.Description;
import org.apache.cxf.jaxrs.model.wadl.Descriptions;
import org.apache.cxf.jaxrs.model.wadl.DocTarget;
import com.google.common.base.Optional;
public class REST {
private final ITextGridRep repository;
private StylesheetManager stylesheetManager;
private StylesheetManager getStylesheetManager() {
if (stylesheetManager == null)
stylesheetManager = new StylesheetManager(servlet, repository);
return stylesheetManager;
}
@Context
private ServletContext servlet;
private final String version;
public REST(final ITextGridRep repository, final String version) {
this.repository = repository;
this.version = version;
}
@GET
@Path("/teicorpus/{uris}")
@Produces("application/tei+xml")
@Descriptions({
@Description(target=DocTarget.METHOD, value="Creates a TEI corpus of all the TEI documents (recursively) aggregated by the given aggregation"),
@Description(target=DocTarget.RETURN, value="TEI corpus document")
})
public Response getCorpus(@Description("TextGrid URIs of the root objects, separated by commas") @PathParam("uris") final String uriList,
@Description("Whether to generate a Content-Disposition: attachment header") @QueryParam("attach") @DefaultValue("true") final boolean attach,
@Description("If true, no intermediate TEI corpus documents will be generated for intermediate aggregations, hierarchical structure will be lost") @QueryParam("flat") @DefaultValue("false") final boolean flat,
@Description("Title for the container if multiple root objects are given") @QueryParam("title") final String titleArgument,
@Description("Session id for accessing restricted resources") @QueryParam("sid") final String sid,
@Context Request request)
throws URISyntaxException, ObjectNotFoundFault, MetadataParseFault, IoFault, AuthFault, ProtocolNotImplementedFault, IOException, SaxonApiException {
TEICorpusExporter exporter = new TEICorpusExporter(repository, request, uriList);
exporter.setFlat(flat);
exporter.setTitle(titleArgument);
return exporter.createResponse().build();
}
@GET
@Path(value = "/epub/{object}")
@Produces(value = "application/epub+zip")
@Description("Converts the given TEI object or the aggregation of TEI objects to an E-Book in EPUB format")
public Response getEPUB(
@Description("The TextGrid URI(s) of the object(s) to convert, separated by commas. Should be either TEI objects or aggregations of TEI (and maybe other) objects")
@PathParam("object") final String uriList,
@Description("URL of an alternative stylesheet to use. Must be compatible.") @QueryParam("stylesheet") final URI xsluri,
@Description("Title if multiple root objects given") @QueryParam("title") final String titleParam,
@Description("Session ID for accessing protected objects") @QueryParam("sid") final String sid,
@Context final Request request)
throws ObjectNotFoundFault, MetadataParseFault, IoFault, AuthFault,
ProtocolNotImplementedFault, IOException, SaxonApiException {
final EPUBSerializer serializer = new EPUBSerializer(repository, getStylesheetManager(), uriList, Optional.fromNullable(sid), request);
serializer.setStylesheet(xsluri);
serializer.setTitle(titleParam);
return serializer.createResponse().build();
}
@GET
@Path(value = "/html/{object}")
@Produces(value = "text/html")
public Response getHTML(
@Description("The TextGrid URIs of the TEI document(s) or aggregation(s) to transform, separated by commas") @PathParam("object") final String uriList,
@Description("If given, an alternative XSLT stylesheet to use") @QueryParam("stylesheet") final URI xsluri,
@Description("If true, check for an <?xsl-stylesheet?> processing instruction in the document to render") @QueryParam("pi") final boolean pi,
@Description("If true and a stylesheet has been given, force reloading the stylesheet, do not cache") @QueryParam("refreshStylesheet") final boolean refreshStylesheet,
@Description("Session ID to access protected resources") @QueryParam("sid") final String sid,
@Description("If true, pass the information the stylesheet that its result will be embedded into some website") @QueryParam("embedded") final boolean embedded,
@Description("URL of the CSS that should be referenced in the HTML that is created") @QueryParam("css") final URI css,
@Description("The requested content type. E.g., text/html or text/xml") @QueryParam("mediatype") final String mediaType,
@Context final Request request) throws ObjectNotFoundFault,
MetadataParseFault, IoFault, AuthFault,
ProtocolNotImplementedFault, WebApplicationException, IOException,
SaxonApiException, ExecutionException {
final HTMLWriter writer = new HTMLWriter(repository, getStylesheetManager(), uriList, xsluri,
refreshStylesheet, pi, embedded, css, sid, mediaType, request);
return writer.createResponse().build();
}
@GET
@Path(value = "/zip/{objects}")
@Produces("application/zip")
public Response getZIP(
@Description("The TextGridURIs of the TEI documents or aggregations to zip, separated by commas (,)")
@PathParam("objects") final String uriList,
@Description("Session ID to access protected resources")
@QueryParam("sid") final String sid,
@Description("(optional) title for the exported data, currently only used for generating the filename. If none is given, the first title of the first object will be used.")
@QueryParam("title") String title,
@Context final Request request) throws MetadataParseFault, ObjectNotFoundFault, IoFault, AuthFault, ProtocolNotImplementedFault, IOException, SaxonApiException {
ZipResult zipResult = new ZipResult(repository, request, uriList);
if (title != null)
zipResult.setTitle(title);
if (sid != null)
zipResult.sid(sid);
return zipResult.createResponse().build();
}
@GET
@Path(value = "/version")
@Produces("text/html")
public StreamingOutput getVersion() {
Version version = new Version(repository, this.version);
return version.get();
}
}
......@@ -28,6 +28,7 @@
import com.google.common.base.Optional;
@Deprecated
@Path("/epub")
@Description("Converts the given TEI object or the aggregation of TEI objects to an E-Book in EPUB format")
public class EPUB {
......
......@@ -28,6 +28,7 @@
import org.apache.cxf.jaxrs.model.wadl.Description;
@Deprecated
@Path("/html")
@Description("Creates an HTML representation of the given TEI document, or aggregation of TEI documents.")
public class HTML {
......@@ -52,7 +53,7 @@ public HTML(final ITextGridRep repository) throws IOException {
@GET
@Path(value = "/{object}")
@Produces(value = "text/xml")
@Produces(value = "text/html")
public Response get(
@Description("The TextGrid URIs of the TEI document(s) or aggregation(s) to transform, separated by commas") @PathParam("object") final String uriList,
@Description("If given, an alternative XSLT stylesheet to use") @QueryParam("stylesheet") final URI xsluri,
......
......@@ -53,6 +53,7 @@
*/
@Description("Creates a TEI corpus of all the TEI documents (recursively) aggregated by the given aggregation")
@Path("/teicorpus")
@Deprecated
public class TEICorpus {
private final ITextGridRep repository;
......
......@@ -22,6 +22,7 @@
import org.apache.cxf.jaxrs.model.wadl.Description;
@Deprecated
@Path("/zip")
public class ZIP {
private final ITextGridRep repository;
......
......@@ -26,66 +26,32 @@ http://cxf.apache.org/schemas/jaxrs.xsd">
</bean>
<jaxrs:server id="services" address="/" publishedEndpointUrl="${aggregator.endpoint.published}">
<jaxrs:serviceBeans>
<!-- bean class="info.textgrid.services.aggregator.HelloWorld" /-->
<bean class="info.textgrid.services.aggregator.teicorpus.TEICorpus" scope="singleton">
<constructor-arg ref="stable-repo"/>
</bean>
<bean class="info.textgrid.services.aggregator.epub.EPUB" scope="singleton">
<constructor-arg ref="stable-repo"/>
</bean>
<bean class="info.textgrid.services.aggregator.pdf.PDF" scope="singleton">
<constructor-arg ref="stable-repo"/>
</bean>
<bean class="info.textgrid.services.aggregator.html.HTML" scope="singleton">
<constructor-arg ref="stable-repo"/>
</bean>
<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"/-->
<bean class="info.textgrid.services.aggregator.GenericExceptionMapper"/>
<!--bean class="org.apache.cxf.jaxrs.impl.WebApplicationExceptionMapper"/-->
</jaxrs:providers>
</jaxrs:server>
<jaxrs:server id="services-dev" address="/dev" publishedEndpointUrl="${aggregator.endpoint.published}/dev">
<jaxrs:serviceBeans>
<!-- bean class="info.textgrid.services.aggregator.HelloWorld" / -->
<bean class="info.textgrid.services.aggregator.teicorpus.TEICorpus" scope="singleton">
<constructor-arg ref="dev-repo" />
</bean>
<bean class="info.textgrid.services.aggregator.epub.EPUB" scope="singleton">
<constructor-arg ref="dev-repo" />
</bean>
<bean class="info.textgrid.services.aggregator.pdf.PDF" scope="singleton">
<constructor-arg ref="dev-repo" />
</bean>
<bean class="info.textgrid.services.aggregator.html.HTML" scope="singleton">
<constructor-arg ref="dev-repo" />
</bean>
<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"/ -->
<!-- bean class="org.apache.cxf.jaxrs.impl.WebApplicationExceptionMapper" /-->
<bean class="info.textgrid.services.aggregator.GenericExceptionMapper"/>
</jaxrs:providers>
<jaxrs:server id="services" address="/"
publishedEndpointUrl="${aggregator.endpoint.published}">
<jaxrs:serviceBeans>
<bean class="info.textgrid.services.aggregator.REST" scope="singleton">
<constructor-arg ref="stable-repo" />
<constructor-arg name="version" value="${project.version}" />
</bean>
</jaxrs:serviceBeans>
<jaxrs:providers>
<bean class="info.textgrid.services.aggregator.GenericExceptionMapper" />
</jaxrs:providers>
</jaxrs:server>
<jaxrs:server id="services-dev" address="/dev"
publishedEndpointUrl="${aggregator.endpoint.published}/dev">
<jaxrs:serviceBeans>
<bean class="info.textgrid.services.aggregator.REST" scope="singleton">
<constructor-arg ref="stable-repo" />
<constructor-arg name="version" value="${project.version}" />
</bean>
</jaxrs:serviceBeans>
<jaxrs:providers>
<bean class="info.textgrid.services.aggregator.GenericExceptionMapper" />
</jaxrs:providers>
</jaxrs:server>
</jaxrs:server>
</beans>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment