Class ProjectService
- All Implemented Interfaces:
IProjectService
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 Summary
ConstructorsConstructorDescriptionProjectService
(IProjectRepository projectRepo, IEligibilityService eligibilityService, IApplicationRepository applicationRepo, IOfficerRegistrationRepository officerRegRepo) Constructs a new ProjectService with the required dependencies. -
Method Summary
Modifier and TypeMethodDescriptioncreateProject
(HDBManager manager, String name, String neighborhood, Map<String, ProjectFlatInfo> flatInfoMap, LocalDate openDate, LocalDate closeDate, int officerSlots) Creates a new project with the specified details.boolean
deleteProject
(HDBManager manager, String projectId) Deletes a project if it meets the deletion criteria.boolean
editCoreProjectDetails
(HDBManager manager, String projectId, String name, String neighborhood, LocalDate openDate, LocalDate closeDate, int officerSlots) Edits the core details of an existing project.findProjectById
(String projectId) Retrieves a project by its unique identifier.getAllProjects
(User user, Map<String, Object> filters) Retrieves all projects visible to a specific user, with optional filters.Retrieves all projects available for an HDB Officer to register for.getProjectsManagedBy
(String managerNRIC) Retrieves all projects managed by a specific manager.getProjectsManagedBy
(String managerNRIC, Map<String, Object> filters) Retrieves all projects managed by a specific manager with optional filters.Retrieves all currently visible projects for which the user is eligible to apply.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.boolean
toggleVisibility
(HDBManager manager, String projectId) Toggles the visibility of a project.
-
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 dataeligibilityService
- Service for eligibility checksapplicationRepo
- Repository for application dataofficerRegRepo
- 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 interfaceIProjectService
- Parameters:
manager
- The HDB manager creating the projectname
- The name of the projectneighborhood
- The neighborhood where the project is locatedflatInfoMap
- A map of flat types and their detailsopenDate
- The opening date for applicationscloseDate
- The closing date for applicationsofficerSlots
- 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 interfaceIProjectService
- Parameters:
manager
- The HDB manager editing the projectprojectId
- The ID of the project to editname
- The new name of the projectneighborhood
- The new neighborhood of the projectopenDate
- The new opening date for applicationscloseDate
- The new closing date for applicationsofficerSlots
- The new maximum number of officer slots- Returns:
- true if the project was successfully updated, false otherwise
-
deleteProject
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 interfaceIProjectService
- Parameters:
manager
- The HDB manager requesting the deletionprojectId
- The ID of the project to delete- Returns:
- true if the project was successfully deleted, false otherwise
-
toggleVisibility
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 interfaceIProjectService
- Parameters:
manager
- The HDB manager requesting the visibility changeprojectId
- The ID of the project to toggle visibility for- Returns:
- true if the visibility was successfully toggled, false otherwise
-
getAllProjects
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 interfaceIProjectService
- Parameters:
user
- The user requesting the projectsfilters
- A map of optional filters to apply- Returns:
- A list of projects matching the criteria
-
getProjectsManagedBy
Retrieves all projects managed by a specific manager.- Specified by:
getProjectsManagedBy
in interfaceIProjectService
- Parameters:
managerNRIC
- The NRIC of the manager- Returns:
- A list of projects managed by the specified manager
-
getProjectsManagedBy
Description copied from interface:IProjectService
Retrieves all projects managed by a specific manager with optional filters.- Specified by:
getProjectsManagedBy
in interfaceIProjectService
- Parameters:
managerNRIC
- The NRIC of the managerfilters
- 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
Retrieves a project by its unique identifier.- Specified by:
findProjectById
in interfaceIProjectService
- Parameters:
projectId
- The ID of the project to retrieve- Returns:
- The Project object, or null if not found
-
getVisibleProjectsForUser
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 interfaceIProjectService
- Parameters:
user
- The user for whom to filter the projects- Returns:
- A list of visible projects for which the user is eligible
-
getVisibleProjectsForUser
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 interfaceIProjectService
- 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
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 interfaceIProjectService
- Parameters:
officer
- The HDB Officer for whom to find available projects- Returns:
- A list of projects available for officer registration
-