Class EligibilityService

java.lang.Object
com.ntu.fdae.group1.bto.services.booking.EligibilityService
All Implemented Interfaces:
IEligibilityService

public class EligibilityService extends Object implements IEligibilityService
Service class that implements eligibility checking rules for the BTO Management System.

This class provides business logic for determining eligibility across various scenarios in the system, including: - Applicant eligibility for projects and flat types based on age and marital status - Officer eligibility for project registration based on concurrency and conflict rules - Manager eligibility for project handling based on concurrency constraints

The service relies on the project repository for information about existing projects when making eligibility determinations.

  • Constructor Details

    • EligibilityService

      public EligibilityService(IProjectRepository projectRepository)
      Constructs a new EligibilityService with the required project repository.
      Parameters:
      projectRepository - Repository for accessing project data
      Throws:
      NullPointerException - if projectRepository is null
  • Method Details

    • canApplicantApply

      public boolean canApplicantApply(User user, Project project)
      Checks if a user is eligible to apply for a specific project.

      Eligibility is determined based on the following rules: - Single applicants aged 35 or older: eligible only for projects with 2-Room flats - Married applicants aged 21 or older: eligible for any project with flats - All other applicants: not eligible

      Specified by:
      canApplicantApply in interface IEligibilityService
      Parameters:
      user - The user (applicant) to check
      project - The project to check eligibility for
      Returns:
      true if the user is eligible to apply for the project, false otherwise
    • isApplicantEligibleForFlatType

      public boolean isApplicantEligibleForFlatType(User user, FlatType flatType)
      Checks if a user is eligible for a specific flat type.

      Eligibility is determined based on the following rules: - Single applicants aged 35 or older: eligible only for 2-Room flats - Married applicants aged 21 or older: eligible for both 2-Room and 3-Room flats - All other applicants: not eligible

      Specified by:
      isApplicantEligibleForFlatType in interface IEligibilityService
      Parameters:
      user - The user to check eligibility for
      flatType - The flat type to check eligibility against
      Returns:
      true if the user is eligible for the flat type, false otherwise
    • canOfficerRegister

      public boolean canOfficerRegister(HDBOfficer officer, Project project, Collection<OfficerRegistration> allRegistrations, Collection<Application> allApplications)
      Determines if an HDB Officer is eligible to register for a specific project.

      The eligibility rules are: 1. The officer must not have applied for the project as an applicant 2. The officer must not be handling another project with an overlapping application period

      Specified by:
      canOfficerRegister in interface IEligibilityService
      Parameters:
      officer - The HDB Officer to check eligibility for
      project - The project the officer wishes to register for
      allRegistrations - Collection of all officer registrations in the system
      allApplications - Collection of all applications in the system
      Returns:
      true if the officer is eligible to register for the project, false otherwise
    • checkManagerProjectHandlingEligibility

      public boolean checkManagerProjectHandlingEligibility(HDBManager manager, LocalDate newProjectOpenDate, LocalDate newProjectCloseDate, Collection<Project> allExistingProjects)
      Checks if an HDB Manager is eligible to handle a new project with the specified dates.

      A manager is eligible if they are not already managing a project with an overlapping application period.

      Application periods overlap when: (StartA < EndB) AND (EndA > StartB)

      Specified by:
      checkManagerProjectHandlingEligibility in interface IEligibilityService
      Parameters:
      manager - The HDB Manager to check eligibility for
      newProjectOpenDate - The opening date of the new project
      newProjectCloseDate - The closing date of the new project
      allExistingProjects - Collection of all existing projects in the system
      Returns:
      true if the manager is eligible to handle the new project, false otherwise