/** DELETE /articles/:id -> delete the "id" article. */
 @RequestMapping(
     value = "/articles/{id}",
     method = RequestMethod.DELETE,
     produces = MediaType.APPLICATION_JSON_VALUE)
 @Timed
 public ResponseEntity<Void> deleteArticle(@PathVariable Long id) {
   log.debug("REST request to delete Article : {}", id);
   articleRepository.delete(id);
   return ResponseEntity.ok()
       .headers(HeaderUtil.createEntityDeletionAlert("article", id.toString()))
       .build();
 }
  /** PUT /articles -> Updates an existing article. */
  @RequestMapping(
      value = "/articles",
      method = RequestMethod.PUT,
      produces = MediaType.APPLICATION_JSON_VALUE)
  @Timed
  public ResponseEntity<Article> updateArticle(@RequestBody Article article)
      throws URISyntaxException {
    log.debug("REST request to update Article : {}", article);
    if (article.getId() == null) {
      return createArticle(article);
    }

    Article result = articleRepository.findOne(article.getId());
    result.setI18nTitle(I18n.setTranslationText(result.getI18nTitle(), article.getTitle()));
    result.setI18nText(I18n.setTranslationText(result.getI18nText(), article.getText()));
    result.setTitle(article.getTitle());
    result.setText(article.getText());

    result = articleRepository.save(result);

    return ResponseEntity.ok()
        .headers(HeaderUtil.createEntityUpdateAlert("article", article.getId().toString()))
        .body(result);
  }
 /** GET /articles/:id -> get the "id" article. */
 @RequestMapping(
     value = "/articles/{id}",
     method = RequestMethod.GET,
     produces = MediaType.APPLICATION_JSON_VALUE)
 @Timed
 public ResponseEntity<Article> getArticle(@PathVariable Long id) {
   log.debug("REST request to get Article : {}", id);
   Article article = articleRepository.findOne(id);
   if (article != null) {
     article.resolveTraduction();
     if (article.getCategory() != null) article.getCategory().resolveTraduction();
   }
   return Optional.ofNullable(article)
       .map(result -> new ResponseEntity<>(result, HttpStatus.OK))
       .orElse(new ResponseEntity<>(HttpStatus.NOT_FOUND));
 }
 /** GET /articles -> get all the articles. */
 @RequestMapping(
     value = "/articles",
     method = RequestMethod.GET,
     produces = MediaType.APPLICATION_JSON_VALUE)
 @Timed
 public ResponseEntity<List<Article>> getAllArticles(Pageable pageable) throws URISyntaxException {
   log.debug("REST request to get a page of Articles");
   Page<Article> page = articleRepository.findAll(pageable);
   page.getContent()
       .stream()
       .forEach(
           p -> {
             p.resolveTraduction();
             if (p.getCategory() != null) p.getCategory().resolveTraduction();
           });
   HttpHeaders headers = PaginationUtil.generatePaginationHttpHeaders(page, "/api/articles");
   return new ResponseEntity<>(page.getContent(), headers, HttpStatus.OK);
 }
  /** POST /articles -> Create a new article. */
  @RequestMapping(
      value = "/articles",
      method = RequestMethod.POST,
      produces = MediaType.APPLICATION_JSON_VALUE)
  @Timed
  public ResponseEntity<Article> createArticle(@RequestBody Article article)
      throws URISyntaxException {
    log.debug("REST request to save Article : {}", article);
    if (article.getId() != null) {
      return ResponseEntity.badRequest()
          .headers(
              HeaderUtil.createFailureAlert(
                  "article", "idexists", "A new article cannot already have an ID"))
          .body(null);
    }

    article.setI18nTitle(I18n.setTranslationText(article.getI18nTitle(), article.getTitle()));
    article.setI18nText(I18n.setTranslationText(article.getI18nText(), article.getText()));

    Article result = articleRepository.save(article);
    return ResponseEntity.created(new URI("/api/articles/" + result.getId()))
        .headers(HeaderUtil.createEntityCreationAlert("article", result.getId().toString()))
        .body(result);
  }