# HG changeset patch # User Torsten Irländer # Date 1370527740 -7200 # Node ID b43b76fc05253bccd10f16ae9ce619590c8d7d0b # Parent 28c6a57a8f9050f727a926e8f7573f7c30299262 Added Response class to wrap the returned data into a response object which have some additional attributes like errors warning etc. diff -r 28c6a57a8f90 -r b43b76fc0525 src/main/java/de/intevation/lada/rest/LProbeService.java --- a/src/main/java/de/intevation/lada/rest/LProbeService.java Wed Jun 05 17:36:47 2013 +0200 +++ b/src/main/java/de/intevation/lada/rest/LProbeService.java Thu Jun 06 16:09:00 2013 +0200 @@ -50,11 +50,12 @@ @GET @Path("/{id}") @Produces("text/json") - public LProbe findById(@PathParam("id") String id) { - return repository.findById(LProbe.class, id); + public Response findById(@PathParam("id") String id) { + LProbe item = repository.findById(LProbe.class, id); + return new Response(true, "200", item); } - /** + /** * Request LProbe via a filter. * * Query parameters are used for the filter in form of key-value pairs. @@ -68,10 +69,11 @@ */ @GET @Produces("text/json") - public List filter(@Context UriInfo info) { + public Response filter(@Context UriInfo info) { MultivaluedMap params = info.getQueryParameters(); if (params.isEmpty()) { - return repository.findAll(LProbe.class); + List items = repository.findAll(LProbe.class); + return new Response(true, "200", items); } String mstId = ""; String uwbId = ""; @@ -91,7 +93,8 @@ begin = null; } } - return repository.filter(mstId, uwbId, begin); + List items = repository.filter(mstId, uwbId, begin); + return new Response(true, "200", items); } @PUT diff -r 28c6a57a8f90 -r b43b76fc0525 src/main/java/de/intevation/lada/rest/Response.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/intevation/lada/rest/Response.java Thu Jun 06 16:09:00 2013 +0200 @@ -0,0 +1,59 @@ +package de.intevation.lada.rest; + +import java.util.ArrayList; +import java.util.List; + +import de.intevation.lada.model.LProbe; + +@SuppressWarnings("serial") +public class Response implements java.io.Serializable { + + private Boolean success; + private String message; + private List data; + private String errors; + private String warnings; + + public Response(Boolean success, String message, LProbe data) { + super(); + this.success = success; + this.message = message; + this.data = new ArrayList(); + this.data.add(data); + } + public Response(boolean success, String message, List data) { + this.success = success; + this.message = message; + this.data = data; + } + public Boolean getSuccess() { + return success; + } + public void setSuccess(Boolean success) { + this.success = success; + } + public String getMessage() { + return message; + } + public void setMessage(String message) { + this.message = message; + } + public List getData() { + return data; + } + public void setData(List data) { + this.data = data; + } + public String getErrors() { + return errors; + } + public void setErrors(String errors) { + this.errors = errors; + } + public String getWarnings() { + return warnings; + } + public void setWarnings(String warnings) { + this.warnings = warnings; + } +}