Class TaskAssignmentService

java.lang.Object
no.ntnu.principes.service.TaskAssignmentService

public class TaskAssignmentService extends Object
Manages task assignments and their lifecycle in the household system. Handles task completion, assignment to members, points calculation, and recurring task management.
  • Constructor Details

    • TaskAssignmentService

      public TaskAssignmentService()
      Creates a new TaskAssignmentService with all required repositories. Repositories are obtained from the central DatabaseManager.
  • Method Details

    • completeTask

      public TaskAssignment completeTask(Long assignmentId)
      Marks a task assignment as completed, awards points, and handles recurring tasks.
      Parameters:
      assignmentId - The ID of the assignment to complete
      Returns:
      The updated task assignment with completed status
      Throws:
      IllegalArgumentException - if the assignment or task is not found
    • assignTask

      public TaskAssignment assignTask(Long taskId, Long memberId, boolean publishEvent)
      Assigns a task to a specific household member. If the task is already assigned to someone else or unassigned, updates the assignment.
      Parameters:
      taskId - The ID of the task to assign
      memberId - The ID of the member to assign the task to
      publishEvent - Whether to publish an event after assignment
      Returns:
      The created or updated task assignment
      Throws:
      IllegalArgumentException - if the task or member is not found
    • assignTask

      public TaskAssignment assignTask(Long taskId, Long memberId)
      Assigns a task to a specific household member. If the task is already assigned to someone else or unassigned, updates the assignment.
      Parameters:
      taskId - The ID of the task to assign
      memberId - The ID of the member to assign the task to
      Returns:
      The created or updated task assignment
      Throws:
      IllegalArgumentException - if the task or member is not found
    • getTasksForMember

      public List<TaskAssignmentDto> getTasksForMember(Long memberId)
      Gets all task assignments for a specific member.
      Parameters:
      memberId - The ID of the member
      Returns:
      A list of task assignment DTOs
    • getImmediateTasksForMember

      public List<TaskAssignmentDto> getImmediateTasksForMember(Long memberId)
      Gets immediate tasks (due within 2 days) for a specific member.
      Parameters:
      memberId - The ID of the member
      Returns:
      A list of immediate task assignment DTOs
    • getTasksForMemberDueAt

      public List<TaskAssignmentDto> getTasksForMemberDueAt(Long memberId, LocalDate dueDate)
      Gets all tasks due at a specific date for a specific member.
      Parameters:
      memberId - The ID of the member
      dueDate - The due date to filter by
      Returns:
      A list of task assignment DTOs
    • cancelTask

      public TaskAssignment cancelTask(Long assignmentId)
      Marks a task assignment as cancelled.
      Parameters:
      assignmentId - The ID of the assignment to cancel
      Returns:
      The updated task assignment with cancelled status
      Throws:
      IllegalArgumentException - if the assignment is not found
    • autoAssignTask

      public TaskAssignment autoAssignTask(Long taskId, boolean publishEvent)
      Automatically assigns a task to the member with the lowest current workload. Workload is calculated based on the total weight of a member's pending tasks.
      Parameters:
      taskId - The ID of the task to assign
      publishEvent - Whether to publish an event after assignment
      Returns:
      The created task assignment
      Throws:
      IllegalArgumentException - if the task is not found
      IllegalStateException - if no members are available or selection fails
    • autoAssignTask

      public TaskAssignment autoAssignTask(Long taskId)
      Automatically assigns a task to the member with the lowest current workload. Workload is calculated based on the total weight of a member's pending tasks.
      Parameters:
      taskId - The ID of the task to assign
      Returns:
      The created task assignment
      Throws:
      IllegalArgumentException - if the task is not found
      IllegalStateException - if no members are available or selection fails
    • calculateTotalWeightForUser

      public int calculateTotalWeightForUser(Long memberId)
    • getTasksByStatus

      public List<TaskAssignmentDto> getTasksByStatus(TaskStatus status)
      Gets all task assignments with a specific status.
      Parameters:
      status - The status to filter by
      Returns:
      A list of task assignment DTOs
    • getAllTasks

      public List<TaskAssignmentDto> getAllTasks()
      Gets all task assignments.
      Returns:
      A list of all task assignment DTOs
    • uncompleteTask

      public void uncompleteTask(Long id)
      Marks a completed task as incomplete. Resets the task status to TODO and clears the completion date.
      Parameters:
      id - The ID of the assignment to uncomplete
      Throws:
      IllegalArgumentException - if the assignment is not found