Search in sources :

Example 1 with Tag

use of com.nixmash.blog.jpa.model.Tag in project nixmash-blog by mintster.

the class PostsController method tagTitles.

@RequestMapping(value = "/titles/tag/{tagValue}", method = GET)
public String tagTitles(@PathVariable("tagValue") String tagValue, Model model) throws TagNotFoundException, UnsupportedEncodingException {
    Tag tag = postService.getTag(URLDecoder.decode(tagValue, "UTF-8"));
    boolean showMore = postService.getPublishedPostsByTagId(tag.getTagId()).size() > TITLE_PAGING_SIZE;
    model.addAttribute("tag", tag);
    model.addAttribute("showmore", showMore);
    return POSTS_TAGTITLES_VIEW;
}
Also used : Tag(com.nixmash.blog.jpa.model.Tag) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with Tag

use of com.nixmash.blog.jpa.model.Tag in project nixmash-blog by mintster.

the class AdminPostsController method tagList.

// endregion
// region Tags
@RequestMapping(value = "/tags", method = GET)
public ModelAndView tagList(Model model) {
    ModelAndView mav = new ModelAndView();
    mav.addObject("tags", postService.getTagCloud(-1));
    mav.addObject("newTag", new Tag());
    mav.setViewName(ADMIN_TAGS_VIEW);
    return mav;
}
Also used : ModelAndView(org.springframework.web.servlet.ModelAndView) Tag(com.nixmash.blog.jpa.model.Tag)

Example 3 with Tag

use of com.nixmash.blog.jpa.model.Tag in project nixmash-blog by mintster.

the class AdminPostsController method addTag.

@RequestMapping(value = "/tags/new", method = RequestMethod.POST)
public String addTag(@Valid TagDTO tagDTO, BindingResult result, SessionStatus status, RedirectAttributes attributes) {
    if (result.hasErrors()) {
        return ADMIN_TAGS_VIEW;
    } else {
        Tag tag = postService.createTag(tagDTO);
        logger.info("Tag Added: {}", tag.getTagValue());
        status.setComplete();
        webUI.addFeedbackMessage(attributes, FEEDBACK_MESSAGE_TAG_ADDED, tag.getTagValue());
        return "redirect:/admin/posts/tags";
    }
}
Also used : Tag(com.nixmash.blog.jpa.model.Tag)

Example 4 with Tag

use of com.nixmash.blog.jpa.model.Tag in project nixmash-blog by mintster.

the class AdminPostsControllerTests method deleteTag_decreases_tag_count.

@Test
public void deleteTag_decreases_tag_count() throws Exception {
    int preTagCount = postService.getTagDTOs().size();
    Tag preTag = postService.getTag("h2tagsix");
    mvc.perform(deleteTagRequest(preTag.getTagId())).andExpect(redirectedUrl("/admin/posts/tags"));
    int postTagCount = postService.getTagDTOs().size();
    assertThat(postTagCount, is(lessThan(preTagCount)));
}
Also used : Tag(com.nixmash.blog.jpa.model.Tag) Test(org.junit.Test)

Example 5 with Tag

use of com.nixmash.blog.jpa.model.Tag in project nixmash-blog by mintster.

the class AdminPostsControllerTests method updateTag_changes_tag_value.

@Test
public void updateTag_changes_tag_value() throws Exception {
    Tag preTag = postService.getTag("h2tagfour");
    mvc.perform(updateTagRequest(preTag.getTagId(), "updateChangesTagName")).andExpect(redirectedUrl("/admin/posts/tags"));
    Tag postTag = postService.getTag("updateChangesTagName");
    assertEquals(preTag.getTagId(), postTag.getTagId());
}
Also used : Tag(com.nixmash.blog.jpa.model.Tag) Test(org.junit.Test)

Aggregations

Tag (com.nixmash.blog.jpa.model.Tag)8 Test (org.junit.Test)4 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 ApplicationConfig (com.nixmash.blog.jpa.config.ApplicationConfig)1 DataConfigProfile (com.nixmash.blog.jpa.enums.DataConfigProfile)1 PostDisplayType (com.nixmash.blog.jpa.enums.PostDisplayType)1 PostType (com.nixmash.blog.jpa.enums.PostType)1 Post (com.nixmash.blog.jpa.model.Post)1 PostTestUtils.getTestCategory (com.nixmash.blog.jpa.utils.PostTestUtils.getTestCategory)1 PostTestUtils.getTestTags (com.nixmash.blog.jpa.utils.PostTestUtils.getTestTags)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Optional (java.util.Optional)1 Set (java.util.Set)1 EntityManager (javax.persistence.EntityManager)1 PersistenceContext (javax.persistence.PersistenceContext)1 Matchers.isA (org.hamcrest.Matchers.isA)1 Assert (org.junit.Assert)1 Before (org.junit.Before)1 RunWith (org.junit.runner.RunWith)1