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 inModifyTaskDto
.
- 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
Task
s.-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final org.slf4j.Logger
The logger used in this class.protected final TaskRepository
<T> The task repository. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
BaseTaskService
(TaskRepository<T> repository) Creates a new instance of classBaseTaskService
. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
afterCreate
(T task, ModifyTaskDto<S> dto) Called after the task is stored in the database.protected void
afterDelete
(long id) Called after the task with the specified identifier is deleted.protected void
afterUpdate
(T task, ModifyTaskDto<S> dto) Called after the task is updated in the database.protected void
beforeCreate
(T task, ModifyTaskDto<S> dto) Called before the task is stored in the database.protected void
beforeDelete
(long id) Called before the task with the specified identifier is deleted.create
(long id, @Valid ModifyTaskDto<S> dto) Creates a new task.protected abstract T
createTask
(long id, ModifyTaskDto<S> dto) Creates a new task.void
delete
(long id) Deletes the task with the specified identifier.get
(long id) Returns the task with the specified identifier.protected TaskModificationResponseDto
mapToReturnData
(T task, boolean create) Maps the task to the data that should be returned to the task administration UI.update
(long id, @Valid ModifyTaskDto<S> dto) Updates an existing task.protected abstract void
updateTask
(T task, ModifyTaskDto<S> dto) Sets the task type specific attributes of the task.
-
Field Details
-
LOG
protected static final org.slf4j.Logger LOGThe logger used in this class. -
repository
The task repository.
-
-
Constructor Details
-
BaseTaskService
Creates a new instance of classBaseTaskService
.- Parameters:
repository
- The task repository.
-
-
Method Details
-
get
Returns the task with the specified identifier.- Specified by:
get
in interfaceTaskService<T extends Task,
S> - Parameters:
id
- The identifier.- Returns:
- The task or an empty result if the task does not exist.
-
create
@Transactional public TaskModificationResponseDto create(long id, @Valid @Valid ModifyTaskDto<S> dto) Creates a new task.- Specified by:
create
in interfaceTaskService<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
@Transactional public TaskModificationResponseDto update(long id, @Valid @Valid ModifyTaskDto<S> dto) Updates an existing task.- Specified by:
update
in interfaceTaskService<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
Deletes the task with the specified identifier.- Specified by:
delete
in interfaceTaskService<T extends Task,
S> - Parameters:
id
- The identifier of the task to delete.
-
createTask
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
Sets the task type specific attributes of the task.- Parameters:
task
- The task.dto
- The new task data.
-
mapToReturnData
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
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
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
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.
-