TSK-726 Refactored public api and history event producer to initialize TaskanaHistory implementations
This commit is contained in:
parent
db5ac76c25
commit
5817cc15a6
|
@ -6,6 +6,7 @@ import java.util.ServiceLoader;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import pro.taskana.configuration.TaskanaEngineConfiguration;
|
||||
import pro.taskana.history.api.TaskanaHistory;
|
||||
import pro.taskana.history.api.TaskanaHistoryEvent;
|
||||
|
||||
|
@ -16,26 +17,30 @@ public final class HistoryEventProducer {
|
|||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(HistoryEventProducer.class);
|
||||
|
||||
TaskanaEngineConfiguration taskanaEngineConfiguration;
|
||||
private static HistoryEventProducer emitterInstance;
|
||||
private ServiceLoader<TaskanaHistory> serviceLoader;
|
||||
private boolean enabled = false;
|
||||
|
||||
public static synchronized HistoryEventProducer getInstance() {
|
||||
|
||||
public static synchronized HistoryEventProducer getInstance(TaskanaEngineConfiguration taskanaEngineConfiguration) {
|
||||
if (emitterInstance == null) {
|
||||
emitterInstance = new HistoryEventProducer();
|
||||
emitterInstance = new HistoryEventProducer(taskanaEngineConfiguration);
|
||||
}
|
||||
return emitterInstance;
|
||||
}
|
||||
|
||||
public static boolean isHistoryEnabled() {
|
||||
return getInstance().isEnabled();
|
||||
return getInstance(null).isEnabled();
|
||||
}
|
||||
|
||||
private HistoryEventProducer() {
|
||||
private HistoryEventProducer(TaskanaEngineConfiguration taskanaEngineConfiguration) {
|
||||
this.taskanaEngineConfiguration = taskanaEngineConfiguration;
|
||||
serviceLoader = ServiceLoader.load(TaskanaHistory.class);
|
||||
Iterator<TaskanaHistory> serviceIterator = serviceLoader.iterator();
|
||||
while (serviceIterator.hasNext()) {
|
||||
TaskanaHistory history = serviceIterator.next();
|
||||
history.initialize(taskanaEngineConfiguration);
|
||||
LOGGER.info("Registered history provider: {}", history.getClass().getName());
|
||||
enabled = true;
|
||||
}
|
||||
|
|
|
@ -1,10 +1,20 @@
|
|||
package pro.taskana.history.api;
|
||||
|
||||
import pro.taskana.configuration.TaskanaEngineConfiguration;
|
||||
|
||||
/**
|
||||
* Interface for TASKANA History Service Provider.
|
||||
*/
|
||||
public interface TaskanaHistory {
|
||||
|
||||
/**
|
||||
* Initialize TaskanaHistory service.
|
||||
*
|
||||
* @param taskanaEngineConfiguration
|
||||
* {@link TaskanaEngineConfiguration} The Taskana engine configuration for needed initialization.
|
||||
*/
|
||||
void initialize(TaskanaEngineConfiguration taskanaEngineConfiguration);
|
||||
|
||||
/**
|
||||
* Create a new history event.
|
||||
*
|
||||
|
|
|
@ -9,7 +9,7 @@ import pro.taskana.security.CurrentUserContext;
|
|||
*/
|
||||
public class TaskanaHistoryEvent {
|
||||
|
||||
protected long id;
|
||||
protected String id;
|
||||
protected String type;
|
||||
protected String userId;
|
||||
protected Instant created;
|
||||
|
@ -19,11 +19,11 @@ public class TaskanaHistoryEvent {
|
|||
userId = CurrentUserContext.getUserid();
|
||||
}
|
||||
|
||||
public long getId() {
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(long id) {
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
|
|
|
@ -68,7 +68,7 @@ public class TaskanaEngineImpl implements TaskanaEngine {
|
|||
this.taskanaEngineConfiguration = taskanaEngineConfiguration;
|
||||
createTransactionFactory(taskanaEngineConfiguration.getUseManagedTransactions());
|
||||
this.sessionManager = createSqlSessionManager();
|
||||
this.historyEventProducer = HistoryEventProducer.getInstance();
|
||||
this.historyEventProducer = HistoryEventProducer.getInstance(taskanaEngineConfiguration);
|
||||
}
|
||||
|
||||
public static TaskanaEngine createTaskanaEngine(TaskanaEngineConfiguration taskanaEngineConfiguration) {
|
||||
|
|
|
@ -15,10 +15,6 @@ import org.springframework.context.annotation.PropertySource;
|
|||
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
|
||||
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
||||
|
||||
import pro.taskana.ClassificationService;
|
||||
import pro.taskana.TaskService;
|
||||
import pro.taskana.TaskanaEngine;
|
||||
import pro.taskana.WorkbasketService;
|
||||
import pro.taskana.configuration.SpringTaskanaEngineConfiguration;
|
||||
|
||||
/**
|
||||
|
@ -93,6 +89,6 @@ public class TaskanaConfig {
|
|||
|
||||
@Bean
|
||||
public ExampleBootstrap exampleBootstrap() {
|
||||
return new ExampleBootstrap() ;
|
||||
return new ExampleBootstrap();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue