From bf475f1c4938575d15c9973f98099bb11136cbee Mon Sep 17 00:00:00 2001 From: Thorsten Vitt <thorsten.vitt@uni-wuerzburg.de> Date: Mon, 20 Jan 2014 14:57:55 +0100 Subject: [PATCH] Removed obsolete REST API classes. --- .../services/aggregator/epub/EPUB.java | 74 --------------- .../services/aggregator/html/HTML.java | 77 ---------------- .../aggregator/teicorpus/TEICorpus.java | 91 ------------------- .../textgrid/services/aggregator/zip/ZIP.java | 54 ----------- .../aggregator/teicorpus/TEICorpusTest.java | 11 +-- 5 files changed, 5 insertions(+), 302 deletions(-) delete mode 100644 src/main/java/info/textgrid/services/aggregator/epub/EPUB.java delete mode 100644 src/main/java/info/textgrid/services/aggregator/html/HTML.java delete mode 100644 src/main/java/info/textgrid/services/aggregator/teicorpus/TEICorpus.java delete mode 100644 src/main/java/info/textgrid/services/aggregator/zip/ZIP.java diff --git a/src/main/java/info/textgrid/services/aggregator/epub/EPUB.java b/src/main/java/info/textgrid/services/aggregator/epub/EPUB.java deleted file mode 100644 index e309dd9..0000000 --- a/src/main/java/info/textgrid/services/aggregator/epub/EPUB.java +++ /dev/null @@ -1,74 +0,0 @@ -package info.textgrid.services.aggregator.epub; - -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.ITextGridRep; -import info.textgrid.services.aggregator.StylesheetManager; -import info.textgrid.services.aggregator.TextGridRepProvider; - -import java.io.IOException; -import java.net.URI; - -import javax.servlet.ServletContext; -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.core.Context; -import javax.ws.rs.core.Request; -import javax.ws.rs.core.Response; - -import net.sf.saxon.s9api.SaxonApiException; - -import org.apache.cxf.jaxrs.model.wadl.Description; - -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 { - - - private ITextGridRep repository = TextGridRepProvider.getInstance(); - - private StylesheetManager stylesheetManager; - private StylesheetManager getStylesheetManager() { - if (stylesheetManager == null) - stylesheetManager = new StylesheetManager(servlet, repository); - return stylesheetManager; - } - - @Context - private ServletContext servlet; - - public EPUB(final ITextGridRep repository) { - this.repository = repository; - } - - @GET - @Path(value = "/{object}") - @Produces(value = "application/epub+zip") - public Response get( - @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(); - - } - -} diff --git a/src/main/java/info/textgrid/services/aggregator/html/HTML.java b/src/main/java/info/textgrid/services/aggregator/html/HTML.java deleted file mode 100644 index 1cf932f..0000000 --- a/src/main/java/info/textgrid/services/aggregator/html/HTML.java +++ /dev/null @@ -1,77 +0,0 @@ -package info.textgrid.services.aggregator.html; - -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.ITextGridRep; -import info.textgrid.services.aggregator.StylesheetManager; -import info.textgrid.services.aggregator.TextGridRepProvider; - -import java.io.IOException; -import java.net.URI; -import java.util.concurrent.ExecutionException; - -import javax.servlet.ServletContext; -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 net.sf.saxon.s9api.SaxonApiException; - -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 { - - - ITextGridRep repository = TextGridRepProvider.getInstance(); - - @Context ServletContext servlet; - - private StylesheetManager stylesheetManager; - - public StylesheetManager getStylesheetManager() { - if (stylesheetManager == null) - stylesheetManager = new StylesheetManager(servlet, repository); - - return stylesheetManager; - } - - public HTML(final ITextGridRep repository) throws IOException { - this.repository = repository; - } - - @GET - @Path(value = "/{object}") - @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, - @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(); - } - -} diff --git a/src/main/java/info/textgrid/services/aggregator/teicorpus/TEICorpus.java b/src/main/java/info/textgrid/services/aggregator/teicorpus/TEICorpus.java deleted file mode 100644 index 271ab34..0000000 --- a/src/main/java/info/textgrid/services/aggregator/teicorpus/TEICorpus.java +++ /dev/null @@ -1,91 +0,0 @@ -package info.textgrid.services.aggregator.teicorpus; - -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.ITextGridRep; - -import java.io.IOException; -import java.net.URISyntaxException; -import java.util.logging.Logger; - -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.core.Context; -import javax.ws.rs.core.Request; -import javax.ws.rs.core.Response; - -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; - -/* - * Generating a TEIcorpus document from a (single) aggregation - * - * Header: - * - * Header could be generated in the same way as in the metadata editor, i.e. - * paste together the ancestor metadata records (including matching work - * records) and then run an XSLT stylesheet. - * - * Children's Header: - * - * For descendant aggregations, we still need a header. Either we consider this - * redundant, or we preserve the metadata records we copied together for the - * respective ancestor levels, append the current level & run the - * transformation. - * - * Body: - * - * Naïve approach: Load and recursively process the aggregations, check each - * one's content type Probably better: SearchClient has a listAggregation() - * method that is also used by the navigator and that returns metadata records. - * We could use this, so it's only one large request per aggregation. Should be - * reasonably fast. - */ -@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; - - final Logger logger = Logger.getLogger("info.textgrid.services.aggregator"); - - public TEICorpus(final ITextGridRep repository) { - this.repository = repository; - } - - - @GET - @Path(value="/{uris}") - @Produces("text/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 get(@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(); - } - -} diff --git a/src/main/java/info/textgrid/services/aggregator/zip/ZIP.java b/src/main/java/info/textgrid/services/aggregator/zip/ZIP.java deleted file mode 100644 index 035241b..0000000 --- a/src/main/java/info/textgrid/services/aggregator/zip/ZIP.java +++ /dev/null @@ -1,54 +0,0 @@ -package info.textgrid.services.aggregator.zip; - -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.ITextGridRep; - -import java.io.IOException; - -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.core.Context; -import javax.ws.rs.core.Request; -import javax.ws.rs.core.Response; - -import net.sf.saxon.s9api.SaxonApiException; - -import org.apache.cxf.jaxrs.model.wadl.Description; - -@Deprecated -@Path("/zip") -public class ZIP { - private final ITextGridRep repository; - - public ZIP(final ITextGridRep repository) { - this.repository = repository; - } - - @GET - @Path(value = "/{objects}") - @Produces("application/zip") - public Response get( - @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(); - } - -} diff --git a/src/test/java/info/textgrid/services/aggregator/teicorpus/TEICorpusTest.java b/src/test/java/info/textgrid/services/aggregator/teicorpus/TEICorpusTest.java index fdac231..52ff3bb 100644 --- a/src/test/java/info/textgrid/services/aggregator/teicorpus/TEICorpusTest.java +++ b/src/test/java/info/textgrid/services/aggregator/teicorpus/TEICorpusTest.java @@ -5,6 +5,7 @@ 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.ITextGridRep; import info.textgrid.services.aggregator.TextGridRepProvider; import java.io.ByteArrayOutputStream; @@ -25,25 +26,23 @@ public class TEICorpusTest { - private TEICorpus teiCorpus; + private ITextGridRep repository; @Before public void setUp() throws Exception { - teiCorpus = new TEICorpus(TextGridRepProvider.getInstance()); + repository = TextGridRepProvider.getInstance(); } @Test(expected = WebApplicationException.class) public void testGet404() throws URISyntaxException, ObjectNotFoundFault, MetadataParseFault, IoFault, AuthFault, ProtocolNotImplementedFault, IOException, SaxonApiException { - final Response response = teiCorpus.get("textgrid:doesnotexist", - true, false, null, null, null); + final Response response = new TEICorpusExporter(repository, null, "textgrid:doesnotexist").createResponse().build(); Assert.assertEquals(404, response.getStatus()); } @Test public void testGet() throws URISyntaxException, WebApplicationException, IOException, ObjectNotFoundFault, MetadataParseFault, IoFault, AuthFault, ProtocolNotImplementedFault, SaxonApiException { - final Response response = teiCorpus.get("textgrid:jmzg.0", true, - false, null, null, null); + final Response response = new TEICorpusExporter(repository, null, "textgrid:jmzg.0").createResponse().build(); final Object entity = response.getEntity(); final ByteArrayOutputStream output = new ByteArrayOutputStream(); ((StreamingOutput) entity).write(output); -- GitLab