/**
   * @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 resourceDTO
   * @param siteId
   * @param comment
   * @return
   * @throws IOException
   * @throws ValidationException
   */
  @PreAuthorize(
      "@tiiltaAuthorization.hasPermission('TemplatingDjango', @userService.getConnected())")
  @RequestMapping(
      value = "/bender/{siteId:.+}/resource",
      method = RequestMethod.POST,
      headers = {"content-type=application/json"})
  public ResponseEntity<BenderResource> createResource(
      @RequestBody @Valid BenderResource resourceDTO,
      @PathVariable("siteId") String siteId,
      @RequestParam(value = "comment", required = false) String comment)
      throws IOException, ValidationException {

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

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

    User user = userService.getConnected();
    resourceDTO.setSite(siteId);
    resourceDTO.setCreationDate(new Date());
    resourceDTO.setUpdateDate(new Date());
    // set Resource Path
    // format path with Path.get
    resourceDTO.setPath(
        Paths.get(
                resourceDTO.getPath()
                    + File.separator
                    + resourceDTO.getName()
                    + "."
                    + StringUtils.lowerCase(resourceDTO.getType()))
            .toString());
    BenderResource createdResource = benderService.persist(resourceDTO);
    if (createdResource != null)
      result =
          new ResponseEntity<>(
              this.getResourceById(createdResource.getId(), null, siteId),
              new HttpHeaders(),
              HttpStatus.OK);

    return result;
  }