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

Error handling cleanup

parent ba6bb869
No related branches found
No related tags found
No related merge requests found
......@@ -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()) {
......
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);
......
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