@RequestMapping(
     method = RequestMethod.GET,
     headers = {ACCEPT_JSON, "Range"})
 public @ResponseBody HttpEntity<List<USState>> listJsonForRange(
     @RequestHeader(value = "Range") String range, HttpServletRequest request) {
   HttpHeaders headers = new HttpHeaders();
   List<USState> body = null;
   Range parsedRange = new Range(range.replaceAll(RANGE_PREFIX, ""));
   long count = USState.countUSStates();
   body = USState.findUSStateEntries(parsedRange.getFirstResult(), parsedRange.getMaxResults());
   headers.add(
       CONTENT_RANGE_HEADER,
       getContentRangeValue(parsedRange.getFirstResult(), body.size(), count));
   return new HttpEntity<List<USState>>(body, headers);
 }
 @RequestMapping(
     value = "/{id}",
     method = {RequestMethod.POST, RequestMethod.PUT},
     headers = {ACCEPT_JSON, "If-Match=*"})
 public String overWriteJson(@Valid @RequestBody USState state, @PathVariable("id") Long id) {
   Assert.isTrue(USState.findUSState(id) != null);
   return updateJson(state, id);
 }
 @RequestMapping(method = RequestMethod.GET, headers = ACCEPT_JSON)
 public @ResponseBody HttpEntity<List<USState>> listJson() {
   HttpHeaders headers = new HttpHeaders();
   List<USState> body = null;
   body = USState.findAllUSStates();
   headers.add(
       CONTENT_RANGE_HEADER,
       getContentRangeValue(0, body.size(), new Integer(body.size()).longValue()));
   return new HttpEntity<List<USState>>(body, headers);
 }
 /**
  * TODO - This doesn't actually get selected since the query param is in the form of 'sort(...)'
  * instead of 'sort=(...)'
  */
 @RequestMapping(
     method = RequestMethod.GET,
     headers = {ACCEPT_JSON, "Range"},
     params = "sort")
 public @ResponseBody HttpEntity<List<USState>> listJsonForRangeSorted(
     @RequestHeader("Range") String range, @RequestParam("sort") String sort) {
   HttpHeaders headers = new HttpHeaders();
   List<USState> body = null;
   Range parsedRange = new Range(range.replaceAll(RANGE_PREFIX, ""));
   long count = USState.countUSStates();
   // TODO - Implement sort param parsing
   body =
       USState.findOrderedUSStateEntries(
           parsedRange.getFirstResult(), parsedRange.getMaxResults(), "");
   headers.add(
       CONTENT_RANGE_HEADER,
       getContentRangeValue(parsedRange.getFirstResult(), body.size(), count));
   return new HttpEntity<List<USState>>(body, headers);
 }
 @RequestMapping(method = RequestMethod.DELETE, headers = ACCEPT_JSON)
 public @ResponseBody ResponseEntity<String> deleteJson(@PathVariable("id") Long id) {
   USState.findUSState(id).remove();
   return new ResponseEntity<String>(HttpStatus.NO_CONTENT);
 }
 /**
  * TODO - Should probably be stricter here in following the HTTP spec, i.e. returning the proper
  * 20x response instead of an automatic redirect
  */
 @RequestMapping(value = "/{id}", method = RequestMethod.PUT, headers = ACCEPT_JSON)
 public String updateJson(@Valid @RequestBody USState state, @PathVariable("id") Long id) {
   Assert.isTrue(id.equals(state.getId()));
   state.merge();
   return "redirect:/usstates/" + state.getId();
 }
 /**
  * TODO - Should probably be stricter here in following the HTTP spec, i.e. returning the proper
  * 20x response instead of an explicit redirect
  */
 @RequestMapping(method = RequestMethod.POST, headers = ACCEPT_JSON)
 public String createJson(@Valid @RequestBody USState state) {
   state.persist();
   return "redirect:/usstates/" + state.getId();
 }
 @RequestMapping(value = "/{id}", method = RequestMethod.GET, headers = ACCEPT_JSON)
 public @ResponseBody USState getJson(@PathVariable("id") Long id) {
   return USState.findUSState(id);
 }