Class BaseTaskService<T extends Task,S>

java.lang.Object
at.jku.dke.etutor.task_app.services.BaseTaskService<T,S>
Type Parameters:
T - The task type.
S - The type of the additional data used in ModifyTaskDto.
All Implemented Interfaces:
TaskService<T,S>
Direct Known Subclasses:
BaseTaskInGroupService

@PreAuthorize("hasAuthority(\'CRUD\')") public abstract class BaseTaskService<T extends Task,S> extends Object implements TaskService<T,S>
This class provides methods for managing Tasks.
  • Field Details

    • LOG

      protected static final org.slf4j.Logger LOG
      The logger used in this class.
    • repository

      protected final TaskRepository<T extends Task> repository
      The task repository.
  • Constructor Details

    • BaseTaskService

      protected BaseTaskService(TaskRepository<T> repository)
      Creates a new instance of class BaseTaskService.
      Parameters:
      repository - The task repository.
  • Method Details

    • get

      @Transactional(readOnly=true) public Optional<T> get(long id)
      Returns the task with the specified identifier.
      Specified by:
      get in interface TaskService<T extends Task,S>
      Parameters:
      id - The identifier.
      Returns:
      The task or an empty result if the task does not exist.
    • create

      Creates a new task.
      Specified by:
      create in interface TaskService<T extends Task,S>
      Parameters:
      id - The task identifier.
      dto - The task data.
      Returns:
      The data that should be sent to the task administration UI (might be null).
      Throws:
      DuplicateKeyException - If a task with the specified identifier already exists.
    • update

      Updates an existing task.
      Specified by:
      update in interface TaskService<T extends Task,S>
      Parameters:
      id - The task identifier.
      dto - The new task data.
      Returns:
      The data that should be sent to the task administration UI (might be null).
      Throws:
      jakarta.persistence.EntityNotFoundException - If the task does not exist.
    • delete

      @Transactional public void delete(long id)
      Deletes the task with the specified identifier.
      Specified by:
      delete in interface TaskService<T extends Task,S>
      Parameters:
      id - The identifier of the task to delete.
    • createTask

      protected abstract T createTask(long id, ModifyTaskDto<S> dto)
      Creates a new task.
      Parameters:
      id - The task identifier.
      dto - The task data.
      Returns:
      The created task.
      Implementation Requirements:
      This method SHOULD NOT save the entity to the database as this is done by the caller. This method SHOULD ONLY set the task type specific attributes of the task. The other attributes are set by the caller.
    • updateTask

      protected abstract void updateTask(T task, ModifyTaskDto<S> dto)
      Sets the task type specific attributes of the task.
      Parameters:
      task - The task.
      dto - The new task data.
    • mapToReturnData

      protected TaskModificationResponseDto mapToReturnData(T task, boolean create)
      Maps the task to the data that should be returned to the task administration UI.
      Parameters:
      task - The task.
      create - true, if the specified task was just created; false if the task was updated.
      Returns:
      The data to send.
    • beforeCreate

      protected void beforeCreate(T task, ModifyTaskDto<S> dto)
      Called before the task is stored in the database.

      Override this method to perform additional actions before creating the task.

      Parameters:
      task - The task to create.
      dto - The task data.
    • afterCreate

      protected void afterCreate(T task, ModifyTaskDto<S> dto)
      Called after the task is stored in the database.

      This method runs in the same transaction as the calling method. Override this method to perform additional actions after creating the task.

      Parameters:
      task - The created task.
      dto - The task data.
    • afterUpdate

      protected void afterUpdate(T task, ModifyTaskDto<S> dto)
      Called after the task is updated in the database.

      This method runs in the same transaction as the calling method. Override this method to perform additional actions after updating the task.

      Parameters:
      task - The updated task.
      dto - The task data.
    • beforeDelete

      protected void beforeDelete(long id)
      Called before the task with the specified identifier is deleted.

      Override this method to perform additional actions before deleting the task.

      Parameters:
      id - The identifier of the task to delete.
    • afterDelete

      protected void afterDelete(long id)
      Called after the task with the specified identifier is deleted.

      This method runs in the same transaction as the calling method. Override this method to perform additional actions after deleting the task.

      Parameters:
      id - The identifier of the deleted task.