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

Adapted TEICorpus export to the new pattern

parent 105fb570
No related branches found
No related tags found
No related merge requests found
......@@ -11,14 +11,12 @@
import info.textgrid.namespaces.middleware.tgcrud.services.tgcrudservice.ObjectNotFoundFault;
import info.textgrid.namespaces.middleware.tgcrud.services.tgcrudservice.ProtocolNotImplementedFault;
import info.textgrid.namespaces.middleware.tgcrud.services.tgcrudservice.TGCrudService;
import info.textgrid.namespaces.middleware.tgcrud.services.tgcrudservice.TGCrudService_Service;
import info.textgrid.namespaces.middleware.tgcrud.services.tgcrudservice.tgcrudclient.TGCrudClientUtilities;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;
......@@ -26,9 +24,7 @@
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Response.Status;
import javax.xml.stream.XMLStreamException;
import javax.xml.ws.BindingProvider;
import javax.xml.ws.Holder;
import javax.xml.ws.soap.MTOMFeature;
import org.codehaus.jettison.json.JSONException;
......
package info.textgrid.services.aggregator.teicorpus;
import info.textgrid.namespaces.metadata.core._2010.ObjectType;
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.TGCrudService;
import info.textgrid.services.aggregator.ArgUtils;
import info.textgrid.namespaces.middleware.tgcrud.services.tgcrudservice.ProtocolNotImplementedFault;
import info.textgrid.services.aggregator.ITextGridRep;
import info.textgrid.services.aggregator.RESTUtils;
import info.textgrid.utils.export.filenames.DefaultFilenamePolicy;
import java.io.IOException;
import java.net.URISyntaxException;
import java.util.Date;
import java.util.logging.Logger;
import javax.ws.rs.DefaultValue;
......@@ -24,7 +20,8 @@
import javax.ws.rs.core.Context;
import javax.ws.rs.core.Request;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.ResponseBuilder;
import net.sf.saxon.s9api.SaxonApiException;
import org.apache.cxf.jaxrs.model.wadl.Description;
import org.apache.cxf.jaxrs.model.wadl.Descriptions;
......@@ -80,46 +77,14 @@ public Response get(@Description("TextGrid URIs of the root objects, separated b
@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 {
logger.fine("TEIcorpus called for root object(s): " + uriList);
final TGCrudService crud = repository.getCRUDService();
logger.finest("Yo, clients are there.");
final ObjectType[] rootObjects = ArgUtils.extractRootObjects(uriList, sid, crud);
// Return fast for If-Modified-Since
final Date lastModified = RESTUtils.createLastModified(rootObjects);
if (request != null) {
ResponseBuilder response304 = request.evaluatePreconditions(lastModified);
if (response304 != null)
return response304.build();
}
throws URISyntaxException, ObjectNotFoundFault, MetadataParseFault, IoFault, AuthFault, ProtocolNotImplementedFault, IOException, SaxonApiException {
final String title = ArgUtils.createTitle(rootObjects, titleArgument);
TEICorpusExporter exporter = new TEICorpusExporter(repository, request, uriList);
exporter.setFlat(flat);
exporter.setTitle(titleArgument);
logger.finer("CRUD request for root aggregations successful");
final TEICorpusSerializer serializer = new TEICorpusSerializer(rootObjects, flat, sid);
serializer.setTitle(title);
final ResponseBuilder builder = Response.ok(serializer, "text/xml");
RESTUtils.configureCache(builder, lastModified, sid == null || sid.isEmpty());
if (attach) {
final String fileName = DefaultFilenamePolicy.INSTANCE.translate(title)
+ (flat ? ".flat" : "") + ".xml";
RESTUtils.addAttachmentFilename(builder, fileName);
}
return builder.build();
// final Response response = search.listAggregation(uri.toString());
// for (final ResultType result : response.getResult()) {
// final String contentType =
// result.getObject().getGeneric().getProvided().getFormat();
// if (contentType.contains("aggregation")) {
// // TODO deal with aggregation
// } else if ("text/xml".equals(contentType)) {
// // TODO deal with
// }
// }
// return null;
return exporter.createResponse().build();
}
}
package info.textgrid.services.aggregator.teicorpus;
import java.io.IOException;
import java.io.OutputStream;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Request;
import javax.ws.rs.core.Response.Status;
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.services.aggregator.AbstractExporter;
import info.textgrid.services.aggregator.ITextGridRep;
public class TEICorpusExporter extends AbstractExporter {
private boolean flat;
public TEICorpusExporter(ITextGridRep repository, Request request,
String uriList) {
super(repository, request, uriList);
setFileExtension("xml");
setMediaType("application/tei+xml");
}
@Override
public void write(OutputStream output) throws IOException,
WebApplicationException {
TEICorpusSerializer serializer;
try {
serializer = new TEICorpusSerializer(getRootObjects(), isFlat(), getSid().orNull());
serializer.setTitle(getTitle());
serializer.write(output);
} catch (ObjectNotFoundFault e) {
throw new WebApplicationException(e, Status.NOT_FOUND);
} catch (MetadataParseFault e) {
throw new WebApplicationException(e, Status.BAD_REQUEST);
} catch (IoFault e) {
throw new WebApplicationException(e);
} catch (AuthFault e) {
throw new WebApplicationException(e, Status.FORBIDDEN);
}
}
public boolean isFlat() {
return flat;
}
public void setFlat(boolean flat) {
this.flat = flat;
}
}
......@@ -11,7 +11,6 @@
import info.textgrid.services.aggregator.AggregationTreeWalker;
import info.textgrid.services.aggregator.TextGridRepProvider;
import info.textgrid.utils.linkrewriter.ConfigurableXMLRewriter;
import info.textgrid.utils.linkrewriter.ConfigurableXMLRewriter.DefaultMergeLinkAdjuster;
import java.io.IOException;
import java.io.OutputStream;
......
......@@ -4,18 +4,20 @@
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.TextGridRepProvider;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.net.URISyntaxException;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.StreamingOutput;
import net.sf.saxon.s9api.SaxonApiException;
import org.apache.cxf.helpers.IOUtils;
import org.junit.Assert;
import org.junit.Before;
......@@ -30,8 +32,8 @@ public void setUp() throws Exception {
teiCorpus = new TEICorpus(TextGridRepProvider.getInstance());
}
@Test(expected = ObjectNotFoundFault.class)
public void testGet404() throws URISyntaxException, ObjectNotFoundFault, MetadataParseFault, IoFault, AuthFault {
@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);
Assert.assertEquals(404, response.getStatus());
......@@ -39,7 +41,7 @@ public void testGet404() throws URISyntaxException, ObjectNotFoundFault, Metadat
@Test
public void testGet() throws URISyntaxException, WebApplicationException,
IOException, ObjectNotFoundFault, MetadataParseFault, IoFault, AuthFault {
IOException, ObjectNotFoundFault, MetadataParseFault, IoFault, AuthFault, ProtocolNotImplementedFault, SaxonApiException {
final Response response = teiCorpus.get("textgrid:jmzg.0", true,
false, null, null, null);
final Object entity = response.getEntity();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment