Mercurial > lada > lada-server
changeset 73:354deea8e738
Fixed generating return value for Create and Update.
author | Torsten Irländer <torsten.irlaender@intevation.de> |
---|---|
date | Wed, 05 Jun 2013 16:53:35 +0200 |
parents | ccfcdb404f9a |
children | 28c6a57a8f90 |
files | src/main/java/de/intevation/lada/rest/LProbeService.java |
diffstat | 1 files changed, 26 insertions(+), 21 deletions(-) [+] |
line wrap: on
line diff
--- a/src/main/java/de/intevation/lada/rest/LProbeService.java Wed Jun 05 16:52:56 2013 +0200 +++ b/src/main/java/de/intevation/lada/rest/LProbeService.java Wed Jun 05 16:53:35 2013 +0200 @@ -9,6 +9,7 @@ import javax.ws.rs.Consumes; import javax.ws.rs.GET; import javax.ws.rs.POST; +import javax.ws.rs.PUT; import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.Produces; @@ -93,33 +94,42 @@ return repository.filter(mstId, uwbId, begin); } + @PUT + @Path("/{id}") + @Produces("text/json") + @Consumes("application/json") + public String update(LProbe probe) { + return "{success: false, errors: {probeId: \"Client not found\"}}"; + } + @POST @Produces("text/json") @Consumes("application/json") public String create(LProbe probe) { boolean success = repository.create(probe); + int generalError = repository.getGeneralError(); if(success) { - return "[{" + - "returncode: 200," + - "errorfields: []," + - createWarningFields() + - "}]"; + return "{" + + "success: true, " + + "message: " + generalError + ", " + + "errors: {" + createErrorFields() + "}, " + + "warnings: {" + createWarningFields() + "}" + + "}"; } else { - int generalError = repository.getGeneralError(); - String response = "[{ \"returncode\": " + generalError + ", "; - response += "\"errors\": {" + createErrorFields() + "}, "; - response += "\"warnings\": {" + createWarningFields() + "}"; - response += "}]"; - return response; + return "{" + + "success: false, " + + "message: " + generalError + ", " + + "errors: {" + createErrorFields() + "}, " + + "warnings: {" + createWarningFields() + "}" + + "}"; } } private String createWarningFields() { Map<String, Integer> warnings = repository.getWarnings(); - String response = "\"fields\": ["; + String response = ""; if (warnings == null || warnings.isEmpty()) { - response += "]"; return response; } boolean first = true; @@ -127,19 +137,16 @@ if (!first) { response +=","; } - response += "{" + "\"" + entry.getKey() + - "\": " + entry.getValue() + "}"; + response += entry.getKey() + ":" + "\"" + entry.getValue() + "\""; first = false; } - response += "]"; return response; } private String createErrorFields() { Map<String, Integer> errors = repository.getErrors(); - String response = "\"fields\": ["; + String response = ""; if (errors.isEmpty()) { - response += "]"; return response; } boolean first = true; @@ -147,11 +154,9 @@ if (!first) { response +=","; } - response += "{" + "\"" + entry.getKey() + - "\": " + entry.getValue() + "}"; + response += entry.getKey() + ":" + "\"" + entry.getValue() + "\""; first = false; } - response += "]"; return response; } }