diff --git a/lib/taskana-core/src/main/java/pro/taskana/TaskanaEngine.java b/lib/taskana-core/src/main/java/pro/taskana/TaskanaEngine.java index 91fb36cf5..6fd5bf9be 100644 --- a/lib/taskana-core/src/main/java/pro/taskana/TaskanaEngine.java +++ b/lib/taskana-core/src/main/java/pro/taskana/TaskanaEngine.java @@ -56,16 +56,22 @@ public interface TaskanaEngine { TaskanaEngineConfiguration getConfiguration(); /** - * The HistoryEventProducer events and emits them to the registered history service providers. - * @return The HistoryEventProducer + * Checks if the history plugin is enabled. + * + * @return true if the history is enabled. Otherwise false. */ - HistoryEventProducer getHistoryEventProducer(); + boolean isHistoryEnabled(); /** - * sets the connection management mode for taskana. + * sets the connection management mode. * * @param mode - * See ConnectionManagementMode + * the connection management mode Valid values are: + * */ void setConnectionManagementMode(ConnectionManagementMode mode); @@ -167,6 +173,13 @@ public interface TaskanaEngine { */ TaskanaEngine getEngine(); + /** + * Retrieve HistoryEventProducer. + * + * @return the HistoryEventProducer instance. + */ + HistoryEventProducer getHistoryEventProducer(); + } } diff --git a/lib/taskana-core/src/main/java/pro/taskana/history/HistoryEventProducer.java b/lib/taskana-core/src/main/java/pro/taskana/history/HistoryEventProducer.java index 2b7dad0e8..7c84e5e54 100644 --- a/lib/taskana-core/src/main/java/pro/taskana/history/HistoryEventProducer.java +++ b/lib/taskana-core/src/main/java/pro/taskana/history/HistoryEventProducer.java @@ -15,9 +15,9 @@ import pro.taskana.history.api.TaskanaHistoryEvent; public final class HistoryEventProducer { private static final Logger LOGGER = LoggerFactory.getLogger(HistoryEventProducer.class); - private static HistoryEventProducer emitterInstance; + private static HistoryEventProducer singleton; + private static boolean enabled = false; private ServiceLoader serviceLoader; - private boolean enabled = false; private HistoryEventProducer(TaskanaEngineConfiguration taskanaEngineConfiguration) { serviceLoader = ServiceLoader.load(TaskanaHistory.class); @@ -32,17 +32,13 @@ public final class HistoryEventProducer { } public static synchronized HistoryEventProducer getInstance(TaskanaEngineConfiguration taskanaEngineConfiguration) { - if (emitterInstance == null) { - emitterInstance = new HistoryEventProducer(taskanaEngineConfiguration); + if (singleton == null) { + singleton = new HistoryEventProducer(taskanaEngineConfiguration); } - return emitterInstance; + return singleton; } public static boolean isHistoryEnabled() { - return getInstance(null).isEnabled(); - } - - public boolean isEnabled() { return enabled; } diff --git a/lib/taskana-core/src/main/java/pro/taskana/impl/TaskServiceImpl.java b/lib/taskana-core/src/main/java/pro/taskana/impl/TaskServiceImpl.java index dbb79c3ad..1c05147a3 100644 --- a/lib/taskana-core/src/main/java/pro/taskana/impl/TaskServiceImpl.java +++ b/lib/taskana-core/src/main/java/pro/taskana/impl/TaskServiceImpl.java @@ -105,7 +105,7 @@ public class TaskServiceImpl implements TaskService { this.workbasketService = taskanaEngine.getEngine().getWorkbasketService(); this.attachmentMapper = attachmentMapper; this.classificationService = taskanaEngine.getEngine().getClassificationService(); - this.historyEventProducer = taskanaEngine.getEngine().getHistoryEventProducer(); + this.historyEventProducer = taskanaEngine.getHistoryEventProducer(); } @Override diff --git a/lib/taskana-core/src/main/java/pro/taskana/impl/TaskanaEngineImpl.java b/lib/taskana-core/src/main/java/pro/taskana/impl/TaskanaEngineImpl.java index f5dc04bd3..53ef14d1e 100644 --- a/lib/taskana-core/src/main/java/pro/taskana/impl/TaskanaEngineImpl.java +++ b/lib/taskana-core/src/main/java/pro/taskana/impl/TaskanaEngineImpl.java @@ -56,20 +56,20 @@ public class TaskanaEngineImpl implements TaskanaEngine { private static final String DEFAULT = "default"; private static final Logger LOGGER = LoggerFactory.getLogger(TaskanaEngineImpl.class); - protected static ThreadLocal> sessionStack = new ThreadLocal<>(); + private static ThreadLocal> sessionStack = new ThreadLocal<>(); protected TaskanaEngineConfiguration taskanaEngineConfiguration; protected TransactionFactory transactionFactory; protected SqlSessionManager sessionManager; protected ConnectionManagementMode mode = ConnectionManagementMode.PARTICIPATE; protected java.sql.Connection connection = null; - protected HistoryEventProducer historyEventProducer; + private HistoryEventProducer historyEventProducer; private Internal internal; protected TaskanaEngineImpl(TaskanaEngineConfiguration taskanaEngineConfiguration) { this.taskanaEngineConfiguration = taskanaEngineConfiguration; createTransactionFactory(taskanaEngineConfiguration.getUseManagedTransactions()); this.sessionManager = createSqlSessionManager(); - this.historyEventProducer = HistoryEventProducer.getInstance(taskanaEngineConfiguration); + historyEventProducer = HistoryEventProducer.getInstance(taskanaEngineConfiguration); this.internal = new Internal(); } @@ -89,7 +89,7 @@ public class TaskanaEngineImpl implements TaskanaEngine { * * @return Stack of SqlSessionManager */ - protected static Deque getSessionStack() { + private static Deque getSessionStack() { Deque stack = sessionStack.get(); if (stack == null) { stack = new ArrayDeque<>(); @@ -98,7 +98,7 @@ public class TaskanaEngineImpl implements TaskanaEngine { return stack; } - protected static SqlSessionManager getSessionFromStack() { + private static SqlSessionManager getSessionFromStack() { Deque stack = getSessionStack(); if (stack.isEmpty()) { return null; @@ -106,11 +106,11 @@ public class TaskanaEngineImpl implements TaskanaEngine { return stack.peek(); } - protected static void pushSessionToStack(SqlSessionManager session) { + private static void pushSessionToStack(SqlSessionManager session) { getSessionStack().push(session); } - protected static void popSessionFromStack() { + private static void popSessionFromStack() { Deque stack = getSessionStack(); if (!stack.isEmpty()) { stack.pop(); @@ -171,21 +171,10 @@ public class TaskanaEngineImpl implements TaskanaEngine { } @Override - public HistoryEventProducer getHistoryEventProducer() { - return historyEventProducer; + public boolean isHistoryEnabled() { + return HistoryEventProducer.isHistoryEnabled(); } - /** - * sets the connection management mode. - * - * @param mode - * - the connection management mode Valid values are: - *
    - *
  • PARTICIPATE - taskana participates in global transaction. This is the default mode.
  • - *
  • AUTOCOMMIT - taskana commits each API call separately
  • - *
  • EXPLICIT - commit processing is managed explicitly by the client
  • - *
- */ @Override public void setConnectionManagementMode(ConnectionManagementMode mode) { if (this.mode == ConnectionManagementMode.EXPLICIT && connection != null @@ -198,15 +187,6 @@ public class TaskanaEngineImpl implements TaskanaEngine { this.mode = mode; } - /** - * Set the database connection to be used by taskana. If this Api is called, taskana uses the connection passed by - * the client for database access in all subsequent API calls until the client resets this connection. Control over - * commit and rollback is the responsibility of the client. In order to close the connection, the client can call - * TaskanaEngine.closeConnection() or TaskanaEngine.setConnection(null). Both calls have the same effect. - * - * @param connection - * The connection that passed into TaskanaEngine - */ @Override public void setConnection(java.sql.Connection connection) throws SQLException { if (connection != null) { @@ -221,10 +201,6 @@ public class TaskanaEngineImpl implements TaskanaEngine { } } - /** - * closes the connection to the database in mode EXPLICIT. In mode EXPLICIT, closes the client's connection, sets it - * to null and switches to mode PARTICIPATE Has the same effect as setConnection(null) - */ @Override public void closeConnection() { if (this.mode == ConnectionManagementMode.EXPLICIT) { @@ -236,14 +212,6 @@ public class TaskanaEngineImpl implements TaskanaEngine { } } - /** - * Checks whether current user is member of any of the specified roles. - * - * @param roles - * The roles that are checked for membership of the current user - * @throws NotAuthorizedException - * If the current user is not member of any specified role - */ @Override public void checkRoleMembership(TaskanaRole... roles) throws NotAuthorizedException { if (!isUserInRole(roles)) { @@ -258,13 +226,6 @@ public class TaskanaEngineImpl implements TaskanaEngine { } } - /** - * check whether the current user is member of one of the roles specified. - * - * @param roles - * The roles that are checked for membership of the current user - * @return true if the current user is a member of at least one of the specified groups - */ @Override public boolean isUserInRole(TaskanaRole... roles) { if (!getConfiguration().isSecurityEnabled()) { @@ -407,5 +368,10 @@ public class TaskanaEngineImpl implements TaskanaEngine { return TaskanaEngineImpl.this; } + @Override + public HistoryEventProducer getHistoryEventProducer() { + return historyEventProducer; + } + } } diff --git a/lib/taskana-core/src/test/java/acceptance/history/TaskEventProducerTest.java b/lib/taskana-core/src/test/java/acceptance/history/TaskEventProducerTest.java index 4571874c7..82ea69b27 100644 --- a/lib/taskana-core/src/test/java/acceptance/history/TaskEventProducerTest.java +++ b/lib/taskana-core/src/test/java/acceptance/history/TaskEventProducerTest.java @@ -5,7 +5,6 @@ import static org.junit.Assert.assertFalse; import org.junit.Test; import acceptance.AbstractAccTest; -import pro.taskana.history.HistoryEventProducer; /** * Acceptance test for historyEventProducer class. @@ -14,7 +13,6 @@ public class TaskEventProducerTest extends AbstractAccTest { @Test public void testHistoryEventProducerIsNotEnabled() { - HistoryEventProducer historyEventProducer = taskanaEngine.getHistoryEventProducer(); - assertFalse(historyEventProducer.isEnabled()); + assertFalse(taskanaEngine.isHistoryEnabled()); } } diff --git a/lib/taskana-core/src/test/java/pro/taskana/impl/TaskServiceImplTest.java b/lib/taskana-core/src/test/java/pro/taskana/impl/TaskServiceImplTest.java index 8f615df67..ab7b08143 100644 --- a/lib/taskana-core/src/test/java/pro/taskana/impl/TaskServiceImplTest.java +++ b/lib/taskana-core/src/test/java/pro/taskana/impl/TaskServiceImplTest.java @@ -120,8 +120,8 @@ public class TaskServiceImplTest { verify(workbasketServiceMock, times(1)).getWorkbasket(destinationWorkbasket.getId()); verify(taskMapperMock, times(1)).update(any()); verify(taskanaEngineInternalMock, times(1)).returnConnection(); - verify(taskanaEngineInternalMock, times(3)).getEngine(); - verify(taskanaEngineMock).getHistoryEventProducer(); + verify(taskanaEngineInternalMock, times(2)).getEngine(); + verify(taskanaEngineInternalMock).getHistoryEventProducer(); verify(taskanaEngineMock).getWorkbasketService(); verify(taskanaEngineMock).getClassificationService(); verifyNoMoreInteractions(attachmentMapperMock, taskanaEngineConfigurationMock, taskanaEngineMock, diff --git a/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/TaskanaEngineController.java b/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/TaskanaEngineController.java index 9e8934533..783657add 100644 --- a/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/TaskanaEngineController.java +++ b/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/TaskanaEngineController.java @@ -100,8 +100,7 @@ public class TaskanaEngineController { @GetMapping(path = "/history-provider-enabled") public ResponseEntity getIsHistoryProviderEnabled() { - ResponseEntity response = ResponseEntity.ok( - ((TaskanaEngineImpl) taskanaEngine).getHistoryEventProducer().isEnabled()); + ResponseEntity response = ResponseEntity.ok(taskanaEngine.isHistoryEnabled()); LOGGER.debug("Exit from getIsHistoryProviderEnabled(), returning {}", response); return response; }