- handle polling message from flash client
- write unit test for conversion of messages
This commit is contained in:
parent
9c4a629a8c
commit
c82689cbb7
@ -18,16 +18,44 @@
|
|||||||
*/
|
*/
|
||||||
package org.bigbluebutton.conference.service.poll;
|
package org.bigbluebutton.conference.service.poll;
|
||||||
|
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
import org.bigbluebutton.core.api.IBigBlueButtonInGW;
|
||||||
import org.red5.logging.Red5LoggerFactory;
|
import org.red5.logging.Red5LoggerFactory;
|
||||||
|
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
import com.google.gson.JsonArray;
|
||||||
|
import com.google.gson.JsonObject;
|
||||||
|
import com.google.gson.JsonParser;
|
||||||
|
|
||||||
|
|
||||||
public class PollService {
|
public class PollService {
|
||||||
private static Logger log = Red5LoggerFactory.getLogger( PollService.class, "bigbluebutton" );
|
private static Logger log = Red5LoggerFactory.getLogger( PollService.class, "bigbluebutton" );
|
||||||
|
|
||||||
|
private IBigBlueButtonInGW bbbInGW;
|
||||||
|
|
||||||
|
public void setBigBlueButtonInGW(IBigBlueButtonInGW inGW) {
|
||||||
|
bbbInGW = inGW;
|
||||||
|
}
|
||||||
|
|
||||||
public void createPoll(String msg){
|
public void createPoll(String msg){
|
||||||
System.out.println("*** PollService:: create poll \n" + msg + "\n");
|
System.out.println("*** PollService:: create poll \n" + msg + "\n");
|
||||||
|
//{"title":"My sample poll","questions":[{"type":"MULTI_CHOICE","responses":["Answer 1","Answer 2","Answer 3"],"question":"What is my name?"}]}
|
||||||
|
|
||||||
|
Gson gson = new Gson();
|
||||||
|
|
||||||
|
JsonParser parser = new JsonParser();
|
||||||
|
JsonObject obj = parser.parse(msg).getAsJsonObject();
|
||||||
|
String title = gson.fromJson(obj.get("title"), String.class);
|
||||||
|
|
||||||
|
JsonArray questions = obj.get("questions").getAsJsonArray();
|
||||||
|
//you can do a loop
|
||||||
|
JsonObject aquestion = questions.get(0).getAsJsonObject();
|
||||||
|
String type = gson.fromJson(aquestion.get("type"), String.class);
|
||||||
|
|
||||||
|
JsonArray responses = aquestion.get("responses").getAsJsonArray();
|
||||||
|
String response = gson.fromJson(responses.get(0), String.class);
|
||||||
|
|
||||||
|
System.out.println(title + ": " + type + " :" + response);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -25,28 +25,28 @@ class PollApp(meetingID: String, recorded: Boolean, outGW: MessageOutGateway) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private def handleGetPolls(msg: GetPolls) {
|
private def handleGetPolls(msg: GetPolls) {
|
||||||
val poll = new ArrayBuffer[PollVO]
|
val poll = new ArrayBuffer[PollVOOut]
|
||||||
|
|
||||||
polls.values.foreach(p => {
|
polls.values.foreach(p => {
|
||||||
val questions = new ArrayBuffer[QuestionVO]
|
val questions = new ArrayBuffer[QuestionVOOut]
|
||||||
p.questions.foreach(q => {
|
p.questions.foreach(q => {
|
||||||
val responses = new ArrayBuffer[ResponseVO]
|
val responses = new ArrayBuffer[ResponseVOOut]
|
||||||
q.responses.foreach(response => {
|
q.responses.foreach(response => {
|
||||||
val r = new ResponseVO(response.id, response.response)
|
val r = new ResponseVOOut(response.id, response.response)
|
||||||
responses += r
|
responses += r
|
||||||
})
|
})
|
||||||
val rArray = new Array[ResponseVO](responses.length)
|
val rArray = new Array[ResponseVOOut](responses.length)
|
||||||
responses.copyToArray(rArray)
|
responses.copyToArray(rArray)
|
||||||
val quest = new QuestionVO(q.id, q.questionType, q.question, rArray)
|
val quest = new QuestionVOOut(q.id, q.questionType, q.question, rArray)
|
||||||
questions += quest
|
questions += quest
|
||||||
})
|
})
|
||||||
val qArray = new Array[QuestionVO](questions.length)
|
val qArray = new Array[QuestionVOOut](questions.length)
|
||||||
questions.copyToArray(qArray)
|
questions.copyToArray(qArray)
|
||||||
|
|
||||||
poll += new PollVO(p.id, p.title, qArray)
|
poll += new PollVOOut(p.id, p.title, qArray)
|
||||||
})
|
})
|
||||||
|
|
||||||
val pArray = new Array[PollVO](poll.length)
|
val pArray = new Array[PollVOOut](poll.length)
|
||||||
poll.copyToArray(pArray)
|
poll.copyToArray(pArray)
|
||||||
outGW.send(new GetPollsReplyOutMsg(meetingID, recorded, msg.requesterID, pArray))
|
outGW.send(new GetPollsReplyOutMsg(meetingID, recorded, msg.requesterID, pArray))
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,8 @@
|
|||||||
|
package org.bigbluebutton.core.apps.poll
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class PollInGateway {
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,46 @@
|
|||||||
|
package org.bigbluebutton.core.apps.poll
|
||||||
|
|
||||||
|
import org.bigbluebutton.core.apps.poll.messages.PollVO
|
||||||
|
import com.google.gson.Gson
|
||||||
|
import com.google.gson.JsonParser
|
||||||
|
import org.bigbluebutton.core.apps.poll.messages.QuestionVO
|
||||||
|
import org.bigbluebutton.core.apps.poll.messages.ResponseVO
|
||||||
|
import org.bigbluebutton.core.util.RandomStringGenerator._
|
||||||
|
|
||||||
|
class PollMessageConverter {
|
||||||
|
|
||||||
|
def convertCreatePollMessage(msg:String):PollVO = {
|
||||||
|
val gson = new Gson();
|
||||||
|
val parser = new JsonParser();
|
||||||
|
val obj = parser.parse(msg).getAsJsonObject();
|
||||||
|
val title = gson.fromJson(obj.get("title"), classOf[String]);
|
||||||
|
|
||||||
|
val questions = obj.get("questions").getAsJsonArray();
|
||||||
|
|
||||||
|
var cvoArray = Array[QuestionVO]()
|
||||||
|
|
||||||
|
var i = 0
|
||||||
|
for (i <- 0 to questions.size() - 1) {
|
||||||
|
val aquestion = questions.get(i).getAsJsonObject();
|
||||||
|
val questionText = gson.fromJson(aquestion.get("question"), classOf[String])
|
||||||
|
val qType = gson.fromJson(aquestion.get("type"), classOf[String])
|
||||||
|
|
||||||
|
val responses = aquestion.get("responses").getAsJsonArray();
|
||||||
|
val rvoArray = Array[ResponseVO]()
|
||||||
|
|
||||||
|
var j = 0
|
||||||
|
for (j <- 0 to responses.size() - 1) {
|
||||||
|
val response = gson.fromJson(responses.get(0), classOf[String]);
|
||||||
|
rvoArray :+ new ResponseVO(j.toString, response)
|
||||||
|
}
|
||||||
|
|
||||||
|
val questionType = if (qType.equalsIgnoreCase(QuestionType.MultiChoice.toString())) QuestionType.MultiChoice else QuestionType.MultiResponse
|
||||||
|
|
||||||
|
cvoArray :+ new QuestionVO(i.toString, questionType, questionText, rvoArray)
|
||||||
|
}
|
||||||
|
|
||||||
|
new PollVO(randomAlphanumericString(12), title, cvoArray)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -6,7 +6,7 @@ import org.bigbluebutton.core.api.InMessage
|
|||||||
import org.bigbluebutton.core.api.IOutMessage
|
import org.bigbluebutton.core.api.IOutMessage
|
||||||
|
|
||||||
// Poll Messages
|
// Poll Messages
|
||||||
case class CreatePoll(meetingID:String, poll: PollVO, requesterID: String) extends InMessage
|
case class CreatePoll(meetingID: String, poll: PollVO, requesterID: String) extends InMessage
|
||||||
case class UpdatePoll(meetingID: String, poll: PollVO) extends InMessage
|
case class UpdatePoll(meetingID: String, poll: PollVO) extends InMessage
|
||||||
case class GetPolls(meetingID: String, requesterID: String) extends InMessage
|
case class GetPolls(meetingID: String, requesterID: String) extends InMessage
|
||||||
case class DestroyPoll(meetingID: String, pollID: String) extends InMessage
|
case class DestroyPoll(meetingID: String, pollID: String) extends InMessage
|
||||||
@ -21,10 +21,13 @@ case class ResponseVO(id: String, text: String)
|
|||||||
case class QuestionVO(id: String, questionType: QuestionType, question: String, responses: Array[ResponseVO])
|
case class QuestionVO(id: String, questionType: QuestionType, question: String, responses: Array[ResponseVO])
|
||||||
case class PollVO(id: String, title: String, questions: Array[QuestionVO], preCreated: Boolean=false)
|
case class PollVO(id: String, title: String, questions: Array[QuestionVO], preCreated: Boolean=false)
|
||||||
|
|
||||||
|
case class ResponseVOOut(id: String, text: String)
|
||||||
|
case class QuestionVOOut(id: String, questionType: QuestionType, question: String, responses: Array[ResponseVOOut])
|
||||||
|
case class PollVOOut(id: String, title: String, questions: Array[QuestionVOOut], preCreated: Boolean=false)
|
||||||
|
|
||||||
// Out Messages
|
// Out Messages
|
||||||
case class GetPollResultReply(meetingID: String, recorded: Boolean, requesterID: String, pollVO: PollVO) extends IOutMessage
|
case class GetPollResultReply(meetingID: String, recorded: Boolean, requesterID: String, pollVO: PollVOOut) extends IOutMessage
|
||||||
case class GetPollsReplyOutMsg(meetingID: String, recorded: Boolean, requesterID: String, polls: Array[PollVO]) extends IOutMessage
|
case class GetPollsReplyOutMsg(meetingID: String, recorded: Boolean, requesterID: String, polls: Array[PollVOOut]) extends IOutMessage
|
||||||
case class ClearPollFailed(meetingID: String, pollID: String, requesterID: String, reason: String) extends IOutMessage
|
case class ClearPollFailed(meetingID: String, pollID: String, requesterID: String, reason: String) extends IOutMessage
|
||||||
case class PollClearedOutMsg(meetingID: String, recorded: Boolean, pollID: String) extends IOutMessage
|
case class PollClearedOutMsg(meetingID: String, recorded: Boolean, pollID: String) extends IOutMessage
|
||||||
case class PollStartedOutMsg(meetingID: String, recorded: Boolean, pollID: String) extends IOutMessage
|
case class PollStartedOutMsg(meetingID: String, recorded: Boolean, pollID: String) extends IOutMessage
|
||||||
|
@ -0,0 +1,16 @@
|
|||||||
|
package org.bigbluebutton.core.util
|
||||||
|
|
||||||
|
object RandomStringGenerator {
|
||||||
|
|
||||||
|
// Random generator
|
||||||
|
val random = new scala.util.Random
|
||||||
|
|
||||||
|
// Generate a random string of length n from the given alphabet
|
||||||
|
def randomString(alphabet: String)(n: Int): String =
|
||||||
|
Stream.continually(random.nextInt(alphabet.size)).map(alphabet).take(n).mkString
|
||||||
|
|
||||||
|
// Generate a random alphabnumeric string of length n
|
||||||
|
def randomAlphanumericString(n: Int) =
|
||||||
|
randomString("abcdefghijklmnopqrstuvwxyz0123456789")(n)
|
||||||
|
}
|
||||||
|
|
@ -1,18 +1,17 @@
|
|||||||
<!DOCTYPE suite SYSTEM "http://beust.com/testng/testng-1.0.dtd" >
|
<!DOCTYPE suite SYSTEM "http://beust.com/testng/testng-1.0.dtd" >
|
||||||
<suite name="BigBlueButton Test Suite">
|
<suite name="BigBlueButton Test Suite">
|
||||||
<test name="Conference tests">
|
<test name="Conference tests">
|
||||||
<!--groups>
|
<groups>
|
||||||
<run>
|
<run>
|
||||||
<exclude name="broken"/>
|
<exclude name="broken"/>
|
||||||
|
<include name="unit"/>
|
||||||
</run>
|
</run>
|
||||||
</groups-->
|
</groups>
|
||||||
|
|
||||||
<packages>
|
<packages>
|
||||||
<package name="org.bigbluebutton.conference"/>
|
<package name="org.bigbluebutton.conference.service.poll"/>
|
||||||
<package name="org.bigbluebutton.conference.service.participants"/>
|
<package name="org.bigbluebutton.core.apps.poll"/>
|
||||||
<package name="org.bigbluebutton.conference.service.archive"/>
|
|
||||||
<package name="org.bigbluebutton.conference.service.archive.playback"/>
|
|
||||||
<package name="org.bigbluebutton.conference.service.archive.recorder"/>
|
|
||||||
</packages>
|
</packages>
|
||||||
</test>
|
</test>
|
||||||
</suite>
|
</suite>
|
||||||
|
@ -0,0 +1,22 @@
|
|||||||
|
package org.bigbluebutton.core.apps.poll
|
||||||
|
|
||||||
|
import org.testng.annotations.BeforeClass
|
||||||
|
import org.testng.annotations.Test
|
||||||
|
|
||||||
|
class PollMessageConverterTest {
|
||||||
|
|
||||||
|
@BeforeClass
|
||||||
|
def setUp() {
|
||||||
|
// code that will be invoked when this test is instantiated
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(groups = Array[String]( "unit" ))
|
||||||
|
def createPoll(){
|
||||||
|
val msg = "{\"title\":\"My sample poll\",\"questions\":[{\"type\":\"MULTI_CHOICE\",\"responses\":[\"Answer 1\",\"Answer 2\",\"Answer 3\"],\"question\":\"What is my name?\"}]}";
|
||||||
|
|
||||||
|
val cut = new PollMessageConverter
|
||||||
|
val pvp = cut.convertCreatePollMessage(msg)
|
||||||
|
|
||||||
|
assert(pvp.title.equals("My sample poll"), "Title not the same.")
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user