Commit 7dee2e4d authored by Matija Obreza's avatar Matija Obreza
Browse files

createGlobalArticle merged with updateGlobalArticle

parent acf89af4
......@@ -101,7 +101,7 @@ public class CreateContentListener extends RunAsAdminListener {
// If nothing is found, parse the resource and create content
if (article == null) {
contentService.createGlobalArticle(slug, locale, entry.getValue().get("title").asText(), entry.getValue().get("body").asText(), null);
contentService.updateGlobalArticle(slug, locale, entry.getValue().get("title").asText(), entry.getValue().get("body").asText(), null);
_logger.info("Created article for slug: " + slug + " lang=" + locale.getLanguage());
}
}
......
......@@ -93,8 +93,6 @@ public interface ContentService {
Article updateArticle(long id, String slug, String title, String body, String summary);
Article createGlobalArticle(String slug, Locale locale, String title, String body, String summary);
Article updateGlobalArticle(String slug, Locale locale, String title, String body, String summary);
ActivityPost getActivityPost(long id);
......
......@@ -169,29 +169,6 @@ public class ContentServiceImpl implements ContentService {
return article;
}
@Override
@Transactional(readOnly = false)
@PreAuthorize("hasRole('ADMINISTRATOR') or hasRole('CONTENTMANAGER')")
@CacheEvict(value = "contentcache", allEntries = true)
public Article createGlobalArticle(String slug, Locale locale, String title, String body, String summary) {
Article article = getGlobalArticle(slug, locale, false);
if (article != null) {
throw new RuntimeException("Article exists");
}
article = new Article();
article.setClassPk(ensureClassPK(Article.class));
article.setLang(locale.getLanguage());
article.setSlug(slug);
article.setTitle(htmlSanitizer.sanitize(title));
article.setSummary(htmlSanitizer.sanitize(summary));
article.setBody(htmlSanitizer.sanitize(body));
article.setPostDate(Calendar.getInstance());
articleRepository.save(article);
return article;
}
@Override
@Transactional(readOnly = false)
@PreAuthorize("hasRole('ADMINISTRATOR') or hasRole('CONTENTMANAGER')")
......@@ -199,7 +176,7 @@ public class ContentServiceImpl implements ContentService {
public Article updateGlobalArticle(String slug, Locale locale, String title, String body, String summary) {
Article article = getGlobalArticle(slug, locale, false);
if (article == null) {
throw new RuntimeException("Article does not exist");
article = new Article();
}
article.setClassPk(ensureClassPK(Article.class));
......
......@@ -344,7 +344,7 @@ public class ArticleController extends BaseController {
public String createNewGlobalArticle(ModelMap model, @RequestParam("slug") String slug, @PathVariable("language") String language,
@RequestParam("title") String title, @RequestParam("body") String body, @RequestParam(value = "summary", required = false) String summary) {
contentService.createGlobalArticle(slug, new Locale(language), title, body, summary);
contentService.updateGlobalArticle(slug, new Locale(language), title, body, summary);
return redirectAfterSave(slug, language);
}
......
......@@ -39,7 +39,7 @@ public class ContentSanitizerTest extends AbstractServicesTest {
String articleBody = "<script></script><h2><small>Genesys account</small><br />Verify your email address</h2><p>You can already use your Genesys account. We need to confirm your email account before granting you access to all Genesys features.</p><p><a href=\"{0}/profile/{1}/validate\" rel=\"nofollow\">Verify {2}</a></p><h2>Validation key: {3}</h2><p>If you didn&#39;t make this request, <a href=\"{0}/profile/{1}/cancel\" rel=\"nofollow\">click here to cancel</a>.</p><p>Thanks,<br />Genesys team</p>";
String expectedBody = "<h2><small>Genesys account</small><br />Verify your email address</h2><p>You can already use your Genesys account. We need to confirm your email account before granting you access to all Genesys features.</p><p><a href=\"{0}/profile/{1}/validate\" rel=\"nofollow\">Verify {2}</a></p><h2>Validation key: {3}</h2><p>If you didn&#39;t make this request, <a href=\"{0}/profile/{1}/cancel\" rel=\"nofollow\">click here to cancel</a>.</p><p>Thanks,<br />Genesys team</p>";
contentService.createGlobalArticle("smtp.email-verification", Locale.ENGLISH, "Test title", articleBody, null);
contentService.updateGlobalArticle("smtp.email-verification", Locale.ENGLISH, "Test title", articleBody, null);
contentSanitizer.sanitizeAll();
......
......@@ -187,7 +187,7 @@ public class ContentServiceTest extends AbstractServicesTest {
String body = "<h1>Create Global Article</h1>";
String summary=null;
Article globalArticle = contentService.createGlobalArticle(slug, locale, title, body, summary);
Article globalArticle = contentService.updateGlobalArticle(slug, locale, title, body, summary);
assertNotNull(globalArticle);
assertTrue(contentService.listArticles(new PageRequest(0, 6)).getContent().size() == 2);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment