changeset 75:b43b76fc0525

Added Response class to wrap the returned data into a response object which have some additional attributes like errors warning etc.
author Torsten Irländer <torsten.irlaender@intevation.de>
date Thu, 06 Jun 2013 16:09:00 +0200
parents 28c6a57a8f90
children 5deb01ba8312
files src/main/java/de/intevation/lada/rest/LProbeService.java src/main/java/de/intevation/lada/rest/Response.java
diffstat 2 files changed, 68 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- 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<LProbe> filter(@Context UriInfo info) {
+    public Response filter(@Context UriInfo info) {
         MultivaluedMap<String, String> params = info.getQueryParameters();
         if (params.isEmpty()) {
-            return repository.findAll(LProbe.class);
+            List<LProbe> 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<LProbe> items = repository.filter(mstId, uwbId, begin);
+        return new Response(true, "200", items);
     }
 
     @PUT
--- /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<LProbe> 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<LProbe>();
+		this.data.add(data);
+	}
+	public Response(boolean success, String message, List<LProbe> 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<LProbe> getData() {
+		return data;
+	}
+	public void setData(List<LProbe> 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;
+	}
+}
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)