TSK-38 Refactor session handling
This commit is contained in:
parent
2449df16dc
commit
ea988efd46
|
|
@ -1,5 +1,6 @@
|
||||||
package pro.taskana;
|
package pro.taskana;
|
||||||
|
|
||||||
|
import pro.taskana.TaskanaEngine.ConnectionManagementMode;
|
||||||
import pro.taskana.configuration.TaskanaEngineConfiguration;
|
import pro.taskana.configuration.TaskanaEngineConfiguration;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -30,4 +31,42 @@ public interface TaskanaEngine {
|
||||||
* @return the TaskanaConfiguration
|
* @return the TaskanaConfiguration
|
||||||
*/
|
*/
|
||||||
TaskanaEngineConfiguration getConfiguration();
|
TaskanaEngineConfiguration getConfiguration();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* sets the connection management mode for taskana.
|
||||||
|
*
|
||||||
|
* @param mode. See ConnectionManagementMode
|
||||||
|
*/
|
||||||
|
void setConnectionManagementMode(ConnectionManagementMode mode);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the connection to be used by taskana in mode CONNECTION_MANAGED_EXTERNALLY.
|
||||||
|
* If this Api is called, taskana uses the connection passed by the client for all subsequent API calls
|
||||||
|
* until the client resets this connection.
|
||||||
|
* Control over commit and rollback of the connection is the responsibility of the client.
|
||||||
|
* In order to close the connection, closeConnection() or setConnection(null) has to be called.
|
||||||
|
*
|
||||||
|
* @param connection - The java.sql.Connection that is controlled by the client
|
||||||
|
*/
|
||||||
|
void setConnection(java.sql.Connection connection);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Closes the client's connection, sets it to null and switches to mode PARTICIPATE.
|
||||||
|
* Only applicable in mode EXPLICIT. Has the same effect as setConnection(null).
|
||||||
|
*/
|
||||||
|
void closeConnection();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Connection management mode.
|
||||||
|
* Controls the connection handling of taskana
|
||||||
|
* 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
|
||||||
|
*/
|
||||||
|
enum ConnectionManagementMode {
|
||||||
|
PARTICIPATE,
|
||||||
|
AUTOCOMMIT,
|
||||||
|
EXPLICIT
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ package pro.taskana.configuration;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
import java.io.StringWriter;
|
import java.io.StringWriter;
|
||||||
|
import java.sql.Connection;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
|
||||||
import javax.sql.DataSource;
|
import javax.sql.DataSource;
|
||||||
|
|
@ -39,8 +40,9 @@ public class DbScriptRunner {
|
||||||
* @throws SQLException
|
* @throws SQLException
|
||||||
*/
|
*/
|
||||||
public void run() throws SQLException {
|
public void run() throws SQLException {
|
||||||
ScriptRunner runner = new ScriptRunner(dataSource.getConnection());
|
Connection connection = dataSource.getConnection();
|
||||||
LOGGER.debug(dataSource.getConnection().getMetaData().toString());
|
ScriptRunner runner = new ScriptRunner(connection);
|
||||||
|
LOGGER.debug(connection.getMetaData().toString());
|
||||||
|
|
||||||
runner.setStopOnError(true);
|
runner.setStopOnError(true);
|
||||||
runner.setLogWriter(logWriter);
|
runner.setLogWriter(logWriter);
|
||||||
|
|
|
||||||
|
|
@ -55,7 +55,7 @@ public class TaskanaEngineConfiguration {
|
||||||
this.securityEnabled = securityEnabled;
|
this.securityEnabled = securityEnabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DataSource createDefaultDataSource() {
|
public static DataSource createDefaultDataSource() {
|
||||||
LOGGER.warn("No datasource is provided. A inmemory db is used: "
|
LOGGER.warn("No datasource is provided. A inmemory db is used: "
|
||||||
+ "'org.h2.Driver', 'jdbc:h2:mem:taskana', 'sa', 'sa'");
|
+ "'org.h2.Driver', 'jdbc:h2:mem:taskana', 'sa', 'sa'");
|
||||||
return createDatasource(H2_DRIVER, JDBC_H2_MEM_TASKANA, USER_NAME, USER_PASSWORD);
|
return createDatasource(H2_DRIVER, JDBC_H2_MEM_TASKANA, USER_NAME, USER_PASSWORD);
|
||||||
|
|
@ -75,7 +75,7 @@ public class TaskanaEngineConfiguration {
|
||||||
* @param dbConfiguration
|
* @param dbConfiguration
|
||||||
* @return DataSource
|
* @return DataSource
|
||||||
*/
|
*/
|
||||||
public DataSource createDatasource(String driver, String jdbcUrl, String username, String password) {
|
public static DataSource createDatasource(String driver, String jdbcUrl, String username, String password) {
|
||||||
return new PooledDataSource(driver, jdbcUrl, username, password);
|
return new PooledDataSource(driver, jdbcUrl, username, password);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,14 @@
|
||||||
|
package pro.taskana.exceptions;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Thrown if ConnectionManagementMode is CONNECTION_MANAGED_EXTERNALLY and an attempt is made to call an API method before the setConnection() method has been called.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("serial")
|
||||||
|
public class ConnectionNotSetException extends RuntimeException {
|
||||||
|
|
||||||
|
public ConnectionNotSetException() {
|
||||||
|
super("Connection not set");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -26,64 +26,87 @@ public class ClassificationServiceImpl implements ClassificationService {
|
||||||
|
|
||||||
private ClassificationMapper classificationMapper;
|
private ClassificationMapper classificationMapper;
|
||||||
private TaskanaEngine taskanaEngine;
|
private TaskanaEngine taskanaEngine;
|
||||||
|
private TaskanaEngineImpl taskanaEngineImpl;
|
||||||
|
|
||||||
public ClassificationServiceImpl(TaskanaEngine taskanaEngine, ClassificationMapper classificationMapper) {
|
public ClassificationServiceImpl(TaskanaEngine taskanaEngine, ClassificationMapper classificationMapper) {
|
||||||
super();
|
super();
|
||||||
this.taskanaEngine = taskanaEngine;
|
this.taskanaEngine = taskanaEngine;
|
||||||
|
this.taskanaEngineImpl = (TaskanaEngineImpl) taskanaEngine;
|
||||||
this.classificationMapper = classificationMapper;
|
this.classificationMapper = classificationMapper;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Classification> getClassificationTree() throws NotAuthorizedException {
|
public List<Classification> getClassificationTree() throws NotAuthorizedException {
|
||||||
List<Classification> rootClassifications;
|
try {
|
||||||
rootClassifications = this.createClassificationQuery().parentClassification("").validUntil(CURRENT_CLASSIFICATIONS_VALID_UNTIL).list();
|
taskanaEngineImpl.openConnection();
|
||||||
return this.populateChildClassifications(rootClassifications);
|
List<Classification> rootClassifications;
|
||||||
|
rootClassifications = this.createClassificationQuery().parentClassification("").validUntil(CURRENT_CLASSIFICATIONS_VALID_UNTIL).list();
|
||||||
|
return this.populateChildClassifications(rootClassifications);
|
||||||
|
} finally {
|
||||||
|
taskanaEngineImpl.returnConnection();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<Classification> populateChildClassifications(List<Classification> classifications) throws NotAuthorizedException {
|
private List<Classification> populateChildClassifications(List<Classification> classifications) throws NotAuthorizedException {
|
||||||
List<Classification> children = new ArrayList<>();
|
try {
|
||||||
for (Classification classification : classifications) {
|
taskanaEngineImpl.openConnection();
|
||||||
List<Classification> childClassifications = this.createClassificationQuery().parentClassification(classification.getId()).validUntil(CURRENT_CLASSIFICATIONS_VALID_UNTIL).list();
|
List<Classification> children = new ArrayList<>();
|
||||||
children.addAll(populateChildClassifications(childClassifications));
|
for (Classification classification : classifications) {
|
||||||
|
List<Classification> childClassifications = this.createClassificationQuery().parentClassification(classification.getId()).validUntil(CURRENT_CLASSIFICATIONS_VALID_UNTIL).list();
|
||||||
|
children.addAll(populateChildClassifications(childClassifications));
|
||||||
|
}
|
||||||
|
classifications.addAll(children);
|
||||||
|
return classifications;
|
||||||
|
} finally {
|
||||||
|
taskanaEngineImpl.returnConnection();
|
||||||
}
|
}
|
||||||
classifications.addAll(children);
|
|
||||||
return classifications;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addClassification(Classification classification) {
|
public void addClassification(Classification classification) {
|
||||||
classification.setId(IdGenerator.generateWithPrefix(ID_PREFIX_CLASSIFICATION));
|
try {
|
||||||
classification.setCreated(Date.valueOf(LocalDate.now()));
|
taskanaEngineImpl.openConnection();
|
||||||
|
classification.setId(IdGenerator.generateWithPrefix(ID_PREFIX_CLASSIFICATION));
|
||||||
|
classification.setCreated(Date.valueOf(LocalDate.now()));
|
||||||
|
|
||||||
this.setDefaultValues(classification);
|
this.setDefaultValues(classification);
|
||||||
|
|
||||||
classificationMapper.insert(classification);
|
classificationMapper.insert(classification);
|
||||||
|
} finally {
|
||||||
|
taskanaEngineImpl.returnConnection();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateClassification(Classification classification) {
|
public void updateClassification(Classification classification) {
|
||||||
this.setDefaultValues(classification);
|
try {
|
||||||
|
taskanaEngineImpl.openConnection();
|
||||||
|
this.setDefaultValues(classification);
|
||||||
|
|
||||||
Classification oldClassification = this.getClassification(classification.getId(), classification.getDomain());
|
Classification oldClassification = this.getClassification(classification.getId(), classification.getDomain());
|
||||||
|
|
||||||
if (oldClassification == null) {
|
if (oldClassification == null) {
|
||||||
classification.setId(IdGenerator.generateWithPrefix(ID_PREFIX_CLASSIFICATION));
|
classification.setId(IdGenerator.generateWithPrefix(ID_PREFIX_CLASSIFICATION));
|
||||||
classification.setCreated(Date.valueOf(LocalDate.now()));
|
classification.setCreated(Date.valueOf(LocalDate.now()));
|
||||||
classificationMapper.insert(classification);
|
classificationMapper.insert(classification);
|
||||||
|
} else {
|
||||||
|
|
||||||
|
// ! If you update an classification twice the same day,
|
||||||
|
// the older version is valid from today until yesterday.
|
||||||
|
if (!oldClassification.getDomain().equals(classification.getDomain())) {
|
||||||
|
classification.setCreated(Date.valueOf(LocalDate.now()));
|
||||||
|
classificationMapper.insert(classification);
|
||||||
|
} else {
|
||||||
|
oldClassification.setValidUntil(Date.valueOf(LocalDate.now().minusDays(1)));
|
||||||
|
classificationMapper.update(oldClassification);
|
||||||
|
classificationMapper.insert(classification);
|
||||||
|
}
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
} finally {
|
||||||
|
taskanaEngineImpl.returnConnection();
|
||||||
// ! If you update an classification twice the same day,
|
|
||||||
// the older version is valid from today until yesterday.
|
|
||||||
if (!oldClassification.getDomain().equals(classification.getDomain())) {
|
|
||||||
classification.setCreated(Date.valueOf(LocalDate.now()));
|
|
||||||
classificationMapper.insert(classification);
|
|
||||||
} else {
|
|
||||||
oldClassification.setValidUntil(Date.valueOf(LocalDate.now().minusDays(1)));
|
|
||||||
classificationMapper.update(oldClassification);
|
|
||||||
classificationMapper.insert(classification);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -109,22 +132,35 @@ public class ClassificationServiceImpl implements ClassificationService {
|
||||||
if (classification.getDomain() == null) {
|
if (classification.getDomain() == null) {
|
||||||
classification.setDomain("");
|
classification.setDomain("");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Classification> getAllClassificationsWithId(String id, String domain) {
|
public List<Classification> getAllClassificationsWithId(String id, String domain) {
|
||||||
return classificationMapper.getAllClassificationsWithId(id, domain);
|
try {
|
||||||
|
taskanaEngineImpl.openConnection();
|
||||||
|
return classificationMapper.getAllClassificationsWithId(id, domain);
|
||||||
|
} finally {
|
||||||
|
taskanaEngineImpl.returnConnection();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Classification getClassification(String id, String domain) {
|
public Classification getClassification(String id, String domain) {
|
||||||
Classification classification = classificationMapper.findByIdAndDomain(id, domain, CURRENT_CLASSIFICATIONS_VALID_UNTIL);
|
try {
|
||||||
|
taskanaEngineImpl.openConnection();
|
||||||
|
Classification result = null;
|
||||||
|
Classification classification = classificationMapper.findByIdAndDomain(id, domain, CURRENT_CLASSIFICATIONS_VALID_UNTIL);
|
||||||
|
|
||||||
if (classification == null) {
|
if (classification == null) {
|
||||||
return classificationMapper.findByIdAndDomain(id, "", CURRENT_CLASSIFICATIONS_VALID_UNTIL);
|
return classificationMapper.findByIdAndDomain(id, "", CURRENT_CLASSIFICATIONS_VALID_UNTIL);
|
||||||
} else {
|
} else {
|
||||||
return classification;
|
return classification;
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
taskanaEngineImpl.returnConnection();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ import java.util.List;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import pro.taskana.TaskService;
|
import pro.taskana.TaskService;
|
||||||
import pro.taskana.TaskanaEngine;
|
import pro.taskana.TaskanaEngine;
|
||||||
import pro.taskana.exceptions.NotAuthorizedException;
|
import pro.taskana.exceptions.NotAuthorizedException;
|
||||||
|
|
@ -36,6 +37,7 @@ public class TaskServiceImpl implements TaskService {
|
||||||
private static final String ID_PREFIX_TASK = "TKI";
|
private static final String ID_PREFIX_TASK = "TKI";
|
||||||
|
|
||||||
private TaskanaEngine taskanaEngine;
|
private TaskanaEngine taskanaEngine;
|
||||||
|
private TaskanaEngineImpl taskanaEngineImpl;
|
||||||
private TaskMapper taskMapper;
|
private TaskMapper taskMapper;
|
||||||
private ObjectReferenceMapper objectReferenceMapper;
|
private ObjectReferenceMapper objectReferenceMapper;
|
||||||
|
|
||||||
|
|
@ -43,139 +45,181 @@ public class TaskServiceImpl implements TaskService {
|
||||||
ObjectReferenceMapper objectReferenceMapper) {
|
ObjectReferenceMapper objectReferenceMapper) {
|
||||||
super();
|
super();
|
||||||
this.taskanaEngine = taskanaEngine;
|
this.taskanaEngine = taskanaEngine;
|
||||||
|
this.taskanaEngineImpl = (TaskanaEngineImpl) taskanaEngine;
|
||||||
this.taskMapper = taskMapper;
|
this.taskMapper = taskMapper;
|
||||||
this.objectReferenceMapper = objectReferenceMapper;
|
this.objectReferenceMapper = objectReferenceMapper;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void claim(String id, String userName) throws TaskNotFoundException {
|
public void claim(String id, String userName) throws TaskNotFoundException {
|
||||||
Task task = taskMapper.findById(id);
|
try {
|
||||||
if (task != null) {
|
taskanaEngineImpl.openConnection();
|
||||||
Timestamp now = new Timestamp(System.currentTimeMillis());
|
Task task = taskMapper.findById(id);
|
||||||
task.setOwner(userName);
|
if (task != null) {
|
||||||
task.setModified(now);
|
Timestamp now = new Timestamp(System.currentTimeMillis());
|
||||||
task.setClaimed(now);
|
task.setOwner(userName);
|
||||||
task.setState(TaskState.CLAIMED);
|
task.setModified(now);
|
||||||
taskMapper.update(task);
|
task.setClaimed(now);
|
||||||
LOGGER.debug("User '{}' claimed task '{}'.", userName, id);
|
task.setState(TaskState.CLAIMED);
|
||||||
} else {
|
taskMapper.update(task);
|
||||||
throw new TaskNotFoundException(id);
|
LOGGER.debug("User '{}' claimed task '{}'.", userName, id);
|
||||||
|
} else {
|
||||||
|
throw new TaskNotFoundException(id);
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
taskanaEngineImpl.returnConnection();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void complete(String id) throws TaskNotFoundException {
|
public void complete(String id) throws TaskNotFoundException {
|
||||||
Task task = taskMapper.findById(id);
|
try {
|
||||||
if (task != null) {
|
taskanaEngineImpl.openConnection();
|
||||||
Timestamp now = new Timestamp(System.currentTimeMillis());
|
Task task = taskMapper.findById(id);
|
||||||
task.setCompleted(now);
|
if (task != null) {
|
||||||
task.setModified(now);
|
Timestamp now = new Timestamp(System.currentTimeMillis());
|
||||||
task.setState(TaskState.COMPLETED);
|
task.setCompleted(now);
|
||||||
taskMapper.update(task);
|
task.setModified(now);
|
||||||
LOGGER.debug("Task '{}' completed.", id);
|
task.setState(TaskState.COMPLETED);
|
||||||
} else {
|
taskMapper.update(task);
|
||||||
throw new TaskNotFoundException(id);
|
LOGGER.debug("Task '{}' completed.", id);
|
||||||
|
} else {
|
||||||
|
throw new TaskNotFoundException(id);
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
taskanaEngineImpl.returnConnection();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Task create(Task task) throws NotAuthorizedException {
|
public Task create(Task task) throws NotAuthorizedException {
|
||||||
taskanaEngine.getWorkbasketService().checkAuthorization(task.getWorkbasketId(), WorkbasketAuthorization.APPEND);
|
try {
|
||||||
|
taskanaEngineImpl.openConnection();
|
||||||
|
taskanaEngine.getWorkbasketService().checkAuthorization(task.getWorkbasketId(), WorkbasketAuthorization.APPEND);
|
||||||
|
|
||||||
Timestamp now = new Timestamp(System.currentTimeMillis());
|
Timestamp now = new Timestamp(System.currentTimeMillis());
|
||||||
task.setId(IdGenerator.generateWithPrefix(ID_PREFIX_TASK));
|
task.setId(IdGenerator.generateWithPrefix(ID_PREFIX_TASK));
|
||||||
task.setState(TaskState.READY);
|
task.setState(TaskState.READY);
|
||||||
task.setCreated(now);
|
task.setCreated(now);
|
||||||
task.setModified(now);
|
task.setModified(now);
|
||||||
task.setRead(false);
|
task.setRead(false);
|
||||||
task.setTransferred(false);
|
task.setTransferred(false);
|
||||||
|
|
||||||
// insert ObjectReference if needed.
|
// insert ObjectReference if needed.
|
||||||
if (task.getPrimaryObjRef() != null) {
|
if (task.getPrimaryObjRef() != null) {
|
||||||
ObjectReference objectReference = this.objectReferenceMapper.findByObjectReference(task.getPrimaryObjRef());
|
ObjectReference objectReference = this.objectReferenceMapper.findByObjectReference(task.getPrimaryObjRef());
|
||||||
if (objectReference == null) {
|
if (objectReference == null) {
|
||||||
objectReference = task.getPrimaryObjRef();
|
objectReference = task.getPrimaryObjRef();
|
||||||
objectReference.setId(IdGenerator.generateWithPrefix(ID_PREFIX_OBJECTR_EFERENCE));
|
objectReference.setId(IdGenerator.generateWithPrefix(ID_PREFIX_OBJECTR_EFERENCE));
|
||||||
this.objectReferenceMapper.insert(objectReference);
|
this.objectReferenceMapper.insert(objectReference);
|
||||||
|
}
|
||||||
|
task.setPrimaryObjRef(objectReference);
|
||||||
}
|
}
|
||||||
task.setPrimaryObjRef(objectReference);
|
this.taskMapper.insert(task);
|
||||||
}
|
|
||||||
this.taskMapper.insert(task);
|
|
||||||
|
|
||||||
LOGGER.debug("Task '{}' created.", task.getId());
|
LOGGER.debug("Task '{}' created.", task.getId());
|
||||||
return task;
|
return task;
|
||||||
|
} finally {
|
||||||
|
taskanaEngineImpl.returnConnection();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Task getTaskById(String id) throws TaskNotFoundException {
|
public Task getTaskById(String id) throws TaskNotFoundException {
|
||||||
Task task = taskMapper.findById(id);
|
try {
|
||||||
if (task != null) {
|
taskanaEngineImpl.openConnection();
|
||||||
return task;
|
Task task = taskMapper.findById(id);
|
||||||
} else {
|
if (task != null) {
|
||||||
throw new TaskNotFoundException(id);
|
return task;
|
||||||
|
} else {
|
||||||
|
throw new TaskNotFoundException(id);
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
taskanaEngineImpl.returnConnection();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<TaskStateCounter> getTaskCountForState(List<TaskState> states) {
|
public List<TaskStateCounter> getTaskCountForState(List<TaskState> states) {
|
||||||
return taskMapper.getTaskCountForState(states);
|
try {
|
||||||
|
taskanaEngineImpl.openConnection();
|
||||||
|
return taskMapper.getTaskCountForState(states);
|
||||||
|
} finally {
|
||||||
|
taskanaEngineImpl.returnConnection();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long getTaskCountForWorkbasketByDaysInPastAndState(String workbasketId, long daysInPast,
|
public long getTaskCountForWorkbasketByDaysInPastAndState(String workbasketId, long daysInPast, List<TaskState> states) {
|
||||||
List<TaskState> states) {
|
try {
|
||||||
LocalDate time = LocalDate.now();
|
taskanaEngineImpl.openConnection();
|
||||||
time = time.minusDays(daysInPast);
|
LocalDate time = LocalDate.now();
|
||||||
Date fromDate = Date.valueOf(time);
|
time = time.minusDays(daysInPast);
|
||||||
return taskMapper.getTaskCountForWorkbasketByDaysInPastAndState(workbasketId, fromDate, states);
|
Date fromDate = Date.valueOf(time);
|
||||||
|
return taskMapper.getTaskCountForWorkbasketByDaysInPastAndState(workbasketId, fromDate, states);
|
||||||
|
} finally {
|
||||||
|
taskanaEngineImpl.returnConnection();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Task transfer(String taskId, String destinationWorkbasketId)
|
public Task transfer(String taskId, String destinationWorkbasketId)
|
||||||
throws TaskNotFoundException, WorkbasketNotFoundException, NotAuthorizedException {
|
throws TaskNotFoundException, WorkbasketNotFoundException, NotAuthorizedException {
|
||||||
Task task = getTaskById(taskId);
|
try {
|
||||||
|
taskanaEngineImpl.openConnection();
|
||||||
|
Task task = getTaskById(taskId);
|
||||||
|
|
||||||
// transfer requires TRANSFER in source and APPEND on destination
|
// transfer requires TRANSFER in source and APPEND on destination workbasket
|
||||||
// workbasket
|
taskanaEngine.getWorkbasketService().checkAuthorization(destinationWorkbasketId, WorkbasketAuthorization.APPEND);
|
||||||
taskanaEngine.getWorkbasketService().checkAuthorization(destinationWorkbasketId,
|
taskanaEngine.getWorkbasketService().checkAuthorization(task.getWorkbasketId(), WorkbasketAuthorization.TRANSFER);
|
||||||
WorkbasketAuthorization.APPEND);
|
|
||||||
taskanaEngine.getWorkbasketService().checkAuthorization(task.getWorkbasketId(),
|
|
||||||
WorkbasketAuthorization.TRANSFER);
|
|
||||||
|
|
||||||
// if security is disabled, the implicit existance check on the
|
// if security is disabled, the implicit existance check on the
|
||||||
// destination workbasket has been skipped and needs to be performed
|
// destination workbasket has been skipped and needs to be performed
|
||||||
if (!taskanaEngine.getConfiguration().isSecurityEnabled()) {
|
if (!taskanaEngine.getConfiguration().isSecurityEnabled()) {
|
||||||
taskanaEngine.getWorkbasketService().getWorkbasket(destinationWorkbasketId);
|
taskanaEngine.getWorkbasketService().getWorkbasket(destinationWorkbasketId);
|
||||||
|
}
|
||||||
|
|
||||||
|
// reset read flag and set transferred flag
|
||||||
|
task.setRead(false);
|
||||||
|
task.setTransferred(true);
|
||||||
|
|
||||||
|
// transfer task from source to destination workbasket
|
||||||
|
task.setWorkbasketId(destinationWorkbasketId);
|
||||||
|
task.setModified(Timestamp.valueOf(LocalDateTime.now()));
|
||||||
|
taskMapper.update(task);
|
||||||
|
|
||||||
|
return getTaskById(taskId);
|
||||||
|
} finally {
|
||||||
|
taskanaEngineImpl.returnConnection();
|
||||||
}
|
}
|
||||||
|
|
||||||
// reset read flag and set transferred flag
|
|
||||||
task.setRead(false);
|
|
||||||
task.setTransferred(true);
|
|
||||||
|
|
||||||
// transfer task from source to destination workbasket
|
|
||||||
task.setWorkbasketId(destinationWorkbasketId);
|
|
||||||
task.setModified(Timestamp.valueOf(LocalDateTime.now()));
|
|
||||||
taskMapper.update(task);
|
|
||||||
|
|
||||||
return getTaskById(taskId);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<DueWorkbasketCounter> getTaskCountByWorkbasketAndDaysInPastAndState(long daysInPast,
|
public List<DueWorkbasketCounter> getTaskCountByWorkbasketAndDaysInPastAndState(long daysInPast,
|
||||||
List<TaskState> states) {
|
List<TaskState> states) {
|
||||||
LocalDate time = LocalDate.now();
|
try {
|
||||||
time = time.minusDays(daysInPast);
|
taskanaEngineImpl.openConnection();
|
||||||
Date fromDate = Date.valueOf(time);
|
LocalDate time = LocalDate.now();
|
||||||
return taskMapper.getTaskCountByWorkbasketIdAndDaysInPastAndState(fromDate, states);
|
time = time.minusDays(daysInPast);
|
||||||
|
Date fromDate = Date.valueOf(time);
|
||||||
|
return taskMapper.getTaskCountByWorkbasketIdAndDaysInPastAndState(fromDate, states);
|
||||||
|
} finally {
|
||||||
|
taskanaEngineImpl.returnConnection();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Task setTaskRead(String taskId, boolean isRead) throws TaskNotFoundException {
|
public Task setTaskRead(String taskId, boolean isRead) throws TaskNotFoundException {
|
||||||
Task task = getTaskById(taskId);
|
try {
|
||||||
task.setRead(true);
|
taskanaEngineImpl.openConnection();
|
||||||
task.setModified(Timestamp.valueOf(LocalDateTime.now()));
|
Task task = getTaskById(taskId);
|
||||||
taskMapper.update(task);
|
task.setRead(true);
|
||||||
return getTaskById(taskId);
|
task.setModified(Timestamp.valueOf(LocalDateTime.now()));
|
||||||
|
taskMapper.update(task);
|
||||||
|
return getTaskById(taskId);
|
||||||
|
} finally {
|
||||||
|
taskanaEngineImpl.returnConnection();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -1,18 +1,26 @@
|
||||||
package pro.taskana.impl;
|
package pro.taskana.impl;
|
||||||
|
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.util.Stack;
|
||||||
|
|
||||||
import org.apache.ibatis.mapping.Environment;
|
import org.apache.ibatis.mapping.Environment;
|
||||||
import org.apache.ibatis.session.Configuration;
|
import org.apache.ibatis.session.Configuration;
|
||||||
import org.apache.ibatis.session.SqlSession;
|
import org.apache.ibatis.session.SqlSession;
|
||||||
import org.apache.ibatis.session.SqlSessionFactory;
|
import org.apache.ibatis.session.SqlSessionFactory;
|
||||||
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
|
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
|
||||||
|
import org.apache.ibatis.session.SqlSessionManager;
|
||||||
import org.apache.ibatis.transaction.TransactionFactory;
|
import org.apache.ibatis.transaction.TransactionFactory;
|
||||||
import org.apache.ibatis.transaction.jdbc.JdbcTransactionFactory;
|
import org.apache.ibatis.transaction.jdbc.JdbcTransactionFactory;
|
||||||
import org.apache.ibatis.transaction.managed.ManagedTransactionFactory;
|
import org.apache.ibatis.transaction.managed.ManagedTransactionFactory;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import pro.taskana.ClassificationService;
|
import pro.taskana.ClassificationService;
|
||||||
import pro.taskana.TaskService;
|
import pro.taskana.TaskService;
|
||||||
import pro.taskana.TaskanaEngine;
|
import pro.taskana.TaskanaEngine;
|
||||||
import pro.taskana.WorkbasketService;
|
import pro.taskana.WorkbasketService;
|
||||||
import pro.taskana.configuration.TaskanaEngineConfiguration;
|
import pro.taskana.configuration.TaskanaEngineConfiguration;
|
||||||
|
import pro.taskana.exceptions.ConnectionNotSetException;
|
||||||
import pro.taskana.impl.persistence.MapTypeHandler;
|
import pro.taskana.impl.persistence.MapTypeHandler;
|
||||||
import pro.taskana.model.mappings.ClassificationMapper;
|
import pro.taskana.model.mappings.ClassificationMapper;
|
||||||
import pro.taskana.model.mappings.DistributionTargetMapper;
|
import pro.taskana.model.mappings.DistributionTargetMapper;
|
||||||
|
|
@ -28,52 +36,42 @@ import pro.taskana.model.mappings.WorkbasketMapper;
|
||||||
public class TaskanaEngineImpl implements TaskanaEngine {
|
public class TaskanaEngineImpl implements TaskanaEngine {
|
||||||
|
|
||||||
private static final String DEFAULT = "default";
|
private static final String DEFAULT = "default";
|
||||||
|
private static final Logger LOGGER = LoggerFactory.getLogger(TaskanaEngineImpl.class);
|
||||||
|
|
||||||
|
protected static ThreadLocal<Stack<SqlSessionManager>> sessionStack = new ThreadLocal<Stack<SqlSessionManager>>();
|
||||||
protected TaskanaEngineConfiguration taskanaEngineConfiguration;
|
protected TaskanaEngineConfiguration taskanaEngineConfiguration;
|
||||||
protected SqlSession session;
|
|
||||||
protected TransactionFactory transactionFactory;
|
protected TransactionFactory transactionFactory;
|
||||||
|
protected SqlSessionManager sessionManager;
|
||||||
protected SqlSessionFactory sessionFactory;
|
protected SqlSessionFactory sessionFactory;
|
||||||
|
protected ConnectionManagementMode mode = ConnectionManagementMode.PARTICIPATE;
|
||||||
private TaskMapper taskMapper;
|
protected java.sql.Connection connection = null;
|
||||||
private WorkbasketMapper workbasketMapper;
|
|
||||||
private DistributionTargetMapper distributionTargetMapper;
|
|
||||||
private ClassificationMapper classificationMapper;
|
|
||||||
private WorkbasketAccessMapper workbasketAccessMapper;
|
|
||||||
private ObjectReferenceMapper objectReferenceMapper;
|
|
||||||
|
|
||||||
private TaskServiceImpl taskServiceImpl;
|
|
||||||
private WorkbasketServiceImpl workbasketServiceImpl;
|
|
||||||
|
|
||||||
public TaskanaEngineImpl(TaskanaEngineConfiguration taskanaEngineConfiguration) {
|
public TaskanaEngineImpl(TaskanaEngineConfiguration taskanaEngineConfiguration) {
|
||||||
this.taskanaEngineConfiguration = taskanaEngineConfiguration;
|
this.taskanaEngineConfiguration = taskanaEngineConfiguration;
|
||||||
|
|
||||||
createTransactionFactory(taskanaEngineConfiguration.getUseContainerManagedTransactions());
|
createTransactionFactory(taskanaEngineConfiguration.getUseContainerManagedTransactions());
|
||||||
|
this.sessionManager = createSqlSessionManager();
|
||||||
this.session = createSqlSessionFactory().openSession();
|
|
||||||
this.taskMapper = session.getMapper(TaskMapper.class);
|
|
||||||
this.workbasketMapper = session.getMapper(WorkbasketMapper.class);
|
|
||||||
this.distributionTargetMapper = session.getMapper(DistributionTargetMapper.class);
|
|
||||||
this.classificationMapper = session.getMapper(ClassificationMapper.class);
|
|
||||||
this.workbasketAccessMapper = session.getMapper(WorkbasketAccessMapper.class);
|
|
||||||
this.objectReferenceMapper = session.getMapper(ObjectReferenceMapper.class);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TaskService getTaskService() {
|
public TaskService getTaskService() {
|
||||||
this.taskServiceImpl = new TaskServiceImpl(this, this.taskMapper, this.objectReferenceMapper);
|
SqlSession session = this.sessionManager;
|
||||||
|
TaskServiceImpl taskServiceImpl = new TaskServiceImpl(this, session.getMapper(TaskMapper.class), session.getMapper(ObjectReferenceMapper.class));
|
||||||
return taskServiceImpl;
|
return taskServiceImpl;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public WorkbasketService getWorkbasketService() {
|
public WorkbasketService getWorkbasketService() {
|
||||||
this.workbasketServiceImpl = new WorkbasketServiceImpl(this, this.workbasketMapper,
|
SqlSession session = this.sessionManager;
|
||||||
this.distributionTargetMapper, this.workbasketAccessMapper);
|
WorkbasketServiceImpl workbasketServiceImpl = new WorkbasketServiceImpl(this, session.getMapper(WorkbasketMapper.class),
|
||||||
|
session.getMapper(DistributionTargetMapper.class),
|
||||||
|
session.getMapper(WorkbasketAccessMapper.class));
|
||||||
return workbasketServiceImpl;
|
return workbasketServiceImpl;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ClassificationService getClassificationService() {
|
public ClassificationService getClassificationService() {
|
||||||
return new ClassificationServiceImpl(this, this.classificationMapper);
|
SqlSession session = this.sessionManager;
|
||||||
|
return new ClassificationServiceImpl(this, session.getMapper(ClassificationMapper.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -82,20 +80,134 @@ public class TaskanaEngineImpl implements TaskanaEngine {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Close session manually, to be done, if a JdbcTransactionFactory is used.
|
* Open the connection to the database.
|
||||||
* Perhaps it is better to separate the commit and the closing mechanism ...
|
* to be called at the begin of each Api call that accesses the database
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
public void closeSession() {
|
public void openConnection() {
|
||||||
this.session.commit();
|
initSqlSession();
|
||||||
this.session.close();
|
if (mode != ConnectionManagementMode.EXPLICIT) {
|
||||||
|
pushSessionToStack(this.sessionManager);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method creates the sqlSessionFactory of myBatis. It integrates all the
|
* Initializes the SqlSessionManager.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
void initSqlSession() {
|
||||||
|
if (mode == ConnectionManagementMode.EXPLICIT && this.connection == null) {
|
||||||
|
throw new ConnectionNotSetException();
|
||||||
|
} else if (mode != ConnectionManagementMode.EXPLICIT) {
|
||||||
|
if (!this.sessionManager.isManagedSessionStarted()) {
|
||||||
|
this.sessionManager.startManagedSession();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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) {
|
||||||
|
this.connection = null;
|
||||||
|
if (sessionManager.isManagedSessionStarted()) {
|
||||||
|
sessionManager.close();
|
||||||
|
}
|
||||||
|
mode = ConnectionManagementMode.PARTICIPATE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the database connection into the pool.
|
||||||
|
* In the case of nested calls, simply pops the latest session from the session stack.
|
||||||
|
* Closes the connection if the session stack is empty.
|
||||||
|
* In mode AUTOCOMMIT commits before the connection is closed.
|
||||||
|
* To be called at the end of each Api call that accesses the database
|
||||||
|
*/
|
||||||
|
public void returnConnection() {
|
||||||
|
if (this.mode != ConnectionManagementMode.EXPLICIT) {
|
||||||
|
popSessionFromStack();
|
||||||
|
if (getSessionStack().isEmpty()
|
||||||
|
&& this.sessionManager != null && this.sessionManager.isManagedSessionStarted()) {
|
||||||
|
if (this.mode == ConnectionManagementMode.AUTOCOMMIT) {
|
||||||
|
try {
|
||||||
|
this.sessionManager.commit();
|
||||||
|
} catch (Exception e) {
|
||||||
|
LOGGER.debug("closeSession(): Tried to Autocommit and caught exception" + e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.sessionManager.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* sets the connection management mode.
|
||||||
|
*
|
||||||
|
* @param mode - the connection management mode
|
||||||
|
* Valid values are
|
||||||
|
* PARTICIPATE - to be used in managed environments where taskana participates in surrounding transactions
|
||||||
|
* AUTOCOMMIT - to be used in non-managed environments. Taskana commits each single API call explicitly
|
||||||
|
* EXPLICIT - to be used in non-managed environments. Gives commit control to the client.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void setConnectionManagementMode(ConnectionManagementMode mode) {
|
||||||
|
if (this.mode == ConnectionManagementMode.EXPLICIT && connection != null
|
||||||
|
&& mode != ConnectionManagementMode.EXPLICIT) {
|
||||||
|
try {
|
||||||
|
connection.close();
|
||||||
|
} catch (SQLException e) {
|
||||||
|
LOGGER.debug("setConnectionManagementMode(" + mode + ") tried to close connection and caught " + e);
|
||||||
|
}
|
||||||
|
connection = null;
|
||||||
|
this.mode = mode;
|
||||||
|
} else {
|
||||||
|
this.mode = mode;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* retrieve the SqlSession used by taskana.
|
||||||
|
* @return the myBatis SqlSession object used by taskana
|
||||||
|
*/
|
||||||
|
public SqlSession getSqlSession() {
|
||||||
|
return this.sessionManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void setConnection(java.sql.Connection connection) {
|
||||||
|
if (connection != null) {
|
||||||
|
this.connection = connection;
|
||||||
|
mode = ConnectionManagementMode.EXPLICIT;
|
||||||
|
sessionManager.startManagedSession(connection);
|
||||||
|
} else {
|
||||||
|
this.connection = null;
|
||||||
|
if (sessionManager.isManagedSessionStarted()) {
|
||||||
|
sessionManager.close();
|
||||||
|
}
|
||||||
|
mode = ConnectionManagementMode.PARTICIPATE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method creates the sqlSessionManager of myBatis. It integrates all the
|
||||||
* SQL mappers
|
* SQL mappers
|
||||||
* @return a {@link SqlSessionFactory}
|
* @return a {@link SqlSessionFactory}
|
||||||
*/
|
*/
|
||||||
private SqlSessionFactory createSqlSessionFactory() {
|
private SqlSessionManager createSqlSessionManager() {
|
||||||
Environment environment = new Environment(DEFAULT, this.transactionFactory,
|
Environment environment = new Environment(DEFAULT, this.transactionFactory,
|
||||||
taskanaEngineConfiguration.getDatasource());
|
taskanaEngineConfiguration.getDatasource());
|
||||||
Configuration configuration = new Configuration(environment);
|
Configuration configuration = new Configuration(environment);
|
||||||
|
|
@ -108,10 +220,15 @@ public class TaskanaEngineImpl implements TaskanaEngine {
|
||||||
configuration.addMapper(ObjectReferenceMapper.class);
|
configuration.addMapper(ObjectReferenceMapper.class);
|
||||||
configuration.addMapper(QueryMapper.class);
|
configuration.addMapper(QueryMapper.class);
|
||||||
configuration.getTypeHandlerRegistry().register(MapTypeHandler.class);
|
configuration.getTypeHandlerRegistry().register(MapTypeHandler.class);
|
||||||
sessionFactory = new SqlSessionFactoryBuilder().build(configuration);
|
SqlSessionFactory sessionFactory = new SqlSessionFactoryBuilder().build(configuration);
|
||||||
return sessionFactory;
|
SqlSessionManager sessionManager = SqlSessionManager.newInstance(sessionFactory);
|
||||||
|
return sessionManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* creates the MyBatis transaction factory.
|
||||||
|
* @param useContainerManagedTransactions
|
||||||
|
*/
|
||||||
private void createTransactionFactory(boolean useContainerManagedTransactions) {
|
private void createTransactionFactory(boolean useContainerManagedTransactions) {
|
||||||
if (useContainerManagedTransactions) {
|
if (useContainerManagedTransactions) {
|
||||||
this.transactionFactory = new ManagedTransactionFactory();
|
this.transactionFactory = new ManagedTransactionFactory();
|
||||||
|
|
@ -120,12 +237,44 @@ public class TaskanaEngineImpl implements TaskanaEngine {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public SqlSession getSession() {
|
/**
|
||||||
return session;
|
* With sessionStack, we maintain a Stack of SqlSessionManager objects on a per thread basis.
|
||||||
|
* SqlSessionManager is the MyBatis object that wraps database connections.
|
||||||
|
* The purpose of this stack is to keep track of nested calls.
|
||||||
|
* Each external API call is wrapped into taskanaEngineImpl.openConnection(); ..... taskanaEngineImpl.returnConnection(); calls.
|
||||||
|
* In order to avoid duplicate opening / closing of connections, we use the sessionStack in the following way:
|
||||||
|
* Each time, an openConnection call is received, we push the current sessionManager onto the stack.
|
||||||
|
* On the first call to openConnection, we call sessionManager.startManagedSession() to open a database connection.
|
||||||
|
* On each call to returnConnection() we pop one instance of sessionManager from the stack.
|
||||||
|
* When the stack becomes empty, we close the database connection by calling sessionManager.close()
|
||||||
|
* @param
|
||||||
|
* @return Stack of SqlSessionManager
|
||||||
|
*/
|
||||||
|
protected static Stack<SqlSessionManager> getSessionStack() {
|
||||||
|
Stack<SqlSessionManager> stack = sessionStack.get();
|
||||||
|
if (stack == null) {
|
||||||
|
stack = new Stack<SqlSessionManager>();
|
||||||
|
sessionStack.set(stack);
|
||||||
|
}
|
||||||
|
return stack;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSession(SqlSession session) {
|
protected static SqlSessionManager getSessionFromStack() {
|
||||||
this.session = session;
|
Stack<SqlSessionManager> stack = getSessionStack();
|
||||||
|
if (stack.isEmpty()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return stack.peek();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected static void pushSessionToStack(SqlSessionManager session) {
|
||||||
|
getSessionStack().push(session);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static void popSessionFromStack() {
|
||||||
|
Stack<SqlSessionManager> stack = getSessionStack();
|
||||||
|
if (!stack.isEmpty()) {
|
||||||
|
stack.pop();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -32,6 +32,7 @@ public class WorkbasketServiceImpl implements WorkbasketService {
|
||||||
private static final String ID_PREFIX_WORKBASKET_AUTHORIZATION = "WAI";
|
private static final String ID_PREFIX_WORKBASKET_AUTHORIZATION = "WAI";
|
||||||
|
|
||||||
private TaskanaEngine taskanaEngine;
|
private TaskanaEngine taskanaEngine;
|
||||||
|
private TaskanaEngineImpl taskanaEngineImpl;
|
||||||
|
|
||||||
private WorkbasketMapper workbasketMapper;
|
private WorkbasketMapper workbasketMapper;
|
||||||
private DistributionTargetMapper distributionTargetMapper;
|
private DistributionTargetMapper distributionTargetMapper;
|
||||||
|
|
@ -43,6 +44,7 @@ public class WorkbasketServiceImpl implements WorkbasketService {
|
||||||
public WorkbasketServiceImpl(TaskanaEngine taskanaEngine, WorkbasketMapper workbasketMapper,
|
public WorkbasketServiceImpl(TaskanaEngine taskanaEngine, WorkbasketMapper workbasketMapper,
|
||||||
DistributionTargetMapper distributionTargetMapper, WorkbasketAccessMapper workbasketAccessMapper) {
|
DistributionTargetMapper distributionTargetMapper, WorkbasketAccessMapper workbasketAccessMapper) {
|
||||||
this.taskanaEngine = taskanaEngine;
|
this.taskanaEngine = taskanaEngine;
|
||||||
|
this.taskanaEngineImpl = (TaskanaEngineImpl) taskanaEngine;
|
||||||
this.workbasketMapper = workbasketMapper;
|
this.workbasketMapper = workbasketMapper;
|
||||||
this.distributionTargetMapper = distributionTargetMapper;
|
this.distributionTargetMapper = distributionTargetMapper;
|
||||||
this.workbasketAccessMapper = workbasketAccessMapper;
|
this.workbasketAccessMapper = workbasketAccessMapper;
|
||||||
|
|
@ -50,130 +52,190 @@ public class WorkbasketServiceImpl implements WorkbasketService {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Workbasket getWorkbasket(String workbasketId) throws WorkbasketNotFoundException {
|
public Workbasket getWorkbasket(String workbasketId) throws WorkbasketNotFoundException {
|
||||||
Workbasket workbasket = workbasketMapper.findById(workbasketId);
|
try {
|
||||||
if (workbasket == null) {
|
taskanaEngineImpl.openConnection();
|
||||||
throw new WorkbasketNotFoundException(workbasketId);
|
Workbasket workbasket = workbasketMapper.findById(workbasketId);
|
||||||
|
if (workbasket == null) {
|
||||||
|
throw new WorkbasketNotFoundException(workbasketId);
|
||||||
|
}
|
||||||
|
|
||||||
|
return workbasket;
|
||||||
|
} finally {
|
||||||
|
taskanaEngineImpl.returnConnection();
|
||||||
}
|
}
|
||||||
return workbasket;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Workbasket> getWorkbaskets(List<WorkbasketAuthorization> permissions) {
|
public List<Workbasket> getWorkbaskets(List<WorkbasketAuthorization> permissions) {
|
||||||
//use a set to avoid duplicates
|
try {
|
||||||
Set<Workbasket> workbaskets = new HashSet<>();
|
taskanaEngineImpl.openConnection();
|
||||||
for (String accessId : CurrentUserContext.getAccessIds()) {
|
//use a set to avoid duplicates
|
||||||
workbaskets.addAll(workbasketMapper.findByPermission(permissions, accessId));
|
Set<Workbasket> workbaskets = new HashSet<>();
|
||||||
|
for (String accessId : CurrentUserContext.getAccessIds()) {
|
||||||
|
workbaskets.addAll(workbasketMapper.findByPermission(permissions, accessId));
|
||||||
|
}
|
||||||
|
List<Workbasket> workbasketList = new ArrayList<Workbasket>();
|
||||||
|
workbasketList.addAll(workbaskets);
|
||||||
|
return workbasketList;
|
||||||
|
} finally {
|
||||||
|
taskanaEngineImpl.returnConnection();
|
||||||
}
|
}
|
||||||
List<Workbasket> workbasketList = new ArrayList<Workbasket>();
|
|
||||||
workbasketList.addAll(workbaskets);
|
|
||||||
return workbasketList;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Workbasket> getWorkbaskets() {
|
public List<Workbasket> getWorkbaskets() {
|
||||||
return workbasketMapper.findAll();
|
try {
|
||||||
|
taskanaEngineImpl.openConnection();
|
||||||
|
return workbasketMapper.findAll();
|
||||||
|
} finally {
|
||||||
|
taskanaEngineImpl.returnConnection();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Workbasket createWorkbasket(Workbasket workbasket) {
|
public Workbasket createWorkbasket(Workbasket workbasket) {
|
||||||
Timestamp now = new Timestamp(System.currentTimeMillis());
|
try {
|
||||||
workbasket.setCreated(now);
|
taskanaEngineImpl.openConnection();
|
||||||
workbasket.setModified(now);
|
Timestamp now = new Timestamp(System.currentTimeMillis());
|
||||||
if (workbasket.getId() == null || workbasket.getId().isEmpty()) {
|
workbasket.setCreated(now);
|
||||||
workbasket.setId(IdGenerator.generateWithPrefix(ID_PREFIX_WORKBASKET));
|
workbasket.setModified(now);
|
||||||
}
|
if (workbasket.getId() == null || workbasket.getId().isEmpty()) {
|
||||||
workbasketMapper.insert(workbasket);
|
workbasket.setId(IdGenerator.generateWithPrefix(ID_PREFIX_WORKBASKET));
|
||||||
LOGGER.debug("Workbasket '{}' created", workbasket.getId());
|
|
||||||
if (workbasket.getDistributionTargets() != null) {
|
|
||||||
for (Workbasket distributionTarget : workbasket.getDistributionTargets()) {
|
|
||||||
if (workbasketMapper.findById(distributionTarget.getId()) == null) {
|
|
||||||
distributionTarget.setCreated(now);
|
|
||||||
distributionTarget.setModified(now);
|
|
||||||
workbasketMapper.insert(distributionTarget);
|
|
||||||
LOGGER.debug("Workbasket '{}' created", distributionTarget.getId());
|
|
||||||
}
|
|
||||||
distributionTargetMapper.insert(workbasket.getId(), distributionTarget.getId());
|
|
||||||
}
|
}
|
||||||
|
workbasketMapper.insert(workbasket);
|
||||||
|
LOGGER.debug("Workbasket '{}' created", workbasket.getId());
|
||||||
|
if (workbasket.getDistributionTargets() != null) {
|
||||||
|
for (Workbasket distributionTarget : workbasket.getDistributionTargets()) {
|
||||||
|
if (workbasketMapper.findById(distributionTarget.getId()) == null) {
|
||||||
|
distributionTarget.setCreated(now);
|
||||||
|
distributionTarget.setModified(now);
|
||||||
|
workbasketMapper.insert(distributionTarget);
|
||||||
|
LOGGER.debug("Workbasket '{}' created", distributionTarget.getId());
|
||||||
|
}
|
||||||
|
distributionTargetMapper.insert(workbasket.getId(), distributionTarget.getId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return workbasketMapper.findById(workbasket.getId());
|
||||||
|
} finally {
|
||||||
|
taskanaEngineImpl.returnConnection();
|
||||||
}
|
}
|
||||||
return workbasketMapper.findById(workbasket.getId());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Workbasket updateWorkbasket(Workbasket workbasket) throws NotAuthorizedException {
|
public Workbasket updateWorkbasket(Workbasket workbasket) throws NotAuthorizedException {
|
||||||
workbasket.setModified(new Timestamp(System.currentTimeMillis()));
|
try {
|
||||||
workbasketMapper.update(workbasket);
|
taskanaEngineImpl.openConnection();
|
||||||
List<String> oldDistributionTargets = distributionTargetMapper.findBySourceId(workbasket.getId());
|
workbasket.setModified(new Timestamp(System.currentTimeMillis()));
|
||||||
List<Workbasket> distributionTargets = workbasket.getDistributionTargets();
|
workbasketMapper.update(workbasket);
|
||||||
for (Workbasket distributionTarget : distributionTargets) {
|
List<String> oldDistributionTargets = distributionTargetMapper.findBySourceId(workbasket.getId());
|
||||||
if (!oldDistributionTargets.contains(distributionTarget.getId())) {
|
List<Workbasket> distributionTargets = workbasket.getDistributionTargets();
|
||||||
if (workbasketMapper.findById(distributionTarget.getId()) == null) {
|
for (Workbasket distributionTarget : distributionTargets) {
|
||||||
workbasketMapper.insert(distributionTarget);
|
if (!oldDistributionTargets.contains(distributionTarget.getId())) {
|
||||||
LOGGER.debug("Workbasket '{}' created", distributionTarget.getId());
|
if (workbasketMapper.findById(distributionTarget.getId()) == null) {
|
||||||
|
workbasketMapper.insert(distributionTarget);
|
||||||
|
LOGGER.debug("Workbasket '{}' created", distributionTarget.getId());
|
||||||
|
}
|
||||||
|
distributionTargetMapper.insert(workbasket.getId(), distributionTarget.getId());
|
||||||
|
} else {
|
||||||
|
oldDistributionTargets.remove(distributionTarget.getId());
|
||||||
}
|
}
|
||||||
distributionTargetMapper.insert(workbasket.getId(), distributionTarget.getId());
|
|
||||||
} else {
|
|
||||||
oldDistributionTargets.remove(distributionTarget.getId());
|
|
||||||
}
|
}
|
||||||
|
distributionTargetMapper.deleteMultiple(workbasket.getId(), oldDistributionTargets);
|
||||||
|
LOGGER.debug("Workbasket '{}' updated", workbasket.getId());
|
||||||
|
return workbasketMapper.findById(workbasket.getId());
|
||||||
|
} finally {
|
||||||
|
taskanaEngineImpl.returnConnection();
|
||||||
}
|
}
|
||||||
distributionTargetMapper.deleteMultiple(workbasket.getId(), oldDistributionTargets);
|
|
||||||
LOGGER.debug("Workbasket '{}' updated", workbasket.getId());
|
|
||||||
return workbasketMapper.findById(workbasket.getId());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public WorkbasketAccessItem createWorkbasketAuthorization(WorkbasketAccessItem workbasketAccessItem) {
|
public WorkbasketAccessItem createWorkbasketAuthorization(WorkbasketAccessItem workbasketAccessItem) {
|
||||||
workbasketAccessItem.setId(IdGenerator.generateWithPrefix(ID_PREFIX_WORKBASKET_AUTHORIZATION));
|
try {
|
||||||
workbasketAccessMapper.insert(workbasketAccessItem);
|
taskanaEngineImpl.openConnection();
|
||||||
return workbasketAccessItem;
|
workbasketAccessItem.setId(IdGenerator.generateWithPrefix(ID_PREFIX_WORKBASKET_AUTHORIZATION));
|
||||||
|
workbasketAccessMapper.insert(workbasketAccessItem);
|
||||||
|
return workbasketAccessItem;
|
||||||
|
} finally {
|
||||||
|
taskanaEngineImpl.returnConnection();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public WorkbasketAccessItem getWorkbasketAuthorization(String id) {
|
public WorkbasketAccessItem getWorkbasketAuthorization(String id) {
|
||||||
return workbasketAccessMapper.findById(id);
|
try {
|
||||||
|
taskanaEngineImpl.openConnection();
|
||||||
|
return workbasketAccessMapper.findById(id);
|
||||||
|
} finally {
|
||||||
|
taskanaEngineImpl.returnConnection();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void deleteWorkbasketAuthorization(String id) {
|
public void deleteWorkbasketAuthorization(String id) {
|
||||||
workbasketAccessMapper.delete(id);
|
try {
|
||||||
|
taskanaEngineImpl.openConnection();
|
||||||
|
workbasketAccessMapper.delete(id);
|
||||||
|
} finally {
|
||||||
|
taskanaEngineImpl.returnConnection();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<WorkbasketAccessItem> getAllAuthorizations() {
|
public List<WorkbasketAccessItem> getAllAuthorizations() {
|
||||||
return workbasketAccessMapper.findAll();
|
try {
|
||||||
|
taskanaEngineImpl.openConnection();
|
||||||
|
return workbasketAccessMapper.findAll();
|
||||||
|
} finally {
|
||||||
|
taskanaEngineImpl.returnConnection();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void checkAuthorization(String workbasketId, WorkbasketAuthorization workbasketAuthorization)
|
public void checkAuthorization(String workbasketId, WorkbasketAuthorization workbasketAuthorization)
|
||||||
throws NotAuthorizedException {
|
throws NotAuthorizedException {
|
||||||
|
try {
|
||||||
|
taskanaEngineImpl.openConnection();
|
||||||
|
// Skip permission check is security is not enabled
|
||||||
|
if (!taskanaEngine.getConfiguration().isSecurityEnabled()) {
|
||||||
|
LOGGER.debug("Skipping permissions check since security is disabled.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Skip permission check if security is not enabled
|
List<String> accessIds = CurrentUserContext.getAccessIds();
|
||||||
if (!taskanaEngine.getConfiguration().isSecurityEnabled()) {
|
LOGGER.debug("Verifying that {} has the permission {} on workbasket {}",
|
||||||
LOGGER.debug("Skipping permissions check since security is disabled.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
List<String> accessIds = CurrentUserContext.getAccessIds();
|
|
||||||
LOGGER.debug("Verifying that {} has the permission {} on workbasket {}",
|
|
||||||
CurrentUserContext.getUserid(), workbasketAuthorization.name(), workbasketId);
|
CurrentUserContext.getUserid(), workbasketAuthorization.name(), workbasketId);
|
||||||
|
|
||||||
List<WorkbasketAccessItem> accessItems = workbasketAccessMapper
|
List<WorkbasketAccessItem> accessItems = workbasketAccessMapper
|
||||||
.findByWorkbasketAndAccessIdAndAuthorizations(workbasketId, accessIds, workbasketAuthorization.name());
|
.findByWorkbasketAndAccessIdAndAuthorizations(workbasketId, accessIds, workbasketAuthorization.name());
|
||||||
|
|
||||||
if (accessItems.size() <= 0) {
|
if (accessItems.size() <= 0) {
|
||||||
throw new NotAuthorizedException("Not authorized. Authorization '" + workbasketAuthorization.name()
|
throw new NotAuthorizedException("Not authorized. Authorization '" + workbasketAuthorization.name()
|
||||||
+ "' on workbasket '" + workbasketId + "' is needed.");
|
+ "' on workbasket '" + workbasketId + "' is needed.");
|
||||||
|
}
|
||||||
|
|
||||||
|
} finally {
|
||||||
|
taskanaEngineImpl.returnConnection();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public WorkbasketAccessItem updateWorkbasketAuthorization(WorkbasketAccessItem workbasketAccessItem) {
|
public WorkbasketAccessItem updateWorkbasketAuthorization(WorkbasketAccessItem workbasketAccessItem) {
|
||||||
workbasketAccessMapper.update(workbasketAccessItem);
|
try {
|
||||||
return workbasketAccessItem;
|
taskanaEngineImpl.openConnection();
|
||||||
|
workbasketAccessMapper.update(workbasketAccessItem);
|
||||||
|
return workbasketAccessItem;
|
||||||
|
} finally {
|
||||||
|
taskanaEngineImpl.returnConnection();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<WorkbasketAccessItem> getWorkbasketAuthorizations(String workbasketId) {
|
public List<WorkbasketAccessItem> getWorkbasketAuthorizations(String workbasketId) {
|
||||||
return workbasketAccessMapper.findByWorkbasketId(workbasketId);
|
try {
|
||||||
|
taskanaEngineImpl.openConnection();
|
||||||
|
return workbasketAccessMapper.findByWorkbasketId(workbasketId);
|
||||||
|
} finally {
|
||||||
|
taskanaEngineImpl.returnConnection();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ import java.util.List;
|
||||||
public class ClassificationQueryImpl implements ClassificationQuery {
|
public class ClassificationQueryImpl implements ClassificationQuery {
|
||||||
|
|
||||||
private static final String LINK_TO_MAPPER = "pro.taskana.model.mappings.QueryMapper.queryClassification";
|
private static final String LINK_TO_MAPPER = "pro.taskana.model.mappings.QueryMapper.queryClassification";
|
||||||
private TaskanaEngineImpl taskanaEngine;
|
private TaskanaEngineImpl taskanaEngineImpl;
|
||||||
private String[] parentClassificationId;
|
private String[] parentClassificationId;
|
||||||
private String[] category;
|
private String[] category;
|
||||||
private String[] type;
|
private String[] type;
|
||||||
|
|
@ -32,7 +32,7 @@ public class ClassificationQueryImpl implements ClassificationQuery {
|
||||||
private Date[] validUntil;
|
private Date[] validUntil;
|
||||||
|
|
||||||
public ClassificationQueryImpl(TaskanaEngine taskanaEngine) {
|
public ClassificationQueryImpl(TaskanaEngine taskanaEngine) {
|
||||||
this.taskanaEngine = (TaskanaEngineImpl) taskanaEngine;
|
this.taskanaEngineImpl = (TaskanaEngineImpl) taskanaEngine;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -115,18 +115,33 @@ public class ClassificationQueryImpl implements ClassificationQuery {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Classification> list() {
|
public List<Classification> list() {
|
||||||
return taskanaEngine.getSession().selectList(LINK_TO_MAPPER, this);
|
try {
|
||||||
|
taskanaEngineImpl.openConnection();
|
||||||
|
return taskanaEngineImpl.getSqlSession().selectList(LINK_TO_MAPPER, this);
|
||||||
|
} finally {
|
||||||
|
taskanaEngineImpl.returnConnection();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Classification> list(int offset, int limit) {
|
public List<Classification> list(int offset, int limit) {
|
||||||
RowBounds rowBounds = new RowBounds(offset, limit);
|
try {
|
||||||
return taskanaEngine.getSession().selectList(LINK_TO_MAPPER, this, rowBounds);
|
taskanaEngineImpl.openConnection();
|
||||||
|
RowBounds rowBounds = new RowBounds(offset, limit);
|
||||||
|
return taskanaEngineImpl.getSqlSession().selectList(LINK_TO_MAPPER, this, rowBounds);
|
||||||
|
} finally {
|
||||||
|
taskanaEngineImpl.returnConnection();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Classification single() {
|
public Classification single() {
|
||||||
return taskanaEngine.getSession().selectOne(LINK_TO_MAPPER, this);
|
try {
|
||||||
|
taskanaEngineImpl.openConnection();
|
||||||
|
return taskanaEngineImpl.getSqlSession().selectOne(LINK_TO_MAPPER, this);
|
||||||
|
} finally {
|
||||||
|
taskanaEngineImpl.returnConnection();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public String[] getParentClassificationId() {
|
public String[] getParentClassificationId() {
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ public class ObjectReferenceQueryImpl implements ObjectReferenceQuery {
|
||||||
|
|
||||||
private static final String LINK_TO_MAPPER = "pro.taskana.model.mappings.QueryMapper.queryObjectReference";
|
private static final String LINK_TO_MAPPER = "pro.taskana.model.mappings.QueryMapper.queryObjectReference";
|
||||||
|
|
||||||
private TaskanaEngineImpl taskanaEngine;
|
private TaskanaEngineImpl taskanaEngineImpl;
|
||||||
private String[] company;
|
private String[] company;
|
||||||
private String[] system;
|
private String[] system;
|
||||||
private String[] systemInstance;
|
private String[] systemInstance;
|
||||||
|
|
@ -24,7 +24,7 @@ public class ObjectReferenceQueryImpl implements ObjectReferenceQuery {
|
||||||
private String[] value;
|
private String[] value;
|
||||||
|
|
||||||
public ObjectReferenceQueryImpl(TaskanaEngine taskanaEngine) {
|
public ObjectReferenceQueryImpl(TaskanaEngine taskanaEngine) {
|
||||||
this.taskanaEngine = (TaskanaEngineImpl) taskanaEngine;
|
this.taskanaEngineImpl = (TaskanaEngineImpl) taskanaEngine;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -59,18 +59,33 @@ public class ObjectReferenceQueryImpl implements ObjectReferenceQuery {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<ObjectReference> list() {
|
public List<ObjectReference> list() {
|
||||||
return taskanaEngine.getSession().selectList(LINK_TO_MAPPER, this);
|
try {
|
||||||
|
taskanaEngineImpl.openConnection();
|
||||||
|
return taskanaEngineImpl.getSqlSession().selectList(LINK_TO_MAPPER, this);
|
||||||
|
} finally {
|
||||||
|
taskanaEngineImpl.returnConnection();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<ObjectReference> list(int offset, int limit) {
|
public List<ObjectReference> list(int offset, int limit) {
|
||||||
RowBounds rowBounds = new RowBounds(offset, limit);
|
try {
|
||||||
return taskanaEngine.getSession().selectList(LINK_TO_MAPPER, this, rowBounds);
|
taskanaEngineImpl.openConnection();
|
||||||
|
RowBounds rowBounds = new RowBounds(offset, limit);
|
||||||
|
return taskanaEngineImpl.getSqlSession().selectList(LINK_TO_MAPPER, this, rowBounds);
|
||||||
|
} finally {
|
||||||
|
taskanaEngineImpl.returnConnection();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ObjectReference single() {
|
public ObjectReference single() {
|
||||||
return taskanaEngine.getSession().selectOne(LINK_TO_MAPPER, this);
|
try {
|
||||||
|
taskanaEngineImpl.openConnection();
|
||||||
|
return taskanaEngineImpl.getSqlSession().selectOne(LINK_TO_MAPPER, this);
|
||||||
|
} finally {
|
||||||
|
taskanaEngineImpl.returnConnection();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public String[] getCompany() {
|
public String[] getCompany() {
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ public class TaskQueryImpl implements TaskQuery {
|
||||||
|
|
||||||
private static final String LINK_TO_MAPPER = "pro.taskana.model.mappings.QueryMapper.queryTasks";
|
private static final String LINK_TO_MAPPER = "pro.taskana.model.mappings.QueryMapper.queryTasks";
|
||||||
|
|
||||||
private TaskanaEngineImpl taskanaEngine;
|
private TaskanaEngineImpl taskanaEngineImpl;
|
||||||
|
|
||||||
private String[] name;
|
private String[] name;
|
||||||
private String description;
|
private String description;
|
||||||
|
|
@ -35,7 +35,7 @@ public class TaskQueryImpl implements TaskQuery {
|
||||||
private String[] customFields;
|
private String[] customFields;
|
||||||
|
|
||||||
public TaskQueryImpl(TaskanaEngine taskanaEngine) {
|
public TaskQueryImpl(TaskanaEngine taskanaEngine) {
|
||||||
this.taskanaEngine = (TaskanaEngineImpl) taskanaEngine;
|
this.taskanaEngineImpl = (TaskanaEngineImpl) taskanaEngine;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -106,42 +106,57 @@ public class TaskQueryImpl implements TaskQuery {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ObjectReferenceQuery createObjectReferenceQuery() {
|
public ObjectReferenceQuery createObjectReferenceQuery() {
|
||||||
return new ObjectReferenceQueryImpl(taskanaEngine);
|
return new ObjectReferenceQueryImpl(taskanaEngineImpl);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Task> list() throws NotAuthorizedException {
|
public List<Task> list() throws NotAuthorizedException {
|
||||||
checkAuthorization();
|
try {
|
||||||
return taskanaEngine.getSession().selectList(LINK_TO_MAPPER, this);
|
taskanaEngineImpl.openConnection();
|
||||||
|
checkAuthorization();
|
||||||
|
return taskanaEngineImpl.getSqlSession().selectList(LINK_TO_MAPPER, this);
|
||||||
|
} finally {
|
||||||
|
taskanaEngineImpl.returnConnection();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Task> list(int offset, int limit) throws NotAuthorizedException {
|
public List<Task> list(int offset, int limit) throws NotAuthorizedException {
|
||||||
checkAuthorization();
|
try {
|
||||||
RowBounds rowBounds = new RowBounds(offset, limit);
|
taskanaEngineImpl.openConnection();
|
||||||
return taskanaEngine.getSession().selectList(LINK_TO_MAPPER, this, rowBounds);
|
checkAuthorization();
|
||||||
|
RowBounds rowBounds = new RowBounds(offset, limit);
|
||||||
|
return taskanaEngineImpl.getSqlSession().selectList(LINK_TO_MAPPER, this, rowBounds);
|
||||||
|
} finally {
|
||||||
|
taskanaEngineImpl.returnConnection();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Task single() throws NotAuthorizedException {
|
public Task single() throws NotAuthorizedException {
|
||||||
checkAuthorization();
|
try {
|
||||||
return taskanaEngine.getSession().selectOne(LINK_TO_MAPPER, this);
|
taskanaEngineImpl.openConnection();
|
||||||
|
checkAuthorization();
|
||||||
|
return taskanaEngineImpl.getSqlSession().selectOne(LINK_TO_MAPPER, this);
|
||||||
|
} finally {
|
||||||
|
taskanaEngineImpl.returnConnection();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkAuthorization() throws NotAuthorizedException {
|
private void checkAuthorization() throws NotAuthorizedException {
|
||||||
if (this.workbasketId != null && this.workbasketId.length > 0) {
|
if (this.workbasketId != null && this.workbasketId.length > 0) {
|
||||||
for (String workbasket : this.workbasketId) {
|
for (String workbasket : this.workbasketId) {
|
||||||
taskanaEngine.getWorkbasketService().checkAuthorization(workbasket, WorkbasketAuthorization.OPEN);
|
taskanaEngineImpl.getWorkbasketService().checkAuthorization(workbasket, WorkbasketAuthorization.OPEN);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public TaskanaEngineImpl getTaskanaEngine() {
|
public TaskanaEngineImpl getTaskanaEngine() {
|
||||||
return taskanaEngine;
|
return taskanaEngineImpl;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTaskanaEngine(TaskanaEngineImpl taskanaEngine) {
|
public void setTaskanaEngine(TaskanaEngineImpl taskanaEngine) {
|
||||||
this.taskanaEngine = taskanaEngine;
|
this.taskanaEngineImpl = taskanaEngine;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String[] getName() {
|
public String[] getName() {
|
||||||
|
|
|
||||||
|
|
@ -34,6 +34,9 @@ public class ClassificationServiceImplTest {
|
||||||
@Mock
|
@Mock
|
||||||
ClassificationMapper classificationMapper;
|
ClassificationMapper classificationMapper;
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
TaskanaEngineImpl taskanaEngineImpl;
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAddClassification() {
|
public void testAddClassification() {
|
||||||
|
|
@ -52,6 +55,8 @@ public class ClassificationServiceImplTest {
|
||||||
public void testModifiedClassification() {
|
public void testModifiedClassification() {
|
||||||
doNothing().when(classificationMapper).insert(any());
|
doNothing().when(classificationMapper).insert(any());
|
||||||
doNothing().when(classificationMapper).update(any());
|
doNothing().when(classificationMapper).update(any());
|
||||||
|
doNothing().when(taskanaEngineImpl).openConnection();
|
||||||
|
doNothing().when(taskanaEngineImpl).returnConnection();
|
||||||
|
|
||||||
int insert = 0;
|
int insert = 0;
|
||||||
|
|
||||||
|
|
@ -86,6 +91,8 @@ public class ClassificationServiceImplTest {
|
||||||
@Test
|
@Test
|
||||||
public void testFindAllClassifications() throws NotAuthorizedException {
|
public void testFindAllClassifications() throws NotAuthorizedException {
|
||||||
doNothing().when(classificationMapper).insert(any());
|
doNothing().when(classificationMapper).insert(any());
|
||||||
|
doNothing().when(taskanaEngineImpl).openConnection();
|
||||||
|
doNothing().when(taskanaEngineImpl).returnConnection();
|
||||||
|
|
||||||
// insert Classifications
|
// insert Classifications
|
||||||
Classification classification0 = new Classification();
|
Classification classification0 = new Classification();
|
||||||
|
|
@ -118,7 +125,8 @@ public class ClassificationServiceImplTest {
|
||||||
@Test
|
@Test
|
||||||
public void testClassificationQuery() throws NotAuthorizedException {
|
public void testClassificationQuery() throws NotAuthorizedException {
|
||||||
doNothing().when(classificationMapper).insert(any());
|
doNothing().when(classificationMapper).insert(any());
|
||||||
|
doNothing().when(taskanaEngineImpl).openConnection();
|
||||||
|
doNothing().when(taskanaEngineImpl).returnConnection();
|
||||||
Classification classification = new Classification();
|
Classification classification = new Classification();
|
||||||
classification.setDescription("DESC");
|
classification.setDescription("DESC");
|
||||||
classificationService.addClassification(classification);
|
classificationService.addClassification(classification);
|
||||||
|
|
|
||||||
|
|
@ -6,13 +6,16 @@ import static org.mockito.ArgumentMatchers.eq;
|
||||||
import java.sql.Timestamp;
|
import java.sql.Timestamp;
|
||||||
|
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.mockito.InjectMocks;
|
import org.mockito.InjectMocks;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.Mockito;
|
import org.mockito.Mockito;
|
||||||
|
import org.mockito.MockitoAnnotations;
|
||||||
import org.mockito.junit.MockitoJUnitRunner;
|
import org.mockito.junit.MockitoJUnitRunner;
|
||||||
import pro.taskana.TaskanaEngine;
|
|
||||||
|
import pro.taskana.WorkbasketService;
|
||||||
import pro.taskana.configuration.TaskanaEngineConfiguration;
|
import pro.taskana.configuration.TaskanaEngineConfiguration;
|
||||||
import pro.taskana.exceptions.NotAuthorizedException;
|
import pro.taskana.exceptions.NotAuthorizedException;
|
||||||
import pro.taskana.exceptions.TaskNotFoundException;
|
import pro.taskana.exceptions.TaskNotFoundException;
|
||||||
|
|
@ -32,25 +35,39 @@ import pro.taskana.model.mappings.TaskMapper;
|
||||||
public class TaskServiceImplTest {
|
public class TaskServiceImplTest {
|
||||||
|
|
||||||
private static final int SLEEP_TIME = 100;
|
private static final int SLEEP_TIME = 100;
|
||||||
|
@Mock
|
||||||
|
TaskanaEngineConfiguration taskanaEngineConfiguration;
|
||||||
|
|
||||||
@InjectMocks
|
@InjectMocks
|
||||||
TaskServiceImpl taskServiceImpl;
|
TaskServiceImpl taskServiceImpl;
|
||||||
@Mock
|
@Mock
|
||||||
TaskanaEngine taskanaEngine;
|
TaskanaEngineImpl taskanaEngine;
|
||||||
@Mock
|
@Mock
|
||||||
TaskanaEngineConfiguration taskanaEngineConfiguration;
|
TaskanaEngineImpl taskanaEngineImpl;
|
||||||
@Mock
|
|
||||||
WorkbasketServiceImpl workbasketServiceImpl;
|
|
||||||
@Mock
|
@Mock
|
||||||
TaskMapper taskMapper;
|
TaskMapper taskMapper;
|
||||||
@Mock
|
@Mock
|
||||||
ObjectReferenceMapper objectReferenceMapper;
|
ObjectReferenceMapper objectReferenceMapper;
|
||||||
|
@Mock
|
||||||
|
WorkbasketService workbasketService;
|
||||||
|
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setup() {
|
||||||
|
MockitoAnnotations.initMocks(this);
|
||||||
|
Mockito.when(taskanaEngine.getWorkbasketService()).thenReturn(workbasketService);
|
||||||
|
try {
|
||||||
|
Mockito.doNothing().when(workbasketService).checkAuthorization(any(), any());
|
||||||
|
} catch (NotAuthorizedException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
Mockito.doNothing().when(taskanaEngineImpl).openConnection();
|
||||||
|
Mockito.doNothing().when(taskanaEngineImpl).returnConnection();
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCreateSimpleTask() throws NotAuthorizedException {
|
public void testCreateSimpleTask() throws NotAuthorizedException {
|
||||||
registerBasicMocks(false);
|
|
||||||
Mockito.doNothing().when(workbasketServiceImpl).checkAuthorization(any(), any());
|
|
||||||
Mockito.doNothing().when(taskMapper).insert(any());
|
Mockito.doNothing().when(taskMapper).insert(any());
|
||||||
|
|
||||||
Task task = new Task();
|
Task task = new Task();
|
||||||
task.setName("Unit Test Task");
|
task.setName("Unit Test Task");
|
||||||
task.setWorkbasketId("1");
|
task.setWorkbasketId("1");
|
||||||
|
|
@ -101,13 +118,17 @@ public class TaskServiceImplTest {
|
||||||
@Test
|
@Test
|
||||||
public void testTransferTaskZuDestinationWorkbasket()
|
public void testTransferTaskZuDestinationWorkbasket()
|
||||||
throws TaskNotFoundException, WorkbasketNotFoundException, NotAuthorizedException {
|
throws TaskNotFoundException, WorkbasketNotFoundException, NotAuthorizedException {
|
||||||
registerBasicMocks(false);
|
|
||||||
Workbasket workbasket2 = createWorkbasket2();
|
Workbasket workbasket2 = createWorkbasket2();
|
||||||
Mockito.when(workbasketServiceImpl.getWorkbasket("2")).thenReturn(workbasket2);
|
|
||||||
|
Mockito.when(taskanaEngine.getWorkbasketService().getWorkbasket("2")).thenReturn(workbasket2);
|
||||||
|
|
||||||
Task task = createUnitTestTask("1", "Unit Test Task 1", "1");
|
Task task = createUnitTestTask("1", "Unit Test Task 1", "1");
|
||||||
task.setRead(true);
|
task.setRead(true);
|
||||||
|
|
||||||
|
// taskanaEngine.getConfiguration().isSecurityEnabled())
|
||||||
|
Mockito.when(taskanaEngine.getConfiguration()).thenReturn(taskanaEngineConfiguration);
|
||||||
|
Mockito.when(taskanaEngineConfiguration.isSecurityEnabled()).thenReturn(false);
|
||||||
|
|
||||||
Assert.assertEquals(taskServiceImpl.getTaskById(task.getId()).getWorkbasketId(), "1");
|
Assert.assertEquals(taskServiceImpl.getTaskById(task.getId()).getWorkbasketId(), "1");
|
||||||
taskServiceImpl.transfer(task.getId(), "2");
|
taskServiceImpl.transfer(task.getId(), "2");
|
||||||
Assert.assertEquals(taskServiceImpl.getTaskById(task.getId()).getWorkbasketId(), "2");
|
Assert.assertEquals(taskServiceImpl.getTaskById(task.getId()).getWorkbasketId(), "2");
|
||||||
|
|
@ -119,8 +140,7 @@ public class TaskServiceImplTest {
|
||||||
@Test(expected = WorkbasketNotFoundException.class)
|
@Test(expected = WorkbasketNotFoundException.class)
|
||||||
public void testTransferFailsIfDestinationWorkbasketDoesNotExist_withSecurityDisabled()
|
public void testTransferFailsIfDestinationWorkbasketDoesNotExist_withSecurityDisabled()
|
||||||
throws TaskNotFoundException, WorkbasketNotFoundException, NotAuthorizedException {
|
throws TaskNotFoundException, WorkbasketNotFoundException, NotAuthorizedException {
|
||||||
registerBasicMocks(false);
|
Mockito.doThrow(WorkbasketNotFoundException.class).when(workbasketService)
|
||||||
Mockito.doThrow(WorkbasketNotFoundException.class).when(workbasketServiceImpl)
|
|
||||||
.checkAuthorization(eq("invalidWorkbasketId"), any());
|
.checkAuthorization(eq("invalidWorkbasketId"), any());
|
||||||
|
|
||||||
Task task = createUnitTestTask("1", "Unit Test Task 1", "1");
|
Task task = createUnitTestTask("1", "Unit Test Task 1", "1");
|
||||||
|
|
@ -132,9 +152,7 @@ public class TaskServiceImplTest {
|
||||||
@Test(expected = WorkbasketNotFoundException.class)
|
@Test(expected = WorkbasketNotFoundException.class)
|
||||||
public void testTransferFailsIfDestinationWorkbasketDoesNotExist_withSecurityEnabled()
|
public void testTransferFailsIfDestinationWorkbasketDoesNotExist_withSecurityEnabled()
|
||||||
throws TaskNotFoundException, WorkbasketNotFoundException, NotAuthorizedException {
|
throws TaskNotFoundException, WorkbasketNotFoundException, NotAuthorizedException {
|
||||||
registerBasicMocks(true);
|
Mockito.doThrow(WorkbasketNotFoundException.class).when(workbasketService).checkAuthorization(eq("invalidWorkbasketId"), any());
|
||||||
Mockito.doThrow(WorkbasketNotFoundException.class).when(workbasketServiceImpl)
|
|
||||||
.checkAuthorization(eq("invalidWorkbasketId"), any());
|
|
||||||
|
|
||||||
Task task = createUnitTestTask("1", "Unit Test Task 1", "1");
|
Task task = createUnitTestTask("1", "Unit Test Task 1", "1");
|
||||||
|
|
||||||
|
|
@ -152,8 +170,6 @@ public class TaskServiceImplTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void should_InsertObjectReference_when_TaskIsCreated() throws NotAuthorizedException {
|
public void should_InsertObjectReference_when_TaskIsCreated() throws NotAuthorizedException {
|
||||||
Mockito.when(taskanaEngine.getWorkbasketService()).thenReturn(workbasketServiceImpl);
|
|
||||||
Mockito.doNothing().when(workbasketServiceImpl).checkAuthorization(any(), any());
|
|
||||||
Mockito.when(objectReferenceMapper.findByObjectReference(any())).thenReturn(null);
|
Mockito.when(objectReferenceMapper.findByObjectReference(any())).thenReturn(null);
|
||||||
|
|
||||||
Task task = createUnitTestTask("1", "Unit Test Task 1", "1");
|
Task task = createUnitTestTask("1", "Unit Test Task 1", "1");
|
||||||
|
|
@ -169,9 +185,6 @@ public class TaskServiceImplTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void should_LinkObjectReference_when_TaskIsCreated() throws NotAuthorizedException {
|
public void should_LinkObjectReference_when_TaskIsCreated() throws NotAuthorizedException {
|
||||||
Mockito.when(taskanaEngine.getWorkbasketService()).thenReturn(workbasketServiceImpl);
|
|
||||||
Mockito.doNothing().when(workbasketServiceImpl).checkAuthorization(any(), any());
|
|
||||||
|
|
||||||
Task task = createUnitTestTask("1", "Unit Test Task 1", "1");
|
Task task = createUnitTestTask("1", "Unit Test Task 1", "1");
|
||||||
ObjectReference primaryObjRef = new ObjectReference();
|
ObjectReference primaryObjRef = new ObjectReference();
|
||||||
primaryObjRef.setSystem("Sol");
|
primaryObjRef.setSystem("Sol");
|
||||||
|
|
@ -208,10 +221,4 @@ public class TaskServiceImplTest {
|
||||||
return workbasket2;
|
return workbasket2;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void registerBasicMocks(boolean securityEnabled) {
|
|
||||||
Mockito.when(taskanaEngine.getConfiguration()).thenReturn(taskanaEngineConfiguration);
|
|
||||||
Mockito.when(taskanaEngineConfiguration.isSecurityEnabled()).thenReturn(securityEnabled);
|
|
||||||
Mockito.when(taskanaEngine.getWorkbasketService()).thenReturn(workbasketServiceImpl);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,15 @@
|
||||||
package pro.taskana.impl;
|
package pro.taskana.impl;
|
||||||
|
|
||||||
|
import static org.mockito.Mockito.times;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.mockito.InjectMocks;
|
import org.mockito.InjectMocks;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
|
import org.mockito.MockitoAnnotations;
|
||||||
import org.mockito.junit.MockitoJUnitRunner;
|
import org.mockito.junit.MockitoJUnitRunner;
|
||||||
import pro.taskana.TaskanaEngine;
|
|
||||||
import pro.taskana.configuration.TaskanaEngineConfiguration;
|
import pro.taskana.configuration.TaskanaEngineConfiguration;
|
||||||
import pro.taskana.exceptions.NotAuthorizedException;
|
import pro.taskana.exceptions.NotAuthorizedException;
|
||||||
import pro.taskana.exceptions.WorkbasketNotFoundException;
|
import pro.taskana.exceptions.WorkbasketNotFoundException;
|
||||||
|
|
@ -44,10 +47,16 @@ public class WorkbasketServiceImplTest {
|
||||||
@Mock
|
@Mock
|
||||||
WorkbasketAccessMapper workbasketAccessMapper;
|
WorkbasketAccessMapper workbasketAccessMapper;
|
||||||
@Mock
|
@Mock
|
||||||
TaskanaEngine taskanaEngine;
|
TaskanaEngineImpl taskanaEngine;
|
||||||
|
@Mock
|
||||||
|
TaskanaEngineImpl taskanaEngineImpl;
|
||||||
@Mock
|
@Mock
|
||||||
TaskanaEngineConfiguration taskanaEngineConfiguration;
|
TaskanaEngineConfiguration taskanaEngineConfiguration;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setup() {
|
||||||
|
MockitoAnnotations.initMocks(this);
|
||||||
|
}
|
||||||
@Test
|
@Test
|
||||||
public void should_ReturnWorkbasket_when_WorkbasketIdExists() throws WorkbasketNotFoundException {
|
public void should_ReturnWorkbasket_when_WorkbasketIdExists() throws WorkbasketNotFoundException {
|
||||||
when(workbasketMapper.findById(any())).thenReturn(new Workbasket());
|
when(workbasketMapper.findById(any())).thenReturn(new Workbasket());
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ package pro.taskana.impl.configuration;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
import java.io.StringWriter;
|
import java.io.StringWriter;
|
||||||
|
import java.sql.Connection;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
|
||||||
import javax.sql.DataSource;
|
import javax.sql.DataSource;
|
||||||
|
|
@ -30,8 +31,9 @@ public class DBCleaner {
|
||||||
* @throws SQLException
|
* @throws SQLException
|
||||||
*/
|
*/
|
||||||
public void clearDb(DataSource dataSource) throws SQLException {
|
public void clearDb(DataSource dataSource) throws SQLException {
|
||||||
ScriptRunner runner = new ScriptRunner(dataSource.getConnection());
|
Connection connection = dataSource.getConnection();
|
||||||
LOGGER.debug(dataSource.getConnection().getMetaData().toString());
|
ScriptRunner runner = new ScriptRunner(connection);
|
||||||
|
LOGGER.debug(connection.getMetaData().toString());
|
||||||
|
|
||||||
runner.setStopOnError(true);
|
runner.setStopOnError(true);
|
||||||
runner.setLogWriter(logWriter);
|
runner.setLogWriter(logWriter);
|
||||||
|
|
|
||||||
|
|
@ -11,12 +11,12 @@ import java.util.Properties;
|
||||||
import javax.security.auth.login.LoginException;
|
import javax.security.auth.login.LoginException;
|
||||||
import javax.sql.DataSource;
|
import javax.sql.DataSource;
|
||||||
|
|
||||||
import org.apache.ibatis.datasource.unpooled.UnpooledDataSource;
|
import org.apache.ibatis.datasource.pooled.PooledDataSource;
|
||||||
import org.h2.jdbcx.JdbcDataSource;
|
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import pro.taskana.TaskanaEngine;
|
import pro.taskana.TaskanaEngine;
|
||||||
import pro.taskana.configuration.TaskanaEngineConfiguration;
|
import pro.taskana.configuration.TaskanaEngineConfiguration;
|
||||||
/**
|
/**
|
||||||
|
|
@ -26,6 +26,7 @@ import pro.taskana.configuration.TaskanaEngineConfiguration;
|
||||||
public class TaskanaEngineConfigurationTest {
|
public class TaskanaEngineConfigurationTest {
|
||||||
private static DataSource dataSource = null;
|
private static DataSource dataSource = null;
|
||||||
private static final Logger LOGGER = LoggerFactory.getLogger(TaskanaEngineConfigurationTest.class);
|
private static final Logger LOGGER = LoggerFactory.getLogger(TaskanaEngineConfigurationTest.class);
|
||||||
|
private static final int POOL_TIME_TO_WAIT = 50;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCreateTaskanaEngine() throws FileNotFoundException, SQLException, LoginException {
|
public void testCreateTaskanaEngine() throws FileNotFoundException, SQLException, LoginException {
|
||||||
|
|
@ -71,10 +72,20 @@ public class TaskanaEngineConfigurationTest {
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
private static DataSource createDefaultDataSource() {
|
private static DataSource createDefaultDataSource() {
|
||||||
JdbcDataSource ds = new JdbcDataSource();
|
// JdbcDataSource ds = new JdbcDataSource();
|
||||||
ds.setURL("jdbc:h2:mem:taskana");
|
// ds.setURL("jdbc:h2:mem:taskana");
|
||||||
ds.setPassword("sa");
|
// ds.setPassword("sa");
|
||||||
ds.setUser("sa");
|
// ds.setUser("sa");
|
||||||
|
|
||||||
|
String jdbcDriver = "org.h2.Driver";
|
||||||
|
String jdbcUrl = "jdbc:h2:mem:taskana";
|
||||||
|
String dbUserName = "sa";
|
||||||
|
String dbPassword = "sa";
|
||||||
|
DataSource ds = new PooledDataSource(Thread.currentThread().getContextClassLoader(), jdbcDriver,
|
||||||
|
jdbcUrl, dbUserName, dbPassword);
|
||||||
|
((PooledDataSource) ds).setPoolTimeToWait(POOL_TIME_TO_WAIT);
|
||||||
|
((PooledDataSource) ds).forceCloseAll(); // otherwise the MyBatis pool is not initialized correctly
|
||||||
|
|
||||||
return ds;
|
return ds;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -112,8 +123,9 @@ public class TaskanaEngineConfigurationTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (propertiesFileIsComplete) {
|
if (propertiesFileIsComplete) {
|
||||||
ds = new UnpooledDataSource(Thread.currentThread().getContextClassLoader(), jdbcDriver,
|
ds = new PooledDataSource(Thread.currentThread().getContextClassLoader(), jdbcDriver,
|
||||||
jdbcUrl, dbUserName, dbPassword);
|
jdbcUrl, dbUserName, dbPassword);
|
||||||
|
((PooledDataSource) ds).forceCloseAll(); // otherwise the MyBatis pool is not initialized correctly
|
||||||
} else {
|
} else {
|
||||||
LOGGER.warn("propertiesFile " + propertiesFileName + " is incomplete" + warningMessage);
|
LOGGER.warn("propertiesFile " + propertiesFileName + " is incomplete" + warningMessage);
|
||||||
LOGGER.warn("Using default Datasource for Test");
|
LOGGER.warn("Using default Datasource for Test");
|
||||||
|
|
|
||||||
|
|
@ -10,13 +10,14 @@ import javax.security.auth.login.LoginException;
|
||||||
import javax.sql.DataSource;
|
import javax.sql.DataSource;
|
||||||
|
|
||||||
import org.h2.store.fs.FileUtils;
|
import org.h2.store.fs.FileUtils;
|
||||||
import org.junit.After;
|
|
||||||
import org.junit.AfterClass;
|
import org.junit.AfterClass;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import pro.taskana.ClassificationService;
|
import pro.taskana.ClassificationService;
|
||||||
import pro.taskana.TaskanaEngine;
|
import pro.taskana.TaskanaEngine;
|
||||||
|
import pro.taskana.TaskanaEngine.ConnectionManagementMode;
|
||||||
import pro.taskana.configuration.TaskanaEngineConfiguration;
|
import pro.taskana.configuration.TaskanaEngineConfiguration;
|
||||||
import pro.taskana.exceptions.NotAuthorizedException;
|
import pro.taskana.exceptions.NotAuthorizedException;
|
||||||
import pro.taskana.impl.TaskanaEngineImpl;
|
import pro.taskana.impl.TaskanaEngineImpl;
|
||||||
|
|
@ -25,10 +26,10 @@ import pro.taskana.impl.configuration.TaskanaEngineConfigurationTest;
|
||||||
import pro.taskana.model.Classification;
|
import pro.taskana.model.Classification;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Integration Test for ClassificationServiceImpl.
|
* Integration Test for ClassificationServiceImpl with connection management mode AUTOCOMMIT.
|
||||||
* @author EH
|
* @author EH
|
||||||
*/
|
*/
|
||||||
public class ClassificationServiceImplIntTest {
|
public class ClassificationServiceImplIntAutoCommitTest {
|
||||||
static int counter = 0;
|
static int counter = 0;
|
||||||
|
|
||||||
private DataSource dataSource;
|
private DataSource dataSource;
|
||||||
|
|
@ -45,6 +46,7 @@ public class ClassificationServiceImplIntTest {
|
||||||
taskanaEngine = taskanaEngineConfiguration.buildTaskanaEngine();
|
taskanaEngine = taskanaEngineConfiguration.buildTaskanaEngine();
|
||||||
classificationService = taskanaEngine.getClassificationService();
|
classificationService = taskanaEngine.getClassificationService();
|
||||||
taskanaEngineImpl = (TaskanaEngineImpl) taskanaEngine;
|
taskanaEngineImpl = (TaskanaEngineImpl) taskanaEngine;
|
||||||
|
taskanaEngineImpl.setConnectionManagementMode(ConnectionManagementMode.AUTOCOMMIT);
|
||||||
DBCleaner cleaner = new DBCleaner();
|
DBCleaner cleaner = new DBCleaner();
|
||||||
cleaner.clearDb(dataSource);
|
cleaner.clearDb(dataSource);
|
||||||
}
|
}
|
||||||
|
|
@ -112,7 +114,7 @@ public class ClassificationServiceImplIntTest {
|
||||||
System.out.println(classification.getParentClassificationId());
|
System.out.println(classification.getParentClassificationId());
|
||||||
|
|
||||||
List<Classification> allClassifications = classificationService.getClassificationTree();
|
List<Classification> allClassifications = classificationService.getClassificationTree();
|
||||||
Assert.assertEquals(2, list.size());
|
Assert.assertEquals(2, allClassifications.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
@ -262,11 +264,6 @@ public class ClassificationServiceImplIntTest {
|
||||||
Assert.assertEquals(1, list.size());
|
Assert.assertEquals(1, list.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
|
||||||
public void cleanUp() {
|
|
||||||
taskanaEngineImpl.closeSession();
|
|
||||||
}
|
|
||||||
|
|
||||||
@AfterClass
|
@AfterClass
|
||||||
public static void cleanUpClass() {
|
public static void cleanUpClass() {
|
||||||
FileUtils.deleteRecursive("~/data", true);
|
FileUtils.deleteRecursive("~/data", true);
|
||||||
|
|
@ -0,0 +1,311 @@
|
||||||
|
package pro.taskana.impl.integration;
|
||||||
|
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
|
import java.sql.Connection;
|
||||||
|
import java.sql.Date;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.time.LocalDate;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import javax.security.auth.login.LoginException;
|
||||||
|
import javax.sql.DataSource;
|
||||||
|
|
||||||
|
import org.h2.store.fs.FileUtils;
|
||||||
|
import org.junit.After;
|
||||||
|
import org.junit.AfterClass;
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import pro.taskana.ClassificationService;
|
||||||
|
import pro.taskana.TaskanaEngine;
|
||||||
|
import pro.taskana.TaskanaEngine.ConnectionManagementMode;
|
||||||
|
import pro.taskana.configuration.TaskanaEngineConfiguration;
|
||||||
|
import pro.taskana.exceptions.NotAuthorizedException;
|
||||||
|
import pro.taskana.impl.TaskanaEngineImpl;
|
||||||
|
import pro.taskana.impl.configuration.DBCleaner;
|
||||||
|
import pro.taskana.impl.configuration.TaskanaEngineConfigurationTest;
|
||||||
|
import pro.taskana.model.Classification;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Integration Test for ClassificationServiceImpl with connection management mode EXPLICIT.
|
||||||
|
* @author BBR
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class ClassificationServiceImplIntExplicitTest {
|
||||||
|
static int counter = 0;
|
||||||
|
|
||||||
|
private DataSource dataSource;
|
||||||
|
private ClassificationService classificationService;
|
||||||
|
private TaskanaEngineConfiguration taskanaEngineConfiguration;
|
||||||
|
private TaskanaEngine taskanaEngine;
|
||||||
|
private TaskanaEngineImpl taskanaEngineImpl;
|
||||||
|
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setup() throws FileNotFoundException, SQLException, LoginException {
|
||||||
|
dataSource = TaskanaEngineConfigurationTest.getDataSource();
|
||||||
|
taskanaEngineConfiguration = new TaskanaEngineConfiguration(dataSource, false);
|
||||||
|
taskanaEngine = taskanaEngineConfiguration.buildTaskanaEngine();
|
||||||
|
classificationService = taskanaEngine.getClassificationService();
|
||||||
|
taskanaEngineImpl = (TaskanaEngineImpl) taskanaEngine;
|
||||||
|
taskanaEngineImpl.setConnectionManagementMode(ConnectionManagementMode.EXPLICIT);
|
||||||
|
DBCleaner cleaner = new DBCleaner();
|
||||||
|
cleaner.clearDb(dataSource);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testInsertClassification() throws SQLException {
|
||||||
|
Connection connection = dataSource.getConnection();
|
||||||
|
taskanaEngineImpl.setConnection(connection);
|
||||||
|
|
||||||
|
Classification classification = new Classification();
|
||||||
|
classificationService.addClassification(classification);
|
||||||
|
|
||||||
|
Assert.assertNotNull(classificationService.getClassification(classification.getId(), ""));
|
||||||
|
connection.commit();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testFindAllClassifications() throws NotAuthorizedException, SQLException {
|
||||||
|
Connection connection = dataSource.getConnection();
|
||||||
|
taskanaEngineImpl.setConnection(connection);
|
||||||
|
Classification classification0 = new Classification();
|
||||||
|
classificationService.addClassification(classification0);
|
||||||
|
Classification classification1 = new Classification();
|
||||||
|
classificationService.addClassification(classification1);
|
||||||
|
Classification classification2 = new Classification();
|
||||||
|
classification2.setParentClassificationId(classification0.getId());
|
||||||
|
classificationService.addClassification(classification2);
|
||||||
|
|
||||||
|
Assert.assertEquals(2 + 1, classificationService.getClassificationTree().size());
|
||||||
|
connection.commit();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testModifiedClassification() throws SQLException {
|
||||||
|
|
||||||
|
Connection connection = dataSource.getConnection();
|
||||||
|
taskanaEngineImpl.setConnection(connection);
|
||||||
|
Classification classification = new Classification();
|
||||||
|
connection.commit();
|
||||||
|
classificationService.addClassification(classification);
|
||||||
|
classification.setDescription("TEST SOMETHING");
|
||||||
|
classificationService.updateClassification(classification);
|
||||||
|
connection.commit();
|
||||||
|
Assert.assertEquals(classification.getValidFrom(), Date.valueOf(LocalDate.now()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testInsertAndClassificationMapper() throws NotAuthorizedException, SQLException {
|
||||||
|
Connection connection = dataSource.getConnection();
|
||||||
|
taskanaEngineImpl.setConnection(connection);
|
||||||
|
Classification classification = new Classification();
|
||||||
|
classificationService.addClassification(classification);
|
||||||
|
Date today = Date.valueOf(LocalDate.now());
|
||||||
|
List<Classification> list = classificationService.createClassificationQuery().validInDomain(Boolean.TRUE).created(today).validFrom(today).validUntil(Date.valueOf("9999-12-31")).list();
|
||||||
|
Assert.assertEquals(1, list.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testUpdateAndClassificationMapper() throws NotAuthorizedException, SQLException {
|
||||||
|
Connection connection = dataSource.getConnection();
|
||||||
|
taskanaEngineImpl.setConnection(connection);
|
||||||
|
Classification classification = new Classification();
|
||||||
|
classificationService.addClassification(classification);
|
||||||
|
System.out.println(classification.getId());
|
||||||
|
classification.setDescription("description");
|
||||||
|
classificationService.updateClassification(classification);
|
||||||
|
|
||||||
|
List<Classification> list = classificationService.createClassificationQuery().validUntil(Date.valueOf("9999-12-31")).list();
|
||||||
|
Assert.assertEquals(1, list.size());
|
||||||
|
list = classificationService.createClassificationQuery().validInDomain(true).list();
|
||||||
|
Assert.assertEquals(2, list.size());
|
||||||
|
|
||||||
|
classification.setDomain("domain");
|
||||||
|
classificationService.updateClassification(classification);
|
||||||
|
System.out.println(classification.getId());
|
||||||
|
list = classificationService.createClassificationQuery().validUntil(Date.valueOf("9999-12-31")).list();
|
||||||
|
Assert.assertEquals(2, list.size());
|
||||||
|
|
||||||
|
System.out.println(classification.getParentClassificationId());
|
||||||
|
|
||||||
|
List<Classification> allClassifications = classificationService.getClassificationTree();
|
||||||
|
Assert.assertEquals(2, allClassifications.size());
|
||||||
|
connection.commit();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testFindWithClassificationMapperDomainAndCategory() throws NotAuthorizedException, SQLException {
|
||||||
|
Connection connection = dataSource.getConnection();
|
||||||
|
taskanaEngineImpl.setConnection(connection);
|
||||||
|
Classification classification1 = new Classification();
|
||||||
|
classification1.setDomain("domain1");
|
||||||
|
classification1.setCategory("category1");
|
||||||
|
classificationService.addClassification(classification1);
|
||||||
|
Classification classification2 = new Classification();
|
||||||
|
classification2.setDomain("domain2");
|
||||||
|
classification2.setCategory("category1");
|
||||||
|
classificationService.addClassification(classification2);
|
||||||
|
Classification classification3 = new Classification();
|
||||||
|
classification3.setDomain("domain1");
|
||||||
|
classification3.setCategory("category2");
|
||||||
|
classificationService.addClassification(classification3);
|
||||||
|
|
||||||
|
List<Classification> list = classificationService.createClassificationQuery().category("category1").domain("domain1").list();
|
||||||
|
Assert.assertEquals(1, list.size());
|
||||||
|
list = classificationService.createClassificationQuery().domain("domain1", "domain3").list();
|
||||||
|
Assert.assertEquals(2, list.size());
|
||||||
|
connection.commit();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testFindWithClassificationMapperCustomAndCategory() throws NotAuthorizedException, SQLException {
|
||||||
|
Connection connection = dataSource.getConnection();
|
||||||
|
taskanaEngineImpl.setConnection(connection);
|
||||||
|
Classification classification1 = new Classification();
|
||||||
|
classification1.setDescription("DESC1");
|
||||||
|
classification1.setCategory("category1");
|
||||||
|
classificationService.addClassification(classification1);
|
||||||
|
Classification classification2 = new Classification();
|
||||||
|
classification2.setDescription("DESC1");
|
||||||
|
classification2.setCustom1("custom1");
|
||||||
|
classification2.setCategory("category1");
|
||||||
|
classificationService.addClassification(classification2);
|
||||||
|
Classification classification3 = new Classification();
|
||||||
|
classification3.setCustom1("custom2");
|
||||||
|
classification3.setCustom2("custom1");
|
||||||
|
classification3.setCategory("category2");
|
||||||
|
classificationService.addClassification(classification3);
|
||||||
|
Classification classification4 = new Classification();
|
||||||
|
classification4.setDescription("description2");
|
||||||
|
classification4.setCustom8("custom2");
|
||||||
|
classification4.setCategory("category1");
|
||||||
|
classificationService.addClassification(classification4);
|
||||||
|
|
||||||
|
List<Classification> list = classificationService.createClassificationQuery().descriptionLike("DESC1").customFields("custom1").list();
|
||||||
|
Assert.assertEquals(1, list.size());
|
||||||
|
list = classificationService.createClassificationQuery().customFields("custom2").list();
|
||||||
|
Assert.assertEquals(2, list.size());
|
||||||
|
list = classificationService.createClassificationQuery().descriptionLike("DESC1").category("category1").list();
|
||||||
|
Assert.assertEquals(2, list.size());
|
||||||
|
connection.commit();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testFindWithClassificationMapperPriorityTypeAndParent() throws NotAuthorizedException, SQLException {
|
||||||
|
Connection connection = dataSource.getConnection();
|
||||||
|
taskanaEngineImpl.setConnection(connection);
|
||||||
|
Classification classification = new Classification();
|
||||||
|
classification.setPriority(Integer.decode("5"));
|
||||||
|
classification.setType("type1");
|
||||||
|
classificationService.addClassification(classification);
|
||||||
|
Classification classification1 = new Classification();
|
||||||
|
classification1.setPriority(Integer.decode("3"));
|
||||||
|
classification1.setType("type1");
|
||||||
|
classification1.setParentClassificationId(classification.getId());
|
||||||
|
classificationService.addClassification(classification1);
|
||||||
|
Classification classification2 = new Classification();
|
||||||
|
classification2.setPriority(Integer.decode("5"));
|
||||||
|
classification2.setType("type2");
|
||||||
|
classification2.setParentClassificationId(classification.getId());
|
||||||
|
classificationService.addClassification(classification2);
|
||||||
|
Classification classification3 = new Classification();
|
||||||
|
classification3.setPriority(Integer.decode("5"));
|
||||||
|
classification3.setType("type1");
|
||||||
|
classification3.setParentClassificationId(classification1.getId());
|
||||||
|
classificationService.addClassification(classification3);
|
||||||
|
|
||||||
|
List<Classification> list = classificationService.createClassificationQuery().parentClassification(classification.getId()).list();
|
||||||
|
Assert.assertEquals(2, list.size());
|
||||||
|
list = classificationService.createClassificationQuery().type("type1").priority(Integer.decode("5")).list();
|
||||||
|
Assert.assertEquals(2, list.size());
|
||||||
|
list = classificationService.createClassificationQuery().priority(Integer.decode("5")).type("type1").parentClassification(classification1.getId()).list();
|
||||||
|
Assert.assertEquals(1, list.size());
|
||||||
|
connection.commit();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testFindWithClassificationMapperServiceLevelNameAndDescription() throws NotAuthorizedException, SQLException {
|
||||||
|
Connection connection = dataSource.getConnection();
|
||||||
|
taskanaEngineImpl.setConnection(connection);
|
||||||
|
int all = 0;
|
||||||
|
Classification classification = new Classification();
|
||||||
|
classification.setServiceLevel("P1D");
|
||||||
|
classification.setName("name1");
|
||||||
|
classification.setDescription("desc");
|
||||||
|
classificationService.addClassification(classification);
|
||||||
|
all++;
|
||||||
|
Classification classification1 = new Classification();
|
||||||
|
classification1.setServiceLevel("P1DT1H");
|
||||||
|
classification1.setName("name1");
|
||||||
|
classification1.setDescription("desc");
|
||||||
|
classificationService.addClassification(classification1);
|
||||||
|
all++;
|
||||||
|
Classification classification2 = new Classification();
|
||||||
|
classification2.setServiceLevel("P1D");
|
||||||
|
classification2.setName("name");
|
||||||
|
classification2.setDescription("desc");
|
||||||
|
classificationService.addClassification(classification2);
|
||||||
|
all++;
|
||||||
|
Classification classification3 = new Classification();
|
||||||
|
classification3.setName("name1");
|
||||||
|
classification3.setDescription("description");
|
||||||
|
classificationService.addClassification(classification3);
|
||||||
|
all++;
|
||||||
|
|
||||||
|
List<Classification> list = classificationService.createClassificationQuery().name("name").list();
|
||||||
|
Assert.assertEquals(1, list.size());
|
||||||
|
list = classificationService.createClassificationQuery().serviceLevel("P1D").descriptionLike("desc").list();
|
||||||
|
Assert.assertEquals(2, list.size());
|
||||||
|
list = classificationService.createClassificationQuery().serviceLevel("P1DT1H").name("name").list();
|
||||||
|
Assert.assertEquals(0, list.size());
|
||||||
|
list = classificationService.createClassificationQuery().descriptionLike("desc%").list();
|
||||||
|
Assert.assertEquals(all, list.size());
|
||||||
|
connection.commit();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDefaultSettingsWithClassificationMapper() throws NotAuthorizedException, SQLException {
|
||||||
|
Connection connection = dataSource.getConnection();
|
||||||
|
taskanaEngineImpl.setConnection(connection);
|
||||||
|
Classification classification = new Classification();
|
||||||
|
Classification classification1 = new Classification();
|
||||||
|
classificationService.addClassification(classification);
|
||||||
|
classificationService.addClassification(classification1);
|
||||||
|
classification1.setParentClassificationId(classification.getId());
|
||||||
|
classificationService.updateClassification(classification1);
|
||||||
|
|
||||||
|
List<Classification>
|
||||||
|
list = classificationService.createClassificationQuery().parentClassification("").list();
|
||||||
|
Assert.assertEquals(2, list.size());
|
||||||
|
list = classificationService.createClassificationQuery().validUntil(Date.valueOf("9999-12-31")).list();
|
||||||
|
Assert.assertEquals(2, list.size());
|
||||||
|
connection.commit();
|
||||||
|
|
||||||
|
List<Classification> listAll = classificationService.createClassificationQuery().list();
|
||||||
|
list = classificationService.createClassificationQuery().validFrom(Date.valueOf(LocalDate.now())).list();
|
||||||
|
Assert.assertEquals(listAll.size(), list.size());
|
||||||
|
list = classificationService.createClassificationQuery().validInDomain(true).list();
|
||||||
|
Assert.assertEquals(listAll.size(), list.size());
|
||||||
|
list = classificationService.createClassificationQuery().created(Date.valueOf(LocalDate.now())).list();
|
||||||
|
Assert.assertEquals(listAll.size(), list.size());
|
||||||
|
|
||||||
|
list = classificationService.createClassificationQuery().domain("domain1").validInDomain(false).list();
|
||||||
|
Assert.assertEquals(0, list.size());
|
||||||
|
list = classificationService.createClassificationQuery().validFrom(Date.valueOf((LocalDate.now()))).validUntil(Date.valueOf(LocalDate.now().minusDays(1))).list();
|
||||||
|
Assert.assertEquals(1, list.size());
|
||||||
|
connection.commit();
|
||||||
|
}
|
||||||
|
|
||||||
|
@After
|
||||||
|
public void cleanUp() {
|
||||||
|
taskanaEngineImpl.setConnection(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@AfterClass
|
||||||
|
public static void cleanUpClass() {
|
||||||
|
FileUtils.deleteRecursive("~/data", true);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -1,8 +1,20 @@
|
||||||
package pro.taskana.impl.integration;
|
package pro.taskana.impl.integration;
|
||||||
|
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import javax.security.auth.login.LoginException;
|
||||||
|
import javax.sql.DataSource;
|
||||||
|
|
||||||
import org.h2.store.fs.FileUtils;
|
import org.h2.store.fs.FileUtils;
|
||||||
import org.junit.*;
|
import org.junit.AfterClass;
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
import pro.taskana.TaskanaEngine;
|
import pro.taskana.TaskanaEngine;
|
||||||
|
import pro.taskana.TaskanaEngine.ConnectionManagementMode;
|
||||||
import pro.taskana.configuration.TaskanaEngineConfiguration;
|
import pro.taskana.configuration.TaskanaEngineConfiguration;
|
||||||
import pro.taskana.exceptions.NotAuthorizedException;
|
import pro.taskana.exceptions.NotAuthorizedException;
|
||||||
import pro.taskana.exceptions.TaskNotFoundException;
|
import pro.taskana.exceptions.TaskNotFoundException;
|
||||||
|
|
@ -18,17 +30,11 @@ import pro.taskana.model.TaskState;
|
||||||
import pro.taskana.persistence.ClassificationQuery;
|
import pro.taskana.persistence.ClassificationQuery;
|
||||||
import pro.taskana.persistence.ObjectReferenceQuery;
|
import pro.taskana.persistence.ObjectReferenceQuery;
|
||||||
|
|
||||||
import javax.security.auth.login.LoginException;
|
|
||||||
import javax.sql.DataSource;
|
|
||||||
import java.io.FileNotFoundException;
|
|
||||||
import java.sql.SQLException;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Integration Test for TaskServiceImpl transactions.
|
* Integration Test for TaskServiceImpl transactions with connection management mode AUTOCOMMIT.
|
||||||
* @author EH
|
* @author EH
|
||||||
*/
|
*/
|
||||||
public class TaskServiceImplTransactionTest {
|
public class TaskServiceImplIntAutocommitTest {
|
||||||
|
|
||||||
private DataSource dataSource;
|
private DataSource dataSource;
|
||||||
private TaskServiceImpl taskServiceImpl;
|
private TaskServiceImpl taskServiceImpl;
|
||||||
|
|
@ -43,6 +49,7 @@ public class TaskServiceImplTransactionTest {
|
||||||
|
|
||||||
taskanaEngine = taskanaEngineConfiguration.buildTaskanaEngine();
|
taskanaEngine = taskanaEngineConfiguration.buildTaskanaEngine();
|
||||||
taskanaEngineImpl = (TaskanaEngineImpl) taskanaEngine;
|
taskanaEngineImpl = (TaskanaEngineImpl) taskanaEngine;
|
||||||
|
taskanaEngineImpl.setConnectionManagementMode(ConnectionManagementMode.AUTOCOMMIT);
|
||||||
taskServiceImpl = (TaskServiceImpl) taskanaEngine.getTaskService();
|
taskServiceImpl = (TaskServiceImpl) taskanaEngine.getTaskService();
|
||||||
DBCleaner cleaner = new DBCleaner();
|
DBCleaner cleaner = new DBCleaner();
|
||||||
cleaner.clearDb(dataSource);
|
cleaner.clearDb(dataSource);
|
||||||
|
|
@ -50,13 +57,12 @@ public class TaskServiceImplTransactionTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testStart() throws FileNotFoundException, SQLException, TaskNotFoundException, NotAuthorizedException {
|
public void testStart() throws FileNotFoundException, SQLException, TaskNotFoundException, NotAuthorizedException {
|
||||||
|
|
||||||
Task task = new Task();
|
Task task = new Task();
|
||||||
task.setName("Unit Test Task");
|
task.setName("Unit Test Task");
|
||||||
String id1 = IdGenerator.generateWithPrefix("TWB");
|
String id1 = IdGenerator.generateWithPrefix("TWB");
|
||||||
task.setWorkbasketId(id1);
|
task.setWorkbasketId(id1);
|
||||||
task = taskServiceImpl.create(task);
|
task = taskServiceImpl.create(task);
|
||||||
taskanaEngineImpl.getSession().commit(); // needed so that the change is visible in the other session
|
//skanaEngineImpl.getSqlSession().commit(); // needed so that the change is visible in the other session
|
||||||
|
|
||||||
TaskanaEngine te2 = taskanaEngineConfiguration.buildTaskanaEngine();
|
TaskanaEngine te2 = taskanaEngineConfiguration.buildTaskanaEngine();
|
||||||
TaskServiceImpl taskServiceImpl2 = (TaskServiceImpl) te2.getTaskService();
|
TaskServiceImpl taskServiceImpl2 = (TaskServiceImpl) te2.getTaskService();
|
||||||
|
|
@ -67,7 +73,6 @@ public class TaskServiceImplTransactionTest {
|
||||||
@Test(expected = TaskNotFoundException.class)
|
@Test(expected = TaskNotFoundException.class)
|
||||||
public void testStartTransactionFail()
|
public void testStartTransactionFail()
|
||||||
throws FileNotFoundException, SQLException, TaskNotFoundException, NotAuthorizedException {
|
throws FileNotFoundException, SQLException, TaskNotFoundException, NotAuthorizedException {
|
||||||
|
|
||||||
Task task = new Task();
|
Task task = new Task();
|
||||||
task.setName("Unit Test Task");
|
task.setName("Unit Test Task");
|
||||||
String id1 = IdGenerator.generateWithPrefix("TWB");
|
String id1 = IdGenerator.generateWithPrefix("TWB");
|
||||||
|
|
@ -99,7 +104,6 @@ public class TaskServiceImplTransactionTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void should_ReturnList_when_BuilderIsUsed() throws SQLException, NotAuthorizedException {
|
public void should_ReturnList_when_BuilderIsUsed() throws SQLException, NotAuthorizedException {
|
||||||
|
|
||||||
Task task = new Task();
|
Task task = new Task();
|
||||||
task.setName("Unit Test Task");
|
task.setName("Unit Test Task");
|
||||||
String id1 = IdGenerator.generateWithPrefix("TWB");
|
String id1 = IdGenerator.generateWithPrefix("TWB");
|
||||||
|
|
@ -124,11 +128,6 @@ public class TaskServiceImplTransactionTest {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
|
||||||
public void cleanUp() {
|
|
||||||
taskanaEngineImpl.closeSession();
|
|
||||||
}
|
|
||||||
|
|
||||||
@AfterClass
|
@AfterClass
|
||||||
public static void cleanUpClass() {
|
public static void cleanUpClass() {
|
||||||
FileUtils.deleteRecursive("~/data", true);
|
FileUtils.deleteRecursive("~/data", true);
|
||||||
|
|
@ -0,0 +1,158 @@
|
||||||
|
package pro.taskana.impl.integration;
|
||||||
|
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
|
import java.sql.Connection;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import javax.security.auth.login.LoginException;
|
||||||
|
import javax.sql.DataSource;
|
||||||
|
|
||||||
|
import org.h2.store.fs.FileUtils;
|
||||||
|
import org.junit.After;
|
||||||
|
import org.junit.AfterClass;
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import pro.taskana.TaskanaEngine;
|
||||||
|
import pro.taskana.TaskanaEngine.ConnectionManagementMode;
|
||||||
|
import pro.taskana.configuration.TaskanaEngineConfiguration;
|
||||||
|
import pro.taskana.exceptions.NotAuthorizedException;
|
||||||
|
import pro.taskana.exceptions.TaskNotFoundException;
|
||||||
|
import pro.taskana.impl.TaskServiceImpl;
|
||||||
|
import pro.taskana.impl.TaskanaEngineImpl;
|
||||||
|
import pro.taskana.impl.configuration.DBCleaner;
|
||||||
|
import pro.taskana.impl.configuration.TaskanaEngineConfigurationTest;
|
||||||
|
import pro.taskana.impl.persistence.ClassificationQueryImpl;
|
||||||
|
import pro.taskana.impl.persistence.ObjectReferenceQueryImpl;
|
||||||
|
import pro.taskana.impl.util.IdGenerator;
|
||||||
|
import pro.taskana.model.Task;
|
||||||
|
import pro.taskana.model.TaskState;
|
||||||
|
import pro.taskana.persistence.ClassificationQuery;
|
||||||
|
import pro.taskana.persistence.ObjectReferenceQuery;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Integration Test for TaskServiceImpl transactions with connection management mode EXPLICIT.
|
||||||
|
* @author EH
|
||||||
|
*/
|
||||||
|
public class TaskServiceImplIntExplicitTest {
|
||||||
|
|
||||||
|
private DataSource dataSource;
|
||||||
|
private TaskServiceImpl taskServiceImpl;
|
||||||
|
private TaskanaEngineConfiguration taskanaEngineConfiguration;
|
||||||
|
private TaskanaEngine taskanaEngine;
|
||||||
|
private TaskanaEngineImpl taskanaEngineImpl;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setup() throws FileNotFoundException, SQLException, LoginException {
|
||||||
|
dataSource = TaskanaEngineConfigurationTest.getDataSource();
|
||||||
|
taskanaEngineConfiguration = new TaskanaEngineConfiguration(dataSource, false, false);
|
||||||
|
taskanaEngine = taskanaEngineConfiguration.buildTaskanaEngine();
|
||||||
|
taskServiceImpl = (TaskServiceImpl) taskanaEngine.getTaskService();
|
||||||
|
taskanaEngineImpl = (TaskanaEngineImpl) taskanaEngine;
|
||||||
|
taskanaEngineImpl.setConnectionManagementMode(ConnectionManagementMode.EXPLICIT);
|
||||||
|
DBCleaner cleaner = new DBCleaner();
|
||||||
|
cleaner.clearDb(dataSource);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testStart() throws FileNotFoundException, SQLException, TaskNotFoundException, NotAuthorizedException {
|
||||||
|
Connection connection = dataSource.getConnection();
|
||||||
|
taskanaEngineImpl.setConnection(connection);
|
||||||
|
Task task = new Task();
|
||||||
|
task.setName("Unit Test Task");
|
||||||
|
String id1 = IdGenerator.generateWithPrefix("TWB");
|
||||||
|
task.setWorkbasketId(id1);
|
||||||
|
task = taskServiceImpl.create(task);
|
||||||
|
taskanaEngineImpl.getSqlSession().commit(); // needed so that the change is visible in the other session
|
||||||
|
|
||||||
|
TaskanaEngine te2 = taskanaEngineConfiguration.buildTaskanaEngine();
|
||||||
|
TaskServiceImpl taskServiceImpl2 = (TaskServiceImpl) te2.getTaskService();
|
||||||
|
Task resultTask = taskServiceImpl2.getTaskById(task.getId());
|
||||||
|
Assert.assertNotNull(resultTask);
|
||||||
|
connection.commit();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = TaskNotFoundException.class)
|
||||||
|
public void testStartTransactionFail()
|
||||||
|
throws FileNotFoundException, SQLException, TaskNotFoundException, NotAuthorizedException {
|
||||||
|
Connection connection = dataSource.getConnection();
|
||||||
|
taskanaEngineImpl.setConnection(connection);
|
||||||
|
// taskServiceImpl = (TaskServiceImpl) taskanaEngine.getTaskService();
|
||||||
|
|
||||||
|
Task task = new Task();
|
||||||
|
task.setName("Unit Test Task");
|
||||||
|
String id1 = IdGenerator.generateWithPrefix("TWB");
|
||||||
|
task.setWorkbasketId("id1");
|
||||||
|
task = taskServiceImpl.create(task);
|
||||||
|
connection.commit();
|
||||||
|
taskServiceImpl.getTaskById(id1);
|
||||||
|
|
||||||
|
TaskanaEngineImpl te2 = (TaskanaEngineImpl) taskanaEngineConfiguration.buildTaskanaEngine();
|
||||||
|
TaskServiceImpl taskServiceImpl2 = (TaskServiceImpl) te2.getTaskService();
|
||||||
|
taskServiceImpl2.getTaskById(id1);
|
||||||
|
connection.commit();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCreateTaskInTaskanaWithDefaultDb()
|
||||||
|
throws FileNotFoundException, SQLException, TaskNotFoundException, NotAuthorizedException {
|
||||||
|
DataSource ds = TaskanaEngineConfiguration.createDefaultDataSource();
|
||||||
|
TaskanaEngineConfiguration taskanaEngineConfiguration = new TaskanaEngineConfiguration(ds, false, false);
|
||||||
|
TaskanaEngine te = taskanaEngineConfiguration.buildTaskanaEngine();
|
||||||
|
Connection connection = ds.getConnection();
|
||||||
|
te.setConnection(connection);
|
||||||
|
TaskServiceImpl taskServiceImpl = (TaskServiceImpl) te.getTaskService();
|
||||||
|
|
||||||
|
Task task = new Task();
|
||||||
|
task.setName("Unit Test Task");
|
||||||
|
String id1 = IdGenerator.generateWithPrefix("TWB");
|
||||||
|
task.setWorkbasketId(id1);
|
||||||
|
task = taskServiceImpl.create(task);
|
||||||
|
|
||||||
|
Assert.assertNotNull(task);
|
||||||
|
Assert.assertNotNull(task.getId());
|
||||||
|
connection.commit();
|
||||||
|
te.setConnection(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void should_ReturnList_when_BuilderIsUsed() throws SQLException, NotAuthorizedException {
|
||||||
|
|
||||||
|
Connection connection = dataSource.getConnection();
|
||||||
|
taskanaEngineImpl.setConnection(connection);
|
||||||
|
Task task = new Task();
|
||||||
|
task.setName("Unit Test Task");
|
||||||
|
String id1 = IdGenerator.generateWithPrefix("TWB");
|
||||||
|
task.setWorkbasketId(id1);
|
||||||
|
task = taskServiceImpl.create(task);
|
||||||
|
|
||||||
|
TaskanaEngineImpl taskanaEngineImpl = (TaskanaEngineImpl) taskanaEngine;
|
||||||
|
ClassificationQuery classificationQuery = new ClassificationQueryImpl(taskanaEngineImpl)
|
||||||
|
.parentClassification("pId1", "pId2").category("cat1", "cat2").type("oneType").name("1Name", "name2")
|
||||||
|
.descriptionLike("my desc").priority(1, 2, 1).serviceLevel("me", "and", "you");
|
||||||
|
|
||||||
|
ObjectReferenceQuery objectReferenceQuery = new ObjectReferenceQueryImpl(taskanaEngineImpl)
|
||||||
|
.company("first comp", "sonstwo gmbh").system("sys").type("type1", "type2")
|
||||||
|
.systemInstance("sysInst1", "sysInst2").value("val1", "val2", "val3");
|
||||||
|
|
||||||
|
List<Task> results = taskServiceImpl.createTaskQuery().name("bla", "test").descriptionLike("test")
|
||||||
|
.priority(1, 2, 2).state(TaskState.CLAIMED).workbasketId("asd", "asdasdasd")
|
||||||
|
.owner("test", "test2", "bla").customFields("test").classification(classificationQuery)
|
||||||
|
.objectReference(objectReferenceQuery).list();
|
||||||
|
|
||||||
|
Assert.assertEquals(0, results.size());
|
||||||
|
connection.commit();
|
||||||
|
}
|
||||||
|
|
||||||
|
@After
|
||||||
|
public void cleanUp() {
|
||||||
|
taskanaEngineImpl.setConnection(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@AfterClass
|
||||||
|
public static void cleanUpClass() {
|
||||||
|
FileUtils.deleteRecursive("~/data", true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -2,7 +2,9 @@ package pro.taskana.impl.integration;
|
||||||
|
|
||||||
import org.h2.store.fs.FileUtils;
|
import org.h2.store.fs.FileUtils;
|
||||||
import org.junit.*;
|
import org.junit.*;
|
||||||
|
|
||||||
import pro.taskana.TaskanaEngine;
|
import pro.taskana.TaskanaEngine;
|
||||||
|
import pro.taskana.TaskanaEngine.ConnectionManagementMode;
|
||||||
import pro.taskana.WorkbasketService;
|
import pro.taskana.WorkbasketService;
|
||||||
import pro.taskana.configuration.TaskanaEngineConfiguration;
|
import pro.taskana.configuration.TaskanaEngineConfiguration;
|
||||||
import pro.taskana.exceptions.NotAuthorizedException;
|
import pro.taskana.exceptions.NotAuthorizedException;
|
||||||
|
|
@ -23,10 +25,10 @@ import java.util.List;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Integration Test for workbasketServiceImpl.
|
* Integration Test for workbasketServiceImpl with connection management mode AUTOCOMMIT.
|
||||||
* @author EH
|
* @author EH
|
||||||
*/
|
*/
|
||||||
public class WorkbasketServiceImplIntTest {
|
public class WorkbasketServiceImplIntAutocommitTest {
|
||||||
|
|
||||||
private static final int SLEEP_TIME = 100;
|
private static final int SLEEP_TIME = 100;
|
||||||
private static final int THREE = 3;
|
private static final int THREE = 3;
|
||||||
|
|
@ -45,6 +47,7 @@ public class WorkbasketServiceImplIntTest {
|
||||||
taskanaEngineConfiguration = new TaskanaEngineConfiguration(dataSource, false);
|
taskanaEngineConfiguration = new TaskanaEngineConfiguration(dataSource, false);
|
||||||
taskanaEngine = taskanaEngineConfiguration.buildTaskanaEngine();
|
taskanaEngine = taskanaEngineConfiguration.buildTaskanaEngine();
|
||||||
taskanaEngineImpl = (TaskanaEngineImpl) taskanaEngine;
|
taskanaEngineImpl = (TaskanaEngineImpl) taskanaEngine;
|
||||||
|
taskanaEngineImpl.setConnectionManagementMode(ConnectionManagementMode.AUTOCOMMIT);
|
||||||
workBasketService = taskanaEngine.getWorkbasketService();
|
workBasketService = taskanaEngine.getWorkbasketService();
|
||||||
DBCleaner cleaner = new DBCleaner();
|
DBCleaner cleaner = new DBCleaner();
|
||||||
cleaner.clearDb(dataSource);
|
cleaner.clearDb(dataSource);
|
||||||
|
|
@ -205,7 +208,7 @@ public class WorkbasketServiceImplIntTest {
|
||||||
|
|
||||||
@After
|
@After
|
||||||
public void cleanUp() {
|
public void cleanUp() {
|
||||||
taskanaEngineImpl.closeSession();
|
taskanaEngineImpl.returnConnection();
|
||||||
}
|
}
|
||||||
|
|
||||||
@AfterClass
|
@AfterClass
|
||||||
|
|
@ -0,0 +1,262 @@
|
||||||
|
package pro.taskana.impl.integration;
|
||||||
|
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
|
import java.sql.Connection;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import javax.security.auth.login.LoginException;
|
||||||
|
import javax.sql.DataSource;
|
||||||
|
|
||||||
|
import org.h2.store.fs.FileUtils;
|
||||||
|
import org.junit.After;
|
||||||
|
import org.junit.AfterClass;
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import pro.taskana.TaskanaEngine;
|
||||||
|
import pro.taskana.TaskanaEngine.ConnectionManagementMode;
|
||||||
|
import pro.taskana.WorkbasketService;
|
||||||
|
import pro.taskana.configuration.TaskanaEngineConfiguration;
|
||||||
|
import pro.taskana.exceptions.NotAuthorizedException;
|
||||||
|
import pro.taskana.exceptions.WorkbasketNotFoundException;
|
||||||
|
import pro.taskana.impl.TaskanaEngineImpl;
|
||||||
|
import pro.taskana.impl.configuration.DBCleaner;
|
||||||
|
import pro.taskana.impl.configuration.TaskanaEngineConfigurationTest;
|
||||||
|
import pro.taskana.impl.util.IdGenerator;
|
||||||
|
import pro.taskana.model.Workbasket;
|
||||||
|
import pro.taskana.model.WorkbasketAccessItem;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Integration Test for workbasketServiceImpl with connection mode EXPLICIT.
|
||||||
|
* @author bbr
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class WorkbasketServiceImplIntExplicitTest {
|
||||||
|
|
||||||
|
private static final int SLEEP_TIME = 100;
|
||||||
|
private static final int THREE = 3;
|
||||||
|
|
||||||
|
static int counter = 0;
|
||||||
|
|
||||||
|
private DataSource dataSource;
|
||||||
|
private TaskanaEngineConfiguration taskanaEngineConfiguration;
|
||||||
|
private TaskanaEngine taskanaEngine;
|
||||||
|
private TaskanaEngineImpl taskanaEngineImpl;
|
||||||
|
private WorkbasketService workBasketService;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setup() throws FileNotFoundException, SQLException, LoginException {
|
||||||
|
dataSource = TaskanaEngineConfigurationTest.getDataSource();
|
||||||
|
taskanaEngineConfiguration = new TaskanaEngineConfiguration(dataSource, false);
|
||||||
|
taskanaEngine = taskanaEngineConfiguration.buildTaskanaEngine();
|
||||||
|
taskanaEngineImpl = (TaskanaEngineImpl) taskanaEngine;
|
||||||
|
taskanaEngineImpl.setConnectionManagementMode(ConnectionManagementMode.EXPLICIT);
|
||||||
|
DBCleaner cleaner = new DBCleaner();
|
||||||
|
cleaner.clearDb(dataSource);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testInsertWorkbasket() throws NotAuthorizedException, SQLException {
|
||||||
|
Connection connection = dataSource.getConnection();
|
||||||
|
taskanaEngineImpl.setConnection(connection);
|
||||||
|
workBasketService = taskanaEngine.getWorkbasketService();
|
||||||
|
int before = workBasketService.getWorkbaskets().size();
|
||||||
|
Workbasket workbasket = new Workbasket();
|
||||||
|
String id1 = IdGenerator.generateWithPrefix("TWB");
|
||||||
|
workbasket.setId(id1);
|
||||||
|
workbasket.setName("Megabasket");
|
||||||
|
workBasketService.createWorkbasket(workbasket);
|
||||||
|
Assert.assertEquals(before + 1, workBasketService.getWorkbaskets().size());
|
||||||
|
connection.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSelectAllWorkbaskets() throws NotAuthorizedException, SQLException {
|
||||||
|
Connection connection = dataSource.getConnection();
|
||||||
|
taskanaEngineImpl.setConnection(connection);
|
||||||
|
workBasketService = taskanaEngine.getWorkbasketService();
|
||||||
|
int before = workBasketService.getWorkbaskets().size();
|
||||||
|
Workbasket workbasket0 = new Workbasket();
|
||||||
|
String id0 = IdGenerator.generateWithPrefix("TWB");
|
||||||
|
workbasket0.setId(id0);
|
||||||
|
workbasket0.setName("Superbasket");
|
||||||
|
workBasketService.createWorkbasket(workbasket0);
|
||||||
|
Workbasket workbasket1 = new Workbasket();
|
||||||
|
String id1 = IdGenerator.generateWithPrefix("TWB");
|
||||||
|
workbasket1.setId(id1);
|
||||||
|
workbasket1.setName("Megabasket");
|
||||||
|
workBasketService.createWorkbasket(workbasket1);
|
||||||
|
Workbasket workbasket2 = new Workbasket();
|
||||||
|
String id2 = IdGenerator.generateWithPrefix("TWB");
|
||||||
|
workbasket2.setId(id2);
|
||||||
|
workbasket2.setName("Hyperbasket");
|
||||||
|
workBasketService.createWorkbasket(workbasket2);
|
||||||
|
Assert.assertEquals(before + THREE, workBasketService.getWorkbaskets().size());
|
||||||
|
connection.commit();
|
||||||
|
connection.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSelectWorkbasket() throws WorkbasketNotFoundException, NotAuthorizedException, SQLException {
|
||||||
|
Connection connection = dataSource.getConnection();
|
||||||
|
taskanaEngineImpl.setConnection(connection);
|
||||||
|
workBasketService = taskanaEngine.getWorkbasketService();
|
||||||
|
Workbasket workbasket0 = new Workbasket();
|
||||||
|
String id0 = IdGenerator.generateWithPrefix("TWB");
|
||||||
|
workbasket0.setId(id0);
|
||||||
|
workbasket0.setName("Superbasket");
|
||||||
|
workBasketService.createWorkbasket(workbasket0);
|
||||||
|
Workbasket workbasket1 = new Workbasket();
|
||||||
|
String id1 = IdGenerator.generateWithPrefix("TWB");
|
||||||
|
workbasket1.setId(id1);
|
||||||
|
workbasket1.setName("Megabasket");
|
||||||
|
workBasketService.createWorkbasket(workbasket1);
|
||||||
|
Workbasket workbasket2 = new Workbasket();
|
||||||
|
String id2 = IdGenerator.generateWithPrefix("TWB");
|
||||||
|
workbasket2.setId(id2);
|
||||||
|
workbasket2.setName("Hyperbasket");
|
||||||
|
workBasketService.createWorkbasket(workbasket2);
|
||||||
|
Workbasket foundWorkbasket = workBasketService.getWorkbasket(id2);
|
||||||
|
Assert.assertEquals(id2, foundWorkbasket.getId());
|
||||||
|
connection.commit();
|
||||||
|
connection.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = WorkbasketNotFoundException.class)
|
||||||
|
public void testGetWorkbasketFail() throws WorkbasketNotFoundException, SQLException {
|
||||||
|
Connection connection = dataSource.getConnection();
|
||||||
|
taskanaEngineImpl.setConnection(connection);
|
||||||
|
workBasketService = taskanaEngine.getWorkbasketService();
|
||||||
|
workBasketService.getWorkbasket("fail");
|
||||||
|
connection.commit();
|
||||||
|
connection.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSelectWorkbasketWithDistribution() throws WorkbasketNotFoundException, NotAuthorizedException, SQLException {
|
||||||
|
Connection connection = dataSource.getConnection();
|
||||||
|
taskanaEngineImpl.setConnection(connection);
|
||||||
|
workBasketService = taskanaEngine.getWorkbasketService();
|
||||||
|
Workbasket workbasket0 = new Workbasket();
|
||||||
|
String id0 = IdGenerator.generateWithPrefix("TWB");
|
||||||
|
workbasket0.setId(id0);
|
||||||
|
workbasket0.setName("Superbasket");
|
||||||
|
Workbasket workbasket1 = new Workbasket();
|
||||||
|
String id1 = IdGenerator.generateWithPrefix("TWB");
|
||||||
|
workbasket1.setId(id1);
|
||||||
|
workbasket1.setName("Megabasket");
|
||||||
|
Workbasket workbasket2 = new Workbasket();
|
||||||
|
String id2 = IdGenerator.generateWithPrefix("TWB");
|
||||||
|
workbasket2.setId(id2);
|
||||||
|
workbasket2.setName("Hyperbasket");
|
||||||
|
workbasket2.setDistributionTargets(new ArrayList<>());
|
||||||
|
workbasket2.getDistributionTargets().add(workbasket0);
|
||||||
|
workbasket2.getDistributionTargets().add(workbasket1);
|
||||||
|
workBasketService.createWorkbasket(workbasket2);
|
||||||
|
Workbasket foundWorkbasket = workBasketService.getWorkbasket(id2);
|
||||||
|
Assert.assertEquals(id2, foundWorkbasket.getId());
|
||||||
|
Assert.assertEquals(2, foundWorkbasket.getDistributionTargets().size());
|
||||||
|
connection.commit();
|
||||||
|
connection.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testUpdateWorkbasket() throws Exception {
|
||||||
|
Connection connection = dataSource.getConnection();
|
||||||
|
taskanaEngineImpl.setConnection(connection);
|
||||||
|
workBasketService = taskanaEngine.getWorkbasketService();
|
||||||
|
Workbasket workbasket0 = new Workbasket();
|
||||||
|
String id0 = IdGenerator.generateWithPrefix("TWB");
|
||||||
|
workbasket0.setId(id0);
|
||||||
|
workbasket0.setName("Superbasket");
|
||||||
|
Workbasket workbasket1 = new Workbasket();
|
||||||
|
String id1 = IdGenerator.generateWithPrefix("TWB");
|
||||||
|
workbasket1.setId(id1);
|
||||||
|
workbasket1.setName("Megabasket");
|
||||||
|
Workbasket workbasket2 = new Workbasket();
|
||||||
|
String id2 = IdGenerator.generateWithPrefix("TWB");
|
||||||
|
workbasket2.setId(id2);
|
||||||
|
workbasket2.setName("Hyperbasket");
|
||||||
|
workbasket2.getDistributionTargets().add(workbasket0);
|
||||||
|
workbasket2.getDistributionTargets().add(workbasket1);
|
||||||
|
workBasketService.createWorkbasket(workbasket2);
|
||||||
|
|
||||||
|
Workbasket workbasket3 = new Workbasket();
|
||||||
|
String id3 = IdGenerator.generateWithPrefix("TWB");
|
||||||
|
workbasket3.setId(id3);
|
||||||
|
workbasket3.setName("hm ... irgend ein basket");
|
||||||
|
workbasket2.getDistributionTargets().clear();
|
||||||
|
workbasket2.getDistributionTargets().add(workbasket3);
|
||||||
|
Thread.sleep(SLEEP_TIME);
|
||||||
|
workBasketService.updateWorkbasket(workbasket2);
|
||||||
|
|
||||||
|
Workbasket foundBasket = workBasketService.getWorkbasket(workbasket2.getId());
|
||||||
|
|
||||||
|
List<Workbasket> distributionTargets = foundBasket.getDistributionTargets();
|
||||||
|
Assert.assertEquals(1, distributionTargets.size());
|
||||||
|
Assert.assertEquals(id3, distributionTargets.get(0).getId());
|
||||||
|
Assert.assertNotEquals(workBasketService.getWorkbasket(id2).getCreated(),
|
||||||
|
workBasketService.getWorkbasket(id2).getModified());
|
||||||
|
Assert.assertEquals(workBasketService.getWorkbasket(id1).getCreated(),
|
||||||
|
workBasketService.getWorkbasket(id1).getModified());
|
||||||
|
Assert.assertEquals(workBasketService.getWorkbasket(id3).getCreated(),
|
||||||
|
workBasketService.getWorkbasket(id3).getModified());
|
||||||
|
connection.commit();
|
||||||
|
connection.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testInsertWorkbasketAccessUser() throws NotAuthorizedException, SQLException {
|
||||||
|
Connection connection = dataSource.getConnection();
|
||||||
|
taskanaEngineImpl.setConnection(connection);
|
||||||
|
workBasketService = taskanaEngine.getWorkbasketService();
|
||||||
|
WorkbasketAccessItem accessItem = new WorkbasketAccessItem();
|
||||||
|
String id1 = IdGenerator.generateWithPrefix("TWB");
|
||||||
|
accessItem.setWorkbasketId(id1);
|
||||||
|
accessItem.setAccessId("Arthur Dent");
|
||||||
|
accessItem.setPermOpen(true);
|
||||||
|
accessItem.setPermRead(true);
|
||||||
|
workBasketService.createWorkbasketAuthorization(accessItem);
|
||||||
|
|
||||||
|
Assert.assertEquals(1, workBasketService.getAllAuthorizations().size());
|
||||||
|
connection.commit();
|
||||||
|
connection.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testUpdateWorkbasketAccessUser() throws NotAuthorizedException, SQLException {
|
||||||
|
Connection connection = dataSource.getConnection();
|
||||||
|
taskanaEngineImpl.setConnection(connection);
|
||||||
|
workBasketService = taskanaEngine.getWorkbasketService();
|
||||||
|
WorkbasketAccessItem accessItem = new WorkbasketAccessItem();
|
||||||
|
String id1 = IdGenerator.generateWithPrefix("TWB");
|
||||||
|
accessItem.setWorkbasketId(id1);
|
||||||
|
accessItem.setAccessId("Arthur Dent");
|
||||||
|
accessItem.setPermOpen(true);
|
||||||
|
accessItem.setPermRead(true);
|
||||||
|
workBasketService.createWorkbasketAuthorization(accessItem);
|
||||||
|
|
||||||
|
Assert.assertEquals(1, workBasketService.getAllAuthorizations().size());
|
||||||
|
|
||||||
|
accessItem.setAccessId("Zaphod Beeblebrox");
|
||||||
|
workBasketService.updateWorkbasketAuthorization(accessItem);
|
||||||
|
|
||||||
|
Assert.assertEquals("Zaphod Beeblebrox",
|
||||||
|
workBasketService.getWorkbasketAuthorization(accessItem.getId()).getAccessId());
|
||||||
|
connection.commit();
|
||||||
|
connection.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
@After
|
||||||
|
public void cleanUp() {
|
||||||
|
taskanaEngineImpl.setConnection(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@AfterClass
|
||||||
|
public static void cleanUpClass() {
|
||||||
|
FileUtils.deleteRecursive("~/data", true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -39,7 +39,7 @@ public class ClassificationQueryImplTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void should_ReturnList_when_BuilderIsUsed() throws NotAuthorizedException {
|
public void should_ReturnList_when_BuilderIsUsed() throws NotAuthorizedException {
|
||||||
when(taskanaEngine.getSession()).thenReturn(sqlSession);
|
when(taskanaEngine.getSqlSession()).thenReturn(sqlSession);
|
||||||
when(sqlSession.selectList(any(), any())).thenReturn(new ArrayList<>());
|
when(sqlSession.selectList(any(), any())).thenReturn(new ArrayList<>());
|
||||||
|
|
||||||
List<Classification> result = classificationQueryImpl.name("test", "asd", "blubber").type("cool", "bla").priority(1, 2)
|
List<Classification> result = classificationQueryImpl.name("test", "asd", "blubber").type("cool", "bla").priority(1, 2)
|
||||||
|
|
@ -49,7 +49,7 @@ public class ClassificationQueryImplTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void should_ReturnListWithOffset_when_BuilderIsUsed() throws NotAuthorizedException {
|
public void should_ReturnListWithOffset_when_BuilderIsUsed() throws NotAuthorizedException {
|
||||||
when(taskanaEngine.getSession()).thenReturn(sqlSession);
|
when(taskanaEngine.getSqlSession()).thenReturn(sqlSession);
|
||||||
when(sqlSession.selectList(any(), any(), any())).thenReturn(new ArrayList<>());
|
when(sqlSession.selectList(any(), any(), any())).thenReturn(new ArrayList<>());
|
||||||
|
|
||||||
List<Classification> result = classificationQueryImpl.name("test", "asd", "blubber").type("cool", "bla").priority(1, 2)
|
List<Classification> result = classificationQueryImpl.name("test", "asd", "blubber").type("cool", "bla").priority(1, 2)
|
||||||
|
|
@ -59,7 +59,7 @@ public class ClassificationQueryImplTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void should_ReturnOneItem_when_BuilderIsUsed() throws NotAuthorizedException {
|
public void should_ReturnOneItem_when_BuilderIsUsed() throws NotAuthorizedException {
|
||||||
when(taskanaEngine.getSession()).thenReturn(sqlSession);
|
when(taskanaEngine.getSqlSession()).thenReturn(sqlSession);
|
||||||
when(sqlSession.selectOne(any(), any())).thenReturn(new Classification());
|
when(sqlSession.selectOne(any(), any())).thenReturn(new Classification());
|
||||||
|
|
||||||
Classification result = classificationQueryImpl.name("test", "asd", "blubber").type("cool", "bla").priority(1, 2)
|
Classification result = classificationQueryImpl.name("test", "asd", "blubber").type("cool", "bla").priority(1, 2)
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,7 @@ public class ObjectReferenceQueryImplTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void should_ReturnList_when_BuilderIsUsed() throws NotAuthorizedException {
|
public void should_ReturnList_when_BuilderIsUsed() throws NotAuthorizedException {
|
||||||
when(taskanaEngine.getSession()).thenReturn(sqlSession);
|
when(taskanaEngine.getSqlSession()).thenReturn(sqlSession);
|
||||||
when(sqlSession.selectList(any(), any())).thenReturn(new ArrayList<>());
|
when(sqlSession.selectList(any(), any())).thenReturn(new ArrayList<>());
|
||||||
|
|
||||||
List<ObjectReference> result = objectReferenceQueryImpl.value("test", "asd", "blubber").type("cool", "bla")
|
List<ObjectReference> result = objectReferenceQueryImpl.value("test", "asd", "blubber").type("cool", "bla")
|
||||||
|
|
@ -49,7 +49,7 @@ public class ObjectReferenceQueryImplTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void should_ReturnListWithOffset_when_BuilderIsUsed() throws NotAuthorizedException {
|
public void should_ReturnListWithOffset_when_BuilderIsUsed() throws NotAuthorizedException {
|
||||||
when(taskanaEngine.getSession()).thenReturn(sqlSession);
|
when(taskanaEngine.getSqlSession()).thenReturn(sqlSession);
|
||||||
when(sqlSession.selectList(any(), any(), any())).thenReturn(new ArrayList<>());
|
when(sqlSession.selectList(any(), any(), any())).thenReturn(new ArrayList<>());
|
||||||
|
|
||||||
List<ObjectReference> result = objectReferenceQueryImpl.value("test", "asd", "blubber").type("cool", "bla")
|
List<ObjectReference> result = objectReferenceQueryImpl.value("test", "asd", "blubber").type("cool", "bla")
|
||||||
|
|
@ -59,7 +59,7 @@ public class ObjectReferenceQueryImplTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void should_ReturnOneItem_when_BuilderIsUsed() throws NotAuthorizedException {
|
public void should_ReturnOneItem_when_BuilderIsUsed() throws NotAuthorizedException {
|
||||||
when(taskanaEngine.getSession()).thenReturn(sqlSession);
|
when(taskanaEngine.getSqlSession()).thenReturn(sqlSession);
|
||||||
when(sqlSession.selectOne(any(), any())).thenReturn(new ObjectReference());
|
when(sqlSession.selectOne(any(), any())).thenReturn(new ObjectReference());
|
||||||
|
|
||||||
ObjectReference result = objectReferenceQueryImpl.value("test", "asd", "blubber").type("cool", "bla")
|
ObjectReference result = objectReferenceQueryImpl.value("test", "asd", "blubber").type("cool", "bla")
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,7 @@ public class TaskQueryImplTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void should_ReturnList_when_BuilderIsUsed() throws NotAuthorizedException {
|
public void should_ReturnList_when_BuilderIsUsed() throws NotAuthorizedException {
|
||||||
when(taskanaEngine.getSession()).thenReturn(sqlSession);
|
when(taskanaEngine.getSqlSession()).thenReturn(sqlSession);
|
||||||
when(sqlSession.selectList(any(), any())).thenReturn(new ArrayList<>());
|
when(sqlSession.selectList(any(), any())).thenReturn(new ArrayList<>());
|
||||||
|
|
||||||
List<Task> result = taskQueryImpl.name("test", "asd", "blubber").customFields("cool", "bla").priority(1, 2)
|
List<Task> result = taskQueryImpl.name("test", "asd", "blubber").customFields("cool", "bla").priority(1, 2)
|
||||||
|
|
@ -50,7 +50,7 @@ public class TaskQueryImplTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void should_ReturnListWithOffset_when_BuilderIsUsed() throws NotAuthorizedException {
|
public void should_ReturnListWithOffset_when_BuilderIsUsed() throws NotAuthorizedException {
|
||||||
when(taskanaEngine.getSession()).thenReturn(sqlSession);
|
when(taskanaEngine.getSqlSession()).thenReturn(sqlSession);
|
||||||
when(sqlSession.selectList(any(), any(), any())).thenReturn(new ArrayList<>());
|
when(sqlSession.selectList(any(), any(), any())).thenReturn(new ArrayList<>());
|
||||||
|
|
||||||
List<Task> result = taskQueryImpl.name("test", "asd", "blubber").customFields("cool", "bla").priority(1, 2)
|
List<Task> result = taskQueryImpl.name("test", "asd", "blubber").customFields("cool", "bla").priority(1, 2)
|
||||||
|
|
@ -60,7 +60,7 @@ public class TaskQueryImplTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void should_ReturnOneItem_when_BuilderIsUsed() throws NotAuthorizedException {
|
public void should_ReturnOneItem_when_BuilderIsUsed() throws NotAuthorizedException {
|
||||||
when(taskanaEngine.getSession()).thenReturn(sqlSession);
|
when(taskanaEngine.getSqlSession()).thenReturn(sqlSession);
|
||||||
when(sqlSession.selectOne(any(), any())).thenReturn(new Task());
|
when(sqlSession.selectOne(any(), any())).thenReturn(new Task());
|
||||||
|
|
||||||
Task result = taskQueryImpl.name("test", "asd", "blubber").customFields("cool", "bla").priority(1, 2)
|
Task result = taskQueryImpl.name("test", "asd", "blubber").customFields("cool", "bla").priority(1, 2)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue