Example #1
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 #2
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);
     }
   }
 }
Example #3
0
 @RequestMapping(value = MappingConstants.ARTICLE, method = RequestMethod.POST)
 @PreAuthorize("hasRole('" + PermissionConstants.ADMIN_CREATE_ARTICLE + "')")
 public @ResponseBody Long createArticle(
     @RequestBody @Valid Article article, @AuthenticationPrincipal CustomUserDetails userDetails) {
   // for the time being the author of the published article is the logged in user
   Set<Long> authorIds = new HashSet<>();
   authorIds.add(userDetails.getId());
   Long articleId = articleService.create(authorIds);
   article.setId(articleId);
   createDictionary(article);
   return articleId;
 }
Example #4
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 #5
0
 @RequestMapping(value = MappingConstants.ARTICLE, method = RequestMethod.PUT)
 @PreAuthorize("hasRole('" + PermissionConstants.ADMIN_CREATE_ARTICLE + "')")
 public @ResponseBody Long updateArticle(@RequestBody @Valid Article article) {
   updateDictionary(article);
   return article.getId();
 }