com.bits.mainserver
Class ServerLogic

java.lang.Object
  extended by java.lang.Thread
      extended by com.bits.mainserver.ServerLogic
All Implemented Interfaces:
IMainServer, java.lang.Runnable

public final class ServerLogic
extends java.lang.Thread
implements IMainServer

ServerLogic is the class that offers the logic to the client the clients activates methods here from remote

Author:
smeitar

Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
 
Field Summary
static java.lang.Integer exportPort
          This is the port that the clients connects to using cajo
static GameProxy gameProxy
           
static java.lang.Boolean isDBConnected
          This shows the state of the connection to the db
static java.lang.String serverIP
          This is the ip address of the server (is used due to linux bug)
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
ServerLogic()
          C'tor
 
Method Summary
 boolean addTaskToExperiment(java.lang.String expName, java.lang.String taskName)
          Adds a TaskModule task to an experiment
 boolean createExperiment(java.lang.String expName)
          Creates a new experiment
 boolean createTask(java.lang.String taskName, java.lang.String script)
          Creates a new task
 void deleteExperiment(java.lang.String name)
          Deletes an experiment
 void deleteTask(java.lang.String name)
          Deletes a task
 boolean deleteTaskFromExperiment(java.lang.String expName, java.lang.String taskName)
          Removes a task from an experiment
 Advisor.AdviceResult getAdviceForUser(java.lang.String userName, java.util.LinkedList<GameResult> resultList)
           
 TrainingProgram getCurrentTrainingProgram(UserInfo user)
          Returns the training program of the user
 RecommendedSession getDoctorRecommendedSession(UserInfo patient)
          Returns the doctor's recommended sessions
 java.util.ArrayList<Task> getExperiment(java.lang.String expName)
          Returns the tasks of an experiment
 java.util.ArrayList<Experiment> getExperimentsList()
          Returns the list of experiments
 byte[] getGame(standards3.games.game.GameProperties game)
          download game
 java.util.LinkedList<standards3.games.game.GameProperties> getGamePropertiesByFilter(java.lang.String filterExpression)
          Returns a list of game properties according to a filter expression
 java.util.LinkedList<GameResult> getGameResultArray(java.lang.String userID, java.util.UUID gameID)
          Returns an array with the results of the user in a game
 java.util.LinkedList<UserInfo> getPatients(UserInfo user)
          Returns patients of a doctor
 RecommendedSession getRecommendedSession(UserInfo user)
          Returns the recommended session
 java.util.HashMap<standards3.games.game.GameProperties,java.util.LinkedList<GameResult>> getResultsForUser(UserInfo ui)
          Returns all the game results of a user
 java.util.HashMap<java.lang.String,java.lang.String[][]> getServerConfigurationData()
          Returns the configuration options of the server
 java.util.LinkedList<Session> getSessionsList()
          Get sessions list
 java.lang.String getTask(java.lang.String taskName)
          Returns the script of a task
 java.util.ArrayList<Task> getTasksList()
          Returns the list of all the tasks
 void initServerRemoting()
          This method setups the remoting
 java.lang.Boolean IsDBConnected()
          Shows the state of connection to the db
 boolean isUserExist(java.lang.String username)
           
 java.lang.String loadRecordedTask()
          Deprecated. 
 java.lang.String loadScript()
          Deprecated. 
 UserInfo login(java.lang.String userID, java.lang.String password)
          Performs login
static void main(java.lang.String[] args)
           
 void refreshGamesServer()
          This method is used to refresh the games in the db according to the game files on the server
 void run()
           
 void saveRecordedTask(java.lang.String task)
          Deprecated. 
 boolean saveScript(java.lang.String script)
          Deprecated. 
 boolean setRecommendedSession(UserInfo ui, RecommendedSession rs, boolean override)
          Sets the recommended session
 void setServerConfigurationData(java.lang.String fileName, java.lang.String[][] configMatrix)
          Sets a configuration in a configuration file
 java.lang.Boolean setUserInfo(UserInfo user)
          Updates the userinfo of the user
 boolean setUserTrainingProgram(UserInfo ui, TrainingProgram tp)
          Sets the training program of the user
 java.lang.Boolean updateResults(UserInfo user, standards3.games.game.GameProperties gp, java.util.UUID tpid, int gameDifficulty, java.lang.String gameRawData, long gameTime, int playerScore, double playerSuccessPercentage, boolean resultsValid)
          Update results of a game for a user
 boolean validatePassword(UserInfo ui, java.lang.String oldPassword, java.lang.String newPassword, java.lang.String newPassword2)
          Validates the password when changing password
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

gameProxy

public static GameProxy gameProxy

exportPort

public static java.lang.Integer exportPort
This is the port that the clients connects to using cajo


