jitas.core
Class Student

java.lang.Object
  extended by jitas.core.Student

public class Student
extends java.lang.Object

Student keeps track of all the domains a student is logged into as well as the domains that the student is able to log into, and their userName and password which the student uses to log into domains.

Version:
08 October 2007
Author:
DeathMarch (c314g2)

Constructor Summary
Student(java.lang.String userName, java.lang.String password, java.util.Set<java.lang.String> allowedDomains)
          Constructor.
 
Method Summary
 void addAllowedDomain(java.lang.String domainName)
          Adds a new domain to the set of domains a student can log into.
 void addSatisfiedConstraints(java.lang.String domainName, java.util.Collection<java.lang.String> satisfiedConstraints)
          Add some satisfied constraints to this students model for the given domain
 void addSolvedProblem(java.lang.String domainName, java.lang.String subdomainName, java.lang.Integer problemID)
          Add a problem to the collection of solved problems for a subdomain
 void addStudentModel(java.lang.String domainName, StudentModel model)
          Add a student model to this students models.
 void addViolatedConstraints(java.lang.String domainName, java.util.Collection<java.lang.String> violatedConstraints)
          Add some violated constraints to this students model for the given domain
 void changePassword(java.lang.String oldPassword, java.lang.String newPassword)
          Change the Student password
static int checkPassword(java.lang.String password)
          Check the password is longer than 2
static int checkUsername(java.lang.String username)
          Validate the username which only allows alphabets, numbers and underscore
 int compareTo(java.lang.Object object)
          Standard compareTo override, based on the userName
 void createStudentModel(java.lang.String domainName)
          Creates a new (empty) StudentModel and adds it to this students models.
static void deleteUser(Student student)
          Deletes students global information -NOT domain information.
 boolean equals(java.lang.Object object1)
           
 java.util.Set<java.lang.String> getAllowedDomains()
          Returns a complete unmodifiable Set of all the domains a student can log into
 java.lang.Integer getCurrentProblemID(java.lang.String domainName)
          Get the ID of the problem the student is currently working on for a given domain
 java.lang.String getCurrentSubdomain(java.lang.String domainName)
          Get the name of the current subdomain of a particular domain
 java.util.Set<java.lang.String> getLiveDomains()
          Returns a complete Set of all the domains a student is currently logged into
 Problem getNextProblem(java.lang.String domainName, java.util.SortedMap<java.lang.Integer,Problem> problems)
          Gets the next problem the student hasnt solved in the current subdomain of a given domain
 Problem getNextProblem(java.lang.String domainName, java.util.SortedMap<java.lang.Integer,Problem> problems, int problemNumber)
          Returns a problem, given a problemID, for a domain
 java.lang.String getPassword()
          Get the encrypted password of this user.
 java.lang.String getProblemStatus(java.lang.String domainName, int problemID)
          Get the status of a given problem, from a given domain.
 double getRating(java.lang.String domainName)
          Get the rating of this student for a given domain.
 java.util.Collection<java.lang.String> getSatisfiedConstraints(java.lang.String domainName)
          Get the collection of constraints satisfied in the given domain
 java.util.Set<java.lang.Integer> getSolvedProblems(java.lang.String domainName, java.lang.String subdomainName)
          Get the IDs of the problems solved for a given subdomain
 java.lang.String getUserName()
          Get the userName of this user.
 java.util.Collection<java.lang.String> getViolatedConstraints(java.lang.String domainName)
          Get the collection of constraints violated in the given domain
 int hashCode()
           
 void incrementRating(java.lang.String domainName, double increment)
          Increment this students rating in the given domain by a certain amount
 void initModel(java.lang.String domainName)
          Make sure a student model exists for the given domain
 boolean isAllowedInDomain(java.lang.String domainName)
          Checks whether a Student has access to a domain or not.
 boolean isLoggedIn(java.lang.String domainName)
          Get the login status for the user (ie if they are logged in or not) for a specific domain
static java.util.Set<Student> loadAllStudents()
          Loads all the Students from xml, and returns a set of those (loaded) Students.
 void login(java.lang.String domainName, java.lang.String password)
          Log the user in to allow further actions
 void logout(java.lang.String domainName)
          Logs this user out of a domain
static Student newStudentFactory(java.lang.String userName, java.lang.String password, java.util.Set<java.lang.String> allowedDomains)
          Construct a new Student Object.
static void persistStudent(Student student)
          Saves the Student to xml, creates a new StudentModel for the domain, and also writes that to XML.
static void removeUser(Student student, java.lang.String domainName)
          Removes access to a specific Domain, for a Student.
 void saveStudentModel(java.lang.String domainName)
          Save the model for a given domain
 void setCurrentProblemStatus(java.lang.String domainName, java.lang.String status)
          Set the status of the current problem for a domain
 void setCurrentSubdomain(java.lang.String domainName, java.lang.String currentSubdomain)
          Set the current working subdomain for a given domain
 void setProblemStatus(java.lang.String domainName, java.lang.String subdomainName, int problemID, java.lang.String status)
          Set the status for a given problem.
 void setRating(java.lang.String domainName, double rating)
          Set this students rating for a given domain.
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Student

