@RequestMapping(value="/{id}", method = RequestMethod.PUT, consumes = "application/json", produces = "application/json")
public String updateWhitelistedSite(@PathVariable("id") Long id, @RequestBody String jsonString, ModelMap m, Principal p) {
JsonObject json;
WhitelistedSite whitelist = null;
try {
json = parser.parse(jsonString).getAsJsonObject();
whitelist = gson.fromJson(json, WhitelistedSite.class);
} catch (JsonParseException e) {
logger.error("updateWhitelistedSite failed due to JsonParseException", e);
m.put("code", HttpStatus.BAD_REQUEST);
m.put("errorMessage", "Could not update whitelisted site. The server encountered a JSON syntax exception. Contact a system administrator for assistance.");
return JsonErrorView.VIEWNAME;
} catch (IllegalStateException e) {
logger.error("updateWhitelistedSite failed due to IllegalStateException", e);
m.put("code", HttpStatus.BAD_REQUEST);
m.put("errorMessage", "Could not update whitelisted site. The server encountered an IllegalStateException. Refresh and try again - if the problem persists, contact a system administrator for assistance.");
return JsonErrorView.VIEWNAME;
}
WhitelistedSite oldWhitelist = whitelistService.getById(id);
if (oldWhitelist == null) {
logger.error("updateWhitelistedSite failed; whitelist with id " + id + " could not be found.");
m.put("code", HttpStatus.NOT_FOUND);
m.put("errorMessage", "Could not update whitelisted site. The requested whitelisted site with id " + id + "could not be found.");
return JsonErrorView.VIEWNAME;
} else {
WhitelistedSite newWhitelist = whitelistService.update(oldWhitelist, whitelist);
m.put("entity", newWhitelist);
return JsonEntityView.VIEWNAME;
}