TSK-171 add sorting to workbasket query
This commit is contained in:
parent
9f86a5ef94
commit
0c5ed430c8
|
@ -3,6 +3,7 @@ package pro.taskana;
|
|||
import java.time.Instant;
|
||||
|
||||
import pro.taskana.exceptions.InvalidArgumentException;
|
||||
import pro.taskana.exceptions.InvalidRequestException;
|
||||
import pro.taskana.model.WorkbasketAuthorization;
|
||||
import pro.taskana.model.WorkbasketType;
|
||||
|
||||
|
@ -151,7 +152,7 @@ public interface WorkbasketQuery extends BaseQuery<WorkbasketSummary> {
|
|||
* @throws InvalidArgumentException
|
||||
* when permission OR the accessIds are NULL.
|
||||
*/
|
||||
WorkbasketQuery accessIdsHavePersmission(WorkbasketAuthorization permission, String... accessIds)
|
||||
WorkbasketQuery accessIdsHavePermission(WorkbasketAuthorization permission, String... accessIds)
|
||||
throws InvalidArgumentException;
|
||||
|
||||
/**
|
||||
|
@ -159,12 +160,52 @@ public interface WorkbasketQuery extends BaseQuery<WorkbasketSummary> {
|
|||
* by default.<br>
|
||||
* The UserContext-AccessIds and the given permission will throw a Exception if they would be NULL.
|
||||
*
|
||||
* @return the current query object.
|
||||
* @param permission
|
||||
* which should be used for results.
|
||||
* @return the current query object.
|
||||
* @throws InvalidArgumentException
|
||||
* when permission OR accessIds of the userContext are NULL.
|
||||
*/
|
||||
WorkbasketQuery callerHasPermission(WorkbasketAuthorization permission) throws InvalidArgumentException;
|
||||
|
||||
/**
|
||||
* Sort the query result by name.
|
||||
*
|
||||
* @return the query
|
||||
* @throws InvalidArgumentException
|
||||
* when orderByName() has already been called.
|
||||
* @throws InvalidRequestException
|
||||
* when orderByName() has already been called.
|
||||
*/
|
||||
WorkbasketQuery orderByName() throws InvalidArgumentException, InvalidRequestException;
|
||||
|
||||
/**
|
||||
* Sort the query result by key.
|
||||
*
|
||||
* @return the query
|
||||
* @throws InvalidRequestException
|
||||
* when orderByKey() has already been called.
|
||||
*/
|
||||
WorkbasketQuery orderByKey() throws InvalidRequestException;
|
||||
|
||||
/**
|
||||
* Sort the query result in ascending order.
|
||||
*
|
||||
* @return the query
|
||||
* @throws InvalidRequestException
|
||||
* when neither orderByKey() nor orderByName has already been called previously or when ascending() or
|
||||
* descending() has been called immediately before this call
|
||||
*/
|
||||
WorkbasketQuery ascending() throws InvalidRequestException;
|
||||
|
||||
/**
|
||||
* Sort the query result in descending order.
|
||||
*
|
||||
* @return the query
|
||||
* @throws InvalidRequestException
|
||||
* when neither orderByKey() nor orderByName has already been called previously or when ascending() or
|
||||
* descending() has been called immediately before this call
|
||||
*/
|
||||
WorkbasketQuery descending() throws InvalidRequestException;
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
package pro.taskana.exceptions;
|
||||
|
||||
/**
|
||||
* This exception is thrown when a method is called in a context where it must not be called.
|
||||
*
|
||||
* @author bbr
|
||||
*/
|
||||
public class InvalidRequestException extends TaskanaException {
|
||||
|
||||
public InvalidRequestException(String msg) {
|
||||
super(msg);
|
||||
}
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
}
|
|
@ -2,7 +2,8 @@ package pro.taskana.impl;
|
|||
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Stack;
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.Deque;
|
||||
|
||||
import org.apache.ibatis.mapping.Environment;
|
||||
import org.apache.ibatis.session.Configuration;
|
||||
|
@ -44,7 +45,7 @@ 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<>();
|
||||
protected static ThreadLocal<Deque<SqlSessionManager>> sessionStack = new ThreadLocal<>();
|
||||
protected TaskanaEngineConfiguration taskanaEngineConfiguration;
|
||||
protected TransactionFactory transactionFactory;
|
||||
protected SqlSessionManager sessionManager;
|
||||
|
@ -222,8 +223,6 @@ public class TaskanaEngineImpl implements TaskanaEngine {
|
|||
String databaseProductName;
|
||||
try (Connection con = taskanaEngineConfiguration.getDatasource().getConnection()) {
|
||||
databaseProductName = con.getMetaData().getDatabaseProductName();
|
||||
databaseProductName = con.getMetaData()
|
||||
.getDatabaseProductName();
|
||||
if (databaseProductName.contains("DB2")) {
|
||||
configuration.setDatabaseId("db2");
|
||||
} else if (databaseProductName.contains("H2")) {
|
||||
|
@ -240,7 +239,7 @@ public class TaskanaEngineImpl implements TaskanaEngine {
|
|||
"Method createSqlSessionManager() could not open a connection to the database. No databaseId has been set.",
|
||||
e);
|
||||
throw new SystemException(
|
||||
"Method createSqlSessionManager() could not open a connection to the database. No databaseId has been set");
|
||||
"Method createSqlSessionManager() could not open a connection to the database. No databaseId has been set.");
|
||||
}
|
||||
|
||||
// add mappers
|
||||
|
@ -283,17 +282,17 @@ public class TaskanaEngineImpl implements TaskanaEngine {
|
|||
*
|
||||
* @return Stack of SqlSessionManager
|
||||
*/
|
||||
protected static Stack<SqlSessionManager> getSessionStack() {
|
||||
Stack<SqlSessionManager> stack = sessionStack.get();
|
||||
protected static Deque<SqlSessionManager> getSessionStack() {
|
||||
Deque<SqlSessionManager> stack = sessionStack.get();
|
||||
if (stack == null) {
|
||||
stack = new Stack<>();
|
||||
stack = new ArrayDeque<>();
|
||||
sessionStack.set(stack);
|
||||
}
|
||||
return stack;
|
||||
}
|
||||
|
||||
protected static SqlSessionManager getSessionFromStack() {
|
||||
Stack<SqlSessionManager> stack = getSessionStack();
|
||||
Deque<SqlSessionManager> stack = getSessionStack();
|
||||
if (stack.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
@ -305,7 +304,7 @@ public class TaskanaEngineImpl implements TaskanaEngine {
|
|||
}
|
||||
|
||||
protected static void popSessionFromStack() {
|
||||
Stack<SqlSessionManager> stack = getSessionStack();
|
||||
Deque<SqlSessionManager> stack = getSessionStack();
|
||||
if (!stack.isEmpty()) {
|
||||
stack.pop();
|
||||
}
|
||||
|
|
|
@ -13,10 +13,11 @@ import pro.taskana.WorkbasketQuery;
|
|||
import pro.taskana.WorkbasketSummary;
|
||||
import pro.taskana.configuration.TaskanaEngineConfiguration;
|
||||
import pro.taskana.exceptions.InvalidArgumentException;
|
||||
import pro.taskana.exceptions.InvalidRequestException;
|
||||
import pro.taskana.exceptions.SystemException;
|
||||
import pro.taskana.impl.util.LoggerUtils;
|
||||
import pro.taskana.model.WorkbasketAuthorization;
|
||||
import pro.taskana.model.WorkbasketType;
|
||||
import pro.taskana.model.mappings.WorkbasketAccessMapper;
|
||||
import pro.taskana.security.CurrentUserContext;
|
||||
|
||||
/**
|
||||
|
@ -28,6 +29,12 @@ public class WorkbasketQueryImpl implements WorkbasketQuery {
|
|||
|
||||
private static final String LINK_TO_MAPPER = "pro.taskana.model.mappings.QueryMapper.queryWorkbasket";
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(WorkbasketQueryImpl.class);
|
||||
private static final String KEY_COL_NAME = "KEY";
|
||||
private static final String NAME_COL_NAME = "NAME";
|
||||
private static final String ASCENDING = " ASC";
|
||||
private static final String DESCENDING = " DESC";
|
||||
private static final String ORDER_BY = "ORDER BY ";
|
||||
|
||||
private String[] accessId;
|
||||
private WorkbasketAuthorization authorization;
|
||||
private String[] nameIn;
|
||||
|
@ -43,10 +50,12 @@ public class WorkbasketQueryImpl implements WorkbasketQuery {
|
|||
private Instant modifiedBefore;
|
||||
private String descriptionLike;
|
||||
private String[] owner;
|
||||
private String orderClause;
|
||||
private TaskanaEngineImpl taskanaEngineImpl;
|
||||
|
||||
public WorkbasketQueryImpl(TaskanaEngine taskanaEngine, WorkbasketAccessMapper workbasketAccessMapper) {
|
||||
public WorkbasketQueryImpl(TaskanaEngine taskanaEngine) {
|
||||
this.taskanaEngineImpl = (TaskanaEngineImpl) taskanaEngine;
|
||||
orderClause = "";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -128,7 +137,74 @@ public class WorkbasketQueryImpl implements WorkbasketQuery {
|
|||
}
|
||||
|
||||
@Override
|
||||
public WorkbasketQuery accessIdsHavePersmission(WorkbasketAuthorization permission, String... accessIds)
|
||||
public WorkbasketQuery orderByName() throws InvalidRequestException {
|
||||
if (orderClause.contains(NAME_COL_NAME)) {
|
||||
throw new InvalidRequestException("orderByName() has already been called");
|
||||
}
|
||||
if (orderClause.isEmpty()) {
|
||||
orderClause = ORDER_BY + NAME_COL_NAME;
|
||||
} else if (orderClause.contains(ORDER_BY)) {
|
||||
orderClause += ", " + NAME_COL_NAME;
|
||||
} else {
|
||||
throw new SystemException("orderByName() was called, but orderClause is unexpectedly: " + orderClause);
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WorkbasketQuery orderByKey() throws InvalidRequestException {
|
||||
if (orderClause.contains(KEY_COL_NAME)) {
|
||||
throw new InvalidRequestException("orderByKey() has already been called");
|
||||
}
|
||||
if (orderClause.isEmpty()) {
|
||||
orderClause = ORDER_BY + KEY_COL_NAME;
|
||||
} else if (orderClause.contains(ORDER_BY)) {
|
||||
orderClause += ", " + KEY_COL_NAME;
|
||||
} else {
|
||||
throw new SystemException("orderByKey() was called, but orderClause is unexpectedly: " + orderClause);
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WorkbasketQuery ascending() throws InvalidRequestException {
|
||||
if (!orderClause.startsWith(ORDER_BY)) {
|
||||
throw new InvalidRequestException(
|
||||
"ascending() has been called before orderByKey() or orderByName() was called");
|
||||
}
|
||||
if (orderClause.endsWith(KEY_COL_NAME) || orderClause.endsWith(NAME_COL_NAME)) {
|
||||
orderClause += ASCENDING;
|
||||
} else if (orderClause.endsWith(ASCENDING) || orderClause.endsWith(DESCENDING)) {
|
||||
throw new InvalidRequestException(
|
||||
"ascending() has been called immediately after ascending() or descending()");
|
||||
} else {
|
||||
throw new SystemException("ascending() was called, but orderClause is unexpectedly: " + orderClause);
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WorkbasketQuery descending() throws InvalidRequestException {
|
||||
if (!orderClause.startsWith(ORDER_BY)) {
|
||||
throw new InvalidRequestException(
|
||||
"descending() has been called before orderByKey or orderByName was called");
|
||||
}
|
||||
if (orderClause.endsWith(KEY_COL_NAME) || orderClause.endsWith(NAME_COL_NAME)) {
|
||||
orderClause += DESCENDING;
|
||||
} else if (orderClause.endsWith(ASCENDING) || orderClause.endsWith(DESCENDING)) {
|
||||
throw new InvalidRequestException(
|
||||
"descending() has been called immediately after ascending() or descending()");
|
||||
} else {
|
||||
throw new SystemException("descending() was called, but orderClause is unexpectedly: " + orderClause);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WorkbasketQuery accessIdsHavePermission(WorkbasketAuthorization permission, String... accessIds)
|
||||
throws InvalidArgumentException {
|
||||
// Checking pre-conditions
|
||||
if (permission == null) {
|
||||
|
@ -154,7 +230,7 @@ public class WorkbasketQueryImpl implements WorkbasketQuery {
|
|||
throw new InvalidArgumentException("Permission cannot be null.");
|
||||
}
|
||||
List<String> ucAccessIds = CurrentUserContext.getAccessIds();
|
||||
if (ucAccessIds != null && ucAccessIds.size() > 0) {
|
||||
if (ucAccessIds != null && !ucAccessIds.isEmpty()) {
|
||||
accessIds = new String[ucAccessIds.size()];
|
||||
accessIds = ucAccessIds.toArray(accessIds);
|
||||
} else {
|
||||
|
@ -280,6 +356,10 @@ public class WorkbasketQueryImpl implements WorkbasketQuery {
|
|||
return owner;
|
||||
}
|
||||
|
||||
public String getOrderClause() {
|
||||
return orderClause;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
|
|
|
@ -302,7 +302,7 @@ public class WorkbasketServiceImpl implements WorkbasketService {
|
|||
|
||||
@Override
|
||||
public WorkbasketQuery createWorkbasketQuery() {
|
||||
return new WorkbasketQueryImpl(taskanaEngine, workbasketAccessMapper);
|
||||
return new WorkbasketQueryImpl(taskanaEngine);
|
||||
}
|
||||
|
||||
private void validateWorkbasket(Workbasket workbasket) throws InvalidWorkbasketException {
|
||||
|
|
|
@ -134,7 +134,7 @@ public interface QueryMapper {
|
|||
@Result(property = "value", column = "VALUE")})
|
||||
List<ObjectReference> queryObjectReference(ObjectReferenceQueryImpl objectReference);
|
||||
|
||||
@Select("<script>SELECT w.ID, w.KEY, w.NAME, w.DOMAIN, W.TYPE, w.DESCRIPTION, w.OWNER, w.ORG_LEVEL_1, w.ORG_LEVEL_2, w.ORG_LEVEL_3, w.ORG_LEVEL_4 from WORKBASKET w "
|
||||
@Select("<script>SELECT DISTINCT w.ID, w.KEY, w.NAME, w.DOMAIN, W.TYPE, w.DESCRIPTION, w.OWNER, w.ORG_LEVEL_1, w.ORG_LEVEL_2, w.ORG_LEVEL_3, w.ORG_LEVEL_4 from WORKBASKET w "
|
||||
+ "<if test='accessId != null'>LEFT OUTER JOIN WORKBASKET_ACCESS_LIST a on w.KEY = a.WORKBASKET_KEY</if> "
|
||||
+ "<where>"
|
||||
+ "<if test='owner != null'>AND w.OWNER IN(<foreach item='item' collection='owner' separator=',' >#{item}</foreach>)</if> "
|
||||
|
@ -171,6 +171,7 @@ public interface QueryMapper {
|
|||
+ "<if test=\"authorization.name().equals('CUSTOM_12')\">PERM_CUSTOM_12</if> = 1 "
|
||||
+ "</if>"
|
||||
+ "</where>"
|
||||
+ "<if test='!orderClause.isEmpty()'> ${orderClause}</if> "
|
||||
+ "</script>")
|
||||
@Results({
|
||||
@Result(property = "id", column = "ID"),
|
||||
|
|
|
@ -1,12 +1,13 @@
|
|||
package acceptance.workbasket;
|
||||
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
|
||||
import org.h2.store.fs.FileUtils;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
|
@ -14,6 +15,7 @@ import acceptance.AbstractAccTest;
|
|||
import pro.taskana.WorkbasketService;
|
||||
import pro.taskana.WorkbasketSummary;
|
||||
import pro.taskana.exceptions.InvalidArgumentException;
|
||||
import pro.taskana.exceptions.InvalidRequestException;
|
||||
import pro.taskana.exceptions.NotAuthorizedException;
|
||||
import pro.taskana.model.WorkbasketType;
|
||||
import pro.taskana.security.JAASRunner;
|
||||
|
@ -155,60 +157,157 @@ public class QueryWorkbasketAccTest extends AbstractAccTest {
|
|||
FileUtils.deleteRecursive("~/data", true);
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
public void testQueryWorkbasketByNameStartsWithSortedByNameAscending()
|
||||
throws SQLException, NotAuthorizedException, InvalidArgumentException {
|
||||
throws SQLException, NotAuthorizedException, InvalidRequestException, InvalidArgumentException {
|
||||
WorkbasketService workbasketService = taskanaEngine.getWorkbasketService();
|
||||
List<WorkbasketSummary> results = workbasketService.createWorkbasketQuery()
|
||||
.nameLike("%Gruppenpostkorb KSC%")
|
||||
// .orderByName()
|
||||
// .ascending()
|
||||
.orderByName()
|
||||
.ascending()
|
||||
.list();
|
||||
Assert.assertEquals(6L, results.size());
|
||||
Assert.assertEquals("GPK_KSC", results.get(0).getKey());
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
public void testQueryWorkbasketByNameStartsWithSortedByNameDescending()
|
||||
throws SQLException, NotAuthorizedException, InvalidArgumentException {
|
||||
throws SQLException, NotAuthorizedException, InvalidRequestException, InvalidArgumentException {
|
||||
WorkbasketService workbasketService = taskanaEngine.getWorkbasketService();
|
||||
List<WorkbasketSummary> results = workbasketService.createWorkbasketQuery()
|
||||
.nameLike("%Gruppenpostkorb KSC%")
|
||||
// .orderByName()
|
||||
// .descending()
|
||||
.orderByName()
|
||||
.descending()
|
||||
.list();
|
||||
Assert.assertEquals(6L, results.size());
|
||||
Assert.assertEquals("GPK_B_KSC_2", results.get(0).getKey());
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
public void testQueryWorkbasketByNameStartsWithSortedByKeyAscending()
|
||||
throws SQLException, NotAuthorizedException, InvalidArgumentException {
|
||||
throws SQLException, NotAuthorizedException, InvalidArgumentException, InvalidRequestException {
|
||||
WorkbasketService workbasketService = taskanaEngine.getWorkbasketService();
|
||||
List<WorkbasketSummary> results = workbasketService.createWorkbasketQuery()
|
||||
.nameLike("%Gruppenpostkorb KSC%")
|
||||
// .orderByKey()
|
||||
// .ascending()
|
||||
.orderByKey()
|
||||
.ascending()
|
||||
.list();
|
||||
Assert.assertEquals(6L, results.size());
|
||||
Assert.assertEquals("GPK_B_KSC", results.get(0).getKey());
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
public void testQueryWorkbasketByNameStartsWithSortedByKeyDescending()
|
||||
throws SQLException, NotAuthorizedException, InvalidArgumentException {
|
||||
throws SQLException, NotAuthorizedException, InvalidArgumentException, InvalidRequestException {
|
||||
WorkbasketService workbasketService = taskanaEngine.getWorkbasketService();
|
||||
List<WorkbasketSummary> results = workbasketService.createWorkbasketQuery()
|
||||
.nameLike("%Gruppenpostkorb KSC%")
|
||||
// .orderByKey()
|
||||
// .descending()
|
||||
.orderByKey()
|
||||
.descending()
|
||||
.list();
|
||||
Assert.assertEquals(6L, results.size());
|
||||
Assert.assertEquals("GPK_KSC_2", results.get(0).getKey());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testQuerySortingWithInvalidInput()
|
||||
throws SQLException, NotAuthorizedException, InvalidArgumentException {
|
||||
WorkbasketService workbasketService = taskanaEngine.getWorkbasketService();
|
||||
|
||||
try {
|
||||
workbasketService.createWorkbasketQuery()
|
||||
.nameLike("%Gruppenpostkorb KSC%")
|
||||
.orderByName()
|
||||
.orderByName()
|
||||
.list();
|
||||
|
||||
fail("WorkbasketQuery should have thrown InvalidRequestException.");
|
||||
} catch (InvalidRequestException ignored) {
|
||||
// nothing to do
|
||||
}
|
||||
|
||||
try {
|
||||
workbasketService.createWorkbasketQuery()
|
||||
.nameLike("%Gruppenpostkorb KSC%")
|
||||
.orderByKey()
|
||||
.orderByKey()
|
||||
.list();
|
||||
|
||||
fail("WorkbasketQuery should have thrown InvalidRequestException.");
|
||||
} catch (InvalidRequestException ignored) {
|
||||
// nothing to do
|
||||
}
|
||||
|
||||
try {
|
||||
workbasketService.createWorkbasketQuery()
|
||||
.nameLike("%Gruppenpostkorb KSC%")
|
||||
.ascending()
|
||||
.orderByName()
|
||||
.list();
|
||||
|
||||
fail("WorkbasketQuery should have thrown InvalidRequestException.");
|
||||
} catch (InvalidRequestException ignored) {
|
||||
// nothing to do
|
||||
}
|
||||
try {
|
||||
workbasketService.createWorkbasketQuery()
|
||||
.nameLike("%Gruppenpostkorb KSC%")
|
||||
.descending()
|
||||
.orderByName()
|
||||
.list();
|
||||
|
||||
fail("WorkbasketQuery should have thrown InvalidRequestException.");
|
||||
} catch (InvalidRequestException ignored) {
|
||||
// nothing to do
|
||||
}
|
||||
try {
|
||||
workbasketService.createWorkbasketQuery()
|
||||
.nameLike("%Gruppenpostkorb KSC%")
|
||||
.orderByName()
|
||||
.ascending()
|
||||
.ascending()
|
||||
.list();
|
||||
|
||||
fail("WorkbasketQuery should have thrown InvalidRequestException.");
|
||||
} catch (InvalidRequestException ignored) {
|
||||
// nothing to do
|
||||
}
|
||||
try {
|
||||
workbasketService.createWorkbasketQuery()
|
||||
.nameLike("%Gruppenpostkorb KSC%")
|
||||
.orderByName()
|
||||
.ascending()
|
||||
.descending()
|
||||
.list();
|
||||
|
||||
fail("WorkbasketQuery should have thrown InvalidRequestException.");
|
||||
} catch (InvalidRequestException ignored) {
|
||||
// nothing to do
|
||||
}
|
||||
try {
|
||||
workbasketService.createWorkbasketQuery()
|
||||
.nameLike("%Gruppenpostkorb KSC%")
|
||||
.orderByName()
|
||||
.descending()
|
||||
.ascending()
|
||||
.list();
|
||||
|
||||
fail("WorkbasketQuery should have thrown InvalidRequestException.");
|
||||
} catch (InvalidRequestException ignored) {
|
||||
// nothing to do
|
||||
}
|
||||
try {
|
||||
workbasketService.createWorkbasketQuery()
|
||||
.nameLike("%Gruppenpostkorb KSC%")
|
||||
.orderByName()
|
||||
.orderByName()
|
||||
.list();
|
||||
|
||||
fail("WorkbasketQuery should have thrown InvalidRequestException.");
|
||||
} catch (InvalidRequestException ignored) {
|
||||
// nothing to do
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -6,7 +6,6 @@ import java.util.List;
|
|||
import org.h2.store.fs.FileUtils;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
|
@ -14,6 +13,7 @@ import acceptance.AbstractAccTest;
|
|||
import pro.taskana.WorkbasketService;
|
||||
import pro.taskana.WorkbasketSummary;
|
||||
import pro.taskana.exceptions.InvalidArgumentException;
|
||||
import pro.taskana.exceptions.InvalidRequestException;
|
||||
import pro.taskana.exceptions.NotAuthorizedException;
|
||||
import pro.taskana.exceptions.SystemException;
|
||||
import pro.taskana.model.WorkbasketAuthorization;
|
||||
|
@ -35,7 +35,7 @@ public class QueryWorkbasketByPermissionAccTest extends AbstractAccTest {
|
|||
throws SQLException, NotAuthorizedException, InvalidArgumentException {
|
||||
WorkbasketService workbasketService = taskanaEngine.getWorkbasketService();
|
||||
List<WorkbasketSummary> results = workbasketService.createWorkbasketQuery()
|
||||
.accessIdsHavePersmission(WorkbasketAuthorization.APPEND, "user_1_1")
|
||||
.accessIdsHavePermission(WorkbasketAuthorization.APPEND, "user_1_1")
|
||||
.list();
|
||||
Assert.assertEquals(2, results.size());
|
||||
Assert.assertEquals("USER_1_1", results.get(1).getKey());
|
||||
|
@ -46,37 +46,39 @@ public class QueryWorkbasketByPermissionAccTest extends AbstractAccTest {
|
|||
throws SQLException, NotAuthorizedException, InvalidArgumentException, SystemException {
|
||||
WorkbasketService workbasketService = taskanaEngine.getWorkbasketService();
|
||||
List<WorkbasketSummary> results = workbasketService.createWorkbasketQuery()
|
||||
.accessIdsHavePersmission(WorkbasketAuthorization.APPEND, "user_1_1", "group_1")
|
||||
.accessIdsHavePermission(WorkbasketAuthorization.APPEND, "user_1_1", "group_1")
|
||||
.list();
|
||||
Assert.assertEquals(9, results.size());
|
||||
Assert.assertEquals(8, results.size());
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
public void testQueryAllTransferTargetsForUserAndGroupSortedByNameAscending()
|
||||
throws SQLException, NotAuthorizedException, InvalidArgumentException, SystemException {
|
||||
throws SQLException, NotAuthorizedException, InvalidArgumentException, SystemException,
|
||||
InvalidRequestException {
|
||||
WorkbasketService workbasketService = taskanaEngine.getWorkbasketService();
|
||||
List<WorkbasketSummary> results = workbasketService.createWorkbasketQuery()
|
||||
.accessIdsHavePersmission(WorkbasketAuthorization.APPEND, "user_1_1", "group_1")
|
||||
// .orderByName()
|
||||
// .ascending()
|
||||
.accessIdsHavePermission(WorkbasketAuthorization.APPEND, "user_1_1", "group_1")
|
||||
.orderByName()
|
||||
.ascending()
|
||||
.list();
|
||||
Assert.assertEquals(9, results.size());
|
||||
Assert.assertEquals("GPK_B_KSC_2", results.get(0).getKey());
|
||||
Assert.assertEquals(8, results.size());
|
||||
Assert.assertEquals("key4", results.get(0).getKey());
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
public void testQueryAllTransferTargetsForUserAndGroupSortedByNameDescending()
|
||||
throws SQLException, NotAuthorizedException, InvalidArgumentException, SystemException {
|
||||
throws SQLException, NotAuthorizedException, InvalidArgumentException, SystemException,
|
||||
InvalidRequestException {
|
||||
WorkbasketService workbasketService = taskanaEngine.getWorkbasketService();
|
||||
List<WorkbasketSummary> results = workbasketService.createWorkbasketQuery()
|
||||
.accessIdsHavePersmission(WorkbasketAuthorization.APPEND, "user_1_1", "group_1")
|
||||
// .orderByName()
|
||||
// .descending()
|
||||
.accessIdsHavePermission(WorkbasketAuthorization.APPEND, "user_1_1", "group_1")
|
||||
.orderByName()
|
||||
.descending()
|
||||
.orderByKey()
|
||||
.ascending()
|
||||
.list();
|
||||
Assert.assertEquals(9, results.size());
|
||||
Assert.assertEquals("GPK_B_KSC_2", results.get(0).getKey());
|
||||
Assert.assertEquals(8, results.size());
|
||||
Assert.assertEquals("USER_2_2", results.get(0).getKey());
|
||||
}
|
||||
|
||||
@WithAccessId(
|
||||
|
@ -89,7 +91,7 @@ public class QueryWorkbasketByPermissionAccTest extends AbstractAccTest {
|
|||
List<WorkbasketSummary> results = workbasketService.createWorkbasketQuery()
|
||||
.callerHasPermission(WorkbasketAuthorization.APPEND)
|
||||
.list();
|
||||
Assert.assertEquals(9, results.size());
|
||||
Assert.assertEquals(8, results.size());
|
||||
}
|
||||
|
||||
@WithAccessId(userName = "user_1_1")
|
||||
|
|
|
@ -79,6 +79,7 @@ public class TaskServiceImplIntAutocommitTest {
|
|||
DataSource ds = TaskanaEngineConfigurationTest.getDataSource();
|
||||
DBCleaner cleaner = new DBCleaner();
|
||||
cleaner.clearDb(ds, true);
|
||||
FileUtils.deleteRecursive("~/data", true);
|
||||
}
|
||||
|
||||
@Before
|
||||
|
@ -162,6 +163,8 @@ public class TaskServiceImplIntAutocommitTest {
|
|||
throws FileNotFoundException, SQLException, TaskNotFoundException, NotAuthorizedException,
|
||||
WorkbasketNotFoundException, ClassificationNotFoundException, ClassificationAlreadyExistException,
|
||||
TaskAlreadyExistException, InvalidWorkbasketException, InvalidArgumentException {
|
||||
DBCleaner cleaner = new DBCleaner();
|
||||
cleaner.clearDb(TaskanaEngineConfiguration.createDefaultDataSource(), false);
|
||||
TaskanaEngineConfiguration taskanaEngineConfiguration = new TaskanaEngineConfiguration(null, false, false);
|
||||
TaskanaEngine te = taskanaEngineConfiguration.buildTaskanaEngine();
|
||||
((TaskanaEngineImpl) te).setConnectionManagementMode(ConnectionManagementMode.AUTOCOMMIT);
|
||||
|
|
|
@ -176,12 +176,12 @@ public class TaskServiceImplIntExplicitTest {
|
|||
WorkbasketNotFoundException, ClassificationNotFoundException, ClassificationAlreadyExistException,
|
||||
TaskAlreadyExistException, InvalidWorkbasketException, InvalidArgumentException {
|
||||
DataSource ds = TaskanaEngineConfiguration.createDefaultDataSource();
|
||||
DBCleaner cleaner = new DBCleaner();
|
||||
cleaner.clearDb(ds, false);
|
||||
TaskanaEngineConfiguration taskanaEngineConfiguration = new TaskanaEngineConfiguration(ds, false, false);
|
||||
TaskanaEngine te = taskanaEngineConfiguration.buildTaskanaEngine();
|
||||
Connection connection = ds.getConnection();
|
||||
te.setConnection(connection);
|
||||
DBCleaner cleaner = new DBCleaner();
|
||||
cleaner.clearDb(ds, false);
|
||||
TaskServiceImpl taskServiceImpl = (TaskServiceImpl) te.getTaskService();
|
||||
WorkbasketServiceImpl workBasketServiceImpl = (WorkbasketServiceImpl) te.getWorkbasketService();
|
||||
ClassificationServiceImpl classificationServiceImpl = (ClassificationServiceImpl) te.getClassificationService();
|
||||
|
|
|
@ -270,7 +270,7 @@ public class WorkbasketServiceImplIntAutocommitTest {
|
|||
Instant thirtyDaysAgo = now.minus(Duration.ofDays(30L));
|
||||
|
||||
WorkbasketQuery query1 = workBasketService.createWorkbasketQuery()
|
||||
.accessIdsHavePersmission(WorkbasketAuthorization.OPEN, "Bernd")
|
||||
.accessIdsHavePermission(WorkbasketAuthorization.OPEN, "Bernd")
|
||||
.nameIn("Basket4");
|
||||
List<WorkbasketSummary> result1 = query1.list();
|
||||
|
||||
|
@ -279,19 +279,19 @@ public class WorkbasketServiceImplIntAutocommitTest {
|
|||
Workbasket workBasket = workBasketService.getWorkbasket(workbasketId);
|
||||
Assert.assertEquals(THREE, workBasketService.getDistributionTargets(workBasket.getId()).size());
|
||||
|
||||
WorkbasketQuery query2 = workBasketService.createWorkbasketQuery().accessIdsHavePersmission(
|
||||
WorkbasketQuery query2 = workBasketService.createWorkbasketQuery().accessIdsHavePermission(
|
||||
WorkbasketAuthorization.OPEN, "Bernd",
|
||||
"Konstantin");
|
||||
List<WorkbasketSummary> result2 = query2.list();
|
||||
Assert.assertEquals(2, result2.size());
|
||||
|
||||
WorkbasketQuery query3 = workBasketService.createWorkbasketQuery().accessIdsHavePersmission(
|
||||
WorkbasketQuery query3 = workBasketService.createWorkbasketQuery().accessIdsHavePermission(
|
||||
WorkbasketAuthorization.CUSTOM_5,
|
||||
"Bernd", "Konstantin");
|
||||
List<WorkbasketSummary> result3 = query3.list();
|
||||
Assert.assertEquals(0, result3.size());
|
||||
|
||||
WorkbasketQuery query4 = workBasketService.createWorkbasketQuery().accessIdsHavePersmission(
|
||||
WorkbasketQuery query4 = workBasketService.createWorkbasketQuery().accessIdsHavePermission(
|
||||
WorkbasketAuthorization.CUSTOM_1,
|
||||
"Bernd");
|
||||
List<WorkbasketSummary> result4 = query4.list();
|
||||
|
|
Loading…
Reference in New Issue