serverIP

public static java.lang.String serverIP
This is the ip address of the server (is used due to linux bug)


isDBConnected

public static java.lang.Boolean isDBConnected
This shows the state of the connection to the db

Constructor Detail

ServerLogic

public ServerLogic()
C'tor

Method Detail

main

public static void main(java.lang.String[] args)

initServerRemoting

public void initServerRemoting()
This method setups the remoting


run

public void run()
Specified by:
run in interface java.lang.Runnable
Overrides:
run in class java.lang.Thread

getGame

public byte[] getGame(standards3.games.game.GameProperties game)
Description copied from interface: IMainServer
download game

Specified by:
getGame in interface IMainServer
Parameters:
game - the game properties
Returns:
the jar file of the game

getSessionsList

public java.util.LinkedList<Session> getSessionsList()
Get sessions list

Specified by:
getSessionsList in interface IMainServer
Returns:
list of sessions

getRecommendedSession

public RecommendedSession getRecommendedSession(UserInfo user)
Returns the recommended session

Specified by:
getRecommendedSession in interface IMainServer
Parameters:
user - userinfo of the user
Returns:
The recommended sessions for this user

getDoctorRecommendedSession

public RecommendedSession getDoctorRecommendedSession(UserInfo patient)
Returns the doctor's recommended sessions

Specified by:
getDoctorRecommendedSession in interface IMainServer
Parameters:
patient - userinfo of the user
Returns:
The recommended session by the doctor

setRecommendedSession

public boolean setRecommendedSession(UserInfo ui,
                                     RecommendedSession rs,
                                     boolean override)
Sets the recommended session

Specified by:
setRecommendedSession in interface IMainServer
Parameters:
ui - userinfo of the user
rs - the recommended session
override - should it override existing session
Returns:
true on success false otherwise

updateResults

public java.lang.Boolean updateResults(UserInfo user,
                                       standards3.games.game.GameProperties gp,
                                       java.util.UUID tpid,
                                       int gameDifficulty,
                                       java.lang.String gameRawData,
                                       long gameTime,
                                       int playerScore,
                                       double playerSuccessPercentage,
                                       boolean resultsValid)
Update results of a game for a user

Specified by:
updateResults in interface IMainServer
Parameters:
user - userinfo of the user
gp - game properties of the game
tpid - training program ID
gameDifficulty - level of difficulty of the game
gameRawData - game raw data
gameTime - time played
playerScore - player score
playerSuccessPercentage - percentage of success of the user
resultsValid - true if the results are valid, false otherwise
Returns:
true if updated results successfully

setUserInfo

public java.lang.Boolean setUserInfo(UserInfo user)
Updates the userinfo of the user

Specified by:
setUserInfo in interface IMainServer
Parameters:
user - the userinfo of the user
Returns:
true if updated successfully

login

public UserInfo login(java.lang.String userID,
                      java.lang.String password)
Performs login

Specified by:
login in interface IMainServer
Parameters:
userID - id of the user
password - password of the user
Returns:
the details if succeeded, null otherwise

loadRecordedTask

@Deprecated
public java.lang.String loadRecordedTask()
Deprecated. 

Specified by:
loadRecordedTask in interface IMainServer

loadScript

@Deprecated
public java.lang.String loadScript()
Deprecated. 

Specified by:
loadScript in interface IMainServer

saveRecordedTask

@Deprecated
public void saveRecordedTask(java.lang.String task)
Deprecated. 

Specified by:
saveRecordedTask in interface IMainServer

saveScript

@Deprecated
public boolean saveScript(java.lang.String script)
Deprecated. 

Specified by:
saveScript in interface IMainServer

getCurrentTrainingProgram

public TrainingProgram getCurrentTrainingProgram(UserInfo user)
Returns the training program of the user

Specified by:
getCurrentTrainingProgram in interface IMainServer
Parameters:
user - userinfo of the user
Returns:
the training program of the user

setUserTrainingProgram

public boolean setUserTrainingProgram(UserInfo ui,
                                      TrainingProgram tp)
Sets the training program of the user

Specified by:
setUserTrainingProgram in interface IMainServer
Parameters:
ui - userinfo of the user
tp - the training program
Returns:
true if updated successfully

getGamePropertiesByFilter

public java.util.LinkedList<standards3.games.game.GameProperties> getGamePropertiesByFilter(java.lang.String filterExpression)
Returns a list of game properties according to a filter expression

Specified by:
getGamePropertiesByFilter in interface IMainServer
Parameters:
filterExpression - expression to filter gameproperties by
Returns:
list of all matching

getGameResultArray

public java.util.LinkedList<GameResult> getGameResultArray(java.lang.String userID,
                                                           java.util.UUID gameID)