public Student(java.lang.String userName,
               java.lang.String password,
               java.util.Set<java.lang.String> allowedDomains)
        throws IllegalUserNameException
Constructor.

Parameters:
userName - The students userName.
password - The encrypted password
allowedDomains - The domains a student can log into
Throws:
java.security.NoSuchAlgorithmException
IllegalUserNameException
Method Detail

login

public void login(java.lang.String domainName,
                  java.lang.String password)
Log the user in to allow further actions

Parameters:
domainName - The name of the domain that user wants to log in
password - The password.
Throws:
java.io.UnsupportedEncodingException
java.security.NoSuchAlgorithmException

logout

public void logout(java.lang.String domainName)
Logs this user out of a domain


isLoggedIn

public boolean isLoggedIn(java.lang.String domainName)
Get the login status for the user (ie if they are logged in or not) for a specific domain

Returns:
True if they are logged in, false otherwise.

initModel

public void initModel(java.lang.String domainName)
Make sure a student model exists for the given domain

Parameters:
domainName - The domain (name)

getUserName

public java.lang.String getUserName()
Get the userName of this user.

Returns:
A copy of userName

getPassword

public java.lang.String getPassword()
Get the encrypted password of this user.

Returns:
A copy of password

checkUsername

public static int checkUsername(java.lang.String username)
Validate the username which only allows alphabets, numbers and underscore

Parameters:
username - The student username that needs to be validated
Returns:
1 if there are any illegal characters; 2 if the username is shorter than lenght of 2; 0 if the username is correct

checkPassword

public static int checkPassword(java.lang.String password)
Check the password is longer than 2

Parameters:
password - The student's password that needs to be checked
Returns:
0 if the password is ok, 2 if the length of the password is shorter than 2

newStudentFactory

public static Student newStudentFactory(java.lang.String userName,
                                        java.lang.String password,
                                        java.util.Set<java.lang.String> allowedDomains)
                                 throws IllegalUserNameException
Construct a new Student Object. Encrypts the given password

Parameters:
userName - The username of the student
password - The plain text password of the student
allowedDomains - A set of domain names the student is allowed to access
Returns:
The newly constructed Student object.
Throws:
IllegalUserNameException - If the username is Illegal

changePassword

public void changePassword(java.lang.String oldPassword,
                           java.lang.String newPassword)
                    throws InvalidPasswordException
Change the Student password

Parameters:
newPassword - The new password that the user wants to change to
oldPassword - The existing password of a user
Throws:
InvalidPasswordException - If the old password is wrong

equals

public boolean equals(java.lang.Object object1)
Overrides:
equals in class java.lang.Object

compareTo

public int compareTo(java.lang.Object object)
              throws java.lang.ClassCastException
Standard compareTo override, based on the userName

Parameters:
object - the Object to be compared
Returns:
a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.
Throws:
java.lang.ClassCastException

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

isAllowedInDomain

public boolean isAllowedInDomain(java.lang.String domainName)
Checks whether a Student has access to a domain or not.

Parameters:
domainName - The name of the domain we want to check
Returns:
True if the student has access to the domain, otherwise false

getAllowedDomains

public java.util.Set<java.lang.String> getAllowedDomains()
Returns a complete unmodifiable Set of all the domains a student can log into

Returns:
a Set of all domains a student can log into

addAllowedDomain

public void addAllowedDomain(java.lang.String domainName)
                      throws StudentModelAlreadyExistsException
Adds a new domain to the set of domains a student can log into. Makes a new StudentModel for the domain and writes it to XML If the domain does not allow student creation, then a AddUserDeniedException

Parameters:
domainName - The domain name that the students can log into
Throws:
AddUserDeniedException
StudentModelAlreadyExistsException
UserAlreadyExistsException

addStudentModel

public void addStudentModel(java.lang.String domainName,
                            StudentModel model)
Add a student model to this students models. Gets called when loading students from XML

Parameters:
domainName - The name of the domain this model is for
model - The StudentModel object

createStudentModel

public void createStudentModel(java.lang.String domainName)
Creates a new (empty) StudentModel and adds it to this students models.

Parameters:
domainName -

getLiveDomains

public java.util.Set<java.lang.String> getLiveDomains()
Returns a complete Set of all the domains a student is currently logged into

Returns:
liveDomains A Set of all domains a student is currently logged into

loadAllStudents

public static java.util.Set<Student> loadAllStudents()
                                              throws java.io.FileNotFoundException
Loads all the Students from xml, and returns a set of those (loaded) Students.

Returns:
Set The set of all the studnets in the system
Throws:
java.io.FileNotFoundException

persistStudent

public static void persistStudent(Student student)
Saves the Student to xml, creates a new StudentModel for the domain, and also writes that to XML. This should be used only when a new Student is being created.

Parameters:
student - The Student to be persisted
Throws:
AddUserDeniedException
StudentModelAlreadyExistsException
UserAlreadyExistsException

removeUser

public static void removeUser(Student student,
                              java.lang.String domainName)
                       throws UserNotFoundException
