Class OfficerRegistrationController

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

public class OfficerRegistrationController extends Object
Controller for officer registration operations. Acts as an intermediary between the UI layer and the Service layer, handling input validation and orchestrating calls to the service.
  • Constructor Details

    • OfficerRegistrationController

      public OfficerRegistrationController(IOfficerRegistrationService regService, IProjectService projService)
      Constructs a new OfficerRegistrationController with necessary services.
      Parameters:
      regService - Service for officer registration operations
      projService - Service for project-related operations
  • Method Details

    • requestRegistration

      public OfficerRegistration requestRegistration(HDBOfficer officer, String projectId) throws RegistrationException
      Handles an HDB Officer's request to register for a specific project. Validates input and delegates the core logic, including eligibility checks, to the registration service.
      Parameters:
      officer - The HDBOfficer making the request. Must not be null.
      projectId - The ID of the project to register for. Must not be null or blank.
      Returns:
      The created OfficerRegistration object (initially PENDING) if successful.
      Throws:
      RegistrationException - if the officer is ineligible, the project doesn't exist, the officer is already registered, or another service-level error occurs.
      IllegalArgumentException - if officer or projectId is null/blank (programmer error).
    • reviewRegistration

      public boolean reviewRegistration(HDBManager manager, String registrationId, boolean approve) throws RegistrationException
      Handles an HDB Manager's review (approval or rejection) of a pending officer registration request. Validates input and delegates the core logic, including authorization and state checks, to the registration service.
      Parameters:
      manager - The HDBManager performing the review. Must not be null.
      registrationId - The ID of the OfficerRegistration to review. Must not be null or blank.
      approve - true to approve the registration, false to reject it.
      Returns:
      true if the review action was successfully processed by the service.
      Throws:
      RegistrationException - if the registration is not found, not pending, the manager lacks permission, approval violates rules (e.g., slots full), or another service-level error occurs.
      IllegalArgumentException - if manager or registrationId is null/blank (programmer error).
    • getMyRegistrationStatus

      public OfficerRegStatus getMyRegistrationStatus(HDBOfficer officer, String projectId)
      Retrieves the current registration status for a specific officer regarding a specific project.
      Parameters:
      officer - The HDBOfficer whose status is requested. Must not be null.
      projectId - The ID of the project. Must not be null or blank.
      Returns:
      The OfficerRegStatus (PENDING, APPROVED, REJECTED), or null if no registration exists for this officer and project combination, or if input parameters are invalid.
    • getPendingRegistrations

      public List<OfficerRegistration> getPendingRegistrations(HDBManager manager)
      Gets a list of all officer registrations currently in the PENDING state. Typically requested by an HDB Manager.
      Parameters:
      manager - The HDBManager requesting the list. Must not be null (indicates authenticated context).
      Returns:
      An immutable List of pending OfficerRegistration objects. Returns an empty list if none are pending.
      Throws:
      IllegalArgumentException - if manager is null (programmer error - context missing).
      RuntimeException - if an unexpected error occurs during retrieval in the service/repository layer.
    • getPendingRegistrationCountForProject

      public int getPendingRegistrationCountForProject(HDBStaff staff, String projectId) throws AuthorizationException
      Gets the count of PENDING officer registrations specifically for a given project. Accessible by the project's managing HDB Manager or an HDB Officer approved for the project. Includes authorization checks based on the staff member's role.
      Parameters:
      staff - The HDBStaff (Manager or Officer) requesting the count. Must not be null.
      projectId - The ID of the project. Must not be null or blank.
      Returns:
      The number of pending registrations for the specified project.
      Throws:
      IllegalArgumentException - if staff or projectId is null/blank.
      AuthorizationException - if the staff member is not authorized for this project based on their role.
      RuntimeException - if the project is not found or an unexpected error occurs during retrieval.
    • findApprovedHandlingProject

      public List<Project> findApprovedHandlingProject(HDBOfficer officer)
      Finds ALL projects an officer is currently approved to handle. Fetches all registrations for the officer and filters for APPROVED status.
      Parameters:
      officer - The officer whose approved projects are sought.
      Returns:
      A List containing all Project objects they are approved for. Returns an empty list if the officer is null, has no registrations, or has no APPROVED registrations.
    • getMyRegistrations

      public List<OfficerRegistration> getMyRegistrations(HDBOfficer officer)
      Retrieves all registration requests submitted by the specified officer.
      Parameters:
      officer - The HDBOfficer whose registrations are requested. Must not be null.
      Returns:
      An immutable List of OfficerRegistration objects for this officer. Returns an empty list if none found or input is invalid.
      Throws:
      IllegalArgumentException - if officer is null.
      RuntimeException - if an unexpected error occurs during retrieval.