Returns an array with the results of the user in a game

Specified by:
getGameResultArray in interface IMainServer
Parameters:
userID - id of the user
gameID - game id
Returns:

refreshGamesServer

public void refreshGamesServer()
This method is used to refresh the games in the db according to the game files on the server

Specified by:
refreshGamesServer in interface IMainServer

IsDBConnected

public java.lang.Boolean IsDBConnected()
Shows the state of connection to the db

Specified by:
IsDBConnected in interface IMainServer
Returns:
true if db is connected, false otherwise

getPatients

public java.util.LinkedList<UserInfo> getPatients(UserInfo user)
Returns patients of a doctor

Specified by:
getPatients in interface IMainServer
Parameters:
user - userinfo of the doctor
Returns:
a list of patients of the doctor

getResultsForUser

public java.util.HashMap<standards3.games.game.GameProperties,java.util.LinkedList<GameResult>> getResultsForUser(UserInfo ui)
Returns all the game results of a user

Specified by:
getResultsForUser in interface IMainServer
Parameters:
ui - userinfo of the user
Returns:
list of games and their results

addTaskToExperiment

public boolean addTaskToExperiment(java.lang.String expName,
                                   java.lang.String taskName)
Adds a TaskModule task to an experiment

Specified by:
addTaskToExperiment in interface IMainServer
Parameters:
expName - experiment name
taskName - task name
Returns:
true on success

createExperiment

public boolean createExperiment(java.lang.String expName)
Creates a new experiment

Specified by:
createExperiment in interface IMainServer
Parameters:
expName - experiment name
Returns:
true on success

createTask

public boolean createTask(java.lang.String taskName,
                          java.lang.String script)
Creates a new task

Specified by:
createTask in interface IMainServer
Parameters:
taskName - name of the task
script - the congolog script of the task
Returns:
true on success

deleteExperiment

public void deleteExperiment(java.lang.String name)
Deletes an experiment

Specified by:
deleteExperiment in interface IMainServer
Parameters:
name - experiment name

deleteTask

public void deleteTask(java.lang.String name)
Deletes a task

Specified by:
deleteTask in interface IMainServer
Parameters:
name - task name

deleteTaskFromExperiment

public boolean deleteTaskFromExperiment(java.lang.String expName,
                                        java.lang.String taskName)
Removes a task from an experiment

Specified by:
deleteTaskFromExperiment in interface IMainServer
Parameters:
expName - name of experiment
taskName - name of task
Returns:
true on success

getExperiment

public java.util.ArrayList<Task> getExperiment(java.lang.String expName)
Returns the tasks of an experiment

Specified by:
getExperiment in interface IMainServer
Parameters:
expName - name of experiment
Returns:
list of tasks in that experiment

getExperimentsList

public java.util.ArrayList<Experiment> getExperimentsList()
Returns the list of experiments

Specified by:
getExperimentsList in interface IMainServer
Returns:
list of experiments

getTask

public java.lang.String getTask(java.lang.String taskName)
Returns the script of a task

Specified by:
getTask in interface IMainServer
Parameters:
taskName - name of the task
Returns:
the script of the task

getTasksList

public java.util.ArrayList<Task> getTasksList()
Returns the list of all the tasks

Specified by:
getTasksList in interface IMainServer
Returns:
Returns the list of all the tasks

validatePassword

public boolean validatePassword(UserInfo ui,
                                java.lang.String oldPassword,
                                java.lang.String newPassword,
                                java.lang.String newPassword2)
                         throws java.lang.Exception
Validates the password when changing password

Specified by:
validatePassword in interface IMainServer
Parameters:
ui - userinfo of the user
oldPassword - the old password the user typed
newPassword - the first new password typed
newPassword2 - the verification of the new password
Returns:
true if the parameters are correct and password changed
Throws:
java.lang.Exception

getServerConfigurationData

public java.util.HashMap<java.lang.String,java.lang.String[][]> getServerConfigurationData()
Returns the configuration options of the server

Specified by:
getServerConfigurationData in interface IMainServer
Returns:
the configuration options of the server

setServerConfigurationData

public void setServerConfigurationData(java.lang.String fileName,
                                       java.lang.String[][] configMatrix)
Sets a configuration in a configuration file

Specified by:
setServerConfigurationData in interface IMainServer
Parameters:
fileName - name of configuration file
configMatrix - the configuration options

isUserExist

public boolean isUserExist(java.lang.String username)
Specified by:
isUserExist in interface IMainServer

getAdviceForUser

public Advisor.AdviceResult getAdviceForUser(java.lang.String userName,
                                             java.util.LinkedList<GameResult> resultList)
Specified by:
getAdviceForUser in interface IMainServer