Removes access to a specific Domain, for a Student. Note: this does not delete a student from the system, only from a certain Domain

Parameters:
student - The student that needs to be removed
domainName - the domain which you want a student to have revoked access on.
Throws:
UserNotFoundException - if a Students student model is not found in domain

deleteUser

public static void deleteUser(Student student)
                       throws UserNotFoundException
Deletes students global information -NOT domain information. To delete student models, use removeUser(Student, Domain).

Parameters:
student - the student which is to be deleted.
Throws:
UserNotFoundException

setCurrentSubdomain

public void setCurrentSubdomain(java.lang.String domainName,
                                java.lang.String currentSubdomain)
Set the current working subdomain for a given domain

Parameters:
domainName - The domain name
currentSubdomain - The name of the current subdomain

getCurrentSubdomain

public java.lang.String getCurrentSubdomain(java.lang.String domainName)
Get the name of the current subdomain of a particular domain

Parameters:
domainName - The domain name
Returns:
The name of the current subdomain for the given domain.

getNextProblem

public Problem getNextProblem(java.lang.String domainName,
                              java.util.SortedMap<java.lang.Integer,Problem> problems)
Gets the next problem the student hasnt solved in the current subdomain of a given domain

Parameters:
domainName - The name of the domain
problems - A collection of problems to choose the next from
Returns:
The next problem

getNextProblem

public Problem getNextProblem(java.lang.String domainName,
                              java.util.SortedMap<java.lang.Integer,Problem> problems,
                              int problemNumber)
Returns a problem, given a problemID, for a domain

Parameters:
domainName - The name of the domain
problems - The problems to select from
problemNumber - The ID of they wanted problem
Returns:
The problem

getProblemStatus

public java.lang.String getProblemStatus(java.lang.String domainName,
                                         int problemID)
Get the status of a given problem, from a given domain.

Parameters:
domainName - The name of the domain
problemID - The ID of the problem
Returns:
The status eg "attempted" etc

getCurrentProblemID

public java.lang.Integer getCurrentProblemID(java.lang.String domainName)
Get the ID of the problem the student is currently working on for a given domain

Parameters:
domainName - The name of the domain
Returns:
The ID of the current problem

setProblemStatus

public void setProblemStatus(java.lang.String domainName,
                             java.lang.String subdomainName,
                             int problemID,
                             java.lang.String status)
Set the status for a given problem.

Parameters:
domainName - The domain name
subdomainName - The subdomain name the problem belongs to
problemID - The ID of the problem
status - The status

setRating

public void setRating(java.lang.String domainName,
                      double rating)
Set this students rating for a given domain.

Parameters:
domainName - The domain name
rating - The new rating

getRating

public double getRating(java.lang.String domainName)
Get the rating of this student for a given domain.

Parameters:
domainName - The domain name
Returns:
The rating for the given domain

incrementRating

public void incrementRating(java.lang.String domainName,
                            double increment)
Increment this students rating in the given domain by a certain amount

Parameters:
domainName - The domain name
increment - The amount to increase the rating by

setCurrentProblemStatus

public void setCurrentProblemStatus(java.lang.String domainName,
                                    java.lang.String status)
Set the status of the current problem for a domain

Parameters:
domainName - The domain name
status - The status for the current problem

addSolvedProblem

public void addSolvedProblem(java.lang.String domainName,
                             java.lang.String subdomainName,
                             java.lang.Integer problemID)
Add a problem to the collection of solved problems for a subdomain

Parameters:
domainName - The domain name
subdomainName - The name of the subdomain the problem belongs to
problemID - The ID of the solved problem

addViolatedConstraints

public void addViolatedConstraints(java.lang.String domainName,
                                   java.util.Collection<java.lang.String> violatedConstraints)
Add some violated constraints to this students model for the given domain

Parameters:
domainName - The domain name
violatedConstraints - A collection of constraints

addSatisfiedConstraints

public void addSatisfiedConstraints(java.lang.String domainName,
                                    java.util.Collection<java.lang.String> satisfiedConstraints)
Add some satisfied constraints to this students model for the given domain

Parameters:
domainName - the domain name
satisfiedConstraints - A collection of constraints

getSolvedProblems

public java.util.Set<java.lang.Integer> getSolvedProblems(java.lang.String domainName,
                                                          java.lang.String subdomainName)
Get the IDs of the problems solved for a given subdomain

Parameters:
domainName - The domain name
subdomainName - The subdomain name
Returns:
The IDs of all the solved problems in the subdomain

getSatisfiedConstraints

public java.util.Collection<java.lang.String> getSatisfiedConstraints(java.lang.String domainName)
Get the collection of constraints satisfied in the given domain

Parameters:
domainName - The domain name
Returns:
All the satisfied constraints for the given domain

getViolatedConstraints

public java.util.Collection<java.lang.String> getViolatedConstraints(java.lang.String domainName)
Get the collection of constraints violated in the given domain

Parameters:
domainName - The domain name
Returns:
All the violated constraints for the given domain

saveStudentModel

public void saveStudentModel(java.lang.String domainName)
Save the model for a given domain

Parameters:
domainName - The domain name