Example usage for org.springframework.web.context.request WebRequest checkNotModified

List of usage examples for org.springframework.web.context.request WebRequest checkNotModified

Introduction

In this page you can find the example usage for org.springframework.web.context.request WebRequest checkNotModified.

Prototype

boolean checkNotModified(String etag);

Source Link

Document

Check whether the requested resource has been modified given the supplied ETag (entity tag), as determined by the application.

Usage

From source file:org.jtalks.jcommune.web.controller.TopicController.java

/**
 * Displays to user a list of messages from the topic with pagination
 *
 * @param topicId the id of selected Topic
 * @param page    page/*from   www.  j  a va  2 s  .  c o  m*/
 * @return {@code ModelAndView}
 * @throws NotFoundException when topic or branch not found
 */
@RequestMapping(value = "/topics/{topicId}", method = RequestMethod.GET)
public ModelAndView showTopicPage(WebRequest request, @PathVariable(TOPIC_ID) Long topicId,
        @RequestParam(value = "page", defaultValue = "1", required = false) String page)
        throws NotFoundException {
    JCUser currentUser = userService.getCurrentUser();
    Topic topic = topicFetchService.get(topicId);

    topicFetchService.checkViewTopicPermission(topic.getBranch().getId());
    Page<Post> postsPage = postService.getPosts(topic, page);

    if (request.checkNotModified(topic.getLastModificationPostDate().getMillis())) {
        return null;
    }
    PostDto postDto = new PostDto();
    PostDraft draft = topic.getDraftForUser(currentUser);
    if (draft != null) {
        postDto = PostDto.getDtoFor(draft);
    }
    lastReadPostService.markTopicPageAsRead(topic, postsPage.getNumber());
    return new ModelAndView("topic/postList").addObject("viewList", locationService.getUsersViewing(topic))
            .addObject("usersOnline", sessionRegistry.getAllPrincipals()).addObject("postsPage", postsPage)
            .addObject("topic", topic).addObject(POST_DTO, postDto)
            .addObject("subscribed", topic.getSubscribers().contains(currentUser))
            .addObject(BREADCRUMB_LIST, breadcrumbBuilder.getForumBreadcrumb(topic));
}