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

Removed obsolete REST API classes.

parent a3519c6d
No related branches found
No related tags found
No related merge requests found
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();
}
}
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();
}
}
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();
}
}
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();
}
}
......@@ -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);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment