From 526f6d69a6c52995865e11cd2fef23ee6ae81e3f Mon Sep 17 00:00:00 2001 From: Richard Alam Date: Thu, 4 Jul 2013 20:49:23 +0000 Subject: [PATCH] - implement taking poll --- .../core/BigBlueButtonInGW.scala | 2 +- .../bigbluebutton/core/apps/poll/Poll.scala | 4 +- .../core/apps/poll/PollApp.scala | 22 +++++++ .../core/apps/poll/PollInGateway.scala | 4 +- .../core/apps/poll/PollMessageConverter.scala | 2 +- .../core/apps/poll/PollModel.scala | 2 +- .../apps/poll/messages/PollMessages.scala | 3 +- .../poll/red5/PollClientMessageSender.scala | 17 +++++ .../core/apps/users/UsersApp.scala | 4 ++ .../modules/polling/model/Poll.as | 11 ++-- .../modules/polling/model/PollingModel.as | 4 +- .../polling/service/PollDataProcessor.as | 64 +++++++++++++++++-- .../modules/polling/vo/PollResponseVO.as | 2 +- 13 files changed, 119 insertions(+), 22 deletions(-) diff --git a/bigbluebutton-apps/src/main/scala/org/bigbluebutton/core/BigBlueButtonInGW.scala b/bigbluebutton-apps/src/main/scala/org/bigbluebutton/core/BigBlueButtonInGW.scala index eae8d8767b..cd3c2370f3 100755 --- a/bigbluebutton-apps/src/main/scala/org/bigbluebutton/core/BigBlueButtonInGW.scala +++ b/bigbluebutton-apps/src/main/scala/org/bigbluebutton/core/BigBlueButtonInGW.scala @@ -156,6 +156,6 @@ class BigBlueButtonInGW(bbbGW: BigBlueButtonGateway) extends IBigBlueButtonInGW } def respondPoll(meetingID: String, requesterID: String, msg: String) { - + pollGW.respondPoll(meetingID, requesterID, msg) } } \ No newline at end of file diff --git a/bigbluebutton-apps/src/main/scala/org/bigbluebutton/core/apps/poll/Poll.scala b/bigbluebutton-apps/src/main/scala/org/bigbluebutton/core/apps/poll/Poll.scala index b616a982f9..fdba26f599 100755 --- a/bigbluebutton-apps/src/main/scala/org/bigbluebutton/core/apps/poll/Poll.scala +++ b/bigbluebutton-apps/src/main/scala/org/bigbluebutton/core/apps/poll/Poll.scala @@ -3,8 +3,8 @@ package org.bigbluebutton.core.apps.poll import scala.collection.mutable.HashMap import scala.collection.mutable.ArrayBuffer -case class QuestionResponsesVO(val questionID:String, val responses:Array[String]) -case class PollResponseVO(val responses: Array[QuestionResponsesVO]) +case class QuestionResponsesVO(val questionID:String, val responseIDs:Array[String]) +case class PollResponseVO(val pollID: String, val responses: Array[QuestionResponsesVO]) case class ResponderVO(responseID: String, user: Responder) case class ResponseVO(id: String, text: String, responders: Array[Responder] = Array[Responder]()) diff --git a/bigbluebutton-apps/src/main/scala/org/bigbluebutton/core/apps/poll/PollApp.scala b/bigbluebutton-apps/src/main/scala/org/bigbluebutton/core/apps/poll/PollApp.scala index dcbd3ec9f7..c81899a833 100755 --- a/bigbluebutton-apps/src/main/scala/org/bigbluebutton/core/apps/poll/PollApp.scala +++ b/bigbluebutton-apps/src/main/scala/org/bigbluebutton/core/apps/poll/PollApp.scala @@ -22,10 +22,32 @@ class PollApp(meetingID: String, recorded: Boolean, outGW: MessageOutGateway, us case startPoll: StartPoll => handleStartPoll(startPoll) case clearPoll: ClearPoll => handleClearPoll(clearPoll) case getPolls: GetPolls => handleGetPolls(getPolls) + case respondPoll: RespondToPoll => handleRespondToPoll(respondPoll) case _ => // do nothing } } + private def handleRespondToPoll(msg: RespondToPoll) { + val pollID = msg.response.pollID + + if (model.hasPoll(pollID)) { + if (usersApp.hasUser(msg.requesterID)) { + val user = usersApp.getUser(msg.requesterID) + val responder = new Responder(user.userID, user.name) + msg.response.responses.foreach(question => { + question.responseIDs.foreach(response => { + model.respondToQuestion(pollID, question.questionID, response, responder) + }) + }) + + model.getPoll(msg.response.pollID) match { + case Some(poll) => outGW.send(new PollResponseOutMsg(meetingID, recorded, responder, msg.response)) + case None => // do nothing + } + } + } + } + private def handleGetPolls(msg: GetPolls) { var polls = model.getPolls outGW.send(new GetPollsReplyOutMsg(meetingID, recorded, msg.requesterID, polls)) diff --git a/bigbluebutton-apps/src/main/scala/org/bigbluebutton/core/apps/poll/PollInGateway.scala b/bigbluebutton-apps/src/main/scala/org/bigbluebutton/core/apps/poll/PollInGateway.scala index 5e1ee66d6c..08e27a7977 100755 --- a/bigbluebutton-apps/src/main/scala/org/bigbluebutton/core/apps/poll/PollInGateway.scala +++ b/bigbluebutton-apps/src/main/scala/org/bigbluebutton/core/apps/poll/PollInGateway.scala @@ -8,6 +8,7 @@ import org.bigbluebutton.core.apps.poll.messages.StartPoll import org.bigbluebutton.core.apps.poll.messages.StopPoll import org.bigbluebutton.core.apps.poll.messages.RemovePoll import org.bigbluebutton.core.apps.poll.messages.GetPolls +import org.bigbluebutton.core.apps.poll.messages.RespondToPoll class PollInGateway(bbbGW: BigBlueButtonGateway) { @@ -43,6 +44,7 @@ class PollInGateway(bbbGW: BigBlueButtonGateway) { } def respondPoll(meetingID: String, requesterID: String, msg: String) { - + val pollResponse = msgConverter.convertTakePollMessage(msg) + bbbGW.accept(new RespondToPoll(meetingID, requesterID, pollResponse)) } } \ No newline at end of file diff --git a/bigbluebutton-apps/src/main/scala/org/bigbluebutton/core/apps/poll/PollMessageConverter.scala b/bigbluebutton-apps/src/main/scala/org/bigbluebutton/core/apps/poll/PollMessageConverter.scala index ae685cb6eb..681a17807a 100755 --- a/bigbluebutton-apps/src/main/scala/org/bigbluebutton/core/apps/poll/PollMessageConverter.scala +++ b/bigbluebutton-apps/src/main/scala/org/bigbluebutton/core/apps/poll/PollMessageConverter.scala @@ -152,6 +152,6 @@ class PollMessageConverter { qVO += new QuestionResponsesVO(questionID, rvoArray.toArray) } - new PollResponseVO(qVO.toArray) + new PollResponseVO(pollID, qVO.toArray) } } \ No newline at end of file diff --git a/bigbluebutton-apps/src/main/scala/org/bigbluebutton/core/apps/poll/PollModel.scala b/bigbluebutton-apps/src/main/scala/org/bigbluebutton/core/apps/poll/PollModel.scala index 4634309dbe..c944c58a1b 100755 --- a/bigbluebutton-apps/src/main/scala/org/bigbluebutton/core/apps/poll/PollModel.scala +++ b/bigbluebutton-apps/src/main/scala/org/bigbluebutton/core/apps/poll/PollModel.scala @@ -7,7 +7,7 @@ class PollModel { private val polls = new HashMap[String, Poll]() -// createSamplePoll + createSamplePoll def createSamplePoll() { addSamplePoll1() diff --git a/bigbluebutton-apps/src/main/scala/org/bigbluebutton/core/apps/poll/messages/PollMessages.scala b/bigbluebutton-apps/src/main/scala/org/bigbluebutton/core/apps/poll/messages/PollMessages.scala index 95890514d2..f9f972a312 100755 --- a/bigbluebutton-apps/src/main/scala/org/bigbluebutton/core/apps/poll/messages/PollMessages.scala +++ b/bigbluebutton-apps/src/main/scala/org/bigbluebutton/core/apps/poll/messages/PollMessages.scala @@ -17,7 +17,7 @@ case class StopPoll(meetingID:String, requesterID: String, pollID: String) exten case class StartPoll(meetingID:String, requesterID: String, pollID: String) extends InMessage case class ClearPoll(meetingID: String, requesterID: String, pollID: String, force: Boolean=false) extends InMessage case class GetPollResult(meetingID:String, requesterID: String, pollID: String) extends InMessage -case class RespondToPoll(meetingID: String, requesterID: String, pollID: String, responses : Array[PollResponseVO]) +case class RespondToPoll(meetingID: String, requesterID: String, response: PollResponseVO) extends InMessage @@ -35,3 +35,4 @@ case class PollStoppedOutMsg(meetingID: String, recorded: Boolean, pollID: Strin case class PollRemovedOutMsg(meetingID: String, recorded: Boolean, pollID: String) extends IOutMessage case class PollUpdatedOutMsg(meetingID: String, recorded: Boolean, pollID: String, pollVO: PollVO) extends IOutMessage case class PollCreatedOutMsg(meetingID: String, recorded: Boolean, pollID: String, pollVO: PollVO) extends IOutMessage +case class PollResponseOutMsg(meetingID: String, recorded: Boolean, responder: Responder, response: PollResponseVO) extends IOutMessage \ No newline at end of file diff --git a/bigbluebutton-apps/src/main/scala/org/bigbluebutton/core/apps/poll/red5/PollClientMessageSender.scala b/bigbluebutton-apps/src/main/scala/org/bigbluebutton/core/apps/poll/red5/PollClientMessageSender.scala index ad1a24ad8f..05d264d1e5 100755 --- a/bigbluebutton-apps/src/main/scala/org/bigbluebutton/core/apps/poll/red5/PollClientMessageSender.scala +++ b/bigbluebutton-apps/src/main/scala/org/bigbluebutton/core/apps/poll/red5/PollClientMessageSender.scala @@ -15,6 +15,7 @@ import com.google.gson.Gson import org.bigbluebutton.conference.meeting.messaging.red5.BroadcastClientMessage import java.util.ArrayList import org.bigbluebutton.core.apps.poll.PollVO +import org.bigbluebutton.core.apps.poll.messages.PollResponseOutMsg class PollClientMessageSender(service: ConnectionInvokerService) extends OutMessageListener2 { @@ -27,10 +28,26 @@ class PollClientMessageSender(service: ConnectionInvokerService) extends OutMess case pollRemovedOutMsg: PollRemovedOutMsg => handlePollRemovedOutMsg(pollRemovedOutMsg) case pollUpdatedOutMsg: PollUpdatedOutMsg => handlePollUpdatedOutMsg(pollUpdatedOutMsg) case pollCreatedOutMsg: PollCreatedOutMsg => handlePollCreatedOutMsg(pollCreatedOutMsg) + case pollResponseOutMsg: PollResponseOutMsg => handlePollResponseOutMsg(pollResponseOutMsg) case _ => // do nothing } } + private def handlePollResponseOutMsg(msg: PollResponseOutMsg) { + val gson = new Gson(); + val map = new java.util.HashMap[String, Object]() + map.put("responder", msg.responder) + map.put("response", msg.response) + + val message = new java.util.HashMap[String, Object]() + message.put("msg", gson.toJson(map)) + + println("PollClientMessageSender - Handling PollResponseOutMsg \n" + message.get("msg") + "\n") + + var m = new BroadcastClientMessage(msg.meetingID, "pollResultUpdatedMessage", message); + service.sendMessage(m); + } + private def handleGetPollsReplyOutMsg(msg: GetPollsReplyOutMsg) { val gson = new Gson(); val message = new java.util.HashMap[String, Object]() diff --git a/bigbluebutton-apps/src/main/scala/org/bigbluebutton/core/apps/users/UsersApp.scala b/bigbluebutton-apps/src/main/scala/org/bigbluebutton/core/apps/users/UsersApp.scala index 28fbd46a02..dd2dea8688 100755 --- a/bigbluebutton-apps/src/main/scala/org/bigbluebutton/core/apps/users/UsersApp.scala +++ b/bigbluebutton-apps/src/main/scala/org/bigbluebutton/core/apps/users/UsersApp.scala @@ -48,6 +48,10 @@ class UsersApp(meetingID: String, recorded: Boolean, outGW: MessageOutGateway) { currentPresenter } + def hasUser(userID: String):Boolean = { + users.hasUser(userID) + } + def getUser(userID:String):UserVO = { users.getUser(userID) } diff --git a/bigbluebutton-client/src/org/bigbluebutton/modules/polling/model/Poll.as b/bigbluebutton-client/src/org/bigbluebutton/modules/polling/model/Poll.as index fae3ef92ab..2c9374beea 100755 --- a/bigbluebutton-client/src/org/bigbluebutton/modules/polling/model/Poll.as +++ b/bigbluebutton-client/src/org/bigbluebutton/modules/polling/model/Poll.as @@ -71,13 +71,10 @@ package org.bigbluebutton.modules.polling.model return _questions; } - public function updateResults(results:ResultsVO):void { - for (var i:int = 0; i < results.results.length; i++) { - var r:ResultVO = results.results[i] as ResultVO; - var q:Question = getQuestion(r.questionID); - if (q != null) { - q.updateResult(r.responseID, r.responder); - } + public function updateResults(questionID:String, responseID:String, responder:Responder):void { + var q:Question = getQuestion(questionID); + if (q != null) { + q.updateResult(responseID, responder); } } diff --git a/bigbluebutton-client/src/org/bigbluebutton/modules/polling/model/PollingModel.as b/bigbluebutton-client/src/org/bigbluebutton/modules/polling/model/PollingModel.as index e78229aaad..4148cd1801 100755 --- a/bigbluebutton-client/src/org/bigbluebutton/modules/polling/model/PollingModel.as +++ b/bigbluebutton-client/src/org/bigbluebutton/modules/polling/model/PollingModel.as @@ -18,10 +18,10 @@ package org.bigbluebutton.modules.polling.model return _polls.toArray(); } - public function updateResults(pollID:String, results:ResultsVO):void { + public function updateResults(pollID:String, questionID:String, responseID:String, responder:Responder):void { if (hasPoll(pollID)) { var poll:Poll = getPoll(pollID); - poll.updateResults(results); + poll.updateResults(questionID, responseID, responder); } } diff --git a/bigbluebutton-client/src/org/bigbluebutton/modules/polling/service/PollDataProcessor.as b/bigbluebutton-client/src/org/bigbluebutton/modules/polling/service/PollDataProcessor.as index a768debea0..7bc2380987 100755 --- a/bigbluebutton-client/src/org/bigbluebutton/modules/polling/service/PollDataProcessor.as +++ b/bigbluebutton-client/src/org/bigbluebutton/modules/polling/service/PollDataProcessor.as @@ -83,13 +83,67 @@ package org.bigbluebutton.modules.polling.service } public function handlePollResultUpdatedMesage(msg:Object):void { - var pollResult:Object = JSON.parse(msg.mesage); + /*** Incoming message + * {"response":{"pollID":"pollID-103","responses":[{"questionID":"q1","responseIDs":["0","1"]}]},"responder":{"userID":"enfjadjc5xnn","name":"RED"}} + */ - if (! model.hasPoll(pollResult.id)) { - - model.updateResults(pollResult.id, msg.results); - dispatcher.dispatchEvent(new PollEvent(PollEvent.POLL_RESULTS_UPDATED, msg.id)); + trace(LOG + "*** Poll Result Update " + msg + " **** \n"); + + if (msg.foo == undefined) { + trace(LOG + "handlePollResultUpdatedMesage - No [foo] parameter."); } + + if (msg.msg == undefined) { + trace(LOG + "handlePollResultUpdatedMesage - No [msg] parameter."); + return; + } + + trace(LOG + "*** Poll Result Update " + msg.msg + " **** \n"); + var map:Object = JSON.parse(msg.msg); + + if (map.response == undefined) { + trace(LOG + "handlePollResultUpdatedMesage - No [response] parameter."); + return; + } + + var response:Object = map.response; + + if (response.pollID == undefined) { + trace(LOG + "handlePollResultUpdatedMesage - No [response.pollID] parameter."); + return; + } + + if (map.responder == undefined || map.responder.userID == undefined || map.responder.name == undefined) { + trace(LOG + "handlePollResultUpdatedMesage - No [responder] parameter."); + return; + } + + var responder:Responder = new Responder(map.responder.userID, map.responder.name); + + if (model.hasPoll(response.pollID)) { + if (response.responses == undefined) { + trace(LOG + "handlePollResultUpdatedMesage - No [response.responses] parameter."); + return; + } + var responses:Array = response.responses as Array; + + for (var j:int = 0; j < responses.length; j++) { + var resp:Object = responses[j]; + if (resp.questionID == undefined || resp.responseIDs == undefined) { + trace(LOG + "handlePollResultUpdatedMesage - No [response.questionID or response.responseIDs] parameter."); + return; + } + var questionID:String = resp.questionID; + + var responseIDs:Array = resp.responseIDs as Array; + for (var i:int = 0; i < responseIDs.length; i++) { + var respID:String = responseIDs[i] as String + model.updateResults(response.pollID, questionID, respID, responder); + } + } + trace(LOG + "*** handlePollResultUpdatedMesage pollID = [" + response.pollID + "] **** \n") + dispatcher.dispatchEvent(new PollEvent(PollEvent.POLL_RESULTS_UPDATED, response.pollID)); + } } public function handlePollCreatedMesage(msg:Object):void { diff --git a/bigbluebutton-client/src/org/bigbluebutton/modules/polling/vo/PollResponseVO.as b/bigbluebutton-client/src/org/bigbluebutton/modules/polling/vo/PollResponseVO.as index c4306dc2d0..00234713cd 100755 --- a/bigbluebutton-client/src/org/bigbluebutton/modules/polling/vo/PollResponseVO.as +++ b/bigbluebutton-client/src/org/bigbluebutton/modules/polling/vo/PollResponseVO.as @@ -22,7 +22,7 @@ package org.bigbluebutton.modules.polling.vo public function toMap():Object { var map:Object = new Object(); - map.id = _id; + map.pollID = _id; map.questions = _questions; return map;