Handling Merge-Conflicts
This commit is contained in:
Marcel Lengl 2017-11-27 09:59:36 +01:00
commit 4c4ee62414
38 changed files with 1874 additions and 572 deletions

View File

@ -2,8 +2,7 @@
<table class="table table-condensed table-hover">
<thead>
<th>ID</th>
<th>UserID</th>
<th>GroupID</th>
<th>AccessID</th>
<th>READ</th>
<th>OPEN</th>
<th>APPEND</th>
@ -14,25 +13,22 @@
<tr>
<td></td>
<td>
<input class="form-control" placeholder="UserId" name="name" [(ngModel)]="workbasketAuthorization.userId" required>
<input class="form-control" placeholder="AccessId" name="name" [(ngModel)]="workbasketAuthorization.accessId" required>
</td>
<td>
<input class="form-control" placeholder="GroupId" name="description" [(ngModel)]="workbasketAuthorization.groupId">
<input type="checkbox" [(ngModel)]="workbasketAuthorization.permRead">
</td>
<td>
<input type="checkbox" [(ngModel)]="workbasketAuthorization.read">
<input type="checkbox" [(ngModel)]="workbasketAuthorization.permOpen">
</td>
<td>
<input type="checkbox" [(ngModel)]="workbasketAuthorization.open">
<input type="checkbox" [(ngModel)]="workbasketAuthorization.permAppend">
</td>
<td>
<input type="checkbox" [(ngModel)]="workbasketAuthorization.append">
<input type="checkbox" [(ngModel)]="workbasketAuthorization.permTransfer">
</td>
<td>
<input type="checkbox" [(ngModel)]="workbasketAuthorization.transfer">
</td>
<td>
<input type="checkbox" [(ngModel)]="workbasketAuthorization.distribute">
<input type="checkbox" [(ngModel)]="workbasketAuthorization.permDistribute">
</td>
<td>
<button type="button" class="btn btn-default" aria-label="Left Align" (click)="onAdd()">
@ -48,43 +44,39 @@
<td *ngIf="workbasketAuthorization.id == editing.id">
<input class="form-control" placeholder="Id" name="editid" [(ngModel)]="editing.id" readonly>
</td>
<td *ngIf="workbasketAuthorization.id != editing.id">{{ workbasketAuthorization.userId }}</td>
<td *ngIf="workbasketAuthorization.id != editing.id">{{ workbasketAuthorization.accessId }}</td>
<td *ngIf="workbasketAuthorization.id == editing.id">
<input class="form-control" placeholder="UserId" name="edituserId" [(ngModel)]="editing.userId">
</td>
<td *ngIf="workbasketAuthorization.id != editing.id">{{ workbasketAuthorization.groupId }}</td>
<td *ngIf="workbasketAuthorization.id == editing.id">
<input class="form-control" placeholder="GroupId" name="editgroupId" [(ngModel)]="editing.groupId">
<input class="form-control" placeholder="AccessId" name="editAccessId" [(ngModel)]="editing.accessId">
</td>
<td *ngIf="workbasketAuthorization.id != editing.id">
<input type="checkbox" [checked]="workbasketAuthorization.read" disabled>
<input type="checkbox" [checked]="workbasketAuthorization.permRead" disabled>
</td>
<td *ngIf="workbasketAuthorization.id == editing.id">
<input type="checkbox" [(ngModel)]="workbasketAuthorization.read">
<input type="checkbox" [(ngModel)]="workbasketAuthorization.permRead">
</td>
<td *ngIf="workbasketAuthorization.id != editing.id">
<input type="checkbox" [checked]="workbasketAuthorization.open" disabled>
<input type="checkbox" [checked]="workbasketAuthorization.permOpen" disabled>
</td>
<td *ngIf="workbasketAuthorization.id == editing.id">
<input type="checkbox" [(ngModel)]="workbasketAuthorization.open">
<input type="checkbox" [(ngModel)]="workbasketAuthorization.permOpen">
</td>
<td *ngIf="workbasketAuthorization.id != editing.id">
<input type="checkbox" [checked]="workbasketAuthorization.append" disabled>
<input type="checkbox" [checked]="workbasketAuthorization.permAppend" disabled>
</td>
<td *ngIf="workbasketAuthorization.id == editing.id">
<input type="checkbox" [(ngModel)]="workbasketAuthorization.append">
<input type="checkbox" [(ngModel)]="workbasketAuthorization.permAppend">
</td>
<td *ngIf="workbasketAuthorization.id != editing.id">
<input type="checkbox" [checked]="workbasketAuthorization.transfer" disabled>
<input type="checkbox" [checked]="workbasketAuthorization.permTransfer" disabled>
</td>
<td *ngIf="workbasketAuthorization.id == editing.id">
<input type="checkbox" [(ngModel)]="workbasketAuthorization.transfer">
<input type="checkbox" [(ngModel)]="workbasketAuthorization.permTransfer">
</td>
<td *ngIf="workbasketAuthorization.id != editing.id">
<input type="checkbox" [checked]="workbasketAuthorization.distribute" disabled>
<input type="checkbox" [checked]="workbasketAuthorization.permDistribute" disabled>
</td>
<td *ngIf="workbasketAuthorization.id == editing.id">
<input type="checkbox" [(ngModel)]="workbasketAuthorization.distribute">
<input type="checkbox" [(ngModel)]="workbasketAuthorization.permDistribute">
</td>
<td *ngIf="workbasketAuthorization.id != editing.id">
<button type="button" class="btn btn-default" aria-label="Left Align" (click)="onEdit(workbasketAuthorization)">
@ -103,4 +95,4 @@
</button>
</td>
</tr>
</table>
</table>

View File

@ -91,7 +91,6 @@
<version>3.5.1</version>
<configuration>
<showWarnings>true</showWarnings>
<failOnWarning>true</failOnWarning>
<compilerArgs>
<arg>-Xlint:all</arg>
</compilerArgs>

View File

@ -1,5 +1,6 @@
package pro.taskana;
import pro.taskana.TaskanaEngine.ConnectionManagementMode;
import pro.taskana.configuration.TaskanaEngineConfiguration;
/**
@ -30,4 +31,42 @@ public interface TaskanaEngine {
* @return the TaskanaConfiguration
*/
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
}
}

View File

