5 ## Add topic is only available for logged in users.
\r
9 require File.join(File.dirname(__FILE__), '../../WEB-INF/lib/ruby/web', 'web_core')
\r
11 include_class 'org.spirit.spring.validate.BotListAddTopicValidator' unless defined? BotListAddTopicValidator
\r
12 include_class 'org.spirit.contract.BotListContractManager' unless defined? BotListContractManager
\r
13 include_class 'org.spirit.form.BotListSearchQueryFiltersForm' unless defined? BotListSearchQueryFiltersForm
\r
14 include_class 'org.spirit.bean.impl.BotListSearchQueryFilters' unless defined? BotListSearchQueryFilters
\r
16 class AddTopicController
\r
18 def initialize(controller)
\r
19 @log = LogFactory::getLog("org.jruby")
\r
20 @controller = controller
\r
21 @daohelper = @controller.searchQueryFiltersDao
\r
24 def getModel(request)
\r
25 topicForm = BotListSearchQueryFiltersForm.new
\r
26 topicForm.viewName = nil
\r
28 if !BotListWebCore.userLoggedIn?(request)
\r
29 topicForm.viewName = "errorInvalidView"
\r
33 queryLine = request.getParameter("query")
\r
34 topicForm.searchTerm = queryLine
\r
37 @controller.auditLogPage(request, "addtopic.html")
\r
39 # Also set the validator
\r
40 @controller.setValidator(BotListAddTopicValidator.new)
\r
44 def onSubmit(request, response, form, errors)
\r
45 # Check the errors first.
\r
46 if errors.getErrorCount() > 0
\r
47 # Revert back to the entry screen
\r
48 form.viewName = "search/addtopic"
\r
52 # Transform the business object from the form.
\r
53 topic = BotListSearchQueryFilters.new
\r
54 topic.rating = 0; topic.views = 0
\r
55 topic.userId = 1; topic.userName = "blah"
\r
56 topic.description = form.description
\r
57 topic.searchTerm = form.searchTerm
\r
58 # Save hot topic record
\r
60 sessionFactory = @daohelper.getSessionFactory()
\r
61 hbm_session = sessionFactory.openSession()
\r
62 tx = hbm_session.beginTransaction()
\r
63 hbm_session.save(topic)
\r
65 rescue Exception => e
\r
71 # Navigate to the confirmation page
\r
72 form.viewName = "botverse/botverse_confirm"
\r
79 AddTopicController.new($controller)
\r