changeset 82:bd41680cc7d5

Changed type of return to Response and removed handling of errors and warnings. This is now done in the Response object.
author Torsten Irländer <torsten.irlaender@intevation.de>
date Fri, 07 Jun 2013 14:30:31 +0200
parents 8830934533b5
children e7c4ae4b5eba
files src/main/java/de/intevation/lada/rest/LProbeService.java
diffstat 1 files changed, 4 insertions(+), 50 deletions(-) [+]
line wrap: on
line diff
--- a/src/main/java/de/intevation/lada/rest/LProbeService.java	Fri Jun 07 14:29:27 2013 +0200
+++ b/src/main/java/de/intevation/lada/rest/LProbeService.java	Fri Jun 07 14:30:31 2013 +0200
@@ -115,58 +115,12 @@
     @POST
     @Produces("text/json")
     @Consumes("application/json")
-    public String create(LProbe probe) {
+    public Response create(LProbe probe) {
         boolean success = repository.create(probe);
         int generalError = repository.getGeneralError();
-        if(success) {
-            return "{" +
-                   "success: true, " +
-                   "message: \"" + generalError + "\", " +
-                   "errors: {" + createErrorFields() + "}, " +
-                   "warnings: {" + createWarningFields() + "}" +
-                   "}";
-        }
-        else {
-            return "{" +
-                   "success: false, " +
-                   "message: \"" + generalError + "\", " +
-                   "errors: {" + createErrorFields() + "}, " +
-                   "warnings: {" + createWarningFields() + "}" +
-                   "}";
-        }
-    }
-
-    private String createWarningFields() {
-        Map<String, Integer> warnings = repository.getWarnings();
-        String response = "";
-        if (warnings == null || warnings.isEmpty()) {
-            return response;
-        }
-        boolean first = true;
-        for (Map.Entry<String, Integer> entry: warnings.entrySet()) {
-            if (!first) {
-                response +=",";
-            }
-            response += entry.getKey() + ":" + "\"" + entry.getValue() + "\"";
-            first = false;
-        }
-        return response;
-    }
-
-    private String createErrorFields() {
-        Map<String, Integer> errors = repository.getErrors();
-        String response = "";
-        if (errors.isEmpty()) {
-            return response;
-        }
-        boolean first = true;
-        for (Map.Entry<String, Integer> entry: errors.entrySet()) {
-            if (!first) {
-                response +=",";
-            }
-            response += entry.getKey() + ":" + "\"" + entry.getValue() + "\"";
-            first = false;
-        }
+        Response response = new Response(success, generalError, probe);
+        response.setWarnings(repository.getWarnings());
+        response.setErrors(repository.getErrors());
         return response;
     }
 }
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)