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.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import pro.taskana.configuration.TaskanaEngineConfiguration;
|
||||||
import pro.taskana.history.api.TaskanaHistory;
|
import pro.taskana.history.api.TaskanaHistory;
|
||||||
import pro.taskana.history.api.TaskanaHistoryEvent;
|
import pro.taskana.history.api.TaskanaHistoryEvent;
|
||||||
|
|
||||||
|
|
@ -16,26 +17,30 @@ public final class HistoryEventProducer {
|
||||||
|
|
||||||
private static final Logger LOGGER = LoggerFactory.getLogger(HistoryEventProducer.class);
|
private static final Logger LOGGER = LoggerFactory.getLogger(HistoryEventProducer.class);
|
||||||
|
|
||||||
|
TaskanaEngineConfiguration taskanaEngineConfiguration;
|
||||||
private static HistoryEventProducer emitterInstance;
|
private static HistoryEventProducer emitterInstance;
|
||||||
private ServiceLoader<TaskanaHistory> serviceLoader;
|
private ServiceLoader<TaskanaHistory> serviceLoader;
|
||||||
private boolean enabled = false;
|
private boolean enabled = false;
|
||||||
|
|
||||||
public static synchronized HistoryEventProducer getInstance() {
|
|
||||||
|
public static synchronized HistoryEventProducer getInstance(TaskanaEngineConfiguration taskanaEngineConfiguration) {
|
||||||
if (emitterInstance == null) {
|
if (emitterInstance == null) {
|
||||||
emitterInstance = new HistoryEventProducer();
|
emitterInstance = new HistoryEventProducer(taskanaEngineConfiguration);
|
||||||
}
|
}
|
||||||
return emitterInstance;
|
return emitterInstance;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isHistoryEnabled() {
|
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);
|
serviceLoader = ServiceLoader.load(TaskanaHistory.class);
|
||||||
Iterator<TaskanaHistory> serviceIterator = serviceLoader.iterator();
|
Iterator<TaskanaHistory> serviceIterator = serviceLoader.iterator();
|
||||||
while (serviceIterator.hasNext()) {
|
while (serviceIterator.hasNext()) {
|
||||||
TaskanaHistory history = serviceIterator.next();
|
TaskanaHistory history = serviceIterator.next();
|
||||||
|
history.initialize(taskanaEngineConfiguration);
|
||||||
LOGGER.info("Registered history provider: {}", history.getClass().getName());
|
LOGGER.info("Registered history provider: {}", history.getClass().getName());
|
||||||
enabled = true;
|
enabled = true;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,20 @@
|
||||||
package pro.taskana.history.api;
|
package pro.taskana.history.api;
|
||||||
|
|
||||||
|
import pro.taskana.configuration.TaskanaEngineConfiguration;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Interface for TASKANA History Service Provider.
|
* Interface for TASKANA History Service Provider.
|
||||||
*/
|
*/
|
||||||
public interface TaskanaHistory {
|
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.
|
* Create a new history event.
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ import pro.taskana.security.CurrentUserContext;
|
||||||
*/
|
*/
|
||||||
public class TaskanaHistoryEvent {
|
public class TaskanaHistoryEvent {
|
||||||
|
|
||||||
protected long id;
|
protected String id;
|
||||||
protected String type;
|
protected String type;
|
||||||
protected String userId;
|
protected String userId;
|
||||||
protected Instant created;
|
protected Instant created;
|
||||||
|
|
@ -19,11 +19,11 @@ public class TaskanaHistoryEvent {
|
||||||
userId = CurrentUserContext.getUserid();
|
userId = CurrentUserContext.getUserid();
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getId() {
|
public String getId() {
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setId(long id) {
|
public void setId(String id) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -68,7 +68,7 @@ public class TaskanaEngineImpl implements TaskanaEngine {
|
||||||
this.taskanaEngineConfiguration = taskanaEngineConfiguration;
|
this.taskanaEngineConfiguration = taskanaEngineConfiguration;
|
||||||
createTransactionFactory(taskanaEngineConfiguration.getUseManagedTransactions());
|
createTransactionFactory(taskanaEngineConfiguration.getUseManagedTransactions());
|
||||||
this.sessionManager = createSqlSessionManager();
|
this.sessionManager = createSqlSessionManager();
|
||||||
this.historyEventProducer = HistoryEventProducer.getInstance();
|
this.historyEventProducer = HistoryEventProducer.getInstance(taskanaEngineConfiguration);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static TaskanaEngine createTaskanaEngine(TaskanaEngineConfiguration 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.jdbc.datasource.DataSourceTransactionManager;
|
||||||
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
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;
|
import pro.taskana.configuration.SpringTaskanaEngineConfiguration;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -93,6 +89,6 @@ public class TaskanaConfig {
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public ExampleBootstrap exampleBootstrap() {
|
public ExampleBootstrap exampleBootstrap() {
|
||||||
return new ExampleBootstrap() ;
|
return new ExampleBootstrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue