diff --git a/src/main/java/info/textgrid/services/aggregator/teicorpus/TEICorpus.java b/src/main/java/info/textgrid/services/aggregator/teicorpus/TEICorpus.java index e7552f0aa2028f6f838fd0fc5ee209039b6525cd..9acade45269fedefea14c56378f9156a5b699096 100644 --- a/src/main/java/info/textgrid/services/aggregator/teicorpus/TEICorpus.java +++ b/src/main/java/info/textgrid/services/aggregator/teicorpus/TEICorpus.java @@ -70,46 +70,32 @@ public Response get(@PathParam("aggregation") final URI uri, @QueryParam("attach") @DefaultValue("true") final boolean attach, @QueryParam("flat") @DefaultValue("false") final boolean flat, @QueryParam("sid") final String sid) - throws URISyntaxException { + throws URISyntaxException, ObjectNotFoundFault, MetadataParseFault, IoFault, AuthFault { logger.fine("TEIcorpus called for root aggregation: " + uri); final TGCrudService crud = repository.getCRUDService(); logger.finest("Yo, clients are there."); - try { - final MetadataContainerType rootAggregationMetadata = crud - .readMetadata(sid, null, uri.toString()); - logger.finer("CRUD request for root aggregation successful"); - final AggregationTreeWalker serializer = new TEICorpusSerializer( - rootAggregationMetadata.getObject(), flat, sid); - final String format = rootAggregationMetadata.getObject().getGeneric().getProvided().getFormat(); - if (!format.contains("aggregation")) { - logger.log(Level.SEVERE, "The requested object {0} is a {1}, not an aggregation, and thus cannot be aggregated.", new Object[] {uri,format}); - throw new WebApplicationException(javax.ws.rs.core.Response - .status(Status.BAD_REQUEST) - .entity(MessageFormat.format( - "The requested object {0} is a {1}, not an aggregation, and thus cannot be aggregated.", uri, - format)).build()); - } - final ResponseBuilder builder = Response.ok(serializer, "text/xml"); - if (attach) { - final String fileName = rootAggregationMetadata.getObject() - .getGeneric().getProvided().getTitle().get(0) - + (flat ? ".flat" : "") + ".xml"; - RESTUtils.addAttachmentFilename(builder, fileName); - } - return builder.build(); - } catch (final ObjectNotFoundFault e) { - logger.log(Level.SEVERE, "CRUD: (Root aggregation) not found", e); - throw new WebApplicationException(e, javax.ws.rs.core.Response.status(Status.NOT_FOUND).entity(e.toString()).build()); - } catch (final MetadataParseFault e) { - logger.log(Level.SEVERE, "CRUD: Could not parse metadata", e); - throw new WebApplicationException(e); - } catch (final IoFault e) { - logger.log(Level.SEVERE, "CRUD: IO Fault", e); - throw new WebApplicationException(e); - } catch (final AuthFault e) { - logger.log(Level.SEVERE, "CRUD: (Root aggregation) AuthFault", e); - throw new WebApplicationException(e, Status.FORBIDDEN); + final MetadataContainerType rootAggregationMetadata = crud + .readMetadata(sid, null, uri.toString()); + logger.finer("CRUD request for root aggregation successful"); + final AggregationTreeWalker serializer = new TEICorpusSerializer( + rootAggregationMetadata.getObject(), flat, sid); + final String format = rootAggregationMetadata.getObject().getGeneric().getProvided().getFormat(); + if (!format.contains("aggregation")) { + logger.log(Level.SEVERE, "The requested object {0} is a {1}, not an aggregation, and thus cannot be aggregated.", new Object[] {uri,format}); + throw new WebApplicationException(javax.ws.rs.core.Response + .status(Status.BAD_REQUEST) + .entity(MessageFormat.format( + "The requested object {0} is a {1}, not an aggregation, and thus cannot be aggregated.", uri, + format)).build()); } + final ResponseBuilder builder = Response.ok(serializer, "text/xml"); + if (attach) { + final String fileName = rootAggregationMetadata.getObject() + .getGeneric().getProvided().getTitle().get(0) + + (flat ? ".flat" : "") + ".xml"; + RESTUtils.addAttachmentFilename(builder, fileName); + } + return builder.build(); // final Response response = search.listAggregation(uri.toString()); // for (final ResultType result : response.getResult()) { 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 ddc4ef762833eda989d7603044162cb6c91cb505..b16276572d92728f251b3f84352cbae113cf2b1e 100644 --- a/src/test/java/info/textgrid/services/aggregator/teicorpus/TEICorpusTest.java +++ b/src/test/java/info/textgrid/services/aggregator/teicorpus/TEICorpusTest.java @@ -1,5 +1,9 @@ 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.services.aggregator.TextGridRepProvider; import java.io.ByteArrayOutputStream; @@ -27,18 +31,18 @@ public void setUp() throws Exception { teiCorpus = new TEICorpus(TextGridRepProvider.getInstance()); } - @Test(expected = WebApplicationException.class) - public void testGet404() throws URISyntaxException { + @Test(expected = ObjectNotFoundFault.class) + public void testGet404() throws URISyntaxException, ObjectNotFoundFault, MetadataParseFault, IoFault, AuthFault { final Response response = teiCorpus.get(URI.create("textgrid:doesnotexist"), - true, false, null); + true, false, null); Assert.assertEquals(404, response.getStatus()); } @Test public void testGet() throws URISyntaxException, WebApplicationException, - IOException { + IOException, ObjectNotFoundFault, MetadataParseFault, IoFault, AuthFault { final Response response = teiCorpus.get(URI.create("textgrid:jmzg.0"), true, - false, null); + false, null); final Object entity = response.getEntity(); final ByteArrayOutputStream output = new ByteArrayOutputStream(); ((StreamingOutput) entity).write(output);