2 // Author: Berlin Brown
6 package org
.spirit
.lift
.agents
8 import java
.util
.Random
9 import org
.springframework
.context
.{ApplicationContext
=> AC
}
10 import org
.spirit
.dao
.impl
.{BotListUserVisitLogDAOImpl
=> LogDAO
}
11 import org
.spirit
.dao
.impl
.{BotListSessionRequestLogDAOImpl
=> SessDAO
}
12 import org
.spirit
.bean
.impl
.{BotListUserVisitLog
=> Log
}
13 import org
.spirit
.bean
.impl
.{BotListSessionRequestLog
=> Sess
}
15 import org
.spirit
.dao
.impl
.{BotListForumGroupDAOImpl
=> ForumDAO
}
16 import org
.spirit
.bean
.impl
.{BotListForumGroup
=> ForumGroup
}
17 import org
.spirit
.bean
.impl
.{BotListUserComments
=> ChatComment
}
19 import net
.liftweb
.http
._
20 import net
.liftweb
.http
.S
._
21 import net
.liftweb
.http
.S
22 import scala
.xml
.{NodeSeq
, Text
, Group
}
23 import net
.liftweb
.util
.Helpers
._
24 import javax
.servlet
.http
.{HttpServlet
, HttpServletRequest
, HttpServletResponse
, HttpSession
}
27 import org
.spirit
.lift
.agents
.model
.{AgentMessage
}
31 * Create a unique string id based on; random number and client ip.
33 def uniqueMsgId (clientip
: String
) : String
= {
34 val t
= (System
.currentTimeMillis
) + 1
36 val rand_long
= r
.nextLong
37 hexEncode(md5( (clientip
+ rand_long
).getBytes
))
39 def auditLogPage (dao
: LogDAO
, request
: HttpServletRequest
, curPage
: String
) = {
41 link
.setRequestUri(request
.getRequestURI
)
42 link
.setRequestPage(curPage
)
43 link
.setHost(request
.getHeader("host"))
44 link
.setReferer(request
.getHeader("referer"))
45 link
.setRemoteHost(request
.getRemoteAddr())
46 link
.setUserAgent(request
.getHeader("user-agent"))
47 dao
.createVisitLog(link
)
49 def createBotForumMsg(httpRequest
: HttpServletRequest
, user
: String
, msg
: String
, title
: String
) {
50 // TODO: do not hard code the forum id.
51 val chatForumGroupId
= 3
52 val bean_obj
= AgentUtil
.getAC(httpRequest
).getBean("forumGroupDaoBean")
53 val forum_dao
= bean_obj
.asInstanceOf
[ForumDAO
]
55 // Populate the comment data
56 val comment
= new ChatComment
57 comment
.setFullName(user
)
58 comment
.setSubject(title
)
59 comment
.setMessage(msg
)
61 // Hibernate oriented approach for creating a comment topic
62 val sessionFactory
= forum_dao
.getSessionFactory
63 val hbm_session
= sessionFactory
.openSession
64 val tx
= hbm_session
.beginTransaction
66 val forum_obj
= hbm_session
.load("org.spirit.bean.impl.BotListForumGroup",
67 new java
.lang
.Long(chatForumGroupId
), null)
68 val forum
= forum_obj
.asInstanceOf
[ForumGroup
]
69 comment
.setForumId(new java
.lang
.Long(chatForumGroupId
))
70 val topics
= forum
.getTopics()
71 // TODO: with release 2.7, this code does not work.
76 def buildRequestSession (dao
: SessDAO
, request
: HttpServletRequest
, key
:String
, value
:String
):String
= {
78 val remote_host
= request
.getRemoteAddr
79 val u_id
= uniqueMsgId(remote_host
)
80 sess
.setRemoteHost(remote_host
)
82 sess
.setMsgValue(value
)
83 sess
.setRequestId(u_id
)
84 dao
.createSessionLog(sess
)
87 def getAC(request
: HttpServletRequest
) = {
88 val sess
= request
.getSession
89 val sc
= sess
.getServletContext
91 // Cast to the application context
92 val acobj
= sc
.getAttribute("org.springframework.web.servlet.FrameworkServlet.CONTEXT.botlistings")
93 acobj
.asInstanceOf
[AC
]
95 def invalidXMLResponse
: XmlResponse
= {
97 <rdf
:RDF xmlns
:rdf
="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
99 <botid
>serverbot
</botid
>
100 <message
>Oops
. Something went wrong
.</message
>
105 def validPostXMLResponse
: XmlResponse
= {
107 <rdf
:RDF xmlns
:rdf
="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
109 <botid
>serverbot
</botid
>
110 <message
>Thanks
, I hope you enjoy your cake
.</message
>