Class BTOManagementSystem

Object
BTOManagementSystem
All Implemented Interfaces:
EnquiriesDelegate

public class BTOManagementSystem extends Object implements 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 Details

  • Constructor Details

    • BTOManagementSystem

      private BTOManagementSystem()
  • Method Details

    • common

      public static BTOManagementSystem 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

      public User findUserByNRIC(String nric)
      Check if user exists
      Parameters:
      nric - The NRIC of user
      Returns:
    • attemptLogin

      public boolean attemptLogin(User user, String password)
      Try to login; if successful, it will set the user property
      Parameters:
      user - The user
      password - The attempted password
      Returns:
      true, if login is successful, false if login fails.
    • login

      private void login(User user)
      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

      public void saveChanges(CSVFileTypes type)
      Save changes to the CSV file
      Parameters:
      type -
    • allUsers

      private ArrayList<User> allUsers()
    • getActiveUser

      public User getActiveUser()
      The logged in user.
    • getProjects

      public ArrayList<BTOProject> getProjects() throws Exception
      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

      public ArrayList<BTOProject> 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

      private ArrayList<BTOProject> getVisibleProjects()
      Get projects that are public visibility (i.e. approved by manager, not expired).
      Returns:
      a list of projects
    • getApplicableProjectsAsApplicant

      public ArrayList<BTOProject> getApplicableProjectsAsApplicant() throws Exception
      Projects
      Returns:
      Throws:
      Exception
    • getScanner

      public Scanner getScanner()
      Use this scanner to get user input.
      Returns:
      Scanner object.
    • getOwnEnquiries

      public List<Enquiry> getOwnEnquiries()
      Description copied from interface: EnquiriesDelegate
      Retrieve all enquiries of own.
      Specified by:
      getOwnEnquiries in interface EnquiriesDelegate
      Returns:
      list of enquiries.
    • getEnquiries

      public List<Enquiry> getEnquiries()
      Description copied from interface: EnquiriesDelegate
      Retrieve enquiries that is respondable by an authorised personnel, subject to individual rights
      Specified by:
      getEnquiries in interface EnquiriesDelegate
      Returns:
      list of enquiries.
    • addEnquiry

      public void addEnquiry(Enquiry enquiry) throws Exception
      Description copied from interface: EnquiriesDelegate
      Add an enquiry to system.
      Specified by:
      addEnquiry in interface EnquiriesDelegate
      Parameters:
      enquiry - The enquiry
      Throws:
      Exception - access control.
    • removeEnquiry

      public void removeEnquiry(Enquiry enquiry) throws Exception
      Description copied from interface: EnquiriesDelegate
      Remove an enquiry in system.
      Specified by:
      removeEnquiry in interface EnquiriesDelegate
      Parameters:
      enquiry - The enquiry to remove
      Throws:
      Exception - access control
    • updateEnquiry

      public void updateEnquiry()
      Description copied from interface: EnquiriesDelegate
      Update an enquiry of system.
      Specified by:
      updateEnquiry in interface EnquiriesDelegate
    • filterProjects

      public ArrayList<BTOProject> filterProjects(ArrayList<BTOProject> filteredProjects)
      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

      public ArrayList<Application> filterApplications(ArrayList<Application> filteredApplications)
      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

      public <U extends User> boolean isActiveUserPermitted(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.
      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 to User
      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

      public void addProject(BTOProject project) throws Exception
      Add a project to system, and persist.
      Parameters:
      project - New project to be added.
      Throws:
      Exception - access control
    • deleteProject

      public void deleteProject(BTOProject project) throws Exception
      Delete a project.
      Parameters:
      project - The project to be deleted.
      Throws:
      Exception - only manager in charge can delete, else throws error.
    • addApplication

      public void addApplication(Application application) throws Exception
      Save an application
      Parameters:
      application - The new application
      Throws:
      Exception - access control
    • getApplications

      public ArrayList<Application> 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

      public ArrayList<Application> getSuccessfulApplications() throws Exception
      Get all applicant's successful applications which the logged in officer is in charge of
      Returns:
      applications
      Throws:
      Exception - access control
    • getWithdrawableApplications

      public ArrayList<Application> getWithdrawableApplications() throws Exception
      Get withdrawal applications
      Returns:
      Throws:
      Exception
    • getWithdrawalApplications

      public ArrayList<Application> getWithdrawalApplications() throws Exception
      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

      public boolean doesProjectExist(String name, BTOProject excludedProject)
      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 a BTOProject if this project should not be checked against. Pass in null if 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