/**
  * @param uuid
  * @param request
  * @return
  * @throws ResponseException
  */
 @RequestMapping(value = "/{resource}/{uuid}", method = RequestMethod.GET)
 @ResponseBody
 public Object retrieve(
     @PathVariable("resource") String resource,
     @PathVariable("uuid") String uuid,
     HttpServletRequest request)
     throws ResponseException {
   RequestContext context = RestUtil.getRequestContext(request);
   CrudResource res = (CrudResource) restService.getResourceByName(buildResourceName(resource));
   return res.retrieve(uuid, context);
 }
 /**
  * @param post
  * @param request
  * @param response
  * @return
  * @throws Exception
  */
 @RequestMapping(value = "/{resource}", method = RequestMethod.POST)
 @ResponseBody
 public Object create(
     @PathVariable("resource") String resource,
     @RequestBody SimpleObject post,
     HttpServletRequest request,
     HttpServletResponse response)
     throws ResponseException {
   RequestContext context = RestUtil.getRequestContext(request);
   CrudResource res = (CrudResource) restService.getResourceByName(buildResourceName(resource));
   Object created = res.create(post, context);
   return RestUtil.created(response, created);
 }
 /**
  * @param uuid
  * @param request
  * @param response
  * @throws Exception
  */
 @RequestMapping(value = "/{resource}/{uuid}", method = RequestMethod.DELETE, params = "purge")
 @ResponseBody
 public Object purge(
     @PathVariable("resource") String resource,
     @PathVariable("uuid") String uuid,
     HttpServletRequest request,
     HttpServletResponse response)
     throws ResponseException {
   RequestContext context = RestUtil.getRequestContext(request);
   CrudResource res = (CrudResource) restService.getResourceByName(buildResourceName(resource));
   res.purge(uuid, context);
   return RestUtil.noContent(response);
 }
  /**
   * @param query
   * @param request
   * @param response
   * @return
   * @throws ResponseException
   */
  @SuppressWarnings("rawtypes")
  @RequestMapping(value = "/{resource}", method = RequestMethod.GET)
  @ResponseBody
  public SimpleObject get(
      @PathVariable("resource") String resource,
      HttpServletRequest request,
      HttpServletResponse response)
      throws ResponseException {
    CrudResource res = (CrudResource) restService.getResourceByName(buildResourceName(resource));

    RequestContext context = RestUtil.getRequestContext(request, Representation.REF);

    @SuppressWarnings("unchecked")
    SearchHandler searchHandler =
        restService.getSearchHandler(buildResourceName(resource), request.getParameterMap());
    if (searchHandler != null) {
      return searchHandler.search(context).toSimpleObject();
    }

    Enumeration parameters = request.getParameterNames();
    while (parameters.hasMoreElements()) {
      if (!RestConstants.SPECIAL_REQUEST_PARAMETERS.contains(parameters.nextElement())) {
        if (res instanceof Searchable) {
          return ((Searchable) res).search(context);
        } else {
          throw new ResourceDoesNotSupportOperationException(
              res.getClass().getSimpleName() + " is not searchable");
        }
      }
    }

    if (res instanceof Listable) {
      return ((Listable) res).getAll(context);
    } else {
      throw new ResourceDoesNotSupportOperationException(
          res.getClass().getSimpleName() + " is not listable");
    }
  }
 /**
  * @param uuid
  * @param post
  * @param request
  * @param response
  * @return
  * @throws Exception
  */
 @RequestMapping(value = "/{resource}/{uuid}", method = RequestMethod.POST)
 @ResponseBody
 public Object update(
     @PathVariable("resource") String resource,
     @PathVariable("uuid") String uuid,
     @RequestBody SimpleObject post,
     HttpServletRequest request,
     HttpServletResponse response)
     throws ResponseException {
   RequestContext context = RestUtil.getRequestContext(request);
   CrudResource res = (CrudResource) restService.getResourceByName(buildResourceName(resource));
   res.update(uuid, post, context);
   return RestUtil.noContent(response);
 }