Example #1
0
 @RequestMapping(value = MappingConstants.ARTICLE_LANGUAGE, method = RequestMethod.PUT)
 @PreAuthorize("hasRole('" + PermissionConstants.ADMIN_CREATE_ARTICLE + "')")
 public @ResponseBody Article changeLanguage(@RequestBody Article article) {
   if (article != null && article.getId() != 0) {
     Article articleWithChangedLanguage = new Article();
     Optional<Dictionary> titleDictionary =
         dictionaryService.find(
             CategoryConstants.ARTICLE_TYPE, article.getId(), CategoryConstants.TITLE);
     Optional<Dictionary> bodyDictionary =
         dictionaryService.find(
             CategoryConstants.ARTICLE_TYPE, article.getId(), CategoryConstants.BODY);
     articleWithChangedLanguage.setId(article.getId());
     articleWithChangedLanguage.setLanguage(article.getLanguage());
     if (titleDictionary.isPresent()) {
       String title = null;
       if (CategoryConstants.EN.equalsIgnoreCase(article.getLanguage())) {
         title = titleDictionary.get().getEn();
       } else if (CategoryConstants.RO.equalsIgnoreCase(article.getLanguage())) {
         title = titleDictionary.get().getRo();
       }
       articleWithChangedLanguage.setTitle(title != null ? title : "");
     }
     if (bodyDictionary.isPresent()) {
       String body = null;
       if (CategoryConstants.EN.equalsIgnoreCase(article.getLanguage())) {
         body = bodyDictionary.get().getEn();
       } else if (CategoryConstants.RO.equalsIgnoreCase(article.getLanguage())) {
         body = bodyDictionary.get().getRo();
       }
       articleWithChangedLanguage.setBody(body != null ? body : "");
     }
     return articleWithChangedLanguage;
   }
   return article;
 }
Example #2
0
 private void createElement(Article article, String category) {
   String element = null;
   if (CategoryConstants.TITLE.equals(category)) {
     element = article.getTitle();
   } else if (CategoryConstants.BODY.equals(category)) {
     element = article.getBody();
   }
   if (element != null && !element.isEmpty()) {
     Dictionary dictionary = new Dictionary();
     dictionary.setObjectType(CategoryConstants.ARTICLE_TYPE);
     dictionary.setObjectId(article.getId());
     dictionary.setCategory(category);
     if (CategoryConstants.EN.equalsIgnoreCase(article.getLanguage())) {
       dictionary.setEn(element);
     } else if (CategoryConstants.RO.equalsIgnoreCase(article.getLanguage())) {
       dictionary.setRo(element);
     }
     dictionaryService.create(dictionary);
   }
 }
Example #3
0
 private void updateElement(Article article, String category) {
   String element = null;
   if (CategoryConstants.TITLE.equals(category)) {
     element = article.getTitle();
   } else if (CategoryConstants.BODY.equals(category)) {
     element = article.getBody();
   }
   if (element != null && !element.isEmpty()) {
     Optional<Dictionary> dictionaryOptional =
         dictionaryService.find(CategoryConstants.ARTICLE_TYPE, article.getId(), category);
     if (dictionaryOptional.isPresent()) {
       Dictionary dictionary = dictionaryOptional.get();
       if (CategoryConstants.EN.equalsIgnoreCase(article.getLanguage())) {
         dictionary.setEn(element);
       } else if (CategoryConstants.RO.equalsIgnoreCase(article.getLanguage())) {
         dictionary.setRo(element);
       }
       dictionaryService.update(dictionary);
     }
   }
 }