/**
   * @param id
   * @param sensitive
   * @return
   */
  @PreAuthorize(
      "@tiiltaAuthorization.hasPermission('TemplatingDjango','Site',#siteId, @userService.getConnected())")
  @RequestMapping(
      value = "/bender/{siteId:.+}/resource/{id}/toggle/sensitive/{sensitive}",
      method = RequestMethod.PUT)
  @ResponseBody
  public Map<String, String> toggleSensitiveResource(
      @PathVariable("id") String id,
      @PathVariable("sensitive") boolean sensitive,
      @PathVariable("siteId") String siteId) {

    Map<String, String> result = new HashMap<>();
    boolean toggled = false;

    BenderResource resource = benderService.getResourceById(id, null);
    if (resource != null) {

      resource.setSensitive(sensitive);
      // enregistrement de la ressource dans une base mongo
      provider.persist(resource);
      toggled = true;
    }
    result.put("toggled", String.valueOf(toggled));
    return result;
  }
  /**
   * @param id
   * @param comment
   * @param siteId
   * @return
   * @throws Throwable
   */
  @PreAuthorize(
      "@tiiltaAuthorization.hasBenderPermission('TemplatingDjango', 'Site' , #siteId, @userService.getConnected(), #id)")
  @RequestMapping(value = "/bender/{siteId:.+}/resource/{id}", method = RequestMethod.DELETE)
  @ResponseBody
  public Map<String, Object> deleteResource(
      @PathVariable("id") String id,
      @RequestHeader("Comment") String comment,
      @PathVariable("siteId") String siteId)
      throws Throwable {

    Map<String, Object> result = new HashMap<>();
    Site site = siteService.getSite(siteId);
    if (site == null) {
      throw new ValidationException("le site est inconnu");
    }

    BenderResource resource = benderService.getResourceById(id, null);
    if (resource == null) {
      throw new ValidationException("Le fichier n'existe pas");
    }

    // supprimer la ressource de la base mongo
    benderService.deleteResource(resource, comment);

    result.put("response", true);
    return result;
  }
  /**
   * @param resourceDTO
   * @param siteId
   * @param id
   * @param response
   * @param comment
   * @return
   * @throws com.sfr.tiilta.client.exception.ValidationException
   * @throws java.io.IOException
   */
  @PreAuthorize(
      "@tiiltaAuthorization.hasBenderPermission('TemplatingDjango', 'Site' , #siteId, @userService.getConnected(), #id)")
  @RequestMapping(
      value = "/bender/{siteId:.+}/resource/{id}",
      method = RequestMethod.PUT,
      headers = {"content-type=application/json"})
  public ResponseEntity<BenderResource> updateResource(
      @RequestBody @Valid BenderResource resourceDTO,
      @PathVariable("siteId") String siteId,
      @PathVariable("id") String id,
      HttpServletResponse response,
      @RequestParam(value = "comment", required = false) String comment)
      throws ValidationException, IOException {

    ResponseEntity<BenderResource> result =
        new ResponseEntity<>(null, new HttpHeaders(), HttpStatus.BAD_REQUEST);

    boolean isSaved = false;

    Site site = siteService.getSite(siteId);
    if (site == null) {
      throw new ValidationException("le site est inconnu");
    }

    if (resourceDTO != null) {

      User user = userService.getConnected();
      BenderResource originResource = benderService.getResourceById(id, null);

      if (originResource == null) {
        throw new ValidationException("Le fichier n'existe pas");
      }

      resourceDTO.setModifiedBy(user.getName());
      resourceDTO.setUpdateDate(new Date());
      resourceDTO.setSite(siteId);

      // Admin only fields
      if (!tiiltaAuthorization.hasPermission(
          Permission.Admin, Subject.Site, siteId, userService.getConnected())) {

        resourceDTO.setSensitive(originResource.isSensitive());
        resourceDTO.setExecutable(originResource.isExecutable());
        resourceDTO.setExecutorType(originResource.getExecutorType());
      }
      benderService.persist(resourceDTO);

      // récupération de la resource sauvegardée avec la dernière version dans SVN
      result =
          new ResponseEntity<>(
              this.getResourceById(id, null, siteId), new HttpHeaders(), HttpStatus.OK);
    }
    return result;
  }
  /**
   * @param id
   * @param version
   * @param siteId
   * @return
   * @throws IOException
   * @throws ValidationException
   */
  @PreAuthorize(
      "@tiiltaAuthorization.hasPermission('TemplatingDjango', @userService.getConnected())")
  @RequestMapping(value = "/bender/{siteId:.+}/resource/{id}", method = RequestMethod.GET)
  @ResponseBody
  public BenderResource getResourceById(
      @PathVariable("id") String id,
      @RequestParam(value = "version", required = false) String version,
      @PathVariable("siteId") String siteId)
      throws IOException, ValidationException {

    BenderResource resourceDTO = null;
    Site site = siteService.getSite(siteId);
    if (site == null) {
      throw new ValidationException("Le site est inconnu");
    }
    resourceDTO = benderService.getResourceById(id, version);

    return resourceDTO;
  }
  /**
   * @param siteId
   * @param id
   * @return
   * @throws ValidationException
   */
  @PreAuthorize(
      "@tiiltaAuthorization.hasPermission('TemplatingDjango', @userService.getConnected())")
  @RequestMapping(value = "/bender/{siteId:.+}/resource/{id}/revisions", method = RequestMethod.GET)
  @ResponseBody
  public List<EntityVersionInfo> getListRevision(
      @PathVariable("siteId") String siteId, @PathVariable("id") String id)
      throws ValidationException {

    List<EntityVersionInfo> versionBeans = new ArrayList<>();
    Site site = siteService.getSite(siteId);
    if (site == null) {
      throw new ValidationException("Le site est inconnu");
    }

    BenderResource resourceDTO = new BenderResource();
    resourceDTO = benderService.getResourceById(id, null);
    if (resourceDTO != null) {

      versionBeans.addAll(
          benderService.getListRevision(site.getEditoRootPath(), resourceDTO.getPath(), 10l));
    }
    return versionBeans;
  }