-
Notifications
You must be signed in to change notification settings - Fork 101
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Closes #2366 - add TaskEndstatePreprocessor
- Loading branch information
Showing
9 changed files
with
259 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
lib/taskana-core/src/main/java/pro/taskana/spi/task/api/TaskEndstatePreprocessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package pro.taskana.spi.task.api; | ||
|
||
import pro.taskana.task.api.models.Task; | ||
|
||
/** | ||
* The TaskEndstatePreprocessor allows to implement customized behaviour before the given | ||
* {@linkplain Task} goes into an {@linkplain pro.taskana.task.api.TaskState#END_STATES end state} | ||
* (cancelled, terminated or completed). | ||
*/ | ||
public interface TaskEndstatePreprocessor { | ||
|
||
/** | ||
* Perform any action before a {@linkplain Task} goes into an {@linkplain | ||
* pro.taskana.task.api.TaskState#END_STATES end state}. A {@linkplain Task} goes into an end | ||
* state at the end of the following methods: {@linkplain | ||
* pro.taskana.task.api.TaskService#completeTask(String)}, {@linkplain | ||
* pro.taskana.task.api.TaskService#cancelTask(String)}, {@linkplain | ||
* pro.taskana.task.api.TaskService#terminateTask(String)}. | ||
* | ||
* <p>This SPI is executed within the same transaction staple as {@linkplain | ||
* pro.taskana.task.api.TaskService#completeTask(String)}, {@linkplain | ||
* pro.taskana.task.api.TaskService#cancelTask(String)}, {@linkplain | ||
* pro.taskana.task.api.TaskService#terminateTask(String)}. | ||
* | ||
* <p>This SPI is executed with the same {@linkplain | ||
* pro.taskana.common.api.security.UserPrincipal} and {@linkplain | ||
* pro.taskana.common.api.security.GroupPrincipal} as in the methods mentioned above. | ||
* | ||
* @param taskToProcess the {@linkplain Task} to preprocess | ||
* @return the modified {@linkplain Task}. <b>IMPORTANT:</b> persistent changes to the {@linkplain | ||
* Task} have to be managed by the service provider | ||
*/ | ||
Task processTaskBeforeEndstate(Task taskToProcess); | ||
} |
39 changes: 39 additions & 0 deletions
39
...ana-core/src/main/java/pro/taskana/spi/task/internal/TaskEndstatePreprocessorManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package pro.taskana.spi.task.internal; | ||
|
||
import static pro.taskana.common.internal.util.CheckedConsumer.wrap; | ||
|
||
import java.util.List; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import pro.taskana.common.internal.util.SpiLoader; | ||
import pro.taskana.spi.task.api.TaskEndstatePreprocessor; | ||
import pro.taskana.task.api.models.Task; | ||
|
||
public class TaskEndstatePreprocessorManager { | ||
|
||
private static final Logger LOGGER = | ||
LoggerFactory.getLogger(TaskEndstatePreprocessorManager.class); | ||
private final List<TaskEndstatePreprocessor> taskEndstatePreprocessors; | ||
|
||
public TaskEndstatePreprocessorManager() { | ||
taskEndstatePreprocessors = SpiLoader.load(TaskEndstatePreprocessor.class); | ||
for (TaskEndstatePreprocessor preprocessor : taskEndstatePreprocessors) { | ||
LOGGER.info( | ||
"Registered TaskEndstatePreprocessor provider: {}", preprocessor.getClass().getName()); | ||
} | ||
if (taskEndstatePreprocessors.isEmpty()) { | ||
LOGGER.info("No TaskEndstatePreprocessor found. Running without TaskEndstatePreprocessor."); | ||
} | ||
} | ||
|
||
public Task processTaskBeforeEndstate(Task taskToProcess) { | ||
if (LOGGER.isDebugEnabled()) { | ||
LOGGER.debug("Sending task to TaskEndstatePreprocessor providers: {}", taskToProcess); | ||
} | ||
taskEndstatePreprocessors.forEach( | ||
wrap( | ||
taskEndstatePreprocessor -> | ||
taskEndstatePreprocessor.processTaskBeforeEndstate(taskToProcess))); | ||
return taskToProcess; | ||
} | ||
} |
Oops, something went wrong.