gt:             if (result.hasErrors()) {
context: package com.nixmash.blog.mvc.controller;
  
  import com.nixmash.blog.jpa.common.ApplicationSettings;
  import com.nixmash.blog.jpa.dto.CategoryDTO;
  import com.nixmash.blog.jpa.dto.PostDTO;
  import com.nixmash.blog.jpa.dto.TagDTO;
  import com.nixmash.blog.jpa.enums.PostDisplayType;
  import com.nixmash.blog.jpa.enums.PostType;
  import com.nixmash.blog.jpa.enums.TwitterCardType;
  import com.nixmash.blog.jpa.exceptions.DuplicatePostNameException;
  import com.nixmash.blog.jpa.exceptions.PostNotFoundException;
  import com.nixmash.blog.jpa.model.Category;
  import com.nixmash.blog.jpa.model.CurrentUser;
  import com.nixmash.blog.jpa.model.Post;
  import com.nixmash.blog.jpa.model.Tag;
  import com.nixmash.blog.jpa.service.PostService;
  import com.nixmash.blog.jpa.utils.PostUtils;
  import com.nixmash.blog.jsoup.dto.PagePreviewDTO;
  import com.nixmash.blog.jsoup.service.JsoupService;
  import com.nixmash.blog.mail.service.FmService;
  import com.nixmash.blog.mvc.components.WebUI;
  import com.nixmash.blog.mvc.containers.PostLink;
  import com.nixmash.blog.solr.model.PostDoc;
  import com.nixmash.blog.solr.service.PostDocService;
  import org.apache.commons.lang3.StringUtils;
  import org.slf4j.Logger;
  import org.slf4j.LoggerFactory;
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.stereotype.Controller;
  import org.springframework.ui.Model;
  import org.springframework.validation.BindingResult;
  import org.springframework.web.bind.annotation.*;
  import org.springframework.web.bind.support.SessionStatus;
  import org.springframework.web.servlet.ModelAndView;
  import org.springframework.web.servlet.mvc.support.RedirectAttributes;
  import org.springframework.web.util.WebUtils;
  
  import javax.servlet.http.HttpServletRequest;
  import javax.validation.Valid;
  import java.util.Date;
  import java.util.HashMap;
  import java.util.List;
  import java.util.Map;
  import java.util.concurrent.TimeUnit;
  
  import static org.springframework.web.bind.annotation.RequestMethod.GET;
  import static org.springframework.web.bind.annotation.RequestMethod.POST;
  
  /**
   * Created by daveburke on 8/29/16.
   */
  @SuppressWarnings("Duplicates")
  @Controller
  @RequestMapping(value = "/admin/posts")
  public class AdminPostsController {
  
      // region static view properties
  
      public static final String ADMIN_POSTS_LIST_VIEW = "admin/posts/list";
      public static final String ADMIN_POST_ADD_VIEW = "admin/posts/addpost";
      public static final String ADMIN_LINK_ADD_VIEW = "admin/posts/addlink";
      public static final String ADMIN_TAGS_VIEW = "admin/posts/tags";
      public static final String ADMIN_POSTLINK_UPDATE_VIEW = "admin/posts/update";
      public static final String ADMIN_POSTS_REINDEX_VIEW = "admin/posts/reindex";
      public static final String ADMIN_POSTMETA_UPDATE_VIEW = "admin/posts/postmeta";
      public static final String ADMIN_CATEGORIES_VIEW = "admin/posts/categories";
  
      // endregion
  
      // region static message.properites
      private static final String MESSAGE_ADMIN_UPDATE_POSTLINK_TITLE = "admin.update.postlink.title";
      private static final String MESSAGE_ADMIN_SOLR_REINDEX_COMPLETE = "admin.solr.posts.reindexed";
      private static final String MESSAGE_ADMIN_POSTMETA_UPDATE_COMPLETE = "admin.posts.postmeta.updated";
  
      private static final String MESSAGE_ADMIN_UPDATE_POSTLINK_HEADING = "admin.update.postlink.heading";
      private static final String ADD_POST_HEADER = "posts.add.note.page.header";
  
      private static final String ADD_LINK_HEADER = "posts.add.link.page.header";
      private static final String FEEDBACK_POST_LINK_ADDED = "feedback.post.link.added";
      private static final String FEEDBACK_POST_POST_ADDED = "feedback.post.post.added";
      public static final String FEEDBACK_POST_UPDATED = "feedback.post.updated";
      private static final String FEEDBACK_MESSAGE_TAG_ADDED = "feedback.message.tag.added";
      private static final String FEEDBACK_MESSAGE_TAG_ERROR = "feedback.message.tag.error";
      private static final String FEEDBACK_MESSAGE_TAG_UPDATED = "feedback.message.tag.updated";
      private static final String FEEDBACK_MESSAGE_TAG_DELETED = "feedback.message.tag.deleted";
  
      private static final String FEEDBACK_MESSAGE_CATEGORY_ADDED = "feedback.message.category.added";
      private static final String FEEDBACK_MESSAGE_CATEGORY_ERROR = "feedback.message.category.error";
      private static final String FEEDBACK_MESSAGE_CATEGORY_UPDATED = "feedback.message.category.updated";
      private static final String FEEDBACK_MESSAGE_CATEGORY_DELETED = "feedback.message.category.deleted";
  
      private static final String UNCATEGORIZED_CANNOT_BE_DELETED = "category.uncategorized.cannot.be.deleted";
      private static final String UNCATEGORIZED_CANNOT_BE_UPDATED = "category.uncategorized.cannot.be.updated";
  
      // endregion
  
      // region class variables
  
      private static final String SESSION_ATTRIBUTE_NEWPOST = "activepostdto";
      public static final String POST_PUBLISH = "publish";
      public static final String POST_DRAFT = "draft";
  
      // endregion
  
      // region beans
  
      private final PostService postService;
      private final PostDocService postDocService;
      private final WebUI webUI;
      private final FmService fmService;
      private final JsoupService jsoupService;
      private final ApplicationSettings applicationSettings;
  
      // endregion
  
      // region Constructor
  
      private static final Logger logger = LoggerFactory.getLogger(AdminPostsController.class);
  
      @Autowired
      public AdminPostsController(PostService postService, PostDocService postDocService, WebUI webUI, FmService fmService, JsoupService jsoupService, ApplicationSettings applicationSettings) {
          this.postService = postService;
          this.postDocService = postDocService;
          this.webUI = webUI;
          this.fmService = fmService;
          this.jsoupService = jsoupService;
          this.applicationSettings = applicationSettings;
      }
  
      // endregion
  
      //region Posts List
  
      @RequestMapping(value = "", method = GET)
      public ModelAndView postsListPage(@RequestParam(value = "allposts", required = false, defaultValue = "false") Boolean allPosts) {
          ModelAndView mav = new ModelAndView();
          int pageLength = 25;
          if (allPosts) {
              mav.addObject("posts", postService.getAllPosts());
              mav.addObject("allposts", true);
              pageLength = 200;
          } else {
              mav.addObject("posts", postService.getAdminRecentPosts());
          }
          mav.addObject("pageLength", pageLength);
          mav.setViewName(ADMIN_POSTS_LIST_VIEW);
          return mav;
      }
  
      //endregion
  
      // region Solr
  
      @RequestMapping(value = "/solr/reindex", method = GET)
      public ModelAndView postsSolrReindexPage() {
          ModelAndView mav = new ModelAndView();
          mav.addObject("solrEnabled", applicationSettings.getSolrEnabled());
          mav.setViewName(ADMIN_POSTS_REINDEX_VIEW);
          return mav;
      }
  
      @RequestMapping(value = "/solr/reindex", params = "reindex", method = GET)
      public ModelAndView reindexSolrPosts() {
          ModelAndView mav = new ModelAndView();
          List<Post> posts = postService.getAllPublishedPosts();
          int postDocCount = posts.size();
  
          long lStartTime = new Date().getTime();
          postDocService.reindexPosts(posts);
          long lEndTime = new Date().getTime();
          long duration = lEndTime - lStartTime;
  
          String totalTime = String.format("%d min, %d sec",
                  TimeUnit.MILLISECONDS.toMinutes(duration),
                  TimeUnit.MILLISECONDS.toSeconds(duration) -
                          TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(duration))
          );
  
  
          String reindexMessage = webUI.getMessage(MESSAGE_ADMIN_SOLR_REINDEX_COMPLETE, postDocCount, totalTime);
  
          mav.addObject("reindexMessage", reindexMessage);
          mav.addObject("hasPostDocCount", true);
          mav.setViewName(ADMIN_POSTS_REINDEX_VIEW);
          return mav;
      }
  
  
      // endregion
  
      // region Update PostMeta  Info
  
      @RequestMapping(value = "/postmeta", method = GET)
      public ModelAndView postMetaUpdatePage() {
          ModelAndView mav = new ModelAndView();
          mav.setViewName(ADMIN_POSTMETA_UPDATE_VIEW);
          return mav;
      }
  
      @RequestMapping(value = "/postmeta", params = "update", method = GET)
      public ModelAndView updatePostMetaData() {
          ModelAndView mav = new ModelAndView();
          List<Post> posts = postService.getAllPublishedPosts();
          int postMetaCount = posts.size();
  
          long lStartTime = new Date().getTime();
          jsoupService.updateAllPostMeta(posts);
          long lEndTime = new Date().getTime();
          long duration = lEndTime - lStartTime;
  
          String totalTime = String.format("%d min, %d sec",
                  TimeUnit.MILLISECONDS.toMinutes(duration),
                  TimeUnit.MILLISECONDS.toSeconds(duration) -
                          TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(duration))
          );
  
  
          String updateMessage = webUI.getMessage(MESSAGE_ADMIN_SOLR_REINDEX_COMPLETE, postMetaCount, totalTime);
  
          mav.addObject("updateMessage", updateMessage);
          mav.addObject("hasPostMetaCount", true);
          mav.setViewName(ADMIN_POSTMETA_UPDATE_VIEW);
          return mav;
      }
      // endregion
  
      //region Add Post GET
  
      @RequestMapping(value = "/add/{type}", method = GET)
      public String addPostLink(@PathVariable("type") String type, Model model, HttpServletRequest request) {
          PostType postType = PostType.valueOf(type.toUpperCase());
          model.addAttribute("postDTO", new PostDTO());
          model.addAttribute("canPreview", false);
          model.addAttribute("categories", postService.getAdminSelectionCategories());
          if (postType == PostType.POST) {
              WebUtils.setSessionAttribute(request, SESSION_ATTRIBUTE_NEWPOST, null);
              model.addAttribute("hasPost", true);
              model.addAttribute("postheader", webUI.getMessage(ADD_POST_HEADER));
              return ADMIN_POST_ADD_VIEW;
          } else {
              model.addAttribute("postLink", new PostLink());
              model.addAttribute("postheader", webUI.getMessage(ADD_LINK_HEADER));
              return ADMIN_LINK_ADD_VIEW;
          }
      }
  
      @RequestMapping(value = "/add/link", params = {"isLink"}, method = GET)
      public String addLink(@RequestParam(value = "isLink") Boolean isLink,
                            @Valid PostLink postLink, BindingResult result, Model model, HttpServletRequest request) {
          model.addAttribute("postheader", webUI.getMessage(ADD_LINK_HEADER));
          if (StringUtils.isEmpty(postLink.getLink())) {
              result.rejectValue("link", "post.link.is.empty");
          } else {
              PagePreviewDTO pagePreview = jsoupService.getPagePreview(postLink.getLink());
              if (pagePreview == null) {
                  result.rejectValue("link", "post.link.page.not.found");
                  return ADMIN_LINK_ADD_VIEW;
              } else {
                  model.addAttribute("categories", postService.getAdminSelectionCategories());
                  model.addAttribute("hasLink", true);
                  model.addAttribute("hasCarousel", true);
                  WebUtils.setSessionAttribute(request, "pagePreview", pagePreview);
                  model.addAttribute("pagePreview", pagePreview);
                  model.addAttribute("postDTO",
                          postDtoFromPagePreview(pagePreview, postLink.getLink()));
              }
          }
          return ADMIN_LINK_ADD_VIEW;
      }
  
      //endregion
  
      //region Add Post POST
  
      @RequestMapping(value = "/add/link", method = POST)
      public String createLinkPost(@Valid PostDTO postDTO, BindingResult result,
                                   CurrentUser currentUser, RedirectAttributes attributes, Model model,
                                   HttpServletRequest request) throws DuplicatePostNameException {
          PagePreviewDTO pagePreview =
                  (PagePreviewDTO) WebUtils.getSessionAttribute(request, "pagePreview");
  
          model.addAttribute("postheader", webUI.getMessage(ADD_LINK_HEADER));
          model.addAttribute("postFormType", "link");
  
          if (!isDuplicatePost(postDTO, null)) {
  