Skip to content

Commit

Permalink
Merge branch 'master' into release
Browse files Browse the repository at this point in the history
Conflicts:
	build.sbt
	conf/application.conf
  • Loading branch information
MatthieuNICOLAS committed Mar 15, 2016
2 parents cb1cc98 + 8539445 commit 4f33b54
Show file tree
Hide file tree
Showing 41 changed files with 397 additions and 245 deletions.
3 changes: 0 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ Getting Started
---------------

First, [install Play Framework](https://www.playframework.com/documentation/2.3.x/Installing).
Also a MongoDB instance have to be running if you want to use the user
account features. [Check this page](http://docs.mongodb.org/manual/installation/)
if you need to install it.

Once you cloned this repository, you can run the application in
production mode by running ```activator start ``` from the root
Expand Down
45 changes: 22 additions & 23 deletions app/actors/PLMActor.scala
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ class PLMActor (

def receive = {
case msg: JsValue =>
Logger.debug("Received a message")
Logger.debug(msg.toString())
Logger.debug("Message received:")
Logger.debug(msg.toString)
var cmd: Option[String] = (msg \ "cmd").asOpt[String]
cmd.getOrElse(None) match {
case "signIn" | "signUp" =>
Expand Down Expand Up @@ -121,7 +121,7 @@ class PLMActor (
plm.setProgrammingLanguage(programmingLanguage)
saveLastProgLang(programmingLanguage)
case _ =>
Logger.debug("setProgrammingLanguage: non-correct JSON")
logNonValidJSON("setProgrammingLanguage: non-correct JSON", msg)
}
case "setLang" =>
var optLang: Option[String] = (msg \ "args" \ "lang").asOpt[String]
Expand All @@ -131,7 +131,7 @@ class PLMActor (
plm.setLang(currentPreferredLang)
savePreferredLang()
case _ =>
Logger.debug("setLang: non-correct JSON")
logNonValidJSON("setLang: non-correct JSON", msg)
}
case "getExercise" =>
var optLessonID: Option[String] = (msg \ "args" \ "lessonID").asOpt[String]
Expand All @@ -143,11 +143,11 @@ class PLMActor (
case (lessonID:String, _) =>
lecture = plm.switchLesson(lessonID)
case (_, _) =>
Logger.debug("getExercise: non-correct JSON")
logNonValidJSON("getExercise: non-correct JSON", msg)
}
if(lecture != null) {
sendMessage("exercise", Json.obj(
"exercise" -> LectureToJson.lectureWrites(lecture, plm.programmingLanguage, plm.getStudentCode, plm.getInitialWorlds, plm.getSelectedWorldID)
"exercise" -> LectureToJson.lectureWrites(lecture, plm.programmingLanguage, plm.getStudentCode, plm.getInitialWorlds, plm.getAnswerWorlds, plm.getSelectedWorldID)
))
}
case "runExercise" =>
Expand All @@ -161,14 +161,14 @@ class PLMActor (
case (lessonID:String, exerciseID: String, code: String, _) =>
plm.runExercise(lessonID, exerciseID, code, null)
case (_, _, _, _) =>
Logger.debug("runExercise: non-correctJSON")
logNonValidJSON("runExercise: non-correctJSON", msg)
}
case "stopExecution" =>
plm.stopExecution
case "revertExercise" =>
var lecture = plm.revertExercise
sendMessage("exercise", Json.obj(
"exercise" -> LectureToJson.lectureWrites(lecture, plm.programmingLanguage, plm.getStudentCode, plm.getInitialWorlds, plm.getSelectedWorldID)
"exercise" -> LectureToJson.lectureWrites(lecture, plm.programmingLanguage, plm.getStudentCode, plm.getInitialWorlds, plm.getAnswerWorlds, plm.getSelectedWorldID)
))
case "getExercises" =>
if(plm.currentExercise != null) {
Expand Down Expand Up @@ -199,10 +199,10 @@ class PLMActor (
case trackUser: Boolean =>
plm.setTrackUser(currentTrackUser)
case _ =>
Logger.debug("setTrackUser: non-correct JSON")
logNonValidJSON("setTrackUser: non-correct JSON", msg)
}
case _ =>
Logger.debug("updateUser: non-correct JSON")
logNonValidJSON("updateUser: non-correct JSON", msg)
}
case "userIdle" =>
setUserIdle
Expand All @@ -216,7 +216,7 @@ class PLMActor (
saveTrackUser(currentTrackUser)
plm.setTrackUser(currentTrackUser)
case _ =>
Logger.debug("setTrackUser: non-correct JSON")
logNonValidJSON("setTrackUser: non-correct JSON", msg)
}
case "submitBugReport" =>
var optTitle: Option[String] = (msg \ "args" \ "title").asOpt[String]
Expand All @@ -225,21 +225,18 @@ class PLMActor (
case (title: String, body: String) =>
gitHubIssueManager.isCorrect(title, body).getOrElse(None) match {
case errorMsg: String =>
Logger.debug("Try to post incorrect issue...")
Logger.debug("Title: "+title+", body: "+body)
sendMessage("incorrectIssue", Json.obj("msg" -> errorMsg))
case None =>
gitHubIssueManager.postIssue(title, body).getOrElse(None) match {
case issueUrl: String =>
Logger.debug("Issue created at: "+ issueUrl)
sendMessage("issueCreated", Json.obj("url" -> issueUrl))
case None =>
Logger.debug("Error while uploading issue...")
Logger.error("Error while uploading issue...")
sendMessage("issueErrored", Json.obj())
}
}
case (_, _) =>
Logger.debug("submitBugReport: non-correct JSON")
logNonValidJSON("submitBugReport: non-correct JSON", msg)
}
case "commonErrorFeedback" =>
var optCommonErrorID: Option[Int] = (msg \ "args" \ "commonErrorID").asOpt[Int]
Expand All @@ -250,20 +247,20 @@ class PLMActor (
case (commonErrorID: Int, accuracy: Int, help: Int, comment: String) =>
plm.signalCommonErrorFeedback(commonErrorID, accuracy, help, comment)
case _ =>
Logger.debug("commonErrorFeedback: non-correct JSON")
logNonValidJSON("commonErrorFeedback: non-correct JSON", msg)
}
case "readTip" =>
var optTipID: Option[String] = (msg \ "args" \ "tipID").asOpt[String]
optTipID.getOrElse(None) match {
case tipID: String =>
plm.signalReadTip(tipID)
case _ =>
Logger.debug("readTip: non-correct JSON")
logNonValidJSON("readTip: non-correct JSON", msg)
}
case "ping" =>
// Do nothing
case _ =>
Logger.debug("cmd: non-correct JSON")
logNonValidJSON("cmd: non-correct JSON", msg)
}
}

Expand Down Expand Up @@ -348,16 +345,13 @@ class PLMActor (
def setUserIdle() {
userIdle = true
idleStart = Instant.apply
Logger.debug("start idling at: "+ idleStart)
}

def clearUserIdle() {
userIdle = false
idleEnd = Instant.apply
if(idleStart != null) {
var duration = Duration.between(idleStart, idleEnd)
Logger.debug("end idling at: "+ idleEnd)
Logger.debug("duration: " + duration)
plm.signalIdle(idleStart.toString, idleEnd.toString, duration.toString)
}
else {
Expand All @@ -375,9 +369,14 @@ class PLMActor (
UserDAORestImpl.update(currentUser)
}
}

def logNonValidJSON(label: String, msg: JsValue) {
Logger.error(label)
Logger.error(msg.toString)
}

override def postStop() = {
Logger.debug("postStop: websocket closed - removing the spies")
Logger.info("postStop: websocket closed - removing the spies")
if(userIdle) {
clearUserIdle
}
Expand Down
8 changes: 4 additions & 4 deletions app/controllers/ApplicationController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class ApplicationController @Inject() (
SecuredRequestHandler { securedRequest =>
Future.successful(HandlerResult(Ok, Some(securedRequest.identity)))
}.map {
case HandlerResult(r, Some(user)) =>
case HandlerResult(r, Some(user)) =>
Right(PLMActor.propsWithUser(executionManager, userAgent, actorUUID, user) _)
case HandlerResult(r, None) =>
var preferredLang: Lang = LangUtils.getPreferredLang(request)
Expand All @@ -52,7 +52,7 @@ class ApplicationController @Inject() (
Right(PLMActor.props(executionManager, userAgent, actorUUID, gitID, newUser, Some(preferredLang), None, Some(false)) _)
}
}

/**
* Returns the user.
*
Expand All @@ -67,8 +67,8 @@ class ApplicationController @Inject() (
)
Future.successful(Ok)
case _ =>
Logger.debug("Actor not found... Weird isn't it?")
Future.successful(Unauthorized)
Logger.error("Actor not found... Weird isn't it?")
Future.successful(Unauthorized)
}
}

Expand Down
4 changes: 2 additions & 2 deletions app/controllers/SocialAuthController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class SocialAuthController @Inject() (
case Some(p: SocialProvider with CommonSocialProfileBuilder) =>
p.authenticate().flatMap {
case Left(result) => Future.successful(result)
case Right(authInfo) =>
case Right(authInfo) =>
var preferredLang: Lang = LangUtils.getPreferredLang(request)
for {
profile <- p.retrieveProfile(authInfo)
Expand All @@ -70,7 +70,7 @@ class SocialAuthController @Inject() (
"user" -> user
)
case _ =>
Logger.debug("Actor not found... Weird isn't it?")
Logger.error("Actor " + actorUUID + " not found")
}
env.eventBus.publish(LoginEvent(user, request, request2Messages))
Ok(Json.obj("token" -> token))
Expand Down
5 changes: 3 additions & 2 deletions app/json/LectureToJson.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import json.world.WorldToJson

object LectureToJson {

def lectureWrites(lecture: Lecture, progLang: ProgrammingLanguage, code: String, initialWorlds: Array[World], selectedWorldID: String): JsValue = {
def lectureWrites(lecture: Lecture, progLang: ProgrammingLanguage, code: String, initialWorlds: Array[World], answerWorlds: Array[World], selectedWorldID: String): JsValue = {
var progLangArray = lecture.asInstanceOf[Exercise].getProgLanguages.toArray(Array[ProgrammingLanguage]())

var json = Json.obj(
Expand All @@ -27,7 +27,8 @@ object LectureToJson {

try {
json = json.as[JsObject] ++ Json.obj(
"initialWorlds" -> WorldToJson.worldsWrite(initialWorlds)
"initialWorlds" -> WorldToJson.worldsWrite(initialWorlds),
"answerWorlds" -> WorldToJson.worldsWrite(answerWorlds)
)
}
catch {
Expand Down
12 changes: 3 additions & 9 deletions app/json/UserToJson.scala
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,10 @@ object UserToJson {
case _ =>
// Do nothing
}
Logger.debug("On envoie: "+json.toString)
json
}

def userRead(json: JsValue): User = {
Logger.debug("Dans userRead: " + json.toString)


var preferredLang: Option[Lang] = None
if(json.as[JsObject].keys.contains("preferredLang")) {
var optCode = (json \ "preferredLang" \ "code").asOpt[String]
Expand All @@ -57,9 +53,7 @@ object UserToJson {
preferredLang = Some(Lang(code))
}
}

Logger.debug("preferredLang: "+ preferredLang.toString)


new User(
gitID = (json \ "gitID").as[String],
email = (json \ "email").asOpt[String],
Expand All @@ -76,4 +70,4 @@ object UserToJson {
trackUser = (json \ "trackUser").asOpt[Boolean]
)
}
}
}
10 changes: 5 additions & 5 deletions app/json/world/TurtleWorldToJson.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ object TurtleWorldToJson {
"sizeHints" -> sizeHintsWrite(turtleWorld.sizeHints())
)
}

def shapesWrite(shapes: Iterator[Shape]): JsValue = {
var jsArray: JsArray = JsArray()
var shape: Shape = null
Expand All @@ -47,12 +47,12 @@ object TurtleWorldToJson {
"color" -> Utils.colorToWrapper(circle.color)
))
case _ =>
Logger.debug("TurtleWorldToJson: shape not supported")
Logger.error("TurtleWorldToJson: shape not supported")
}
}
return jsArray
}

def sizeHintsWrite(sizeHints: Iterator[SizeHint]): JsValue = {
var jsArray: JsArray = JsArray()
var sizeHint: SizeHint = null
Expand All @@ -68,5 +68,5 @@ object TurtleWorldToJson {
}
return jsArray
}
}

}
10 changes: 5 additions & 5 deletions app/models/GitHubIssueManager.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ object GitHubIssueManager {
* @author matthieu
*/
class GitHubIssueManager {

def postIssue(title: String, body: String): Option[String] = {
var client: GitHubClient = new GitHubClient
client.setOAuth2Token(GitHubIssueManager.oAuth2Token)
Expand All @@ -33,17 +33,17 @@ class GitHubIssueManager {
}
catch {
case ex: IOException => {
Logger.debug("Error while uploading issue: ")
Logger.debug(ex.getLocalizedMessage)
Logger.error("Error while uploading issue: ")
Logger.error(ex.getLocalizedMessage)
None
}
}
}

def isCorrect(title: String, body: String): Option[String] = {
if(title.isEmpty) {
return Some("The current title is empty, please specify a relevant title.\n")
}
None
}
}
}
4 changes: 4 additions & 0 deletions app/models/PLM.scala
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ class PLM(
if(_currentExercise != null && _currentExercise.getWorlds(WorldKind.INITIAL) != null) _currentExercise.getWorlds(WorldKind.INITIAL).toArray(Array[World]()) else null
}

def getAnswerWorlds(): Array[World] = {
if(_currentExercise != null && _currentExercise.getWorlds(WorldKind.ANSWER) != null) _currentExercise.getWorlds(WorldKind.ANSWER).toArray(Array[World]()) else null
}

def getAPI(): String = {
var api: String = ""
if(getInitialWorlds != null) {
Expand Down
Loading

0 comments on commit 4f33b54

Please sign in to comment.