Class ProjectController

java.lang.Object
com.ntu.fdae.group1.bto.controllers.project.ProjectController

public class ProjectController extends Object
Controller for project-related operations
  • Constructor Details

    • ProjectController

      public ProjectController(IProjectService projectService)
      Constructs a new ProjectController
      Parameters:
      projectService - The project service to use
  • 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
      Parameters:
      manager - The manager creating the project
      name - Project name
      neighborhood - Project location
      flatInfoMap - Information about flat types
      openDate - Opening date for applications
      closeDate - Closing date for applications
      officerSlots - Number of slots for officers
      Returns:
      The created project
    • editProject

      public boolean editProject(HDBManager manager, String projectId, String name, String neighborhood, LocalDate openDate, LocalDate closeDate, int officerSlots)
      Edits an existing project
      Parameters:
      manager - The manager editing the project
      projectId - ID of the project to edit
      name - New name
      neighborhood - New location
      openDate - New opening date
      closeDate - New closing date
      officerSlots - New number of officer slots
      Returns:
      true if edit was successful, false otherwise
    • deleteProject

      public boolean deleteProject(HDBManager manager, String projectId)
      Deletes a project
      Parameters:
      manager - The manager deleting the project
      projectId - ID of the project to delete
      Returns:
      true if deletion was successful, false otherwise
    • toggleProjectVisibility

      public boolean toggleProjectVisibility(HDBManager manager, String projectId)
      Toggles the visibility of a project
      Parameters:
      manager - The manager toggling visibility
      projectId - ID of the project to toggle
      Returns:
      true if toggle was successful, false otherwise
    • getVisibleProjectsForUser

      public List<Project> getVisibleProjectsForUser(User user)
      Gets projects visible to a user (without additional filters).
      Parameters:
      user - The user to get visible projects for
      Returns:
      List of visible projects
    • getVisibleProjectsForUser

      public List<Project> getVisibleProjectsForUser(User user, Map<String,Object> filters)
      Retrieves projects that are visible to a specific user, with optional filtering.
      Parameters:
      user - The user for whom to retrieve visible projects
      filters - Optional filters to apply to the results (e.g., neighborhood, flat types)
      Returns:
      A list of projects visible to the user, filtered as specified
    • getAllProjects

      public List<Project> getAllProjects(User user, Map<String,Object> filter) throws AuthorizationException
      Retrieves all projects in the system, with optional filtering.

      This method is restricted to HDB staff members and will throw an exception if accessed by regular applicants.

      Parameters:
      user - The user requesting the projects (must be HDB staff)
      filter - Optional filters to apply to the results (e.g., neighborhood, flat types)
      Returns:
      A list of all projects, filtered as specified
      Throws:
      AuthorizationException - If the user is not authorized to view all projects
    • getProjectsManagedBy

      public List<Project> getProjectsManagedBy(HDBManager manager)
      Gets projects managed by a specific HDB Manager object.
      Parameters:
      manager - The HDBManager object.
      Returns:
      List of projects managed by the manager.
    • getProjectsManagedBy

      public List<Project> getProjectsManagedBy(HDBManager manager, Map<String,Object> filters)
      Retrieves projects managed by a specific HDB manager, with optional filtering.
      Parameters:
      manager - The HDB manager whose projects to retrieve
      filters - Optional filters to apply to the results (e.g., neighborhood, flat types)
      Returns:
      A list of projects managed by the specified manager, filtered as specified
    • findProjectById

      public Project findProjectById(String projectId)
      Finds a project by its ID
      Parameters:
      projectId - ID of the project to find
      Returns:
      The project, or null if not found
    • getProjectsAvailableForRegistration

      public List<Project> getProjectsAvailableForRegistration(HDBOfficer officer)
      Gets projects potentially available for the given officer to register for handling. Delegates filtering logic (e.g., excluding projects already applied for or registered for) to the ProjectService.
      Parameters:
      officer - The HDBOfficer requesting the list. Must not be null.
      Returns:
      A List of Project objects available for registration, sorted by name.
      Throws:
      IllegalArgumentException - if officer is null.
      RuntimeException - if an unexpected error occurs during retrieval.