Class ApplicationService
- All Implemented Interfaces:
IApplicationService
- Processing new application submissions with eligibility checks
- Managing application withdrawals
- Supporting the review process for applications and withdrawals by managers
- Retrieving applications based on various criteria
- Enforcing business rules for the application process
- Ensuring applicants meet eligibility criteria for projects and flat types
- Preventing HDB officers from applying to projects they are registered to manage
- Maintaining correct flat unit inventory during application approval
- Enforcing proper authorization for application reviews
- Managing the application state transitions
-
Constructor Summary
ConstructorsConstructorDescriptionApplicationService
(IApplicationRepository appRepo, IProjectRepository projRepo, IEligibilityService eligSvc, IOfficerRegistrationRepository officerRegRepo) Constructs a new ApplicationService with the specified repositories and services. -
Method Summary
Modifier and TypeMethodDescriptiongetApplicationForUser
(String applicantNric) Gets the application for a specific applicantgetApplicationsByProject
(String projectId) Gets all applications for a specific projectGets all applications with a specific statusboolean
requestWithdrawal
(User user) Requests withdrawal of an existing applicationboolean
reviewApplication
(HDBManager manager, String applicationId, boolean approve) Reviews an applicationboolean
reviewWithdrawal
(HDBManager manager, String applicationId, boolean approve) Reviews a withdrawal requestsubmitApplication
(User user, String projectId, FlatType preferredFlatType) Submits a new application for a project
-
Constructor Details
-
ApplicationService
public ApplicationService(IApplicationRepository appRepo, IProjectRepository projRepo, IEligibilityService eligSvc, IOfficerRegistrationRepository officerRegRepo) Constructs a new ApplicationService with the specified repositories and services.Uses dependency injection to receive the required repositories and services.
- Parameters:
appRepo
- Repository for application dataprojRepo
- Repository for project dataeligSvc
- Service for checking eligibilityofficerRegRepo
- Repository for officer registration data
-
-
Method Details
-
submitApplication
public Application submitApplication(User user, String projectId, FlatType preferredFlatType) throws ApplicationException Submits a new application for a project This implementation performs extensive validation before submission:- Validates that inputs are not null
- Checks that the project exists and is currently open for applications
- Verifies the applicant doesn't already have an active application
- Validates that the applicant meets eligibility requirements
- Ensures the preferred flat type is available and the applicant is eligible for it
- Prevents HDB officers from applying to projects they're registered for
- Specified by:
submitApplication
in interfaceIApplicationService
- Parameters:
user
- The applicant submitting the applicationprojectId
- ID of the project to apply forpreferredFlatType
- The type of flat the applicant prefers- Returns:
- The created application
- Throws:
ApplicationException
- if application submission fails
-
requestWithdrawal
Requests withdrawal of an existing application This implementation validates that:- The applicant has an active application to withdraw
- The application hasn't already been withdrawn
- The application is in a valid state for withdrawal
Note that this method only requests the withdrawal, which must be reviewed by a manager before becoming finalized.
- Specified by:
requestWithdrawal
in interfaceIApplicationService
- Parameters:
user
- The applicant requesting withdrawal- Returns:
- true if request was successful, false otherwise
- Throws:
ApplicationException
- if withdrawal request fails
-
reviewApplication
public boolean reviewApplication(HDBManager manager, String applicationId, boolean approve) throws ApplicationException Reviews an application This implementation validates that:- The application exists and is associated with a valid project
- The manager is authorized to review the application (manages the project)
- The application is in a valid state for review (PENDING, no withdrawal request)
- Checks if the requested flat type is still available
- Decrements the available unit count for that flat type
- Updates the application status to SUCCESSFUL
- Specified by:
reviewApplication
in interfaceIApplicationService
- Parameters:
manager
- The manager reviewing the applicationapplicationId
- ID of the application to reviewapprove
- true to approve, false to reject- Returns:
- true if review was successful, false otherwise
- Throws:
ApplicationException
- if the review process fails
-
reviewWithdrawal
public boolean reviewWithdrawal(HDBManager manager, String applicationId, boolean approve) throws ApplicationException Reviews a withdrawal request This implementation validates that:- The application exists and is associated with a valid project
- The manager is authorized to review the withdrawal (manages the project)
- The application actually has a pending withdrawal request
- The application status is set to UNSUCCESSFUL
- The withdrawal request date is cleared
- The withdrawal request date is cleared, but the status remains unchanged
- The application continues in its original process
- Specified by:
reviewWithdrawal
in interfaceIApplicationService
- Parameters:
manager
- The manager reviewing the withdrawalapplicationId
- ID of the application to withdrawapprove
- true to approve, false to reject withdrawal- Returns:
- true if review was successful, false otherwise
- Throws:
ApplicationException
- if the withdrawal review process fails
-
getApplicationForUser
Gets the application for a specific applicantThis implementation validates the applicant NRIC and delegates to the repository layer to retrieve the appropriate application. In this system, an applicant can only have one "active" application at a time, so this method returns the most relevant one.
- Specified by:
getApplicationForUser
in interfaceIApplicationService
- Parameters:
applicantNric
- NRIC of the applicant- Returns:
- The application, or null if not found
-
getApplicationsByProject
Gets all applications for a specific projectThis implementation validates the project ID and handles potential exceptions during data retrieval, ensuring that null results are converted to empty lists for consistent API behavior.
- Specified by:
getApplicationsByProject
in interfaceIApplicationService
- Parameters:
projectId
- ID of the project- Returns:
- List of applications for the project
- Throws:
DataAccessException
-
getApplicationsByStatus
public List<Application> getApplicationsByStatus(ApplicationStatus status) throws DataAccessException Gets all applications with a specific statusThis implementation validates the status parameter and handles potential exceptions during data retrieval, ensuring that null results are converted to empty lists for consistent API behavior.
Note: This method returns applications across all projects, so additional authorization checks may be needed in the controller layer.
- Specified by:
getApplicationsByStatus
in interfaceIApplicationService
- Parameters:
status
- Status to filter by- Returns:
- List of applications with the specified status
- Throws:
DataAccessException
-