@ -1,13 +1,13 @@
package pro.taskana;
import java.util.List;
import pro.taskana.exceptions.NotAuthorizedException;
import pro.taskana.exceptions.WorkbasketNotFoundException;
import pro.taskana.model.Workbasket;
import pro.taskana.model.WorkbasketAccessItem;
import pro.taskana.model.WorkbasketAuthorization;
import java.util.List;
/**
* This service manages the Workbaskets.
*/
@ -43,11 +43,9 @@ public interface WorkbasketService {
Workbasket updateWorkbasket(Workbasket workbasket) throws NotAuthorizedException;
/**
* Create a new authorization for a specific workbasket and a specific user.
* @param workbasket
* the choosen workbasket
* @param user
* the choosen user
* Create a new Workbasket Authorization with a Workbasket and a AccessId.
* @param workbasketAccessItem
* the new workbasketAccessItem
* @return
*/
WorkbasketAccessItem createWorkbasketAuthorization(WorkbasketAccessItem workbasketAccessItem);
@ -74,11 +72,10 @@ public interface WorkbasketService {
void deleteWorkbasketAuthorization(String id);
/**
* This method checks the authorization with the saved one.
* @param workbasket
* the workbasket to check
* @param userId
* the user to check
* This method checks the authorization with the saved one for the actual User.
*
* @param workbasketId
* the workbasket we want to access
* @param authorization
* the needed Authorization
* @throws WorkbasketNotFoundException

View File

@ -3,6 +3,7 @@ package pro.taskana.configuration;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.sql.Connection;
import java.sql.SQLException;
import javax.sql.DataSource;
@ -39,8 +40,9 @@ public class DbScriptRunner {
* @throws SQLException
*/
public void run() throws SQLException {
ScriptRunner runner = new ScriptRunner(dataSource.getConnection());
LOGGER.debug(dataSource.getConnection().getMetaData().toString());
Connection connection = dataSource.getConnection();
ScriptRunner runner = new ScriptRunner(connection);
LOGGER.debug(connection.getMetaData().toString());
runner.setStopOnError(true);
runner.setLogWriter(logWriter);

View File

@ -55,7 +55,7 @@ public class TaskanaEngineConfiguration {
this.securityEnabled = securityEnabled;
}
public DataSource createDefaultDataSource() {
public static DataSource createDefaultDataSource() {
LOGGER.warn("No datasource is provided. A inmemory db is used: "
+ "'org.h2.Driver', 'jdbc:h2:mem:taskana', 'sa', 'sa'");
return createDatasource(H2_DRIVER, JDBC_H2_MEM_TASKANA, USER_NAME, USER_PASSWORD);
@ -75,7 +75,7 @@ public class TaskanaEngineConfiguration {
* @param dbConfiguration
* @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);
}

View File

@ -0,0 +1,13 @@
package pro.taskana.exceptions;
/**
* Thrown in ConnectionManagementMode AUTOCOMMIT when an attempt to commit fails.
*
*/
@SuppressWarnings("serial")
public class AutocommitFailedException extends RuntimeException {
public AutocommitFailedException(Throwable cause) {
super("Autocommit failed", cause);
}
}

View File

@ -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");
}
}

View File

@ -1,8 +1,7 @@
package pro.taskana.impl.persistence;
package pro.taskana.impl;
import org.apache.ibatis.session.RowBounds;
import pro.taskana.TaskanaEngine;
import pro.taskana.impl.TaskanaEngineImpl;
import pro.taskana.model.Classification;
import pro.taskana.persistence.ClassificationQuery;
@ -16,7 +15,7 @@ import java.util.List;
public class ClassificationQueryImpl implements ClassificationQuery {
private static final String LINK_TO_MAPPER = "pro.taskana.model.mappings.QueryMapper.queryClassification";
private TaskanaEngineImpl taskanaEngine;
private TaskanaEngineImpl taskanaEngineImpl;
private String[] parentClassificationId;
private String[] category;
private String[] type;
@ -32,7 +31,7 @@ public class ClassificationQueryImpl implements ClassificationQuery {
private Date[] validUntil;
public ClassificationQueryImpl(TaskanaEngine taskanaEngine) {
this.taskanaEngine = (TaskanaEngineImpl) taskanaEngine;
this.taskanaEngineImpl = (TaskanaEngineImpl) taskanaEngine;
}
@Override
@ -115,18 +114,33 @@ public class ClassificationQueryImpl implements ClassificationQuery {
@Override
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
public List<Classification> list(int offset, int limit) {
RowBounds rowBounds = new RowBounds(offset, limit);
return taskanaEngine.getSession().selectList(LINK_TO_MAPPER, this, rowBounds);
try {
taskanaEngineImpl.openConnection();
RowBounds rowBounds = new RowBounds(offset, limit);
return taskanaEngineImpl.getSqlSession().selectList(LINK_TO_MAPPER, this, rowBounds);
} finally {
taskanaEngineImpl.returnConnection();
}
}
@Override
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() {

View File

@ -3,7 +3,6 @@ package pro.taskana.impl;
import pro.taskana.ClassificationService;
import pro.taskana.TaskanaEngine;
import pro.taskana.exceptions.NotAuthorizedException;
import pro.taskana.impl.persistence.ClassificationQueryImpl;
import pro.taskana.impl.util.IdGenerator;
import pro.taskana.model.Classification;
import pro.taskana.model.mappings.ClassificationMapper;
@ -24,62 +23,85 @@ public class ClassificationServiceImpl implements ClassificationService {
public static final Date CURRENT_CLASSIFICATIONS_VALID_UNTIL = Date.valueOf("9999-12-31");
private ClassificationMapper classificationMapper;
private TaskanaEngine taskanaEngine;
private TaskanaEngineImpl taskanaEngineImpl;
public ClassificationServiceImpl(TaskanaEngine taskanaEngine, ClassificationMapper classificationMapper) {
super();
this.taskanaEngine = taskanaEngine;
this.taskanaEngineImpl = (TaskanaEngineImpl) taskanaEngine;
this.classificationMapper = classificationMapper;
}
@Override
public List<Classification> getClassificationTree() throws NotAuthorizedException {
List<Classification> rootClassifications;
rootClassifications = this.createClassificationQuery().parentClassification("").validUntil(CURRENT_CLASSIFICATIONS_VALID_UNTIL).list();
return this.populateChildClassifications(rootClassifications);
try {
taskanaEngineImpl.openConnection();
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 {
List<Classification> children = new ArrayList<>();
for (Classification classification : classifications) {
List<Classification> childClassifications = this.createClassificationQuery().parentClassification(classification.getId()).validUntil(CURRENT_CLASSIFICATIONS_VALID_UNTIL).list();
children.addAll(populateChildClassifications(childClassifications));
try {
taskanaEngineImpl.openConnection();
List<Classification> children = new ArrayList<>();
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
public void addClassification(Classification classification) {
classification.setId(IdGenerator.generateWithPrefix(ID_PREFIX_CLASSIFICATION));
classification.setCreated(Date.valueOf(LocalDate.now()));
try {
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
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) {
classification.setId(IdGenerator.generateWithPrefix(ID_PREFIX_CLASSIFICATION));
classification.setCreated(Date.valueOf(LocalDate.now()));
classificationMapper.insert(classification);
if (oldClassification == null) {
classification.setId(IdGenerator.generateWithPrefix(ID_PREFIX_CLASSIFICATION));
classification.setCreated(Date.valueOf(LocalDate.now()));
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;
}
// ! 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);
} finally {
taskanaEngineImpl.returnConnection();
}
}
@ -105,20 +127,32 @@ public class ClassificationServiceImpl implements ClassificationService {
if (classification.getDomain() == null) {
classification.setDomain("");
}
}
@Override
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
public Classification getClassification(String id, String domain) {
Classification classification;
if (domain == null) {
classification = classificationMapper.findByIdAndDomain(id, "", CURRENT_CLASSIFICATIONS_VALID_UNTIL);
} else {
classification = classificationMapper.findByIdAndDomain(id, domain, CURRENT_CLASSIFICATIONS_VALID_UNTIL);
Classification classification = null;
try {
taskanaEngineImpl.openConnection();
if (domain == null) {
classification = classificationMapper.findByIdAndDomain(id, "", CURRENT_CLASSIFICATIONS_VALID_UNTIL);
} else {
classification = classificationMapper.findByIdAndDomain(id, domain, CURRENT_CLASSIFICATIONS_VALID_UNTIL);
}
} finally {
taskanaEngineImpl.returnConnection();
}
return classification;
}

View File

@ -1,10 +1,9 @@
package pro.taskana.impl.persistence;
package pro.taskana.impl;
import java.util.List;
import org.apache.ibatis.session.RowBounds;
import pro.taskana.TaskanaEngine;
import pro.taskana.impl.TaskanaEngineImpl;
import pro.taskana.model.ObjectReference;
import pro.taskana.persistence.ObjectReferenceQuery;
@ -16,7 +15,7 @@ public class ObjectReferenceQueryImpl implements ObjectReferenceQuery {
private static final String LINK_TO_MAPPER = "pro.taskana.model.mappings.QueryMapper.queryObjectReference";
private TaskanaEngineImpl taskanaEngine;
private TaskanaEngineImpl taskanaEngineImpl;
private String[] company;
private String[] system;
private String[] systemInstance;
@ -24,7 +23,7 @@ public class ObjectReferenceQueryImpl implements ObjectReferenceQuery {
private String[] value;
public ObjectReferenceQueryImpl(TaskanaEngine taskanaEngine) {
this.taskanaEngine = (TaskanaEngineImpl) taskanaEngine;
this.taskanaEngineImpl = (TaskanaEngineImpl) taskanaEngine;
}
@Override
@ -59,18 +58,33 @@ public class ObjectReferenceQueryImpl implements ObjectReferenceQuery {
@Override
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
public List<ObjectReference> list(int offset, int limit) {
RowBounds rowBounds = new RowBounds(offset, limit);
return taskanaEngine.getSession().selectList(LINK_TO_MAPPER, this, rowBounds);
try {
taskanaEngineImpl.openConnection();
RowBounds rowBounds = new RowBounds(offset, limit);
return taskanaEngineImpl.getSqlSession().selectList(LINK_TO_MAPPER, this, rowBounds);
} finally {
taskanaEngineImpl.returnConnection();
}
}
@Override
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() {

View File

@ -1,4 +1,4 @@
package pro.taskana.impl.persistence;
package pro.taskana.impl;
import java.util.List;
@ -6,7 +6,6 @@ import org.apache.ibatis.session.RowBounds;
import pro.taskana.TaskanaEngine;
import pro.taskana.exceptions.NotAuthorizedException;
import pro.taskana.impl.TaskanaEngineImpl;
import pro.taskana.model.Task;
import pro.taskana.model.TaskState;
import pro.taskana.model.WorkbasketAuthorization;
@ -21,7 +20,7 @@ public class TaskQueryImpl implements TaskQuery {
private static final String LINK_TO_MAPPER = "pro.taskana.model.mappings.QueryMapper.queryTasks";
private TaskanaEngineImpl taskanaEngine;
private TaskanaEngineImpl taskanaEngineImpl;
private String[] name;
private String description;
@ -36,7 +35,7 @@ public class TaskQueryImpl implements TaskQuery {
private String[] customFields;
public TaskQueryImpl(TaskanaEngine taskanaEngine) {
this.taskanaEngine = (TaskanaEngineImpl) taskanaEngine;
this.taskanaEngineImpl = (TaskanaEngineImpl) taskanaEngine;
}
@Override
@ -107,43 +106,57 @@ public class TaskQueryImpl implements TaskQuery {
@Override
public ObjectReferenceQuery createObjectReferenceQuery() {
return new ObjectReferenceQueryImpl(taskanaEngine);
return new ObjectReferenceQueryImpl(taskanaEngineImpl);
}
@Override
public List<Task> list() throws NotAuthorizedException {
checkAuthorization();
List<Task> tempTaskList = taskanaEngine.getSession().selectList(LINK_TO_MAPPER, this);
return tempTaskList;
try {
taskanaEngineImpl.openConnection();
checkAuthorization();
return taskanaEngineImpl.getSqlSession().selectList(LINK_TO_MAPPER, this);
} finally {
taskanaEngineImpl.returnConnection();
}
}
@Override
public List<Task> list(int offset, int limit) throws NotAuthorizedException {
checkAuthorization();
RowBounds rowBounds = new RowBounds(offset, limit);
return taskanaEngine.getSession().selectList(LINK_TO_MAPPER, this, rowBounds);
try {
taskanaEngineImpl.openConnection();
checkAuthorization();
RowBounds rowBounds = new RowBounds(offset, limit);
return taskanaEngineImpl.getSqlSession().selectList(LINK_TO_MAPPER, this, rowBounds);
} finally {
taskanaEngineImpl.returnConnection();
}
}
@Override
public Task single() throws NotAuthorizedException {
checkAuthorization();
return taskanaEngine.getSession().selectOne(LINK_TO_MAPPER, this);
try {
taskanaEngineImpl.openConnection();
checkAuthorization();
return taskanaEngineImpl.getSqlSession().selectOne(LINK_TO_MAPPER, this);
} finally {
taskanaEngineImpl.returnConnection();
}
}
private void checkAuthorization() throws NotAuthorizedException {
if (this.workbasketId != null && this.workbasketId.length > 0) {
for (String workbasket : this.workbasketId) {
taskanaEngine.getWorkbasketService().checkAuthorization(workbasket, WorkbasketAuthorization.OPEN);
taskanaEngineImpl.getWorkbasketService().checkAuthorization(workbasket, WorkbasketAuthorization.OPEN);
}
}
}
public TaskanaEngineImpl getTaskanaEngine() {
return taskanaEngine;
return taskanaEngineImpl;
}
public void setTaskanaEngine(TaskanaEngineImpl taskanaEngine) {
this.taskanaEngine = taskanaEngine;
this.taskanaEngineImpl = taskanaEngine;
}
public String[] getName() {

View File

@ -8,12 +8,12 @@ import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import pro.taskana.TaskService;
import pro.taskana.TaskanaEngine;
import pro.taskana.exceptions.NotAuthorizedException;
import pro.taskana.exceptions.TaskNotFoundException;
import pro.taskana.exceptions.WorkbasketNotFoundException;
import pro.taskana.impl.persistence.TaskQueryImpl;
import pro.taskana.impl.util.IdGenerator;
import pro.taskana.model.DueWorkbasketCounter;
import pro.taskana.model.ObjectReference;
@ -36,6 +36,7 @@ public class TaskServiceImpl implements TaskService {
private static final String ID_PREFIX_TASK = "TKI";
private TaskanaEngine taskanaEngine;
private TaskanaEngineImpl taskanaEngineImpl;
private TaskMapper taskMapper;
private ObjectReferenceMapper objectReferenceMapper;
@ -43,139 +44,181 @@ public class TaskServiceImpl implements TaskService {
ObjectReferenceMapper objectReferenceMapper) {
super();
this.taskanaEngine = taskanaEngine;
this.taskanaEngineImpl = (TaskanaEngineImpl) taskanaEngine;
this.taskMapper = taskMapper;
this.objectReferenceMapper = objectReferenceMapper;
}
@Override
public void claim(String id, String userName) throws TaskNotFoundException {
Task task = taskMapper.findById(id);
if (task != null) {
Timestamp now = new Timestamp(System.currentTimeMillis());
task.setOwner(userName);
task.setModified(now);
task.setClaimed(now);
task.setState(TaskState.CLAIMED);
taskMapper.update(task);
LOGGER.debug("User '{}' claimed task '{}'.", userName, id);
} else {
throw new TaskNotFoundException(id);
try {
taskanaEngineImpl.openConnection();
Task task = taskMapper.findById(id);
if (task != null) {
Timestamp now = new Timestamp(System.currentTimeMillis());
task.setOwner(userName);
task.setModified(now);
task.setClaimed(now);
task.setState(TaskState.CLAIMED);
taskMapper.update(task);
LOGGER.debug("User '{}' claimed task '{}'.", userName, id);
} else {
throw new TaskNotFoundException(id);
}
} finally {
taskanaEngineImpl.returnConnection();
}
}
@Override
public void complete(String id) throws TaskNotFoundException {
Task task = taskMapper.findById(id);
if (task != null) {
Timestamp now = new Timestamp(System.currentTimeMillis());
task.setCompleted(now);
task.setModified(now);
task.setState(TaskState.COMPLETED);
taskMapper.update(task);
LOGGER.debug("Task '{}' completed.", id);
} else {
throw new TaskNotFoundException(id);
try {
taskanaEngineImpl.openConnection();
Task task = taskMapper.findById(id);
if (task != null) {
Timestamp now = new Timestamp(System.currentTimeMillis());
task.setCompleted(now);
task.setModified(now);
task.setState(TaskState.COMPLETED);
taskMapper.update(task);
LOGGER.debug("Task '{}' completed.", id);
} else {
throw new TaskNotFoundException(id);
}
} finally {
taskanaEngineImpl.returnConnection();
}
}
@Override
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());
task.setId(IdGenerator.generateWithPrefix(ID_PREFIX_TASK));
task.setState(TaskState.READY);
task.setCreated(now);
task.setModified(now);
task.setRead(false);
task.setTransferred(false);
Timestamp now = new Timestamp(System.currentTimeMillis());
task.setId(IdGenerator.generateWithPrefix(ID_PREFIX_TASK));
task.setState(TaskState.READY);
task.setCreated(now);
task.setModified(now);
task.setRead(false);
task.setTransferred(false);
// insert ObjectReference if needed.
if (task.getPrimaryObjRef() != null) {
ObjectReference objectReference = this.objectReferenceMapper.findByObjectReference(task.getPrimaryObjRef());
if (objectReference == null) {
objectReference = task.getPrimaryObjRef();
objectReference.setId(IdGenerator.generateWithPrefix(ID_PREFIX_OBJECTR_EFERENCE));
this.objectReferenceMapper.insert(objectReference);
// insert ObjectReference if needed.
if (task.getPrimaryObjRef() != null) {
ObjectReference objectReference = this.objectReferenceMapper.findByObjectReference(task.getPrimaryObjRef());
if (objectReference == null) {
objectReference = task.getPrimaryObjRef();
objectReference.setId(IdGenerator.generateWithPrefix(ID_PREFIX_OBJECTR_EFERENCE));
this.objectReferenceMapper.insert(objectReference);
}
task.setPrimaryObjRef(objectReference);
}
task.setPrimaryObjRef(objectReference);
}
this.taskMapper.insert(task);
this.taskMapper.insert(task);
LOGGER.debug("Task '{}' created.", task.getId());
return task;
LOGGER.debug("Task '{}' created.", task.getId());
return task;
} finally {
taskanaEngineImpl.returnConnection();
}
}
@Override
public Task getTaskById(String id) throws TaskNotFoundException {
Task task = taskMapper.findById(id);
if (task != null) {
return task;
} else {
throw new TaskNotFoundException(id);
try {
taskanaEngineImpl.openConnection();
Task task = taskMapper.findById(id);
if (task != null) {
return task;
} else {
throw new TaskNotFoundException(id);
}
} finally {
taskanaEngineImpl.returnConnection();
}
}
@Override
public List<TaskStateCounter> getTaskCountForState(List<TaskState> states) {
return taskMapper.getTaskCountForState(states);
try {
taskanaEngineImpl.openConnection();
return taskMapper.getTaskCountForState(states);
} finally {
taskanaEngineImpl.returnConnection();
}
}
@Override
public long getTaskCountForWorkbasketByDaysInPastAndState(String workbasketId, long daysInPast,
List<TaskState> states) {
LocalDate time = LocalDate.now();
time = time.minusDays(daysInPast);
Date fromDate = Date.valueOf(time);
return taskMapper.getTaskCountForWorkbasketByDaysInPastAndState(workbasketId, fromDate, states);
public long getTaskCountForWorkbasketByDaysInPastAndState(String workbasketId, long daysInPast, List<TaskState> states) {
try {
taskanaEngineImpl.openConnection();
LocalDate time = LocalDate.now();
time = time.minusDays(daysInPast);
Date fromDate = Date.valueOf(time);
return taskMapper.getTaskCountForWorkbasketByDaysInPastAndState(workbasketId, fromDate, states);
} finally {
taskanaEngineImpl.returnConnection();
}
}
@Override
public Task transfer(String taskId, String destinationWorkbasketId)
throws TaskNotFoundException, WorkbasketNotFoundException, NotAuthorizedException {
Task task = getTaskById(taskId);
try {
taskanaEngineImpl.openConnection();
Task task = getTaskById(taskId);
// transfer requires TRANSFER in source and APPEND on destination
// workbasket
taskanaEngine.getWorkbasketService().checkAuthorization(destinationWorkbasketId,
WorkbasketAuthorization.APPEND);
taskanaEngine.getWorkbasketService().checkAuthorization(task.getWorkbasketId(),
WorkbasketAuthorization.TRANSFER);
// transfer requires TRANSFER in source and APPEND on destination workbasket
taskanaEngine.getWorkbasketService().checkAuthorization(destinationWorkbasketId, WorkbasketAuthorization.APPEND);
taskanaEngine.getWorkbasketService().checkAuthorization(task.getWorkbasketId(), WorkbasketAuthorization.TRANSFER);
// if security is disabled, the implicit existance check on the
// destination workbasket has been skipped and needs to be performed
if (!taskanaEngine.getConfiguration().isSecurityEnabled()) {
taskanaEngine.getWorkbasketService().getWorkbasket(destinationWorkbasketId);
// if security is disabled, the implicit existance check on the
// destination workbasket has been skipped and needs to be performed
if (!taskanaEngine.getConfiguration().isSecurityEnabled()) {
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
public List<DueWorkbasketCounter> getTaskCountByWorkbasketAndDaysInPastAndState(long daysInPast,
List<TaskState> states) {
LocalDate time = LocalDate.now();
time = time.minusDays(daysInPast);
Date fromDate = Date.valueOf(time);
return taskMapper.getTaskCountByWorkbasketIdAndDaysInPastAndState(fromDate, states);
try {
taskanaEngineImpl.openConnection();
LocalDate time = LocalDate.now();
time = time.minusDays(daysInPast);
Date fromDate = Date.valueOf(time);
return taskMapper.getTaskCountByWorkbasketIdAndDaysInPastAndState(fromDate, states);
} finally {
taskanaEngineImpl.returnConnection();
}
}
@Override
public Task setTaskRead(String taskId, boolean isRead) throws TaskNotFoundException {
Task task = getTaskById(taskId);
task.setRead(true);
task.setModified(Timestamp.valueOf(LocalDateTime.now()));
taskMapper.update(task);
return getTaskById(taskId);
try {
taskanaEngineImpl.openConnection();
Task task = getTaskById(taskId);
task.setRead(true);
task.setModified(Timestamp.valueOf(LocalDateTime.now()));
taskMapper.update(task);
return getTaskById(taskId);
} finally {
taskanaEngineImpl.returnConnection();
}
}
@Override

View File

@ -1,18 +1,26 @@
package pro.taskana.impl;
import java.util.Stack;
import org.apache.ibatis.mapping.Environment;
import org.apache.ibatis.session.Configuration;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.apache.ibatis.session.SqlSessionManager;
import org.apache.ibatis.transaction.TransactionFactory;
import org.apache.ibatis.transaction.jdbc.JdbcTransactionFactory;
import org.apache.ibatis.transaction.managed.ManagedTransactionFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import pro.taskana.ClassificationService;
import pro.taskana.TaskService;
import pro.taskana.TaskanaEngine;
import pro.taskana.WorkbasketService;
import pro.taskana.configuration.TaskanaEngineConfiguration;
import pro.taskana.exceptions.AutocommitFailedException;
import pro.taskana.exceptions.ConnectionNotSetException;
import pro.taskana.impl.persistence.MapTypeHandler;
import pro.taskana.model.mappings.ClassificationMapper;
import pro.taskana.model.mappings.DistributionTargetMapper;
@ -28,52 +36,42 @@ import pro.taskana.model.mappings.WorkbasketMapper;
public class TaskanaEngineImpl implements TaskanaEngine {
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 SqlSession session;
protected TransactionFactory transactionFactory;
protected SqlSessionManager sessionManager;
protected SqlSessionFactory sessionFactory;
private TaskMapper taskMapper;
private WorkbasketMapper workbasketMapper;
private DistributionTargetMapper distributionTargetMapper;
private ClassificationMapper classificationMapper;
private WorkbasketAccessMapper workbasketAccessMapper;
private ObjectReferenceMapper objectReferenceMapper;
private TaskServiceImpl taskServiceImpl;
private WorkbasketServiceImpl workbasketServiceImpl;
protected ConnectionManagementMode mode = ConnectionManagementMode.PARTICIPATE;
protected java.sql.Connection connection = null;
public TaskanaEngineImpl(TaskanaEngineConfiguration taskanaEngineConfiguration) {
this.taskanaEngineConfiguration = taskanaEngineConfiguration;
createTransactionFactory(taskanaEngineConfiguration.getUseContainerManagedTransactions());
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);
this.sessionManager = createSqlSessionManager();
}
@Override
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;
}
@Override
public WorkbasketService getWorkbasketService() {
this.workbasketServiceImpl = new WorkbasketServiceImpl(this, this.workbasketMapper,
this.distributionTargetMapper, this.workbasketAccessMapper);
SqlSession session = this.sessionManager;
WorkbasketServiceImpl workbasketServiceImpl = new WorkbasketServiceImpl(this, session.getMapper(WorkbasketMapper.class),
session.getMapper(DistributionTargetMapper.class),
session.getMapper(WorkbasketAccessMapper.class));
return workbasketServiceImpl;
}
@Override
public ClassificationService getClassificationService() {
return new ClassificationServiceImpl(this, this.classificationMapper);
SqlSession session = this.sessionManager;
return new ClassificationServiceImpl(this, session.getMapper(ClassificationMapper.class));
}
@Override
@ -82,20 +80,131 @@ public class TaskanaEngineImpl implements TaskanaEngine {
}
/**
* Close session manually, to be done, if a JdbcTransactionFactory is used.
* Perhaps it is better to separate the commit and the closing mechanism ...
* sets the connection management mode.
*
* @param mode - the connection management mode
* Valid values are
* PARTICIPATE - taskana participates in global transaction. This is the default mode
* AUTOCOMMIT - taskana commits each API call separately
* EXPLICIT - commit processing is managed explicitly by the client
*/
public void closeSession() {
this.session.commit();
this.session.close();
@Override
public void setConnectionManagementMode(ConnectionManagementMode mode) {
if (this.mode == ConnectionManagementMode.EXPLICIT && connection != null
&& mode != ConnectionManagementMode.EXPLICIT) {
if (sessionManager.isManagedSessionStarted()) {
sessionManager.close();
}
connection = null;
}
this.mode = mode;
}
/**
* This method creates the sqlSessionFactory of myBatis. It integrates all the
* 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;
}
}
/**
* 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;
}
}
/**
* Open the connection to the database.
* to be called at the begin of each Api call that accesses the database
*
*/
void openConnection() {
initSqlSession();
if (mode != ConnectionManagementMode.EXPLICIT) {
pushSessionToStack(this.sessionManager);
}
}
/**
* 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();
}
}
}
/**
* 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
*/
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.error("closeSession(): Tried to Autocommit and caught exception" + e);
throw new AutocommitFailedException(e);
}
}
this.sessionManager.close();
}
}
}
/**
* retrieve the SqlSession used by taskana.
* @return the myBatis SqlSession object used by taskana
*/
SqlSession getSqlSession() {
return this.sessionManager;
}
/**
* This method creates the sqlSessionManager of myBatis. It integrates all the
* SQL mappers
* @return a {@link SqlSessionFactory}
*/
private SqlSessionFactory createSqlSessionFactory() {
private SqlSessionManager createSqlSessionManager() {
Environment environment = new Environment(DEFAULT, this.transactionFactory,
taskanaEngineConfiguration.getDatasource());
Configuration configuration = new Configuration(environment);
@ -108,10 +217,15 @@ public class TaskanaEngineImpl implements TaskanaEngine {
configuration.addMapper(ObjectReferenceMapper.class);
configuration.addMapper(QueryMapper.class);
configuration.getTypeHandlerRegistry().register(MapTypeHandler.class);
sessionFactory = new SqlSessionFactoryBuilder().build(configuration);
return sessionFactory;
SqlSessionFactory sessionFactory = new SqlSessionFactoryBuilder().build(configuration);
SqlSessionManager sessionManager = SqlSessionManager.newInstance(sessionFactory);
return sessionManager;
}
/**
* creates the MyBatis transaction factory.
* @param useContainerManagedTransactions
*/
private void createTransactionFactory(boolean useContainerManagedTransactions) {
if (useContainerManagedTransactions) {
this.transactionFactory = new ManagedTransactionFactory();
@ -120,12 +234,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) {
this.session = session;
protected static SqlSessionManager getSessionFromStack() {
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();
}
}
}

View File

@ -1,8 +1,5 @@
package pro.taskana.impl;
import java.sql.Timestamp;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import pro.taskana.TaskanaEngine;
@ -17,6 +14,13 @@ import pro.taskana.model.mappings.DistributionTargetMapper;
import pro.taskana.model.mappings.WorkbasketAccessMapper;
import pro.taskana.model.mappings.WorkbasketMapper;
import pro.taskana.security.CurrentUserContext;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
/**
* This is the implementation of WorkbasketService.
*/
@ -28,6 +32,7 @@ public class WorkbasketServiceImpl implements WorkbasketService {
private static final String ID_PREFIX_WORKBASKET_AUTHORIZATION = "WAI";
private TaskanaEngine taskanaEngine;
private TaskanaEngineImpl taskanaEngineImpl;
private WorkbasketMapper workbasketMapper;
private DistributionTargetMapper distributionTargetMapper;
@ -39,6 +44,7 @@ public class WorkbasketServiceImpl implements WorkbasketService {
public WorkbasketServiceImpl(TaskanaEngine taskanaEngine, WorkbasketMapper workbasketMapper,
DistributionTargetMapper distributionTargetMapper, WorkbasketAccessMapper workbasketAccessMapper) {
this.taskanaEngine = taskanaEngine;
this.taskanaEngineImpl = (TaskanaEngineImpl) taskanaEngine;
this.workbasketMapper = workbasketMapper;
this.distributionTargetMapper = distributionTargetMapper;
this.workbasketAccessMapper = workbasketAccessMapper;
@ -46,123 +52,190 @@ public class WorkbasketServiceImpl implements WorkbasketService {
@Override
public Workbasket getWorkbasket(String workbasketId) throws WorkbasketNotFoundException {
Workbasket workbasket = workbasketMapper.findById(workbasketId);
if (workbasket == null) {
throw new WorkbasketNotFoundException(workbasketId);
try {
taskanaEngineImpl.openConnection();
Workbasket workbasket = workbasketMapper.findById(workbasketId);
if (workbasket == null) {
throw new WorkbasketNotFoundException(workbasketId);
}
return workbasket;
} finally {
taskanaEngineImpl.returnConnection();
}
return workbasket;
}
@Override
public List<Workbasket> getWorkbaskets(List<WorkbasketAuthorization> permissions) {
return workbasketMapper.findByPermission(permissions, CurrentUserContext.getUserid());
try {
taskanaEngineImpl.openConnection();
//use a set to avoid duplicates
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();
}
}
@Override
public List<Workbasket> getWorkbaskets() {
return workbasketMapper.findAll();
try {
taskanaEngineImpl.openConnection();
return workbasketMapper.findAll();
} finally {
taskanaEngineImpl.returnConnection();
}
}
@Override
public Workbasket createWorkbasket(Workbasket workbasket) {
Timestamp now = new Timestamp(System.currentTimeMillis());
workbasket.setCreated(now);
workbasket.setModified(now);
if (workbasket.getId() == null || workbasket.getId().isEmpty()) {
workbasket.setId(IdGenerator.generateWithPrefix(ID_PREFIX_WORKBASKET));
}
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());
try {
taskanaEngineImpl.openConnection();
Timestamp now = new Timestamp(System.currentTimeMillis());
workbasket.setCreated(now);
workbasket.setModified(now);
if (workbasket.getId() == null || workbasket.getId().isEmpty()) {
workbasket.setId(IdGenerator.generateWithPrefix(ID_PREFIX_WORKBASKET));
}
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
public Workbasket updateWorkbasket(Workbasket workbasket) throws NotAuthorizedException {
workbasket.setModified(new Timestamp(System.currentTimeMillis()));
workbasketMapper.update(workbasket);
List<String> oldDistributionTargets = distributionTargetMapper.findBySourceId(workbasket.getId());
List<Workbasket> distributionTargets = workbasket.getDistributionTargets();
for (Workbasket distributionTarget : distributionTargets) {
if (!oldDistributionTargets.contains(distributionTarget.getId())) {
if (workbasketMapper.findById(distributionTarget.getId()) == null) {
workbasketMapper.insert(distributionTarget);
LOGGER.debug("Workbasket '{}' created", distributionTarget.getId());
try {
taskanaEngineImpl.openConnection();
workbasket.setModified(new Timestamp(System.currentTimeMillis()));
workbasketMapper.update(workbasket);
List<String> oldDistributionTargets = distributionTargetMapper.findBySourceId(workbasket.getId());
List<Workbasket> distributionTargets = workbasket.getDistributionTargets();
for (Workbasket distributionTarget : distributionTargets) {
if (!oldDistributionTargets.contains(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
public WorkbasketAccessItem createWorkbasketAuthorization(WorkbasketAccessItem workbasketAccessItem) {
workbasketAccessItem.setId(IdGenerator.generateWithPrefix(ID_PREFIX_WORKBASKET_AUTHORIZATION));
workbasketAccessMapper.insert(workbasketAccessItem);
return workbasketAccessItem;
try {
taskanaEngineImpl.openConnection();
workbasketAccessItem.setId(IdGenerator.generateWithPrefix(ID_PREFIX_WORKBASKET_AUTHORIZATION));
workbasketAccessMapper.insert(workbasketAccessItem);
return workbasketAccessItem;
} finally {
taskanaEngineImpl.returnConnection();
}
}
@Override
public WorkbasketAccessItem getWorkbasketAuthorization(String id) {
return workbasketAccessMapper.findById(id);
try {
taskanaEngineImpl.openConnection();
return workbasketAccessMapper.findById(id);
} finally {
taskanaEngineImpl.returnConnection();
}
}
@Override
public void deleteWorkbasketAuthorization(String id) {
workbasketAccessMapper.delete(id);
try {
taskanaEngineImpl.openConnection();
workbasketAccessMapper.delete(id);
} finally {
taskanaEngineImpl.returnConnection();
}
}
@Override
public List<WorkbasketAccessItem> getAllAuthorizations() {
return workbasketAccessMapper.findAll();
try {
taskanaEngineImpl.openConnection();
return workbasketAccessMapper.findAll();
} finally {
taskanaEngineImpl.returnConnection();
}
}
@Override
public void checkAuthorization(String workbasketId, WorkbasketAuthorization workbasketAuthorization)
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 is security is not enabled
if (!taskanaEngine.getConfiguration().isSecurityEnabled()) {
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);
String userId = CurrentUserContext.getUserid();
LOGGER.debug("Verifying that {} has the permission {} on workbasket {}", userId, workbasketAuthorization.name(),
workbasketId);
List<WorkbasketAccessItem> accessItems = workbasketAccessMapper
.findByWorkbasketAndAccessIdAndAuthorizations(workbasketId, accessIds, workbasketAuthorization.name());
List<WorkbasketAccessItem> accessItems = workbasketAccessMapper
.findByWorkbasketAndUserAndAuthorization(workbasketId, userId, workbasketAuthorization.name());
if (accessItems.size() <= 0) {
throw new NotAuthorizedException("Not authorized. Authorization '" + workbasketAuthorization.name()
+ "' on workbasket '" + workbasketId + "' is needed.");
if (accessItems.size() <= 0) {
throw new NotAuthorizedException("Not authorized. Authorization '" + workbasketAuthorization.name()
+ "' on workbasket '" + workbasketId + "' is needed.");
}
} finally {
taskanaEngineImpl.returnConnection();
}
}
@Override
public WorkbasketAccessItem updateWorkbasketAuthorization(WorkbasketAccessItem workbasketAccessItem) {
workbasketAccessMapper.update(workbasketAccessItem);
return workbasketAccessItem;
try {
taskanaEngineImpl.openConnection();
workbasketAccessMapper.update(workbasketAccessItem);
return workbasketAccessItem;
} finally {
taskanaEngineImpl.returnConnection();
}
}
@Override
public List<WorkbasketAccessItem> getWorkbasketAuthorizations(String workbasketId) {
return workbasketAccessMapper.findByWorkbasketId(workbasketId);
try {
taskanaEngineImpl.openConnection();
return workbasketAccessMapper.findByWorkbasketId(workbasketId);
} finally {
taskanaEngineImpl.returnConnection();
}
}
}

View File

@ -7,13 +7,21 @@ public class WorkbasketAccessItem {
private String id;
private String workbasketId;
private String userId;
private String groupId;
private boolean read;
private boolean open;
private boolean append;
private boolean transfer;
private boolean distribute;
private String accessId;
private boolean permRead;
private boolean permOpen;
private boolean permAppend;
private boolean permTransfer;
private boolean permDistribute;
private boolean permCustom1;
private boolean permCustom2;
private boolean permCustom3;
private boolean permCustom4;
private boolean permCustom5;
private boolean permCustom6;
private boolean permCustom7;
private boolean permCustom8;
public String getId() {
return id;
@ -31,59 +39,115 @@ public class WorkbasketAccessItem {
this.workbasketId = workbasketId;
}
public String getUserId() {
return userId;
public String getAccessId() {
return accessId;
}
public void setUserId(String userId) {
this.userId = userId;
public void setAccessId(String accessId) {
this.accessId = accessId;
}
public String getGroupId() {
return groupId;
public boolean isPermRead() {
return permRead;
}
public void setGroupId(String groupId) {
this.groupId = groupId;
public void setPermRead(boolean permRead) {
this.permRead = permRead;
}
public boolean isRead() {
return read;
public boolean isPermOpen() {
return permOpen;
}
public void setRead(boolean read) {
this.read = read;
public void setPermOpen(boolean permOpen) {
this.permOpen = permOpen;
}
public boolean isOpen() {
return open;
public boolean isPermAppend() {
return permAppend;
}
public void setOpen(boolean open) {
this.open = open;
public void setPermAppend(boolean permAppend) {
this.permAppend = permAppend;
}
public boolean isAppend() {
return append;
public boolean isPermTransfer() {
return permTransfer;
}
public void setAppend(boolean append) {
this.append = append;
public void setPermTransfer(boolean permTransfer) {
this.permTransfer = permTransfer;
}
public boolean isTransfer() {
return transfer;
public boolean isPermDistribute() {
return permDistribute;
}
public void setTransfer(boolean transfer) {
this.transfer = transfer;
public void setPermDistribute(boolean permDistribute) {
this.permDistribute = permDistribute;
}
public boolean isDistribute() {
return distribute;
public boolean isPermCustom1() {
return permCustom1;
}
public void setDistribute(boolean distribute) {
this.distribute = distribute;
public void setPermCustom1(boolean permCustom1) {
this.permCustom1 = permCustom1;
}
public boolean isPermCustom2() {
return permCustom2;
}
public void setPermCustom2(boolean permCustom2) {
this.permCustom2 = permCustom2;
}
public boolean isPermCustom3() {
return permCustom3;
}
public void setPermCustom3(boolean permCustom3) {
this.permCustom3 = permCustom3;
}
public boolean isPermCustom4() {
return permCustom4;
}
public void setPermCustom4(boolean permCustom4) {
this.permCustom4 = permCustom4;
}
public boolean isPermCustom5() {
return permCustom5;
}
public void setPermCustom5(boolean permCustom5) {
this.permCustom5 = permCustom5;
}
public boolean isPermCustom6() {
return permCustom6;
}
public void setPermCustom6(boolean permCustom6) {
this.permCustom6 = permCustom6;
}
public boolean isPermCustom7() {
return permCustom7;
}
public void setPermCustom7(boolean permCustom7) {
this.permCustom7 = permCustom7;
}
public boolean isPermCustom8() {
return permCustom8;
}
public void setPermCustom8(boolean permCustom8) {
this.permCustom8 = permCustom8;
}
}

View File

@ -4,9 +4,10 @@ import org.apache.ibatis.annotations.One;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import pro.taskana.impl.persistence.ClassificationQueryImpl;
import pro.taskana.impl.persistence.ObjectReferenceQueryImpl;
import pro.taskana.impl.persistence.TaskQueryImpl;
import pro.taskana.impl.ClassificationQueryImpl;
import pro.taskana.impl.ObjectReferenceQueryImpl;
import pro.taskana.impl.TaskQueryImpl;
import pro.taskana.model.Classification;
import pro.taskana.model.ObjectReference;
import pro.taskana.model.Task;
@ -91,7 +92,7 @@ public interface QueryMapper {
@Result(property = "custom10", column = "CUSTOM_10") })
List<Task> queryTasks(TaskQueryImpl taskQuery);
@Select("<script>SELECT ID, PARENT_CLASSIFICATION_ID, CATEGORY, TYPE, CREATED, NAME, DESCRIPTION, PRIORITY, SERVICE_LEVEL "
@Select("<script>SELECT ID, PARENT_CLASSIFICATION_ID, CATEGORY, TYPE, DOMAIN, VALID_IN_DOMAIN, CREATED, NAME, DESCRIPTION, PRIORITY, SERVICE_LEVEL, CUSTOM_1, CUSTOM_2, CUSTOM_3, CUSTOM_4, CUSTOM_5, CUSTOM_6, CUSTOM_7, CUSTOM_8, VALID_FROM, VALID_UNTIL "
+ "FROM CLASSIFICATION "
+ "<where>"
+ "<if test='parentClassificationId != null'>AND PARENT_CLASSIFICATION_ID IN(<foreach item='item' collection='parentClassificationId' separator=',' >#{item}</foreach>)</if> "

View File

@ -1,116 +1,132 @@
package pro.taskana.model.mappings;
import java.util.List;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.annotations.*;
import pro.taskana.model.WorkbasketAccessItem;
import java.util.List;
/**
* This class is the mybatis mapping of workbasket access items.
*/
public interface WorkbasketAccessMapper {
@Select("SELECT ID, WORKBASKET_ID, USER_ID, GROUP_ID, READ, OPEN, APPEND, TRANSFER, DISTRIBUTE FROM WORKBASKET_ACCESS_LIST WHERE ID = #{id}")
@Select("SELECT ID, WORKBASKET_ID, ACCESS_ID, PERM_READ, PERM_OPEN, PERM_APPEND, PERM_TRANSFER, PERM_DISTRIBUTE, PERM_CUSTOM_1, PERM_CUSTOM_2, PERM_CUSTOM_3, PERM_CUSTOM_4, PERM_CUSTOM_5, PERM_CUSTOM_6, PERM_CUSTOM_7, PERM_CUSTOM_8 FROM WORKBASKET_ACCESS_LIST WHERE ID = #{id}")
@Results(value = {
@Result(property = "id", column = "ID"),
@Result(property = "workbasketId", column = "WORKBASKET_ID"),
@Result(property = "userId", column = "USER_ID"),
@Result(property = "groupId", column = "GROUP_ID"),
@Result(property = "read", column = "READ"),
@Result(property = "open", column = "OPEN"),
@Result(property = "append", column = "APPEND"),
@Result(property = "transfer", column = "TRANSFER"),
@Result(property = "distribute", column = "DISTRIBUTE") })
@Result(property = "accessId", column = "ACCESS_ID"),
@Result(property = "permRead", column = "PERM_READ"),
@Result(property = "permOpen", column = "PERM_OPEN"),
@Result(property = "permAppend", column = "PERM_APPEND"),
@Result(property = "permTransfer", column = "PERM_TRANSFER"),
@Result(property = "permDistribute", column = "PERM_DISTRIBUTE"),
@Result(property = "permCustom1", column = "PERM_CUSTOM_1"),
@Result(property = "permCustom2", column = "PERM_CUSTOM_2"),
@Result(property = "permCustom3", column = "PERM_CUSTOM_3"),
@Result(property = "permCustom4", column = "PERM_CUSTOM_4"),
@Result(property = "permCustom5", column = "PERM_CUSTOM_5"),
@Result(property = "permCustom6", column = "PERM_CUSTOM_6"),
@Result(property = "permCustom7", column = "PERM_CUSTOM_7"),
@Result(property = "permCustom8", column = "PERM_CUSTOM_8")})
WorkbasketAccessItem findById(@Param("id") String id);
@Select("SELECT ID, WORKBASKET_ID, USER_ID, GROUP_ID, READ, OPEN, APPEND, TRANSFER, DISTRIBUTE FROM WORKBASKET_ACCESS_LIST WHERE USER_ID = #{userId}")
@Select("SELECT ID, WORKBASKET_ID, ACCESS_ID, PERM_READ, PERM_OPEN, PERM_APPEND, PERM_TRANSFER, PERM_DISTRIBUTE, PERM_CUSTOM_1, PERM_CUSTOM_2, PERM_CUSTOM_3, PERM_CUSTOM_4, PERM_CUSTOM_5, PERM_CUSTOM_6, PERM_CUSTOM_7, PERM_CUSTOM_8 FROM WORKBASKET_ACCESS_LIST WHERE ACCESS_ID = #{accessId}")
@Results(value = {
@Result(property = "id", column = "ID"),
@Result(property = "workbasketId", column = "WORKBASKET_ID"),
@Result(property = "userId", column = "USER_ID"),
@Result(property = "groupId", column = "GROUP_ID"),
@Result(property = "read", column = "READ"),
@Result(property = "open", column = "OPEN"),
@Result(property = "append", column = "APPEND"),
@Result(property = "transfer", column = "TRANSFER"),
@Result(property = "distribute", column = "DISTRIBUTE") })
List<WorkbasketAccessItem> findByUserId(@Param("userId") String userId);
@Result(property = "accessId", column = "ACCESS_ID"),
@Result(property = "permRead", column = "PERM_READ"),
@Result(property = "permOpen", column = "PERM_OPEN"),
@Result(property = "permAppend", column = "PERM_APPEND"),
@Result(property = "permTransfer", column = "PERM_TRANSFER"),
@Result(property = "permDistribute", column = "PERM_DISTRIBUTE"),
@Result(property = "permCustom1", column = "PERM_CUSTOM_1"),
@Result(property = "permCustom2", column = "PERM_CUSTOM_2"),
@Result(property = "permCustom3", column = "PERM_CUSTOM_3"),
@Result(property = "permCustom4", column = "PERM_CUSTOM_4"),
@Result(property = "permCustom5", column = "PERM_CUSTOM_5"),
@Result(property = "permCustom6", column = "PERM_CUSTOM_6"),
@Result(property = "permCustom7", column = "PERM_CUSTOM_7"),
@Result(property = "permCustom8", column = "PERM_CUSTOM_8")})
List<WorkbasketAccessItem> findByAccessId(@Param("accessId") String accessId);
@Select("SELECT ID, WORKBASKET_ID, USER_ID, GROUP_ID, READ, OPEN, APPEND, TRANSFER, DISTRIBUTE FROM WORKBASKET_ACCESS_LIST WHERE WORKBASKET_ID = #{id}")
@Select("SELECT ID, WORKBASKET_ID, ACCESS_ID, PERM_READ, PERM_OPEN, PERM_APPEND, PERM_TRANSFER, PERM_DISTRIBUTE, PERM_CUSTOM_1, PERM_CUSTOM_2, PERM_CUSTOM_3, PERM_CUSTOM_4, PERM_CUSTOM_5, PERM_CUSTOM_6, PERM_CUSTOM_7, PERM_CUSTOM_8 FROM WORKBASKET_ACCESS_LIST WHERE WORKBASKET_ID = #{id}")
@Results(value = {
@Result(property = "id", column = "ID"),
@Result(property = "workbasketId", column = "WORKBASKET_ID"),
@Result(property = "userId", column = "USER_ID"),
@Result(property = "groupId", column = "GROUP_ID"),
@Result(property = "read", column = "READ"),
@Result(property = "open", column = "OPEN"),
@Result(property = "append", column = "APPEND"),
@Result(property = "transfer", column = "TRANSFER"),
@Result(property = "distribute", column = "DISTRIBUTE") })
@Result(property = "accessId", column = "ACCESS_ID"),
@Result(property = "permRead", column = "PERM_READ"),
@Result(property = "permOpen", column = "PERM_OPEN"),
@Result(property = "permAppend", column = "PERM_APPEND"),
@Result(property = "permTransfer", column = "PERM_TRANSFER"),
@Result(property = "permDistribute", column = "PERM_DISTRIBUTE"),
@Result(property = "permCustom1", column = "PERM_CUSTOM_1"),
@Result(property = "permCustom2", column = "PERM_CUSTOM_2"),
@Result(property = "permCustom3", column = "PERM_CUSTOM_3"),
@Result(property = "permCustom4", column = "PERM_CUSTOM_4"),
@Result(property = "permCustom5", column = "PERM_CUSTOM_5"),
@Result(property = "permCustom6", column = "PERM_CUSTOM_6"),
@Result(property = "permCustom7", column = "PERM_CUSTOM_7"),
@Result(property = "permCustom8", column = "PERM_CUSTOM_8")})
List<WorkbasketAccessItem> findByWorkbasketId(@Param("id") String id);
@Select("SELECT ID, WORKBASKET_ID, USER_ID, GROUP_ID, READ, OPEN, APPEND, TRANSFER, DISTRIBUTE FROM WORKBASKET_ACCESS_LIST ORDER BY ID")
@Select("SELECT ID, WORKBASKET_ID, ACCESS_ID, PERM_READ, PERM_OPEN, PERM_APPEND, PERM_TRANSFER, PERM_DISTRIBUTE, PERM_CUSTOM_1, PERM_CUSTOM_2, PERM_CUSTOM_3, PERM_CUSTOM_4, PERM_CUSTOM_5, PERM_CUSTOM_6, PERM_CUSTOM_7, PERM_CUSTOM_8 FROM WORKBASKET_ACCESS_LIST ORDER BY ID")
@Results(value = {
@Result(property = "id", column = "ID"),
@Result(property = "workbasketId", column = "WORKBASKET_ID"),
@Result(property = "userId", column = "USER_ID"),
@Result(property = "groupId", column = "GROUP_ID"),
@Result(property = "read", column = "READ"),
@Result(property = "open", column = "OPEN"),
@Result(property = "append", column = "APPEND"),
@Result(property = "transfer", column = "TRANSFER"),
@Result(property = "distribute", column = "DISTRIBUTE") })
@Result(property = "accessId", column = "ACCESS_ID"),
@Result(property = "permRead", column = "PERM_READ"),
@Result(property = "permOpen", column = "PERM_OPEN"),
@Result(property = "permAppend", column = "PERM_APPEND"),
@Result(property = "permTransfer", column = "PERM_TRANSFER"),
@Result(property = "permDistribute", column = "PERM_DISTRIBUTE"),
@Result(property = "permCustom1", column = "PERM_CUSTOM_1"),
@Result(property = "permCustom2", column = "PERM_CUSTOM_2"),
@Result(property = "permCustom3", column = "PERM_CUSTOM_3"),
@Result(property = "permCustom4", column = "PERM_CUSTOM_4"),
@Result(property = "permCustom5", column = "PERM_CUSTOM_5"),
@Result(property = "permCustom6", column = "PERM_CUSTOM_6"),
@Result(property = "permCustom7", column = "PERM_CUSTOM_7"),
@Result(property = "permCustom8", column = "PERM_CUSTOM_8")})
List<WorkbasketAccessItem> findAll();
@Insert("INSERT INTO WORKBASKET_ACCESS_LIST (ID, WORKBASKET_ID, USER_ID, GROUP_ID, READ, OPEN, APPEND, TRANSFER, DISTRIBUTE) "
+ "VALUES (#{workbasketAccessItem.id}, #{workbasketAccessItem.workbasketId}, #{workbasketAccessItem.userId}, #{workbasketAccessItem.groupId}, #{workbasketAccessItem.read}, #{workbasketAccessItem.open}, #{workbasketAccessItem.append}, #{workbasketAccessItem.transfer}, #{workbasketAccessItem.distribute})")
@Insert("INSERT INTO WORKBASKET_ACCESS_LIST (ID, WORKBASKET_ID, ACCESS_ID, PERM_READ, PERM_OPEN, PERM_APPEND, PERM_TRANSFER, PERM_DISTRIBUTE, PERM_CUSTOM_1, PERM_CUSTOM_2, PERM_CUSTOM_3, PERM_CUSTOM_4, PERM_CUSTOM_5, PERM_CUSTOM_6, PERM_CUSTOM_7, PERM_CUSTOM_8) "
+ "VALUES (#{workbasketAccessItem.id}, #{workbasketAccessItem.workbasketId}, #{workbasketAccessItem.accessId}, #{workbasketAccessItem.permRead}, #{workbasketAccessItem.permOpen}, #{workbasketAccessItem.permAppend}, #{workbasketAccessItem.permTransfer}, #{workbasketAccessItem.permDistribute}, #{workbasketAccessItem.permCustom1}, #{workbasketAccessItem.permCustom2}, #{workbasketAccessItem.permCustom3}, #{workbasketAccessItem.permCustom4}, #{workbasketAccessItem.permCustom5}, #{workbasketAccessItem.permCustom6}, #{workbasketAccessItem.permCustom7}, #{workbasketAccessItem.permCustom8})")
@Options(keyProperty = "id", keyColumn = "ID")
void insert(@Param("workbasketAccessItem") WorkbasketAccessItem workbasketAccessItem);
@Update("UPDATE WORKBASKET_ACCESS_LIST SET WORKBASKET_ID = #{workbasketAccessItem.workbasketId}, USER_ID = #{workbasketAccessItem.userId}, GROUP_ID = #{workbasketAccessItem.groupId}, READ = #{workbasketAccessItem.read}, OPEN = #{workbasketAccessItem.open}, APPEND = #{workbasketAccessItem.append}, TRANSFER = #{workbasketAccessItem.transfer}, DISTRIBUTE = #{workbasketAccessItem.distribute} "
@Update("UPDATE WORKBASKET_ACCESS_LIST SET WORKBASKET_ID = #{workbasketAccessItem.workbasketId}, ACCESS_ID = #{workbasketAccessItem.accessId}, PERM_READ = #{workbasketAccessItem.permRead}, PERM_OPEN = #{workbasketAccessItem.permOpen}, PERM_APPEND = #{workbasketAccessItem.permAppend}, PERM_TRANSFER = #{workbasketAccessItem.permTransfer}, PERM_DISTRIBUTE = #{workbasketAccessItem.permDistribute}, PERM_CUSTOM_1 = #{workbasketAccessItem.permCustom1}, PERM_CUSTOM_2 = #{workbasketAccessItem.permCustom2}, PERM_CUSTOM_3 = #{workbasketAccessItem.permCustom3}, PERM_CUSTOM_4 = #{workbasketAccessItem.permCustom4}, PERM_CUSTOM_5 = #{workbasketAccessItem.permCustom5}, PERM_CUSTOM_6 = #{workbasketAccessItem.permCustom6}, PERM_CUSTOM_7 = #{workbasketAccessItem.permCustom7}, PERM_CUSTOM_8 = #{workbasketAccessItem.permCustom8} "
+ "WHERE id = #{workbasketAccessItem.id}")
void update(@Param("workbasketAccessItem") WorkbasketAccessItem workbasketAccessItem);
@Delete("DELETE FROM WORKBASKET_ACCESS_LIST where id = #{id}")
void delete(@Param("id") String id);
@Select("<script>SELECT ID, WORKBASKET_ID, USER_ID, GROUP_ID, READ, OPEN, APPEND, TRANSFER, DISTRIBUTE "
@Select("<script>SELECT ID, WORKBASKET_ID, ACCESS_ID, PERM_READ, PERM_OPEN, PERM_APPEND, PERM_TRANSFER, PERM_DISTRIBUTE, PERM_CUSTOM_1, PERM_CUSTOM_2, PERM_CUSTOM_3, PERM_CUSTOM_4, PERM_CUSTOM_5, PERM_CUSTOM_6, PERM_CUSTOM_7, PERM_CUSTOM_8 "
+ "FROM WORKBASKET_ACCESS_LIST "
+ "WHERE WORKBASKET_ID = #{workbasketId} "
+ "AND USER_ID = #{userId} "
+ "AND <if test=\"authorization == 'OPEN'\">OPEN</if>"
+ "<if test=\"authorization == 'READ'\">READ</if>"
+ "<if test=\"authorization == 'APPEND'\">APPEND</if>"
+ "<if test=\"authorization == 'TRANSFER'\">TRANSFER</if>"
+ "<if test=\"authorization == 'DISTRIBUTE'\">DISTRIBUTE</if> = 1</script>")
+ "AND ACCESS_ID IN(<foreach item='item' collection='accessIds' separator=',' >#{item}</foreach>)"
+ "AND <if test=\"authorization == 'OPEN'\">PERM_OPEN</if>"
+ "<if test=\"authorization == 'READ'\">PERM_READ</if>"
+ "<if test=\"authorization == 'APPEND'\">PERM_APPEND</if>"
+ "<if test=\"authorization == 'TRANSFER'\">PERM_TRANSFER</if>"
+ "<if test=\"authorization == 'DISTRIBUTE'\">PERM_DISTRIBUTE</if> = 1</script>")
@Results(value = {
@Result(property = "id", column = "ID"),
@Result(property = "workbasketId", column = "WORKBASKET_ID"),
@Result(property = "userId", column = "USER_ID"),
@Result(property = "groupId", column = "GROUP_ID"),
@Result(property = "read", column = "READ"),
@Result(property = "open", column = "OPEN"),
@Result(property = "append", column = "APPEND"),
@Result(property = "transfer", column = "TRANSFER"),
@Result(property = "distribute", column = "DISTRIBUTE") })
List<WorkbasketAccessItem> findByWorkbasketAndUserAndAuthorization(@Param("workbasketId") String workbasketId, @Param("userId") String userId, @Param("authorization") String authorization);
@Result(property = "accessId", column = "ACCESS_ID"),
@Result(property = "permRead", column = "PERM_READ"),
@Result(property = "permOpen", column = "PERM_OPEN"),
@Result(property = "permAppend", column = "PERM_APPEND"),
@Result(property = "permTransfer", column = "PERM_TRANSFER"),
@Result(property = "permDistribute", column = "PERM_DISTRIBUTE"),
@Result(property = "permCustom1", column = "PERM_CUSTOM_1"),
@Result(property = "permCustom2", column = "PERM_CUSTOM_2"),
@Result(property = "permCustom3", column = "PERM_CUSTOM_3"),
@Result(property = "permCustom4", column = "PERM_CUSTOM_4"),
@Result(property = "permCustom5", column = "PERM_CUSTOM_5"),
@Result(property = "permCustom6", column = "PERM_CUSTOM_6"),
@Result(property = "permCustom7", column = "PERM_CUSTOM_7"),
@Result(property = "permCustom8", column = "PERM_CUSTOM_8")})
List<WorkbasketAccessItem> findByWorkbasketAndAccessIdAndAuthorizations(@Param("workbasketId") String workbasketId, @Param("accessIds") List<String> accessIds, @Param("authorization") String authorization);
@Select("SELECT ID, WORKBASKET_ID, USER_ID, GROUP_ID, READ, OPEN, APPEND, TRANSFER, DISTRIBUTE FROM WORKBASKET_ACCESS_LIST WHERE WORKBASKET_ID = #{workbasketId} AND GROUP_ID = #{groupId}")
@Results(value = {
@Result(property = "id", column = "ID"),
@Result(property = "workbasketId", column = "WORKBASKET_ID"),
@Result(property = "userId", column = "USER_ID"),
@Result(property = "groupId", column = "GROUP_ID"),
@Result(property = "read", column = "READ"),
@Result(property = "open", column = "OPEN"),
@Result(property = "append", column = "APPEND"),
@Result(property = "transfer", column = "TRANSFER"),
@Result(property = "distribute", column = "DISTRIBUTE") })
List<WorkbasketAccessItem> findByWorkbasketAndGroup(@Param("workbasketId") String workbasketId, @Param("groupId") String groupId);
}

View File

@ -1,19 +1,11 @@
package pro.taskana.model.mappings;
import java.util.List;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Many;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;
import pro.taskana.model.Workbasket;
import pro.taskana.model.WorkbasketAuthorization;
import java.util.List;
/**
* This class is the mybatis mapping of workbaskets.
*/
@ -52,7 +44,7 @@ public interface WorkbasketMapper {
List<Workbasket> findAll();
@Select("<script>SELECT W.ID, W.CREATED, W.MODIFIED, W.NAME, W.DESCRIPTION, W.OWNER FROM WORKBASKET AS W "
+ "INNER JOIN WORKBASKET_ACCESS_LIST AS ACL " + "ON (W.ID = ACL.WORKBASKET_ID AND USER_ID = #{userId}) "
+ "INNER JOIN WORKBASKET_ACCESS_LIST AS ACL " + "ON (W.ID = ACL.WORKBASKET_ID AND ACL.ACCESS_ID = #{accessId}) "
+ "WHERE <foreach collection='authorizations' item='authorization' separator=' AND '>"
+ "<if test=\"authorization.name() == 'OPEN'\">OPEN</if>"
+ "<if test=\"authorization.name() == 'READ'\">READ</if>"
@ -68,7 +60,7 @@ public interface WorkbasketMapper {
@Result(property = "description", column = "DESCRIPTION"),
@Result(property = "owner", column = "OWNER"),
@Result(property = "distributionTargets", column = "ID", javaType = List.class, many = @Many(fetchType = FetchType.DEFAULT, select = "findByDistributionTargets")) })
List<Workbasket> findByPermission(@Param("authorizations") List<WorkbasketAuthorization> authorizations, @Param("userId") String userId);
List<Workbasket> findByPermission(@Param("authorizations") List<WorkbasketAuthorization> authorizations, @Param("accessId") String accessId);
@Insert("INSERT INTO WORKBASKET (ID, CREATED, MODIFIED, NAME, DESCRIPTION, OWNER) VALUES (#{workbasket.id}, #{workbasket.created}, #{workbasket.modified}, #{workbasket.name}, #{workbasket.description}, #{workbasket.owner})")
@Options(keyProperty = "id", keyColumn = "ID")

View File

@ -1,15 +1,15 @@
package pro.taskana.security;
import java.lang.reflect.Method;
import java.security.AccessController;
import java.util.List;
import java.util.Set;
import javax.security.auth.Subject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.security.auth.Subject;
import java.lang.reflect.Method;
import java.security.AccessController;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
/**
* Provides the context information about the current (calling) user. The
* context is gathered from the JAAS subject.
@ -105,4 +105,15 @@ public final class CurrentUserContext {
return null;
}
public static List<String> getAccessIds() {
List<String> accessIds = new ArrayList<>();
accessIds.add(getUserid());
if (getGroupIds() != null) {
accessIds.addAll(getGroupIds());
}
if (accessIds.isEmpty()) {
return null;
}
return accessIds;
}
}

View File

@ -81,13 +81,20 @@ CREATE TABLE CLASSIFICATION(
CREATE TABLE WORKBASKET_ACCESS_LIST(
ID CHAR(40) NOT NULL,
WORKBASKET_ID CHAR(40) NOT NULL,
USER_ID VARCHAR(255) NULL,
GROUP_ID VARCHAR(255) NULL,
READ BOOLEAN NOT NULL,
OPEN BOOLEAN NOT NULL,
APPEND BOOLEAN NOT NULL,
TRANSFER BOOLEAN NOT NULL,
DISTRIBUTE BOOLEAN NOT NULL,
ACCESS_ID VARCHAR(255) NULL,
PERM_READ BOOLEAN NOT NULL,
PERM_OPEN BOOLEAN NOT NULL,
PERM_APPEND BOOLEAN NOT NULL,
PERM_TRANSFER BOOLEAN NOT NULL,
PERM_DISTRIBUTE BOOLEAN NOT NULL,
PERM_CUSTOM_1 BOOLEAN NOT NULL,
PERM_CUSTOM_2 BOOLEAN NOT NULL,
PERM_CUSTOM_3 BOOLEAN NOT NULL,
PERM_CUSTOM_4 BOOLEAN NOT NULL,
PERM_CUSTOM_5 BOOLEAN NOT NULL,
PERM_CUSTOM_6 BOOLEAN NOT NULL,
PERM_CUSTOM_7 BOOLEAN NOT NULL,
PERM_CUSTOM_8 BOOLEAN NOT NULL,
PRIMARY KEY (ID)
);

View File

@ -1,4 +1,4 @@
package pro.taskana.impl.persistence;
package pro.taskana.impl;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.when;
@ -13,8 +13,8 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import pro.taskana.exceptions.NotAuthorizedException;
import pro.taskana.impl.TaskanaEngineImpl;
import pro.taskana.model.Classification;
/**
@ -39,7 +39,7 @@ public class ClassificationQueryImplTest {
@Test
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<>());
List<Classification> result = classificationQueryImpl.name("test", "asd", "blubber").type("cool", "bla").priority(1, 2)
@ -49,7 +49,7 @@ public class ClassificationQueryImplTest {
@Test
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<>());
List<Classification> result = classificationQueryImpl.name("test", "asd", "blubber").type("cool", "bla").priority(1, 2)
@ -59,7 +59,7 @@ public class ClassificationQueryImplTest {
@Test
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());
Classification result = classificationQueryImpl.name("test", "asd", "blubber").type("cool", "bla").priority(1, 2)

View File

@ -22,7 +22,6 @@ import org.mockito.Spy;
import org.mockito.junit.MockitoJUnitRunner;
import pro.taskana.exceptions.NotAuthorizedException;
import pro.taskana.impl.persistence.TestClassificationQuery;
import pro.taskana.model.Classification;
import pro.taskana.model.mappings.ClassificationMapper;
@ -40,6 +39,9 @@ public class ClassificationServiceImplTest {
@Mock
ClassificationMapper classificationMapper;
@Mock
TaskanaEngineImpl taskanaEngineImpl;
@Test
public void testAddClassification() {
doNothing().when(classificationMapper).insert(any());
@ -57,6 +59,8 @@ public class ClassificationServiceImplTest {
public void testModifiedClassification() {
doNothing().when(classificationMapper).insert(any());
doNothing().when(classificationMapper).update(any());
doNothing().when(taskanaEngineImpl).openConnection();
doNothing().when(taskanaEngineImpl).returnConnection();
int insert = 0;
@ -91,6 +95,8 @@ public class ClassificationServiceImplTest {
@Test
public void testFindAllClassifications() throws NotAuthorizedException {
doNothing().when(classificationMapper).insert(any());
doNothing().when(taskanaEngineImpl).openConnection();
doNothing().when(taskanaEngineImpl).returnConnection();
// insert Classifications
Classification classification0 = new Classification();
@ -123,7 +129,8 @@ public class ClassificationServiceImplTest {
@Test
public void testClassificationQuery() throws NotAuthorizedException {
doNothing().when(classificationMapper).insert(any());
doNothing().when(taskanaEngineImpl).openConnection();
doNothing().when(taskanaEngineImpl).returnConnection();
Classification classification = new Classification();
classification.setDescription("DESC");
classificationService.addClassification(classification);

View File

@ -1,4 +1,4 @@
package pro.taskana.impl.persistence;
package pro.taskana.impl;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.when;
@ -13,8 +13,8 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import pro.taskana.exceptions.NotAuthorizedException;
import pro.taskana.impl.TaskanaEngineImpl;
import pro.taskana.model.ObjectReference;
/**
@ -39,7 +39,7 @@ public class ObjectReferenceQueryImplTest {
@Test
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<>());
List<ObjectReference> result = objectReferenceQueryImpl.value("test", "asd", "blubber").type("cool", "bla")
@ -49,7 +49,7 @@ public class ObjectReferenceQueryImplTest {
@Test
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<>());
List<ObjectReference> result = objectReferenceQueryImpl.value("test", "asd", "blubber").type("cool", "bla")
@ -59,7 +59,7 @@ public class ObjectReferenceQueryImplTest {
@Test
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());
ObjectReference result = objectReferenceQueryImpl.value("test", "asd", "blubber").type("cool", "bla")

View File

@ -1,4 +1,4 @@
package pro.taskana.impl.persistence;
package pro.taskana.impl;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.when;
@ -13,8 +13,8 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import pro.taskana.exceptions.NotAuthorizedException;
import pro.taskana.impl.TaskanaEngineImpl;
import pro.taskana.model.Task;
import pro.taskana.model.TaskState;
@ -40,7 +40,7 @@ public class TaskQueryImplTest {
@Test
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<>());
List<Task> result = taskQueryImpl.name("test", "asd", "blubber").customFields("cool", "bla").priority(1, 2)
@ -50,7 +50,7 @@ public class TaskQueryImplTest {
@Test
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<>());
List<Task> result = taskQueryImpl.name("test", "asd", "blubber").customFields("cool", "bla").priority(1, 2)
@ -60,7 +60,7 @@ public class TaskQueryImplTest {
@Test
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());
Task result = taskQueryImpl.name("test", "asd", "blubber").customFields("cool", "bla").priority(1, 2)

View File

@ -6,13 +6,16 @@ import static org.mockito.ArgumentMatchers.eq;
import java.sql.Timestamp;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import org.mockito.junit.MockitoJUnitRunner;
import pro.taskana.TaskanaEngine;
import pro.taskana.WorkbasketService;
import pro.taskana.configuration.TaskanaEngineConfiguration;
import pro.taskana.exceptions.NotAuthorizedException;
import pro.taskana.exceptions.TaskNotFoundException;
@ -32,25 +35,39 @@ import pro.taskana.model.mappings.TaskMapper;
public class TaskServiceImplTest {
private static final int SLEEP_TIME = 100;
@Mock
TaskanaEngineConfiguration taskanaEngineConfiguration;
@InjectMocks
TaskServiceImpl taskServiceImpl;
@Mock
TaskanaEngine taskanaEngine;
TaskanaEngineImpl taskanaEngine;
@Mock
TaskanaEngineConfiguration taskanaEngineConfiguration;
@Mock
WorkbasketServiceImpl workbasketServiceImpl;
TaskanaEngineImpl taskanaEngineImpl;
@Mock
TaskMapper taskMapper;
@Mock
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
public void testCreateSimpleTask() throws NotAuthorizedException {
registerBasicMocks(false);
Mockito.doNothing().when(workbasketServiceImpl).checkAuthorization(any(), any());
Mockito.doNothing().when(taskMapper).insert(any());
Task task = new Task();
task.setName("Unit Test Task");
task.setWorkbasketId("1");
@ -101,13 +118,17 @@ public class TaskServiceImplTest {
@Test
public void testTransferTaskZuDestinationWorkbasket()
throws TaskNotFoundException, WorkbasketNotFoundException, NotAuthorizedException {
registerBasicMocks(false);
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.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");
taskServiceImpl.transfer(task.getId(), "2");
Assert.assertEquals(taskServiceImpl.getTaskById(task.getId()).getWorkbasketId(), "2");
@ -119,8 +140,7 @@ public class TaskServiceImplTest {
@Test(expected = WorkbasketNotFoundException.class)
public void testTransferFailsIfDestinationWorkbasketDoesNotExist_withSecurityDisabled()
throws TaskNotFoundException, WorkbasketNotFoundException, NotAuthorizedException {
registerBasicMocks(false);
Mockito.doThrow(WorkbasketNotFoundException.class).when(workbasketServiceImpl)
Mockito.doThrow(WorkbasketNotFoundException.class).when(workbasketService)
.checkAuthorization(eq("invalidWorkbasketId"), any());
Task task = createUnitTestTask("1", "Unit Test Task 1", "1");
@ -132,9 +152,7 @@ public class TaskServiceImplTest {
@Test(expected = WorkbasketNotFoundException.class)
public void testTransferFailsIfDestinationWorkbasketDoesNotExist_withSecurityEnabled()
throws TaskNotFoundException, WorkbasketNotFoundException, NotAuthorizedException {
registerBasicMocks(true);
Mockito.doThrow(WorkbasketNotFoundException.class).when(workbasketServiceImpl)
.checkAuthorization(eq("invalidWorkbasketId"), any());
Mockito.doThrow(WorkbasketNotFoundException.class).when(workbasketService).checkAuthorization(eq("invalidWorkbasketId"), any());
Task task = createUnitTestTask("1", "Unit Test Task 1", "1");
@ -152,8 +170,6 @@ public class TaskServiceImplTest {
@Test
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);
Task task = createUnitTestTask("1", "Unit Test Task 1", "1");
@ -169,9 +185,6 @@ public class TaskServiceImplTest {
@Test
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");
ObjectReference primaryObjRef = new ObjectReference();
primaryObjRef.setSystem("Sol");
@ -208,10 +221,4 @@ public class TaskServiceImplTest {
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);
}
}

View File

@ -1,4 +1,4 @@
package pro.taskana.impl.persistence;
package pro.taskana.impl;
import pro.taskana.exceptions.NotAuthorizedException;
import pro.taskana.model.Classification;

View File

@ -1,21 +1,15 @@
package pro.taskana.impl;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import java.util.ArrayList;
import java.util.List;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.mockito.junit.MockitoJUnitRunner;
import pro.taskana.TaskanaEngine;
import pro.taskana.configuration.TaskanaEngineConfiguration;
import pro.taskana.exceptions.NotAuthorizedException;
import pro.taskana.exceptions.WorkbasketNotFoundException;
@ -26,6 +20,12 @@ import pro.taskana.model.mappings.DistributionTargetMapper;
import pro.taskana.model.mappings.WorkbasketAccessMapper;
import pro.taskana.model.mappings.WorkbasketMapper;
import java.util.ArrayList;
import java.util.List;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.*;
/**
* Unit Test for workbasketServiceImpl.
* @author EH
@ -47,10 +47,16 @@ public class WorkbasketServiceImplTest {
@Mock
WorkbasketAccessMapper workbasketAccessMapper;
@Mock
TaskanaEngine taskanaEngine;
TaskanaEngineImpl taskanaEngine;
@Mock
TaskanaEngineImpl taskanaEngineImpl;
@Mock
TaskanaEngineConfiguration taskanaEngineConfiguration;
@Before
public void setup() {
MockitoAnnotations.initMocks(this);
}
@Test
public void should_ReturnWorkbasket_when_WorkbasketIdExists() throws WorkbasketNotFoundException {
when(workbasketMapper.findById(any())).thenReturn(new Workbasket());
@ -226,9 +232,9 @@ public class WorkbasketServiceImplTest {
WorkbasketAccessItem accessItem = new WorkbasketAccessItem();
accessItem.setWorkbasketId("1");
accessItem.setUserId("Arthur Dent");
accessItem.setOpen(true);
accessItem.setRead(true);
accessItem.setAccessId("Arthur Dent");
accessItem.setPermOpen(true);
accessItem.setPermRead(true);
accessItem = workbasketServiceImpl.createWorkbasketAuthorization(accessItem);
Assert.assertNotNull(accessItem.getId());
@ -241,18 +247,18 @@ public class WorkbasketServiceImplTest {
WorkbasketAccessItem accessItem = new WorkbasketAccessItem();
accessItem.setWorkbasketId("1");
accessItem.setUserId("Arthur Dent");
accessItem.setOpen(true);
accessItem.setRead(true);
accessItem.setAccessId("Arthur Dent");
accessItem.setPermOpen(true);
accessItem.setPermRead(true);
accessItem = workbasketServiceImpl.createWorkbasketAuthorization(accessItem);
Assert.assertNotNull(accessItem.getId());
doNothing().when(workbasketAccessMapper).update(any());
accessItem.setUserId("Zaphod Beeblebrox");
accessItem.setAccessId("Zaphod Beeblebrox");
workbasketServiceImpl.updateWorkbasketAuthorization(accessItem);
Assert.assertEquals("Zaphod Beeblebrox", accessItem.getUserId());
Assert.assertEquals("Zaphod Beeblebrox", accessItem.getAccessId());
}
@Test(expected = NotAuthorizedException.class)
@ -269,7 +275,7 @@ public class WorkbasketServiceImplTest {
when(taskanaEngine.getConfiguration()).thenReturn(taskanaEngineConfiguration);
when(taskanaEngine.getConfiguration().isSecurityEnabled()).thenReturn(true);
when(workbasketAccessMapper.findByWorkbasketAndUserAndAuthorization(any(), any(), any()))
when(workbasketAccessMapper.findByWorkbasketAndAccessIdAndAuthorizations(any(), any(), any()))
.thenReturn(new ArrayList<WorkbasketAccessItem>() {
{
add(new WorkbasketAccessItem());
@ -278,7 +284,7 @@ public class WorkbasketServiceImplTest {
workbasketServiceImpl.checkAuthorization("1", WorkbasketAuthorization.READ);
verify(workbasketAccessMapper, times(1)).findByWorkbasketAndUserAndAuthorization(any(), any(), any());
verify(workbasketAccessMapper, times(1)).findByWorkbasketAndAccessIdAndAuthorizations(any(), any(), any());
}
@Test

View File

@ -3,6 +3,7 @@ package pro.taskana.impl.configuration;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.sql.Connection;
import java.sql.SQLException;
import javax.sql.DataSource;
@ -18,6 +19,7 @@ import pro.taskana.configuration.DbScriptRunner;
public class DBCleaner {
private static final Logger LOGGER = LoggerFactory.getLogger(DbScriptRunner.class);
private static final String DB_CLEAR_SCRIPT = "/sql/clear-db.sql";
private static final String DB_DROP_TABLES_SCRIPT = "/sql/drop-tables.sql";
private StringWriter outWriter = new StringWriter();
private PrintWriter logWriter = new PrintWriter(outWriter);
@ -27,20 +29,26 @@ public class DBCleaner {
/**
* Clears the db.
* @param dropTables if true drop tables, else clean tables
* @throws SQLException
*/
public void clearDb(DataSource dataSource) throws SQLException {
ScriptRunner runner = new ScriptRunner(dataSource.getConnection());
LOGGER.debug(dataSource.getConnection().getMetaData().toString());
public void clearDb(DataSource dataSource, boolean dropTables) throws SQLException {
try (Connection connection = dataSource.getConnection()) {
ScriptRunner runner = new ScriptRunner(connection);
LOGGER.debug(connection.getMetaData().toString());
runner.setStopOnError(true);
runner.setLogWriter(logWriter);
runner.setErrorLogWriter(errorLogWriter);
runner.runScript(new InputStreamReader(this.getClass().getResourceAsStream(DB_CLEAR_SCRIPT)));
runner.closeConnection();
runner.setStopOnError(true);
runner.setLogWriter(logWriter);
runner.setErrorLogWriter(errorLogWriter);
if (dropTables) {
runner.runScript(new InputStreamReader(this.getClass().getResourceAsStream(DB_DROP_TABLES_SCRIPT)));
} else {
runner.runScript(new InputStreamReader(this.getClass().getResourceAsStream(DB_CLEAR_SCRIPT)));
}
} catch (Exception e) {
LOGGER.error("caught Exception " + e);
}
LOGGER.debug(outWriter.toString());
if (!errorWriter.toString().trim().isEmpty()) {
LOGGER.error(errorWriter.toString());

View File

@ -11,12 +11,12 @@ import java.util.Properties;
import javax.security.auth.login.LoginException;
import javax.sql.DataSource;
import org.apache.ibatis.datasource.unpooled.UnpooledDataSource;
import org.h2.jdbcx.JdbcDataSource;
import org.apache.ibatis.datasource.pooled.PooledDataSource;
import org.junit.Assert;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import pro.taskana.TaskanaEngine;
import pro.taskana.configuration.TaskanaEngineConfiguration;
/**
@ -26,6 +26,7 @@ import pro.taskana.configuration.TaskanaEngineConfiguration;
public class TaskanaEngineConfigurationTest {
private static DataSource dataSource = null;
private static final Logger LOGGER = LoggerFactory.getLogger(TaskanaEngineConfigurationTest.class);
private static final int POOL_TIME_TO_WAIT = 50;
@Test
public void testCreateTaskanaEngine() throws FileNotFoundException, SQLException, LoginException {
@ -71,10 +72,20 @@ public class TaskanaEngineConfigurationTest {
* @return
*/
private static DataSource createDefaultDataSource() {
JdbcDataSource ds = new JdbcDataSource();
ds.setURL("jdbc:h2:mem:taskana");
ds.setPassword("sa");
ds.setUser("sa");
// JdbcDataSource ds = new JdbcDataSource();
// ds.setURL("jdbc:h2:mem:taskana");
// ds.setPassword("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;
}
@ -112,8 +123,9 @@ public class TaskanaEngineConfigurationTest {
}
if (propertiesFileIsComplete) {
ds = new UnpooledDataSource(Thread.currentThread().getContextClassLoader(), jdbcDriver,
ds = new PooledDataSource(Thread.currentThread().getContextClassLoader(), jdbcDriver,
jdbcUrl, dbUserName, dbPassword);
((PooledDataSource) ds).forceCloseAll(); // otherwise the MyBatis pool is not initialized correctly
} else {
LOGGER.warn("propertiesFile " + propertiesFileName + " is incomplete" + warningMessage);
LOGGER.warn("Using default Datasource for Test");

View File

@ -10,13 +10,15 @@ 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.BeforeClass;
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;
@ -25,10 +27,10 @@ import pro.taskana.impl.configuration.TaskanaEngineConfigurationTest;
import pro.taskana.model.Classification;
/**
* Integration Test for ClassificationServiceImpl.
* Integration Test for ClassificationServiceImpl with connection management mode AUTOCOMMIT.
* @author EH
*/
public class ClassificationServiceImplIntTest {
public class ClassificationServiceImplIntAutoCommitTest {
static int counter = 0;
private DataSource dataSource;
@ -37,6 +39,12 @@ public class ClassificationServiceImplIntTest {
private TaskanaEngine taskanaEngine;
private TaskanaEngineImpl taskanaEngineImpl;
@BeforeClass
public static void resetDb() throws SQLException {
DataSource ds = TaskanaEngineConfigurationTest.getDataSource();
DBCleaner cleaner = new DBCleaner();
cleaner.clearDb(ds, true);
}
@Before
public void setup() throws FileNotFoundException, SQLException, LoginException {
@ -45,8 +53,9 @@ public class ClassificationServiceImplIntTest {
taskanaEngine = taskanaEngineConfiguration.buildTaskanaEngine();
classificationService = taskanaEngine.getClassificationService();
taskanaEngineImpl = (TaskanaEngineImpl) taskanaEngine;
taskanaEngineImpl.setConnectionManagementMode(ConnectionManagementMode.AUTOCOMMIT);
DBCleaner cleaner = new DBCleaner();
cleaner.clearDb(dataSource);
cleaner.clearDb(dataSource, false);
}
@Test
@ -112,7 +121,7 @@ public class ClassificationServiceImplIntTest {
System.out.println(classification.getParentClassificationId());
List<Classification> allClassifications = classificationService.getClassificationTree();
Assert.assertEquals(2, list.size());
Assert.assertEquals(2, allClassifications.size());
}
@Test
@ -262,11 +271,6 @@ public class ClassificationServiceImplIntTest {
Assert.assertEquals(1, list.size());
}
@After
public void cleanUp() {
taskanaEngineImpl.closeSession();
}
@AfterClass
public static void cleanUpClass() {
FileUtils.deleteRecursive("~/data", true);

View File

@ -0,0 +1,318 @@
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.BeforeClass;
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;
@BeforeClass
public static void resetDb() throws SQLException {
DataSource ds = TaskanaEngineConfigurationTest.getDataSource();
DBCleaner cleaner = new DBCleaner();
cleaner.clearDb(ds, true);
}
@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, false);
}
@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);
}
}

View File

@ -1,34 +1,41 @@
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.junit.*;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.Before;
import org.junit.BeforeClass;
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.ClassificationQueryImpl;
import pro.taskana.impl.ObjectReferenceQueryImpl;
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;
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
*/
public class TaskServiceImplTransactionTest {
public class TaskServiceImplIntAutocommitTest {
private DataSource dataSource;
private TaskServiceImpl taskServiceImpl;
@ -36,6 +43,13 @@ public class TaskServiceImplTransactionTest {
private TaskanaEngine taskanaEngine;
private TaskanaEngineImpl taskanaEngineImpl;
@BeforeClass
public static void resetDb() throws SQLException {
DataSource ds = TaskanaEngineConfigurationTest.getDataSource();
DBCleaner cleaner = new DBCleaner();
cleaner.clearDb(ds, true);
}
@Before
public void setup() throws FileNotFoundException, SQLException, LoginException {
dataSource = TaskanaEngineConfigurationTest.getDataSource();
@ -43,20 +57,20 @@ public class TaskServiceImplTransactionTest {
taskanaEngine = taskanaEngineConfiguration.buildTaskanaEngine();
taskanaEngineImpl = (TaskanaEngineImpl) taskanaEngine;
taskanaEngineImpl.setConnectionManagementMode(ConnectionManagementMode.AUTOCOMMIT);
taskServiceImpl = (TaskServiceImpl) taskanaEngine.getTaskService();
DBCleaner cleaner = new DBCleaner();
cleaner.clearDb(dataSource);
cleaner.clearDb(dataSource, false);
}
@Test
public void testStart() throws FileNotFoundException, SQLException, TaskNotFoundException, NotAuthorizedException {
Task task = new Task();
task.setName("Unit Test Task");
String id1 = IdGenerator.generateWithPrefix("TWB");
task.setWorkbasketId(id1);
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();
TaskServiceImpl taskServiceImpl2 = (TaskServiceImpl) te2.getTaskService();
@ -67,7 +81,6 @@ public class TaskServiceImplTransactionTest {
@Test(expected = TaskNotFoundException.class)
public void testStartTransactionFail()
throws FileNotFoundException, SQLException, TaskNotFoundException, NotAuthorizedException {
Task task = new Task();
task.setName("Unit Test Task");
String id1 = IdGenerator.generateWithPrefix("TWB");
@ -99,7 +112,6 @@ public class TaskServiceImplTransactionTest {
@Test
public void should_ReturnList_when_BuilderIsUsed() throws SQLException, NotAuthorizedException {
Task task = new Task();
task.setName("Unit Test Task");
String id1 = IdGenerator.generateWithPrefix("TWB");
@ -124,11 +136,6 @@ public class TaskServiceImplTransactionTest {
}
@After
public void cleanUp() {
taskanaEngineImpl.closeSession();
}
@AfterClass
public static void cleanUpClass() {
FileUtils.deleteRecursive("~/data", true);

View File

@ -0,0 +1,166 @@
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.BeforeClass;
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.ClassificationQueryImpl;
import pro.taskana.impl.ObjectReferenceQueryImpl;
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.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;
@BeforeClass
public static void resetDb() throws SQLException {
DataSource ds = TaskanaEngineConfigurationTest.getDataSource();
DBCleaner cleaner = new DBCleaner();
cleaner.clearDb(ds, true);
}
@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, false);
}
@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);
connection.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);
}
}

View File

@ -9,12 +9,14 @@ 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.BeforeClass;
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;
@ -28,10 +30,10 @@ import pro.taskana.model.WorkbasketAccessItem;
/**
* Integration Test for workbasketServiceImpl.
* Integration Test for workbasketServiceImpl with connection management mode AUTOCOMMIT.
* @author EH
*/
public class WorkbasketServiceImplIntTest {
public class WorkbasketServiceImplIntAutocommitTest {
private static final int SLEEP_TIME = 100;
private static final int THREE = 3;
@ -44,15 +46,23 @@ public class WorkbasketServiceImplIntTest {
private TaskanaEngineImpl taskanaEngineImpl;
private WorkbasketService workBasketService;
@BeforeClass
public static void resetDb() throws SQLException {
DataSource ds = TaskanaEngineConfigurationTest.getDataSource();
DBCleaner cleaner = new DBCleaner();
cleaner.clearDb(ds, true);
}
@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.AUTOCOMMIT);
workBasketService = taskanaEngine.getWorkbasketService();
DBCleaner cleaner = new DBCleaner();
cleaner.clearDb(dataSource);
cleaner.clearDb(dataSource, false);
}
@Test
@ -181,9 +191,9 @@ public class WorkbasketServiceImplIntTest {
WorkbasketAccessItem accessItem = new WorkbasketAccessItem();
String id1 = IdGenerator.generateWithPrefix("TWB");
accessItem.setWorkbasketId(id1);
accessItem.setUserId("Arthur Dent");
accessItem.setOpen(true);
accessItem.setRead(true);
accessItem.setAccessId("Arthur Dent");
accessItem.setPermOpen(true);
accessItem.setPermRead(true);
workBasketService.createWorkbasketAuthorization(accessItem);
Assert.assertEquals(1, workBasketService.getAllAuthorizations().size());
@ -194,23 +204,18 @@ public class WorkbasketServiceImplIntTest {
WorkbasketAccessItem accessItem = new WorkbasketAccessItem();
String id1 = IdGenerator.generateWithPrefix("TWB");
accessItem.setWorkbasketId(id1);
accessItem.setUserId("Arthur Dent");
accessItem.setOpen(true);
accessItem.setRead(true);
accessItem.setAccessId("Arthur Dent");
accessItem.setPermOpen(true);
accessItem.setPermRead(true);
workBasketService.createWorkbasketAuthorization(accessItem);
Assert.assertEquals(1, workBasketService.getAllAuthorizations().size());
accessItem.setUserId("Zaphod Beeblebrox");
accessItem.setAccessId("Zaphod Beeblebrox");
workBasketService.updateWorkbasketAuthorization(accessItem);
Assert.assertEquals("Zaphod Beeblebrox",
workBasketService.getWorkbasketAuthorization(accessItem.getId()).getUserId());
}
@After
public void cleanUp() {
taskanaEngineImpl.closeSession();
workBasketService.getWorkbasketAuthorization(accessItem.getId()).getAccessId());
}
@AfterClass

View File

@ -0,0 +1,270 @@
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.BeforeClass;
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;
@BeforeClass
public static void resetDb() throws SQLException {
DataSource ds = TaskanaEngineConfigurationTest.getDataSource();
DBCleaner cleaner = new DBCleaner();
cleaner.clearDb(ds, true);
}
@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, false);
}
@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);
}
}

View File

@ -0,0 +1,8 @@
DROP TABLE TASKANA_SCHEMA_VERSION;
DROP TABLE TASK;
DROP TABLE WORKBASKET;
DROP TABLE DISTRIBUTION_TARGETS;
DROP TABLE CLASSIFICATION;
DROP TABLE WORKBASKET_ACCESS_LIST;
DROP TABLE OBJECT_REFERENCE;
COMMIT;

View File

@ -1,3 +1,3 @@
INSERT INTO WORKBASKET_ACCESS_LIST VALUES ('1', '1', 'Elena', null, true, true, true, true, true);
INSERT INTO WORKBASKET_ACCESS_LIST VALUES ('2', '2', 'Max', null, true, true, true, true, true);
INSERT INTO WORKBASKET_ACCESS_LIST VALUES ('3', '3', 'Simone', null, true, true, true, true, true);
INSERT INTO WORKBASKET_ACCESS_LIST VALUES ('1', '1', 'Elena', true, true, true, true, true, false, false, false, false, false, false, false, false);
INSERT INTO WORKBASKET_ACCESS_LIST VALUES ('2', '2', 'Max', true, true, true, true, true, true, true, true, true, false, false, false, false);
INSERT INTO WORKBASKET_ACCESS_LIST VALUES ('3', '3', 'Simone', true, true, true, true, true, true, true, true, true, true, true, true, true);