Пример #1
0
  /**
   * @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;
  }
Пример #2
0
  /**
   * @param siteId
   * @param env
   * @param version
   * @param id
   * @return
   * @throws ValidationException
   * @throws IOException
   */
  @PreAuthorize(
      "@tiiltaAuthorization.hasBenderPermission('TemplatingDjango', 'Site' , #siteId, @userService.getConnected(), #id)")
  @RequestMapping(
      value = "/bender/{siteId:.+}/{env}/resource/{id}/publish",
      method = RequestMethod.PUT)
  @ResponseBody
  public Map<String, Object> publish(
      @PathVariable("siteId") String siteId,
      @PathVariable("env") String env,
      @RequestParam(value = "version", required = false) String version,
      @PathVariable("id") String id)
      throws ValidationException, IOException {

    BenderResource resourceDTO = this.getResourceById(id, version, siteId);

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

    if (resourceDTO != null) {
      return benderService.publishResource(site, env, resourceDTO, ncdnClient);
    } else {
      return null;
    }
  }
Пример #3
0
  /**
   * @param siteId
   * @param id
   * @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:.+}/{env}/resource/{id}/run", method = RequestMethod.PUT)
  @ResponseBody
  public Map<String, Object> run(
      @PathVariable("siteId") String siteId,
      @PathVariable("env") String env,
      @PathVariable("id") String id,
      @RequestParam(value = "version", required = false) String version)
      throws ValidationException, IOException {

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

    boolean isExecuted = false;
    BenderResource resourceDTO = this.getResourceById(id, version, siteId);
    if (resourceDTO != null) {
      isExecuted = benderService.executeResource(site, env, resourceDTO);
    }

    Map<String, Object> result = Maps.newHashMap();
    result.put("isExecuted", isExecuted);
    return result;
  }
Пример #4
0
  /**
   * @param name
   * @param listType
   * @param sort
   * @param page
   * @param siteId
   * @return
   * @throws ValidationException
   */
  @PreAuthorize(
      "@tiiltaAuthorization.hasPermission('TemplatingDjango', @userService.getConnected())")
  @RequestMapping(value = "/bender/{siteId:.+}/resource/search", method = RequestMethod.GET)
  @ResponseBody
  public List<BenderResource> getResourceByNameOrTypes(
      @RequestParam(value = "name") String name,
      @RequestParam(value = "type", required = false) List<String> listType,
      @RequestParam(value = "sort", required = false) List<String> sort,
      @RequestParam(value = "page", required = false) Integer page,
      @PathVariable("siteId") String siteId)
      throws ValidationException {

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

    List<BenderResource> listResourceDTO = new ArrayList<>();
    // par défaut on affiche la première page
    if (page == null) {
      page = 0;
    }

    List<BenderResourceDO> listResource =
        benderService.getListResourcesByNameOrType(name, listType, sort, page, siteId);

    for (BenderResourceDO resource : listResource) {
      listResourceDTO.add(BenderResourceDO.getResourceDTO(resource));
    }
    return listResourceDTO;
  }
Пример #5
0
  /**
   * @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;
  }
Пример #6
0
  /**
   * @param siteId
   * @return
   * @throws ValidationException
   * @throws IOException
   */
  @PreAuthorize(
      "@tiiltaAuthorization.hasPermission('TemplatingDjango', @userService.getConnected())")
  @RequestMapping(value = "/bender/{siteId:.+}/resource/environment", method = RequestMethod.GET)
  @ResponseBody
  public Map<String, List<String>> getEnvironment(@PathVariable("siteId") String siteId)
      throws ValidationException, IOException {

    Site site = siteService.getSite(siteId);
    if (site == null) {
      throw new ValidationException("le site est inconnu");
    }
    return site.getClusterByEnvironment();
  }
Пример #7
0
  /**
   * @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;
  }
Пример #8
0
  /**
   * @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;
  }
Пример #9
0
  /**
   * @param siteId
   * @param path
   * @param listType
   * @return
   * @throws ValidationException
   */
  @PreAuthorize(
      "@tiiltaAuthorization.hasPermission('TemplatingDjango', @userService.getConnected())")
  @RequestMapping(value = "/bender/{siteId:.+}/resource/browse", method = RequestMethod.GET)
  @ResponseBody
  public List<BenderResource> browseDirectory(
      @PathVariable("siteId") String siteId,
      @RequestParam("path") String path,
      @RequestParam("type") List<String> listType)
      throws ValidationException {

    Site site = siteService.getSite(siteId);
    List<BenderResource> listResource = new ArrayList<>();
    if (site == null) {
      throw new ValidationException("le site est inconnu");
    } else {
      listResource = benderService.browseDirectory(site, path, listType);
    }
    return listResource;
  }
Пример #10
0
  /**
   * @param siteId
   * @param path
   * @throws ValidationException
   */
  @PreAuthorize(
      "@tiiltaAuthorization.hasPermission('TemplatingDjango', @userService.getConnected())")
  @RequestMapping(value = "/bender/{siteId:.+}/resource/rescan", method = RequestMethod.POST)
  @ResponseStatus(value = HttpStatus.OK)
  public void scanResources(
      @PathVariable("siteId") String siteId,
      @RequestParam(value = "path", required = false) String path)
      throws ValidationException {

    // récupérer le répertoire à scanner
    Site site = siteService.getSite(siteId);
    if (site == null) {
      throw new ValidationException("Le site est inconnu");
    } else {

      LOGGER.info("Démarrage du scan du siteId : {}, path : {}", site.getId(), path);
      benderService.scanLocalResources(site, path);
      LOGGER.info("Fin du scan du siteId : {}, path : {}", site.getId(), path);
    }
  }
Пример #11
0
  /**
   * @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;
  }