Package sc2002.FCS1.grp2
Class BTOManagementSystem
Object
BTOManagementSystem
- All Implemented Interfaces:
EnquiriesDelegate
The key class that handles all important data.
It acts as a single source of truth by design, to facilitate two things: -
Consistency for persisting data - Ensure proper access control
The idea is that this class shall hold the entire pool of data across any
persistable objects, including but not limited to users, projects, and other
related objects.
Other classes shall take great care by only referencing objects provided by
this class. This ensures that, when an attempt is made to persist data by
encoding into CSV files, data remains consistent, for that, any changes made,
shall be made to the same object, and not a copy of the object.
Other classes that require the data, should take great care in ensuring that
it is retrieved in a manner, which User classes cannot be passed around to
get the data, rather the `activeUser` property of this class, shall be the
only truth towards the current logged in user, ensuring proper access
control.
- Author:
- Vincent Neo
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate Userprivate ArrayList<Application> private static BTOManagementSystemprivate ArrayList<HDBManager> private ArrayList<HDBOfficer> private ArrayList<BTOProject> private Scanner -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddApplication(Application application) Save an applicationvoidaddEnquiry(Enquiry enquiry) Add an enquiry to system.voidaddProject(BTOProject project) Add a project to system, and persist.allUsers()booleanattemptLogin(User user, String password) Try to login; if successful, it will set the user propertyprivate voidCall this on every system init for automated checks on expirable content.voidcleanup()Do final cleanup, call when finishedstatic BTOManagementSystemcommon()The shared object, singleton style.private voidLinks necessary objects to certain class types.voiddeleteProject(BTOProject project) Delete a project.booleandoesProjectExist(String name, BTOProject excludedProject) Checks if there is already a project with a similar name.filterApplications(ArrayList<Application> filteredApplications) Get the applications that are filtered by the active user's filter.filterProjects(ArrayList<BTOProject> filteredProjects) Get the projects that are filtered by the active user's filter.findUserByNRIC(String nric) Check if user existsThe logged in user.<U extends User>
UgetActiveUserForPermittedTask(Class<U> expectedType) Get the active user, and checks for access rights before returning.Retrieve projects applicable for the current user.ProjectsGet applicable applications, depending on logged in user access rightsRetrieve enquiries that is respondable by an authorised personnel, subject to individual rightsRetrieve all enquiries of own.Retrieve all projects of the system.Use this scanner to get user input.Get all applicant's successful applications which the logged in officer is in charge ofprivate ArrayList<BTOProject> Get projects that are public visibility (i.e.Get withdrawal applicationsGet withdrawal applications made by applicant.<U extends User>
booleanisActiveUserPermitted(Class<U> expectedType) Decide if the current active user should be permitted to do a certain task, based on access rights by type of user.private voidCall this when login is successful.voidlogout()Call this when user logout, resets stuffprivate voidSets all expired projects as non-visible.voidremoveEnquiry(Enquiry enquiry) Remove an enquiry in system.voidsaveChanges(CSVFileTypes type) Save changes to the CSV filevoidUpdate an enquiry of system.
-
Field Details
-
commonInstance
-
applicants
-
managers
-
officers
-
projects
-
enquiries
-
applications
-
activeUser
-
scanner
-
-
Constructor Details
-
BTOManagementSystem
private BTOManagementSystem()
-
-
Method Details
-
common
The shared object, singleton style.- Returns:
- a common instance of this class.
-
crosslinking
private void crosslinking()Links necessary objects to certain class types. For example, an application is related to both an applicant and project classes. This method links it all together, post parsing. -
automatedChecks
private void automatedChecks()Call this on every system init for automated checks on expirable content. -
projectsClosureUponExpiry
private void projectsClosureUponExpiry()Sets all expired projects as non-visible. -
findUserByNRIC
Check if user exists- Parameters:
nric- The NRIC of user- Returns:
-
attemptLogin
Try to login; if successful, it will set the user property- Parameters:
user- The userpassword- The attempted password- Returns:
- true, if login is successful, false if login fails.
-
login
Call this when login is successful. This will set the user property and setup the enquiries system.- Parameters:
user- The user.
-
logout
public void logout()Call this when user logout, resets stuff -
saveChanges
Save changes to the CSV file- Parameters:
type-
-
allUsers
-
getActiveUser
The logged in user. -
getProjects
Retrieve all projects of the system. Great care must be exercised when using this getter. Do not use unless necessary.- Returns:
- all projects, regardless of visibility, applicability, intended for front-end filtering.
- Throws:
Exception
-
getApplicableProjects
Retrieve projects applicable for the current user.- Returns:
- For applicants, it will return projects with public visibility, subject to eligibility criteria; For officers, it will return projects that the officer is involved in; For managers, it will return projects whereby the manager is in charge of.
-
getVisibleProjects
Get projects that are public visibility (i.e. approved by manager, not expired).- Returns:
- a list of projects
-
getApplicableProjectsAsApplicant
Projects- Returns:
- Throws:
Exception
-
getScanner
Use this scanner to get user input.- Returns:
Scannerobject.
-
getOwnEnquiries
Description copied from interface:EnquiriesDelegateRetrieve all enquiries of own.- Specified by:
getOwnEnquiriesin interfaceEnquiriesDelegate- Returns:
- list of enquiries.
-
getEnquiries
Description copied from interface:EnquiriesDelegateRetrieve enquiries that is respondable by an authorised personnel, subject to individual rights- Specified by:
getEnquiriesin interfaceEnquiriesDelegate- Returns:
- list of enquiries.
-
addEnquiry
Description copied from interface:EnquiriesDelegateAdd an enquiry to system.- Specified by:
addEnquiryin interfaceEnquiriesDelegate- Parameters:
enquiry- The enquiry- Throws:
Exception- access control.
-
removeEnquiry
Description copied from interface:EnquiriesDelegateRemove an enquiry in system.- Specified by:
removeEnquiryin interfaceEnquiriesDelegate- Parameters:
enquiry- The enquiry to remove- Throws:
Exception- access control
-
updateEnquiry
public void updateEnquiry()Description copied from interface:EnquiriesDelegateUpdate an enquiry of system.- Specified by:
updateEnquiryin interfaceEnquiriesDelegate
-
filterProjects
Get the projects that are filtered by the active user's filter.- Parameters:
filteredProjects- The list of projects to be filtered.- Returns:
- The filtered list of projects.
-
filterApplications
Get the applications that are filtered by the active user's filter.- Parameters:
filteredApplications- The list of projects to be filtered.- Returns:
- The filtered list of projects.
-
isActiveUserPermitted
Decide if the current active user should be permitted to do a certain task, based on access rights by type of user.- Type Parameters:
U- Type of User- Parameters:
expectedType- Provide the expected user class type here.- Returns:
- true if active user is of given user type, hence permitted, false if otherwise.
-
getActiveUserForPermittedTask
public <U extends User> U getActiveUserForPermittedTask(Class<U> expectedType) throws InsufficientAccessRightsException Get the active user, and checks for access rights before returning.- Type Parameters:
U- The class that conforms toUser- Parameters:
expectedType- The expected access rights user class type- Returns:
- the user, suggests that access rights is granted, based on logged in user.
- Throws:
InsufficientAccessRightsException- access control
-
addProject
Add a project to system, and persist.- Parameters:
project- New project to be added.- Throws:
Exception- access control
-
deleteProject
Delete a project.- Parameters:
project- The project to be deleted.- Throws:
Exception- only manager in charge can delete, else throws error.
-
addApplication
Save an application- Parameters:
application- The new application- Throws:
Exception- access control
-
getApplications
Get applicable applications, depending on logged in user access rights- Returns:
- manager's in charge project's applications or applicant's applications, depending on logged in user.
-
getSuccessfulApplications
Get all applicant's successful applications which the logged in officer is in charge of- Returns:
- applications
- Throws:
Exception- access control
-
getWithdrawableApplications
Get withdrawal applications- Returns:
- Throws:
Exception
-
getWithdrawalApplications
Get withdrawal applications made by applicant. Applicant can only view his/her own withdrawal applications. Manager can view all withdrawal Applications of projects that he/her is in charge of. Officer is unable to access this method.- Returns:
- Throws:
Exception
-
doesProjectExist
Checks if there is already a project with a similar name. Names must not be the same, regardless of caoitalisation or spaces. For example, if a project of name: "Woodlands UrbanVille" exists, a new project name of "wOoDLanDs URBANVille" or "woodlandsurbanville" will not be allowed.- Parameters:
name- Name of new project to be checked against.excludedProject- Pass aBTOProjectif this project should not be checked against. Pass innullif otherwise.- Returns:
- true if such a project name already exists, false if such a name is considered new by system.
-
cleanup
public void cleanup()Do final cleanup, call when finished
-