Class EligibilityService
- All Implemented Interfaces:
IEligibilityService
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 Summary
ConstructorsConstructorDescriptionEligibilityService
(IProjectRepository projectRepository) Constructs a new EligibilityService with the required project repository. -
Method Summary
Modifier and TypeMethodDescriptionboolean
canApplicantApply
(User user, Project project) Checks if a user is eligible to apply for a specific project.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.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.boolean
isApplicantEligibleForFlatType
(User user, FlatType flatType) Checks if a user is eligible for a specific flat type.
-
Constructor Details
-
EligibilityService
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
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 interfaceIEligibilityService
- Parameters:
user
- The user (applicant) to checkproject
- The project to check eligibility for- Returns:
- true if the user is eligible to apply for the project, false otherwise
-
isApplicantEligibleForFlatType
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 interfaceIEligibilityService
- Parameters:
user
- The user to check eligibility forflatType
- 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 interfaceIEligibilityService
- Parameters:
officer
- The HDB Officer to check eligibility forproject
- The project the officer wishes to register forallRegistrations
- Collection of all officer registrations in the systemallApplications
- 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 interfaceIEligibilityService
- Parameters:
manager
- The HDB Manager to check eligibility fornewProjectOpenDate
- The opening date of the new projectnewProjectCloseDate
- The closing date of the new projectallExistingProjects
- Collection of all existing projects in the system- Returns:
- true if the manager is eligible to handle the new project, false otherwise
-