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); } }
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); } } }