Class ApplicationService

java.lang.Object
com.ntu.fdae.group1.bto.services.project.ApplicationService
All Implemented Interfaces:
IApplicationService

public class ApplicationService extends Object implements IApplicationService
Implementation of the IApplicationService interface that manages the application lifecycle in the BTO Management System. This service handles all aspects of BTO project applications, including:
  • 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
The service enforces complex business rules such as:
  • 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 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 data
      projRepo - Repository for project data
      eligSvc - Service for checking eligibility
      officerRegRepo - 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 interface IApplicationService
      Parameters:
      user - The applicant submitting the application
      projectId - ID of the project to apply for
      preferredFlatType - The type of flat the applicant prefers
      Returns:
      The created application
      Throws:
      ApplicationException - if application submission fails
    • requestWithdrawal

      public boolean requestWithdrawal(User user) throws ApplicationException
      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 interface IApplicationService
      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)
      When approving an application, this method also:
      • 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 interface IApplicationService
      Parameters:
      manager - The manager reviewing the application
      applicationId - ID of the application to review
      approve - 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
      When approving a withdrawal:
      • The application status is set to UNSUCCESSFUL
      • The withdrawal request date is cleared
      When rejecting a withdrawal:
      • The withdrawal request date is cleared, but the status remains unchanged
      • The application continues in its original process
      Specified by:
      reviewWithdrawal in interface IApplicationService
      Parameters:
      manager - The manager reviewing the withdrawal
      applicationId - ID of the application to withdraw
      approve - true to approve, false to reject withdrawal
      Returns:
      true if review was successful, false otherwise
      Throws:
      ApplicationException - if the withdrawal review process fails
    • getApplicationForUser

      public Application getApplicationForUser(String applicantNric)
      Gets the application for a specific applicant

      This 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 interface IApplicationService
      Parameters:
      applicantNric - NRIC of the applicant
      Returns:
      The application, or null if not found
    • getApplicationsByProject

      public List<Application> getApplicationsByProject(String projectId) throws DataAccessException
      Gets all applications for a specific project

      This 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 interface IApplicationService
      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 status

      This 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 interface IApplicationService
      Parameters:
      status - Status to filter by
      Returns:
      List of applications with the specified status
      Throws:
      DataAccessException