From 0c3d4402057ff446129ded0635a350c3bcaa5eab Mon Sep 17 00:00:00 2001 From: Stanislav Date: Mon, 25 Jan 2016 14:12:26 +0300 Subject: [PATCH] JC-2282 Fixed request mapping for QnA plugin --- ...nsactionalTypeAwarePluginTopicService.java | 2 +- .../web/controller/TopicController.java | 21 +++++++++++++++++++ .../web/controller/TopicControllerTest.java | 4 ++++ .../WEB-INF/spring-dispatcher-servlet.xml | 2 ++ 4 files changed, 28 insertions(+), 1 deletion(-) diff --git a/jcommune-plugin-api/src/main/java/org/jtalks/jcommune/plugin/api/service/transactional/TransactionalTypeAwarePluginTopicService.java b/jcommune-plugin-api/src/main/java/org/jtalks/jcommune/plugin/api/service/transactional/TransactionalTypeAwarePluginTopicService.java index 2f9a8cfb68..9c4b072168 100644 --- a/jcommune-plugin-api/src/main/java/org/jtalks/jcommune/plugin/api/service/transactional/TransactionalTypeAwarePluginTopicService.java +++ b/jcommune-plugin-api/src/main/java/org/jtalks/jcommune/plugin/api/service/transactional/TransactionalTypeAwarePluginTopicService.java @@ -82,7 +82,7 @@ public void setTopicModificationService(PluginTopicModificationService topicModi */ public Topic get(Long id, String type) throws NotFoundException { Topic topic = topicFetchService.get(id); - if (!topic.getType().equals(type)) { + if (!topic.getType().equalsIgnoreCase(type)) { throw new NotFoundException(); } return topic; diff --git a/jcommune-view/jcommune-web-controller/src/main/java/org/jtalks/jcommune/web/controller/TopicController.java b/jcommune-view/jcommune-web-controller/src/main/java/org/jtalks/jcommune/web/controller/TopicController.java index 5748ab3044..333e65dec7 100644 --- a/jcommune-view/jcommune-web-controller/src/main/java/org/jtalks/jcommune/web/controller/TopicController.java +++ b/jcommune-view/jcommune-web-controller/src/main/java/org/jtalks/jcommune/web/controller/TopicController.java @@ -18,6 +18,7 @@ import org.joda.time.DateTime; import org.jtalks.jcommune.model.entity.*; import org.jtalks.jcommune.plugin.api.exceptions.NotFoundException; +import org.jtalks.jcommune.plugin.api.service.transactional.TransactionalTypeAwarePluginTopicService; import org.jtalks.jcommune.plugin.api.web.dto.PostDto; import org.jtalks.jcommune.plugin.api.web.dto.TopicDto; import org.jtalks.jcommune.plugin.api.web.dto.json.JsonResponse; @@ -75,6 +76,7 @@ public class TopicController { private TopicModificationService topicModificationService; private TopicFetchService topicFetchService; + private TransactionalTypeAwarePluginTopicService pluginTopicService; private TopicDraftService topicDraftService; private PostService postService; private BranchService branchService; @@ -117,6 +119,7 @@ public void initBinder(WebDataBinder binder) { @Autowired public TopicController(TopicModificationService topicModificationService, PostService postService, + TransactionalTypeAwarePluginTopicService pluginTopicService, BranchService branchService, LastReadPostService lastReadPostService, UserService userService, @@ -129,6 +132,7 @@ public TopicController(TopicModificationService topicModificationService, RetryTemplate retryTemplate) { this.topicModificationService = topicModificationService; this.postService = postService; + this.pluginTopicService = pluginTopicService; this.branchService = branchService; this.lastReadPostService = lastReadPostService; this.userService = userService; @@ -291,6 +295,23 @@ public ModelAndView showTopicPage(WebRequest request, @PathVariable(TOPIC_ID) Lo .addObject(BREADCRUMB_LIST, breadcrumbBuilder.getForumBreadcrumb(topic)); } + /** + * Displays to user a list of messages from the topic with pagination + * + * @param topicId the id of selected Topic + * @param page page + * @return {@code ModelAndView} + * @throws NotFoundException when topic or branch not found + */ + @RequestMapping(value = "/topics/{topicType:[A-Za-z]+}/{topicId}", method = RequestMethod.GET) + public String showTopicPage(WebRequest request,@PathVariable() String topicType, @PathVariable(TOPIC_ID) Long topicId, + @RequestParam(value = "page", defaultValue = "1", required = false) String page) + throws NotFoundException { + Topic topic = pluginTopicService.get(topicId, topicType); + + return "redirect:/topics/"+topicId; + } + /** * Shows edit topic page with form, populated with fields from topic. * diff --git a/jcommune-view/jcommune-web-controller/src/test/java/org/jtalks/jcommune/web/controller/TopicControllerTest.java b/jcommune-view/jcommune-web-controller/src/test/java/org/jtalks/jcommune/web/controller/TopicControllerTest.java index 42162658d7..27d3722648 100644 --- a/jcommune-view/jcommune-web-controller/src/test/java/org/jtalks/jcommune/web/controller/TopicControllerTest.java +++ b/jcommune-view/jcommune-web-controller/src/test/java/org/jtalks/jcommune/web/controller/TopicControllerTest.java @@ -17,6 +17,7 @@ import org.jtalks.common.model.entity.Section; import org.jtalks.jcommune.model.dto.PageRequest; import org.jtalks.jcommune.model.entity.*; +import org.jtalks.jcommune.plugin.api.service.transactional.TransactionalTypeAwarePluginTopicService; import org.jtalks.jcommune.service.*; import org.jtalks.jcommune.plugin.api.exceptions.NotFoundException; import org.jtalks.jcommune.service.nontransactional.LocationService; @@ -89,6 +90,8 @@ public class TopicControllerTest { private LastReadPostService lastReadPostService; @Mock private EntityToDtoConverter converter; + @Mock + private TransactionalTypeAwarePluginTopicService pluginTopicService; private TopicController controller; @Mock @@ -104,6 +107,7 @@ public void initEnvironment() { controller = new TopicController( topicModificationService, postService, + pluginTopicService, branchService, lastReadPostService, userService, diff --git a/jcommune-view/jcommune-web-view/src/main/webapp/WEB-INF/spring-dispatcher-servlet.xml b/jcommune-view/jcommune-web-view/src/main/webapp/WEB-INF/spring-dispatcher-servlet.xml index 56326104eb..a39faeaa61 100644 --- a/jcommune-view/jcommune-web-view/src/main/webapp/WEB-INF/spring-dispatcher-servlet.xml +++ b/jcommune-view/jcommune-web-view/src/main/webapp/WEB-INF/spring-dispatcher-servlet.xml @@ -31,6 +31,8 @@ + +