Class ProjectService

java.lang.Object
com.ntu.fdae.group1.bto.services.project.ProjectService
All Implemented Interfaces:
IProjectService

public class ProjectService extends Object implements IProjectService
Service class for managing project-related operations in the BTO Management System.

This class provides business logic for creating, editing, deleting, and retrieving project information. It interacts with repositories and other services to enforce application rules and ensure data consistency.

Key responsibilities include: - Managing project lifecycle (creation, editing, deletion) - Enforcing eligibility rules for managers and applicants - Filtering and retrieving projects based on user roles and criteria - Handling visibility toggles and officer registration constraints

  • Constructor Details

    • ProjectService

      public ProjectService(IProjectRepository projectRepo, IEligibilityService eligibilityService, IApplicationRepository applicationRepo, IOfficerRegistrationRepository officerRegRepo)
      Constructs a new ProjectService with the required dependencies.
      Parameters:
      projectRepo - Repository for project data
      eligibilityService - Service for eligibility checks
      applicationRepo - Repository for application data
      officerRegRepo - Repository for officer registration data
      Throws:
      NullPointerException - if any of the required dependencies are null
  • Method Details

    • createProject

      public Project createProject(HDBManager manager, String name, String neighborhood, Map<String,ProjectFlatInfo> flatInfoMap, LocalDate openDate, LocalDate closeDate, int officerSlots)
      Creates a new project with the specified details.

      Validates the input parameters, checks manager eligibility, and ensures the project meets all business rules before saving it to the repository.

      Specified by:
      createProject in interface IProjectService
      Parameters:
      manager - The HDB manager creating the project
      name - The name of the project
      neighborhood - The neighborhood where the project is located
      flatInfoMap - A map of flat types and their details
      openDate - The opening date for applications
      closeDate - The closing date for applications
      officerSlots - The maximum number of officer slots for the project
      Returns:
      The created Project object, or null if creation fails
    • editCoreProjectDetails

      public boolean editCoreProjectDetails(HDBManager manager, String projectId, String name, String neighborhood, LocalDate openDate, LocalDate closeDate, int officerSlots)
      Edits the core details of an existing project.

      Validates the input parameters, checks manager permissions, and ensures the updated project meets all business rules before saving the changes.

      Specified by:
      editCoreProjectDetails in interface IProjectService
      Parameters:
      manager - The HDB manager editing the project
      projectId - The ID of the project to edit
      name - The new name of the project
      neighborhood - The new neighborhood of the project
      openDate - The new opening date for applications
      closeDate - The new closing date for applications
      officerSlots - The new maximum number of officer slots
      Returns:
      true if the project was successfully updated, false otherwise
    • deleteProject

      public boolean deleteProject(HDBManager manager, String projectId)
      Deletes a project if it meets the deletion criteria.

      Ensures the project has no active applications and that the manager has the necessary permissions to delete it.

      Specified by:
      deleteProject in interface IProjectService
      Parameters:
      manager - The HDB manager requesting the deletion
      projectId - The ID of the project to delete
      Returns:
      true if the project was successfully deleted, false otherwise
    • toggleVisibility

      public boolean toggleVisibility(HDBManager manager, String projectId)
      Toggles the visibility of a project.

      Allows the manager to make a project visible or hidden, depending on its current state.

      Specified by:
      toggleVisibility in interface IProjectService
      Parameters:
      manager - The HDB manager requesting the visibility change
      projectId - The ID of the project to toggle visibility for
      Returns:
      true if the visibility was successfully toggled, false otherwise
    • getAllProjects

      public List<Project> getAllProjects(User user, Map<String,Object> filters)
      Retrieves all projects visible to a specific user, with optional filters.

      Filters can include criteria such as neighborhood, flat type, and visibility.

      Specified by:
      getAllProjects in interface IProjectService
      Parameters:
      user - The user requesting the projects
      filters - A map of optional filters to apply
      Returns:
      A list of projects matching the criteria
    • getProjectsManagedBy

      public List<Project> getProjectsManagedBy(String managerNRIC)
      Retrieves all projects managed by a specific manager.
      Specified by:
      getProjectsManagedBy in interface IProjectService
      Parameters:
      managerNRIC - The NRIC of the manager
      Returns:
      A list of projects managed by the specified manager
    • getProjectsManagedBy

      public List<Project> getProjectsManagedBy(String managerNRIC, Map<String,Object> filters)
      Description copied from interface: IProjectService
      Retrieves all projects managed by a specific manager with optional filters.
      Specified by:
      getProjectsManagedBy in interface IProjectService
      Parameters:
      managerNRIC - The NRIC of the manager
      filters - A map of optional filters to apply (neighborhood, flat type, visibility)
      Returns:
      A list of projects managed by the manager that match the filter criteria
    • findProjectById

      public Project findProjectById(String projectId)
      Retrieves a project by its unique identifier.
      Specified by:
      findProjectById in interface IProjectService
      Parameters:
      projectId - The ID of the project to retrieve
      Returns:
      The Project object, or null if not found
    • getVisibleProjectsForUser

      public List<Project> getVisibleProjectsForUser(User user)
      Description copied from interface: IProjectService
      Retrieves all currently visible projects for which the user is eligible to apply.

      This is a convenience overload that calls getVisibleProjectsForUser with an empty filter map.

      Specified by:
      getVisibleProjectsForUser in interface IProjectService
      Parameters:
      user - The user for whom to filter the projects
      Returns:
      A list of visible projects for which the user is eligible
    • getVisibleProjectsForUser

      public List<Project> getVisibleProjectsForUser(User user, Map<String,Object> filters)
      Gets a list of projects that are currently visible and eligible for a specific user (typically an Applicant or Officer acting as one) to potentially apply for. Filters based on project visibility, application closing date, and user eligibility rules. The list is sorted alphabetically by project name.
      Specified by:
      getVisibleProjectsForUser in interface IProjectService
      Parameters:
      user - The user for whom to filter the projects.
      filters - A map of optional filters (e.g., neighbourhood, flat type).
      Returns:
      A List of eligible and visible Project objects, sorted by name.
    • getProjectsAvailableForOfficerRegistration

      public List<Project> getProjectsAvailableForOfficerRegistration(HDBOfficer officer)
      Description copied from interface: IProjectService
      Retrieves all projects available for an HDB Officer to register for.

      An officer can register for a project if: - They have not applied for the project as an applicant - They are not already registered for the project - They are not registered for another project with an overlapping application period

      Specified by:
      getProjectsAvailableForOfficerRegistration in interface IProjectService
      Parameters:
      officer - The HDB Officer for whom to find available projects
      Returns:
      A list of projects available for officer registration