TSK-169: Pagination-Method for Query-Classes with wrapped Exception for an offset which is out of bounds/rows.

This commit is contained in:
Marcel Lengl 2018-01-31 13:49:26 +01:00 committed by Holger Hagen
parent 252d36a13d
commit 035fee5cb9
20 changed files with 1004 additions and 80 deletions

View File

@ -35,6 +35,23 @@ public interface BaseQuery<T> {
*/
List<T> list(int offset, int limit) throws NotAuthorizedException;
/**
* This method will return all results for page X with a size of Y of the current query.<br>
* Negative pageNumber/size will be changed to 0 and the last page got maybe less elements.
*
* @param pageNumber
* current pagination page starting at 0.
* @param pageSize
* amount of elements for this page.
* @return resulList for the current query starting at X and returning max Y elements.
* @throws NotAuthorizedException
*/
default List<T> listPage(int pageNumber, int pageSize) throws NotAuthorizedException {
int offset = (pageNumber < 0) ? 0 : (pageNumber * pageSize);
int limit = (pageSize < 0) ? 0 : pageSize;
return list(offset, limit);
}
/**
* This method will return a single object of {@link T}.
*
@ -44,4 +61,12 @@ public interface BaseQuery<T> {
*/
T single() throws NotAuthorizedException;
/**
* Counting the amount of rows/results for the current query. This can be used for a pagination afterwards.
*
* @throws NotAuthorizedException
* when permissions not granted.
* @return resultRowCount
*/
long count() throws NotAuthorizedException;
}

View File

@ -14,7 +14,6 @@ public interface ClassificationService {
/**
* Get all available Classification summaries as a tree.
*
* @return The List of all Classification summaries
*/
List<ClassificationSummary> getClassificationTree();

View File

@ -4,6 +4,7 @@ import java.time.Instant;
import java.util.Arrays;
import java.util.List;
import org.apache.ibatis.exceptions.PersistenceException;
import org.apache.ibatis.session.RowBounds;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -11,6 +12,8 @@ import org.slf4j.LoggerFactory;
import pro.taskana.ClassificationQuery;
import pro.taskana.ClassificationSummary;
import pro.taskana.TaskanaEngine;
import pro.taskana.exceptions.NotAuthorizedException;
import pro.taskana.exceptions.TaskanaRuntimeException;
import pro.taskana.impl.util.LoggerUtils;
/**
@ -21,6 +24,7 @@ import pro.taskana.impl.util.LoggerUtils;
public class ClassificationQueryImpl implements ClassificationQuery {
private static final String LINK_TO_MAPPER = "pro.taskana.model.mappings.QueryMapper.queryClassification";
private static final String LINK_TO_COUNTER = "pro.taskana.model.mappings.QueryMapper.countQueryClassifications";
private static final Logger LOGGER = LoggerFactory.getLogger(ClassificationQueryImpl.class);
private TaskanaEngineImpl taskanaEngineImpl;
private String[] key;
@ -146,6 +150,16 @@ public class ClassificationQueryImpl implements ClassificationQuery {
RowBounds rowBounds = new RowBounds(offset, limit);
result = taskanaEngineImpl.getSqlSession().selectList(LINK_TO_MAPPER, this, rowBounds);
return result;
} catch (Exception e) {
if (e instanceof PersistenceException) {
if (e.getMessage().contains("ERRORCODE=-4470")) {
TaskanaRuntimeException ex = new TaskanaRuntimeException(
"The offset beginning was set over the amount of result-rows.", e.getCause());
ex.setStackTrace(e.getStackTrace());
throw ex;
}
}
throw e;
} finally {
taskanaEngineImpl.returnConnection();
if (LOGGER.isDebugEnabled()) {
@ -274,6 +288,20 @@ public class ClassificationQueryImpl implements ClassificationQuery {
this.customFields = customFields;
}
@Override
public long count() throws NotAuthorizedException {
LOGGER.debug("entry to count(), this = {}", this);
Long rowCount = null;
try {
taskanaEngineImpl.openConnection();
rowCount = taskanaEngineImpl.getSqlSession().selectOne(LINK_TO_COUNTER, this);
return (rowCount == null) ? 0L : rowCount;
} finally {
taskanaEngineImpl.returnConnection();
LOGGER.debug("exit from count(). Returning result {} ", rowCount);
}
}
@Override
public String toString() {
StringBuilder builder = new StringBuilder();

View File

@ -3,22 +3,27 @@ package pro.taskana.impl;
import java.util.Arrays;
import java.util.List;
import org.apache.ibatis.exceptions.PersistenceException;
import org.apache.ibatis.session.RowBounds;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import pro.taskana.ObjectReferenceQuery;
import pro.taskana.TaskanaEngine;
import pro.taskana.exceptions.NotAuthorizedException;
import pro.taskana.exceptions.TaskanaRuntimeException;
import pro.taskana.impl.util.LoggerUtils;
import pro.taskana.model.ObjectReference;
/**
* Implementation of ObjectReferenceQuery interface.
*
* @author EH
*/
public class ObjectReferenceQueryImpl implements ObjectReferenceQuery {
private static final String LINK_TO_MAPPER = "pro.taskana.model.mappings.QueryMapper.queryObjectReference";
private static final String LINK_TO_COUNTER = "pro.taskana.model.mappings.QueryMapper.countQueryObjectReferences";
private static final Logger LOGGER = LoggerFactory.getLogger(ObjectReferenceQueryImpl.class);
private TaskanaEngineImpl taskanaEngineImpl;
@ -68,13 +73,14 @@ public class ObjectReferenceQueryImpl implements ObjectReferenceQuery {
List<ObjectReference> result = null;
try {
taskanaEngineImpl.openConnection();
result = taskanaEngineImpl.getSqlSession().selectList(LINK_TO_MAPPER, this);
result = taskanaEngineImpl.getSqlSession().selectList(LINK_TO_MAPPER, this);
return result;
} finally {
taskanaEngineImpl.returnConnection();
if (LOGGER.isDebugEnabled()) {
int numberOfResultObjects = result == null ? 0 : result.size();
LOGGER.debug("exit from list(). Returning {} resulting Objects: {} ", numberOfResultObjects, LoggerUtils.listToString(result));
LOGGER.debug("exit from list(). Returning {} resulting Objects: {} ", numberOfResultObjects,
LoggerUtils.listToString(result));
}
}
}
@ -88,13 +94,24 @@ public class ObjectReferenceQueryImpl implements ObjectReferenceQuery {
RowBounds rowBounds = new RowBounds(offset, limit);
result = taskanaEngineImpl.getSqlSession().selectList(LINK_TO_MAPPER, this, rowBounds);
return result;
} catch (Exception e) {
if (e instanceof PersistenceException) {
if (e.getMessage().contains("ERRORCODE=-4470")) {
TaskanaRuntimeException ex = new TaskanaRuntimeException(
"The offset beginning was set over the amount of result-rows.", e.getCause());
ex.setStackTrace(e.getStackTrace());
throw ex;
}
}
throw e;
} finally {
taskanaEngineImpl.returnConnection();
if (LOGGER.isDebugEnabled()) {
int numberOfResultObjects = result == null ? 0 : result.size();
LOGGER.debug("exit from list(offset,limit). Returning {} resulting Objects: {} ", numberOfResultObjects, LoggerUtils.listToString(result));
LOGGER.debug("exit from list(offset,limit). Returning {} resulting Objects: {} ", numberOfResultObjects,
LoggerUtils.listToString(result));
}
}
}
}
@Override
@ -151,6 +168,20 @@ public class ObjectReferenceQueryImpl implements ObjectReferenceQuery {
this.value = value;
}
@Override
public long count() throws NotAuthorizedException {
LOGGER.debug("entry to count(), this = {}", this);
Long rowCount = null;
try {
taskanaEngineImpl.openConnection();
rowCount = taskanaEngineImpl.getSqlSession().selectOne(LINK_TO_COUNTER, this);
return (rowCount == null) ? 0L : rowCount;
} finally {
taskanaEngineImpl.returnConnection();
LOGGER.debug("exit from count(). Returning result {} ", rowCount);
}
}
@Override
public String toString() {
StringBuilder builder = new StringBuilder();

View File

@ -2,9 +2,9 @@ package pro.taskana.impl;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.apache.ibatis.exceptions.PersistenceException;
import org.apache.ibatis.session.RowBounds;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -14,6 +14,7 @@ import pro.taskana.TaskQuery;
import pro.taskana.TaskSummary;
import pro.taskana.TaskanaEngine;
import pro.taskana.exceptions.NotAuthorizedException;
import pro.taskana.exceptions.TaskanaRuntimeException;
import pro.taskana.impl.util.LoggerUtils;
import pro.taskana.model.TaskState;
import pro.taskana.model.WorkbasketAuthorization;
@ -24,9 +25,9 @@ import pro.taskana.model.WorkbasketAuthorization;
public class TaskQueryImpl implements TaskQuery {
private static final String LINK_TO_MAPPER = "pro.taskana.model.mappings.QueryMapper.queryTasks";
private static final String LINK_TO_COUNTER = "pro.taskana.model.mappings.QueryMapper.countQueryTasks";
private static final Logger LOGGER = LoggerFactory.getLogger(TaskQueryImpl.class);
private TaskanaEngineImpl taskanaEngineImpl;
private ClassificationServiceImpl classificationService;
private TaskServiceImpl taskService;
private String[] name;
private String description;
@ -53,7 +54,6 @@ public class TaskQueryImpl implements TaskQuery {
public TaskQueryImpl(TaskanaEngine taskanaEngine) {
this.taskanaEngineImpl = (TaskanaEngineImpl) taskanaEngine;
this.classificationService = (ClassificationServiceImpl) taskanaEngineImpl.getClassificationService();
this.taskService = (TaskServiceImpl) taskanaEngineImpl.getTaskService();
}
@ -196,12 +196,13 @@ public class TaskQueryImpl implements TaskQuery {
@Override
public List<TaskSummary> list() throws NotAuthorizedException {
LOGGER.debug("entry to list(), this = {}", this);
List<TaskSummary> result = new ArrayList<>();
try {
LOGGER.debug("entry to list(), this = {}", this);
taskanaEngineImpl.openConnection();
checkAuthorization();
List<TaskSummaryImpl> tasks = taskanaEngineImpl.getSqlSession().selectList(LINK_TO_MAPPER, this);
List<TaskSummaryImpl> tasks = new ArrayList<>();
tasks = taskanaEngineImpl.getSqlSession().selectList(LINK_TO_MAPPER, this);
result = taskService.augmentTaskSummariesByContainedSummaries(tasks);
return result;
} finally {
@ -225,6 +226,16 @@ public class TaskQueryImpl implements TaskQuery {
List<TaskSummaryImpl> tasks = taskanaEngineImpl.getSqlSession().selectList(LINK_TO_MAPPER, this, rowBounds);
result = taskService.augmentTaskSummariesByContainedSummaries(tasks);
return result;
} catch (Exception e) {
if (e instanceof PersistenceException) {
if (e.getMessage().contains("ERRORCODE=-4470")) {
TaskanaRuntimeException ex = new TaskanaRuntimeException(
"The offset beginning was set over the amount of result-rows.", e.getCause());
ex.setStackTrace(e.getStackTrace());
throw ex;
}
}
throw e;
} finally {
taskanaEngineImpl.returnConnection();
if (LOGGER.isDebugEnabled()) {
@ -258,6 +269,21 @@ public class TaskQueryImpl implements TaskQuery {
}
}
@Override
public long count() throws NotAuthorizedException {
LOGGER.debug("entry to count(), this = {}", this);
Long rowCount = null;
try {
taskanaEngineImpl.openConnection();
checkAuthorization();
rowCount = taskanaEngineImpl.getSqlSession().selectOne(LINK_TO_COUNTER, this);
return (rowCount == null) ? 0L : rowCount;
} finally {
taskanaEngineImpl.returnConnection();
LOGGER.debug("exit from count(). Returning result {} ", rowCount);
}
}
private void checkAuthorization() throws NotAuthorizedException {
if (this.workbasketKey != null && this.workbasketKey.length > 0) {
for (String wbKey : this.workbasketKey) {

View File

@ -4,6 +4,7 @@ import java.time.Instant;
import java.util.Arrays;
import java.util.List;
import org.apache.ibatis.exceptions.PersistenceException;
import org.apache.ibatis.session.RowBounds;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -14,7 +15,9 @@ import pro.taskana.WorkbasketSummary;
import pro.taskana.configuration.TaskanaEngineConfiguration;
import pro.taskana.exceptions.InvalidArgumentException;
import pro.taskana.exceptions.InvalidRequestException;
import pro.taskana.exceptions.NotAuthorizedException;
import pro.taskana.exceptions.SystemException;
import pro.taskana.exceptions.TaskanaRuntimeException;
import pro.taskana.impl.util.LoggerUtils;
import pro.taskana.model.WorkbasketAuthorization;
import pro.taskana.model.WorkbasketType;
@ -28,6 +31,7 @@ import pro.taskana.security.CurrentUserContext;
public class WorkbasketQueryImpl implements WorkbasketQuery {
private static final String LINK_TO_MAPPER = "pro.taskana.model.mappings.QueryMapper.queryWorkbasket";
private static final String LINK_TO_COUNTER = "pro.taskana.model.mappings.QueryMapper.countQueryWorkbaskets";
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";
@ -272,6 +276,16 @@ public class WorkbasketQueryImpl implements WorkbasketQuery {
RowBounds rowBounds = new RowBounds(offset, limit);
workbaskets = taskanaEngineImpl.getSqlSession().selectList(LINK_TO_MAPPER, this, rowBounds);
return workbaskets;
} catch (Exception e) {
if (e instanceof PersistenceException) {
if (e.getMessage().contains("ERRORCODE=-4470")) {
TaskanaRuntimeException ex = new TaskanaRuntimeException(
"The offset beginning was set over the amount of result-rows.", e.getCause());
ex.setStackTrace(e.getStackTrace());
throw ex;
}
}
throw e;
} finally {
taskanaEngineImpl.returnConnection();
if (LOGGER.isDebugEnabled()) {
@ -360,6 +374,20 @@ public class WorkbasketQueryImpl implements WorkbasketQuery {
return orderClause;
}
@Override
public long count() throws NotAuthorizedException {
LOGGER.debug("entry to count(), this = {}", this);
Long rowCount = null;
try {
taskanaEngineImpl.openConnection();
rowCount = taskanaEngineImpl.getSqlSession().selectOne(LINK_TO_COUNTER, this);
return (rowCount == null) ? 0L : rowCount;
} finally {
taskanaEngineImpl.returnConnection();
LOGGER.debug("exit from count(). Returning result {} ", rowCount);
}
}
@Override
public String toString() {
StringBuilder builder = new StringBuilder();

View File

@ -186,4 +186,98 @@ public interface QueryMapper {
@Result(property = "orgLevel3", column = "ORG_LEVEL_3"),
@Result(property = "orgLevel4", column = "ORG_LEVEL_4")})
List<WorkbasketSummaryImpl> queryWorkbasket(WorkbasketQueryImpl workbasketQuery);
@Select("<script>SELECT COUNT(ID) FROM TASK t "
+ "<where>"
+ "<if test='name != null'>AND t.NAME IN(<foreach item='item' collection='name' separator=',' >#{item}</foreach>)</if> "
+ "<if test='description != null'>AND t.DESCRIPTION like #{description}</if> "
+ "<if test='note != null'>AND t.NOTE like #{note}</if> "
+ "<if test='priority != null'>AND t.PRIORITY IN(<foreach item='item' collection='priority' separator=',' >#{item}</foreach>)</if> "
+ "<if test='states != null'>AND t.STATE IN(<foreach item='item' collection='states' separator=',' >#{item}</foreach>)</if> "
+ "<if test='workbasketKey != null'>AND t.WORKBASKET_KEY IN(<foreach item='item' collection='workbasketKey' separator=',' >#{item}</foreach>)</if> "
+ "<if test='classificationKey != null'>AND t.CLASSIFICATION_KEY IN(<foreach item='item' collection='classificationKey' separator=',' >#{item}</foreach>)</if> "
+ "<if test='domain != null'>AND t.DOMAIN IN(<foreach item='item' collection='domain' separator=',' >#{item}</foreach>)</if> "
+ "<if test='owner != null'>AND t.OWNER IN(<foreach item='item' collection='owner' separator=',' >#{item}</foreach>)</if> "
+ "<if test='isRead != null'>AND t.IS_READ = #{isRead}</if> "
+ "<if test='isTransferred != null'>AND t.IS_TRANSFERRED = #{isTransferred}</if> "
+ "<if test='porCompanyIn != null'>AND t.POR_COMPANY IN(<foreach item='item' collection='porCompanyIn' separator=',' >#{item}</foreach>)</if> "
+ "<if test='porCompanyLike != null'>AND t.POR_COMPANY like #{porCompanyLike}</if> "
+ "<if test='porSystemIn != null'>AND t.POR_SYSTEM IN(<foreach item='item' collection='porSystemIn' separator=',' >#{item}</foreach>)</if> "
+ "<if test='porSystemLike != null'>AND t.POR_SYSTEM like #{porSystemLike}</if> "
+ "<if test='porSystemInstanceIn != null'>AND t.POR_INSTANCE IN(<foreach item='item' collection='porSystemInstanceIn' separator=',' >#{item}</foreach>)</if> "
+ "<if test='porSystemInstanceLike != null'>AND t.POR_INSTANCE like #{porSystemInstanceLike}</if> "
+ "<if test='porTypeIn != null'>AND t.POR_TYPE IN(<foreach item='item' collection='porTypeIn' separator=',' >#{item}</foreach>)</if> "
+ "<if test='porTypeLike != null'>AND t.POR_TYPE like #{porTypeLike}</if> "
+ "<if test='porValueIn != null'>AND t.POR_VALUE IN(<foreach item='item' collection='porValueIn' separator=',' >#{item}</foreach>)</if> "
+ "<if test='porValueLike != null'>AND t.POR_VALUE like #{porValueLike}</if> "
+ "<if test='customFields != null'>AND (t.CUSTOM_1 IN(<foreach item='item' collection='customFields' separator=',' >#{item}</foreach>) OR t.CUSTOM_2 IN(<foreach item='item' collection='customFields' separator=',' >#{item}</foreach>) OR t.CUSTOM_3 IN(<foreach item='item' collection='customFields' separator=',' >#{item}</foreach>) OR t.CUSTOM_4 IN(<foreach item='item' collection='customFields' separator=',' >#{item}</foreach>) OR t.CUSTOM_5 IN(<foreach item='item' collection='customFields' separator=',' >#{item}</foreach>) OR t.CUSTOM_6 IN(<foreach item='item' collection='customFields' separator=',' >#{item}</foreach>) OR t.CUSTOM_7 IN(<foreach item='item' collection='customFields' separator=',' >#{item}</foreach>) OR t.CUSTOM_8 IN(<foreach item='item' collection='customFields' separator=',' >#{item}</foreach>) OR t.CUSTOM_9 IN(<foreach item='item' collection='customFields' separator=',' >#{item}</foreach>) OR t.CUSTOM_10 IN(<foreach item='item' collection='customFields' separator=',' >#{item}</foreach>))</if> "
+ "</where>"
+ "</script>")
Long countQueryTasks(TaskQueryImpl taskQuery);
@Select("<script>SELECT COUNT(ID) FROM CLASSIFICATION "
+ "<where>"
+ "<if test='key != null'>AND KEY IN(<foreach item='item' collection='key' separator=',' >#{item}</foreach>)</if> "
+ "<if test='parentClassificationKey != null'>AND PARENT_CLASSIFICATION_KEY IN(<foreach item='item' collection='parentClassificationKey' separator=',' >#{item}</foreach>)</if> "
+ "<if test='category != null'>AND CATEGORY IN(<foreach item='item' collection='category' separator=',' >#{item}</foreach>)</if> "
+ "<if test='type != null'>AND TYPE IN(<foreach item='item' collection='type' separator=',' >#{item}</foreach>)</if> "
+ "<if test='domain != null'>AND DOMAIN IN(<foreach item='item' collection='domain' separator=',' >#{item}</foreach>)</if> "
+ "<if test='validInDomain != null'>AND VALID_IN_DOMAIN = #{validInDomain}</if> "
+ "<if test='created != null'>AND CREATED IN(<foreach item='item' collection='created' separator=',' >SUBSTRING(#{item}, 1, 10)</foreach>)</if> "
+ "<if test='name != null'>AND NAME IN(<foreach item='item' collection='name' separator=',' >#{item}</foreach>)</if> "
+ "<if test='description != null'>AND DESCRIPTION like #{description}</if> "
+ "<if test='priority != null'>AND PRIORITY IN(<foreach item='item' collection='priority' separator=',' >#{item}</foreach>)</if> "
+ "<if test='serviceLevel != null'>AND SERVICE_LEVEL IN(<foreach item='item' collection='serviceLevel' separator=',' >#{item}</foreach>)</if> "
+ "<if test='applicationEntryPoint != null'>AND APPLICATION_ENTRY_POINT IN(<foreach item='item' collection='applicationEntryPoint' separator=',' >#{item}</foreach>)</if> "
+ "<if test='customFields != null'>AND (CUSTOM_1 IN(<foreach item='item' collection='customFields' separator=',' >#{item}</foreach>) OR CUSTOM_2 IN(<foreach item='item' collection='customFields' separator=',' >#{item}</foreach>) OR CUSTOM_3 IN(<foreach item='item' collection='customFields' separator=',' >#{item}</foreach>) OR CUSTOM_4 IN(<foreach item='item' collection='customFields' separator=',' >#{item}</foreach>) OR CUSTOM_5 IN(<foreach item='item' collection='customFields' separator=',' >#{item}</foreach>) OR CUSTOM_6 IN(<foreach item='item' collection='customFields' separator=',' >#{item}</foreach>) OR CUSTOM_7 IN(<foreach item='item' collection='customFields' separator=',' >#{item}</foreach>) OR CUSTOM_8 IN(<foreach item='item' collection='customFields' separator=',' >#{item}</foreach>))</if> "
+ "</where>"
+ "</script>")
Long countQueryClassifications(ClassificationQueryImpl classificationQuery);
@Select("<script>SELECT COUNT(ID) FROM OBJECT_REFERENCE "
+ "<where>"
+ "<if test='company != null'>AND COMPANY IN(<foreach item='item' collection='company' separator=',' >#{item}</foreach>)</if> "
+ "<if test='system != null'>AND SYSTEM IN(<foreach item='item' collection='system' separator=',' >#{item}</foreach>)</if> "
+ "<if test='systemInstance != null'>AND SYSTEM_INSTANCE IN(<foreach item='item' collection='systemInstance' separator=',' >#{item}</foreach>)</if> "
+ "<if test='type != null'>AND TYPE IN(<foreach item='item' collection='type' separator=',' >#{item}</foreach>)</if> "
+ "<if test='value != null'>AND VALUE IN(<foreach item='item' collection='value' separator=',' >#{item}</foreach>)</if> "
+ "</where>"
+ "</script>")
Long countQueryObjectReferences(ObjectReferenceQueryImpl objectReference);
@Select("<script>SELECT COUNT(ID) 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> "
+ "<if test='keyIn != null'>AND UPPER(w.KEY) IN(<foreach item='item' collection='keyIn' separator=',' >#{item}</foreach>)</if> "
+ "<if test='keyLike != null'>AND (<foreach item='item' collection='keyLike' separator=' OR ' >UPPER(w.KEY) LIKE #{item}</foreach>)</if> "
+ "<if test='nameIn != null'>AND UPPER(w.NAME) IN(<foreach item='item' collection='nameIn' separator=',' >#{item}</foreach>)</if> "
+ "<if test='nameLike != null'>AND (<foreach item='item' collection='nameLike' separator=' OR ' >UPPER(w.NAME) LIKE #{item}</foreach>)</if> "
+ "<if test='keyOrNameLike != null'>AND (<foreach item='item' collection='keyOrNameLike' separator=' OR ' >UPPER(w.NAME) LIKE #{item} OR UPPER(w.KEY) LIKE #{item}</foreach>)</if> "
+ "<if test='domain != null'>AND w.DOMAIN IN(<foreach item='item' collection='domain' separator=',' >#{item}</foreach>)</if> "
+ "<if test='type!= null'>AND w.TYPE IN(<foreach item='item' collection='type' separator=',' >#{item}</foreach>)</if> "
+ "<if test='createdAfter != null'>AND w.CREATED &gt; #{createdAfter}</if> "
+ "<if test='createdBefore != null'>AND w.CREATED &lt; #{createdBefore}</if> "
+ "<if test='modifiedAfter != null'>AND w.MODIFIED &gt; #{modifiedAfter}</if> "
+ "<if test='modifiedBefore != null'>AND w.MODIFIED &lt; #{modifiedBefore}</if> "
+ "<if test='descriptionLike != null'>AND UPPER(w.DESCRIPTION) like #{descriptionLike}</if> "
+ "<if test='accessId != null'>AND a.ACCESS_ID IN(<foreach item='item' collection='accessId' separator=',' >#{item}</foreach>) AND PERM_READ = 1 </if> "
+ "<if test='authorization != null'>AND "
+ "<if test=\"authorization.name().equals('OPEN')\">PERM_OPEN</if> "
+ "<if test=\"authorization.name().equals('READ')\">PERM_READ</if>"
+ "<if test=\"authorization.name().equals('APPEND')\">PERM_APPEND</if>"
+ "<if test=\"authorization.name().equals('TRANSFER')\">PERM_TRANSFER</if>"
+ "<if test=\"authorization.name().equals('DISTRIBUTE')\">PERM_DISTRIBUTE</if>"
+ "<if test=\"authorization.name().equals('CUSTOM_1')\">PERM_CUSTOM_1</if>"
+ "<if test=\"authorization.name().equals('CUSTOM_2')\">PERM_CUSTOM_2</if>"
+ "<if test=\"authorization.name().equals('CUSTOM_3')\">PERM_CUSTOM_3</if>"
+ "<if test=\"authorization.name().equals('CUSTOM_4')\">PERM_CUSTOM_4</if>"
+ "<if test=\"authorization.name().equals('CUSTOM_5')\">PERM_CUSTOM_5</if>"
+ "<if test=\"authorization.name().equals('CUSTOM_6')\">PERM_CUSTOM_6</if>"
+ "<if test=\"authorization.name().equals('CUSTOM_7')\">PERM_CUSTOM_7</if>"
+ "<if test=\"authorization.name().equals('CUSTOM_8')\">PERM_CUSTOM_8</if> = 1 "
+ "</if>"
+ "</where>"
+ "</script>")
Long countQueryWorkbaskets(WorkbasketQueryImpl workbasketQuery);
}

View File

@ -0,0 +1,171 @@
package acceptance.classification;
import static org.hamcrest.core.IsEqual.equalTo;
import static org.junit.Assert.assertThat;
import java.util.List;
import org.h2.store.fs.FileUtils;
import org.junit.AfterClass;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import acceptance.AbstractAccTest;
import pro.taskana.ClassificationService;
import pro.taskana.ClassificationSummary;
import pro.taskana.exceptions.NotAuthorizedException;
import pro.taskana.exceptions.TaskanaRuntimeException;
import pro.taskana.security.JAASRunner;
/**
* Acceptance test for all "query classifications with pagination" scenarios.
*/
@RunWith(JAASRunner.class)
public class QueryClassificationWithPaginationAccTest extends AbstractAccTest {
public QueryClassificationWithPaginationAccTest() {
super();
}
@Test
public void testGetFirstPageOfClassificationQueryWithOffset() throws NotAuthorizedException {
ClassificationService classificationService = taskanaEngine.getClassificationService();
List<ClassificationSummary> results = classificationService.createClassificationQuery()
.domain("DOMAIN_A")
.list(0, 5);
assertThat(results.size(), equalTo(5));
}
@Test
public void testGetSecondPageOfClassificationQueryWithOffset() throws NotAuthorizedException {
ClassificationService classificationService = taskanaEngine.getClassificationService();
List<ClassificationSummary> results = classificationService.createClassificationQuery()
.domain("DOMAIN_A")
.list(5, 5);
assertThat(results.size(), equalTo(5));
}
@Test
public void testListOffsetAndLimitOutOfBounds() throws NotAuthorizedException {
ClassificationService classificationService = taskanaEngine.getClassificationService();
// both will be 0, working
List<ClassificationSummary> results = classificationService.createClassificationQuery()
.domain("DOMAIN_A")
.list(-1, -3);
assertThat(results.size(), equalTo(0));
// limit will be 0
results = classificationService.createClassificationQuery()
.domain("DOMAIN_A")
.list(1, -3);
assertThat(results.size(), equalTo(0));
// offset will be 0
results = classificationService.createClassificationQuery()
.domain("DOMAIN_A")
.list(-1, 3);
assertThat(results.size(), equalTo(3));
}
@Test
public void testPaginationWithPages() throws NotAuthorizedException {
ClassificationService classificationService = taskanaEngine.getClassificationService();
// Getting full page
int pageNumber = 1;
int pageSize = 4;
List<ClassificationSummary> results = classificationService.createClassificationQuery()
.domain("DOMAIN_A")
.listPage(pageNumber, pageSize);
assertThat(results.size(), equalTo(4));
// Getting full page
pageNumber = 3;
pageSize = 4;
results = classificationService.createClassificationQuery()
.domain("DOMAIN_A")
.listPage(pageNumber, pageSize);
assertThat(results.size(), equalTo(4));
// Getting last results on 1 big page
pageNumber = 0;
pageSize = 100;
results = classificationService.createClassificationQuery()
.domain("DOMAIN_A")
.listPage(pageNumber, pageSize);
assertThat(results.size(), equalTo(16));
// Getting last results on multiple pages
pageNumber = 1;
pageSize = 10;
results = classificationService.createClassificationQuery()
.domain("DOMAIN_A")
.listPage(pageNumber, pageSize);
assertThat(results.size(), equalTo(6));
}
@Test
public void testPaginationNullAndNegativeLimitsIgnoring() throws NotAuthorizedException {
ClassificationService classificationService = taskanaEngine.getClassificationService();
// 0 limit/size = 0 results
int pageNumber = 1;
int pageSize = 0;
List<ClassificationSummary> results = classificationService.createClassificationQuery()
.domain("DOMAIN_A")
.listPage(pageNumber, pageSize);
assertThat(results.size(), equalTo(0));
// Negative will be 0 = all results
pageNumber = 1;
pageSize = -1;
results = classificationService.createClassificationQuery()
.domain("DOMAIN_A")
.listPage(pageNumber, pageSize);
assertThat(results.size(), equalTo(0));
// Negative page = first page
pageNumber = -1;
pageSize = 10;
results = classificationService.createClassificationQuery()
.domain("DOMAIN_A")
.listPage(pageNumber, pageSize);
assertThat(results.size(), equalTo(10));
}
/**
* Testcase only for DB2 users, because H2 doesn´t throw a Exception when the offset is set to high.<br>
* Using DB2 should throw a unchecked RuntimeException for a offset which is out of bounds.
*
* @throws NotAuthorizedException
*/
@Ignore
@Test(expected = TaskanaRuntimeException.class)
public void testPaginationThrowingExceptionWhenPageOutOfBounds() throws NotAuthorizedException {
ClassificationService classificationService = taskanaEngine.getClassificationService();
// entrypoint set outside result amount
int pageNumber = 5;
int pageSize = 10;
classificationService.createClassificationQuery()
.domain("DOMAIN_A")
.listPage(pageNumber, pageSize);
}
@Test
public void testCountOfClassificationsQuery()
throws NotAuthorizedException {
ClassificationService classificationService = taskanaEngine.getClassificationService();
long count = classificationService.createClassificationQuery()
.domain("DOMAIN_A")
.count();
assertThat(count, equalTo(16L));
}
@AfterClass
public static void cleanUpClass() {
FileUtils.deleteRecursive("~/data", true);
}
}

View File

@ -0,0 +1,147 @@
package acceptance.objectreference;
import static org.hamcrest.core.IsEqual.equalTo;
import static org.junit.Assert.assertThat;
import java.util.List;
import org.h2.store.fs.FileUtils;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import acceptance.AbstractAccTest;
import pro.taskana.ObjectReferenceQuery;
import pro.taskana.TaskQuery;
import pro.taskana.TaskService;
import pro.taskana.exceptions.NotAuthorizedException;
import pro.taskana.exceptions.TaskanaRuntimeException;
import pro.taskana.model.ObjectReference;
import pro.taskana.security.JAASRunner;
/**
* Acceptance test for all "query classifications with pagination" scenarios.
*/
@RunWith(JAASRunner.class)
public class QueryObjectreferencesWithPaginationAccTest extends AbstractAccTest {
private TaskService taskService;
private TaskQuery taskQuery;
private ObjectReferenceQuery objRefQuery;
public QueryObjectreferencesWithPaginationAccTest() {
super();
}
@Before
public void before() {
taskService = taskanaEngine.getTaskService();
taskQuery = taskService.createTaskQuery();
objRefQuery = taskQuery.createObjectReferenceQuery();
}
@Test
public void testGetFirstPageOfObjectRefQueryWithOffset() throws NotAuthorizedException {
List<ObjectReference> results = objRefQuery.list(0, 5);
assertThat(results.size(), equalTo(3));
}
@Test
public void testGetSecondPageOfObjectRefQueryWithOffset() throws NotAuthorizedException {
List<ObjectReference> results = objRefQuery.list(2, 5);
assertThat(results.size(), equalTo(1));
}
@Test
public void testListOffsetAndLimitOutOfBounds() throws NotAuthorizedException {
// both will be 0, working
List<ObjectReference> results = objRefQuery.list(-1, -3);
assertThat(results.size(), equalTo(0));
// limit will be 0
results = objRefQuery.list(1, -3);
assertThat(results.size(), equalTo(0));
// offset will be 0
results = objRefQuery.list(-1, 3);
assertThat(results.size(), equalTo(3));
}
@Test
public void testPaginationWithPages() throws NotAuthorizedException {
// Getting full page
int pageNumber = 0;
int pageSize = 10;
List<ObjectReference> results = objRefQuery.listPage(pageNumber, pageSize);
assertThat(results.size(), equalTo(3));
// Getting full page
pageNumber = 1;
pageSize = 2;
results = objRefQuery.listPage(pageNumber, pageSize);
assertThat(results.size(), equalTo(1));
// Getting last results on 1 big page
pageNumber = 0;
pageSize = 100;
results = objRefQuery.listPage(pageNumber, pageSize);
assertThat(results.size(), equalTo(3));
// Getting last results on multiple pages
pageNumber = 1;
pageSize = 2;
results = objRefQuery.listPage(pageNumber, pageSize);
assertThat(results.size(), equalTo(1));
}
@Test
public void testPaginationNullAndNegativeLimitsIgnoring() throws NotAuthorizedException {
// 0 limit/size = 0 results
int pageNumber = 1;
int pageSize = 0;
List<ObjectReference> results = objRefQuery.listPage(pageNumber, pageSize);
assertThat(results.size(), equalTo(0));
// Negative will be 0 = all results
pageNumber = 1;
pageSize = -1;
results = objRefQuery.listPage(pageNumber, pageSize);
assertThat(results.size(), equalTo(0));
// Negative page = first page
pageNumber = -1;
pageSize = 10;
results = objRefQuery.listPage(pageNumber, pageSize);
assertThat(results.size(), equalTo(3));
}
/**
* Testcase only for DB2 users, because H2 doesn´t throw a Exception when the offset is set to high.<br>
* Using DB2 should throw a unchecked RuntimeException for a offset which is out of bounds.
*
* @throws NotAuthorizedException
*/
@Ignore
@Test(expected = TaskanaRuntimeException.class)
public void testPaginationThrowingExceptionWhenPageOutOfBounds() throws NotAuthorizedException {
// entrypoint set outside result amount
int pageNumber = 5;
int pageSize = 10;
objRefQuery.listPage(pageNumber, pageSize);
}
@Test
public void testCountOfClassificationsQuery()
throws NotAuthorizedException {
long count = objRefQuery.count();
assertThat(count, equalTo(3L));
}
@AfterClass
public static void cleanUpClass() {
FileUtils.deleteRecursive("~/data", true);
}
}

View File

@ -145,14 +145,13 @@ public class CreateTaskAccTest extends AbstractAccTest {
WorkbasketNotFoundException, TaskAlreadyExistException, InvalidWorkbasketException {
TaskService taskService = taskanaEngine.getTaskService();
Task createdTask = null;
Task newTask = makeNewTask(taskService);
newTask.addAttachment(createAttachment("DOCTYPE_DEFAULT",
null,
"E-MAIL", "2018-01-15", createSimpleCustomProperties(3)));
try {
createdTask = taskService.createTask(newTask);
fail("taskService should have thrown InvalidArgumentException.");
taskService.createTask(newTask);
fail("Should have thrown an InvalidArgumentException, becasue Attachment-ObjRef is null.");
} catch (InvalidArgumentException ex) {
// nothing to do
}
@ -162,8 +161,8 @@ public class CreateTaskAccTest extends AbstractAccTest {
createObjectReference("COMPANY_A", "SYSTEM_B", "INSTANCE_B", "ArchiveId", null),
"E-MAIL", "2018-01-15", createSimpleCustomProperties(3)));
try {
createdTask = taskService.createTask(newTask);
fail("taskService should have thrown InvalidArgumentException.");
taskService.createTask(newTask);
fail("Should have thrown an InvalidArgumentException, becasue ObjRef-Value is null.");
} catch (InvalidArgumentException ex) {
// nothing to do
}
@ -174,8 +173,8 @@ public class CreateTaskAccTest extends AbstractAccTest {
"12345678901234567890123456789012345678901234567890"),
"E-MAIL", "2018-01-15", createSimpleCustomProperties(3)));
try {
createdTask = taskService.createTask(newTask);
fail("taskService should have thrown InvalidArgumentException.");
taskService.createTask(newTask);
fail("Should have thrown an InvalidArgumentException, becasue ObjRef-Type is null.");
} catch (InvalidArgumentException ex) {
// nothing to do
}
@ -185,8 +184,8 @@ public class CreateTaskAccTest extends AbstractAccTest {
"12345678901234567890123456789012345678901234567890"),
"E-MAIL", "2018-01-15", createSimpleCustomProperties(3)));
try {
createdTask = taskService.createTask(newTask);
fail("taskService should have thrown InvalidArgumentException.");
taskService.createTask(newTask);
fail("Should have thrown an InvalidArgumentException, becasue ObjRef-SystemInstance is null.");
} catch (InvalidArgumentException ex) {
// nothing to do
}
@ -196,8 +195,8 @@ public class CreateTaskAccTest extends AbstractAccTest {
"12345678901234567890123456789012345678901234567890"),
"E-MAIL", "2018-01-15", createSimpleCustomProperties(3)));
try {
createdTask = taskService.createTask(newTask);
fail("taskService should have thrown InvalidArgumentException.");
taskService.createTask(newTask);
fail("Should have thrown an InvalidArgumentException, becasue ObjRef-System is null.");
} catch (InvalidArgumentException ex) {
// nothing to do
}
@ -207,12 +206,11 @@ public class CreateTaskAccTest extends AbstractAccTest {
"12345678901234567890123456789012345678901234567890"),
"E-MAIL", "2018-01-15", createSimpleCustomProperties(3)));
try {
createdTask = taskService.createTask(newTask);
fail("taskService should have thrown InvalidArgumentException.");
taskService.createTask(newTask);
fail("Should have thrown an InvalidArgumentException, becasue ObjRef-Company is null.");
} catch (InvalidArgumentException ex) {
// nothing to do
}
}
private Task makeNewTask(TaskService taskService) throws ClassificationNotFoundException {
@ -302,74 +300,67 @@ public class CreateTaskAccTest extends AbstractAccTest {
TaskService taskService = taskanaEngine.getTaskService();
Task newTask = taskService.newTask("USER_1_1");
newTask.setClassificationKey("T2100");
Task createdTask;
try {
createdTask = taskService.createTask(newTask);
taskService.createTask(newTask);
fail("Should have thrown an InvalidArgumentException, becasue ObjRef is null.");
} catch (InvalidArgumentException ex) {
// nothing to do
}
// Exception
newTask = taskService.newTask("USER_1_1");
newTask.setClassificationKey("T2100");
newTask.setPrimaryObjRef(createObjectReference("COMPANY_A", "SYSTEM_A", "INSTANCE_A", "VNR", null));
try {
createdTask = taskService.createTask(newTask);
taskService.createTask(newTask);
fail("Should have thrown an InvalidArgumentException, becasue ObjRef-Value is null.");
} catch (InvalidArgumentException ex) {
// nothing to do
}
// Exception
newTask = taskService.newTask("USER_1_1");
newTask.setClassificationKey("T2100");
newTask.setPrimaryObjRef(createObjectReference("COMPANY_A", "SYSTEM_A", "INSTANCE_A", null, "1234567"));
try {
createdTask = taskService.createTask(newTask);
taskService.createTask(newTask);
fail("Should have thrown an InvalidArgumentException, becasue ObjRef-Type is null.");
} catch (InvalidArgumentException ex) {
// nothing to do
}
// Exception
newTask = taskService.newTask("USER_1_1");
newTask.setClassificationKey("T2100");
newTask.setPrimaryObjRef(createObjectReference("COMPANY_A", "SYSTEM_A", null, "VNR", "1234567"));
try {
createdTask = taskService.createTask(newTask);
taskService.createTask(newTask);
fail("Should have thrown an InvalidArgumentException, becasue ObjRef-SystemInstances is null.");
} catch (InvalidArgumentException ex) {
// nothing to do
}
// Exception
newTask = taskService.newTask("USER_1_1");
newTask.setClassificationKey("T2100");
newTask.setPrimaryObjRef(createObjectReference("COMPANY_A", null, "INSTANCE_A", "VNR", "1234567"));
try {
createdTask = taskService.createTask(newTask);
taskService.createTask(newTask);
fail("Should have thrown an InvalidArgumentException, becasue ObjRef-System is null.");
} catch (InvalidArgumentException ex) {
// nothing to do
}
// Exception
newTask = taskService.newTask("USER_1_1");
newTask.setClassificationKey("T2100");
newTask.setPrimaryObjRef(createObjectReference(null, "SYSTEM_A", "INSTANCE_A", "VNR", "1234567"));
try {
createdTask = taskService.createTask(newTask);
taskService.createTask(newTask);
fail("Should have thrown an InvalidArgumentException, becasue ObjRef-Company is null.");
} catch (InvalidArgumentException ex) {
// nothing to do
}
// Exception
}
@WithAccessId(

View File

@ -36,7 +36,7 @@ public class QueryTasksByWorkbasketAccTest extends AbstractAccTest {
public void testThrowsExceptionIfNoOpenerPermissionOnQueriedWorkbasket()
throws SQLException, NotAuthorizedException, InvalidArgumentException {
TaskService taskService = taskanaEngine.getTaskService();
List<TaskSummary> results = taskService.createTaskQuery()
taskService.createTaskQuery()
.workbasketKeyIn("USER_2_1")
.list();
}
@ -48,7 +48,7 @@ public class QueryTasksByWorkbasketAccTest extends AbstractAccTest {
public void testThrowsExceptionIfNoOpenerPermissionOnAtLeastOneQueriedWorkbasket()
throws SQLException, NotAuthorizedException, InvalidArgumentException {
TaskService taskService = taskanaEngine.getTaskService();
List<TaskSummary> results = taskService.createTaskQuery()
taskService.createTaskQuery()
.workbasketKeyIn("USER_1_1", "USER_2_1")
.list();
}

View File

@ -17,6 +17,7 @@ import pro.taskana.TaskService;
import pro.taskana.TaskSummary;
import pro.taskana.exceptions.InvalidArgumentException;
import pro.taskana.exceptions.NotAuthorizedException;
import pro.taskana.exceptions.TaskanaRuntimeException;
import pro.taskana.security.JAASRunner;
import pro.taskana.security.WithAccessId;
@ -34,42 +35,165 @@ public class QueryTasksWithPaginationAccTest extends AbstractAccTest {
userName = "teamlead_1",
groupNames = {"group_1"})
@Test
public void testGetFirstPageOfTaskQuery()
public void testGetFirstPageOfTaskQueryWithOffset()
throws SQLException, NotAuthorizedException, InvalidArgumentException {
TaskService taskService = taskanaEngine.getTaskService();
List<TaskSummary> results = taskService.createTaskQuery()
.workbasketKeyIn("GPK_KSC")
.list(0, 10);
assertThat(results.size(), equalTo(10));
assertThat(results.get(0).getTaskId(), equalTo("TKI:000000000000000000000000000000000003"));
}
@WithAccessId(
userName = "teamlead_1",
groupNames = {"group_1"})
@Test
public void testSecondPageOfTaskQuery()
public void testSecondPageOfTaskQueryWithOffset()
throws SQLException, NotAuthorizedException, InvalidArgumentException {
TaskService taskService = taskanaEngine.getTaskService();
List<TaskSummary> results = taskService.createTaskQuery()
.workbasketKeyIn("GPK_KSC")
.list(10, 10);
assertThat(results.size(), equalTo(10));
assertThat(results.get(0).getTaskId(), equalTo("TKI:000000000000000000000000000000000013"));
}
@WithAccessId(
userName = "teamlead_1",
groupNames = {"group_1"})
@Test
public void testListOffsetAndLimitOutOfBounds()
throws SQLException, NotAuthorizedException, InvalidArgumentException {
TaskService taskService = taskanaEngine.getTaskService();
// both will be 0, working
List<TaskSummary> results = taskService.createTaskQuery()
.workbasketKeyIn("GPK_KSC")
.list(-1, -3);
assertThat(results.size(), equalTo(0));
// limit will be 0
results = taskService.createTaskQuery()
.workbasketKeyIn("GPK_KSC")
.list(1, -3);
assertThat(results.size(), equalTo(0));
// offset will be 0
results = taskService.createTaskQuery()
.workbasketKeyIn("GPK_KSC")
.list(-1, 3);
assertThat(results.size(), equalTo(3));
}
@WithAccessId(
userName = "teamlead_1",
groupNames = {"group_1"})
@Test
public void testPaginationWithPages()
throws SQLException, NotAuthorizedException, InvalidArgumentException {
TaskService taskService = taskanaEngine.getTaskService();
// Getting full page
int pageNumber = 1;
int pageSize = 4;
List<TaskSummary> results = taskService.createTaskQuery()
.workbasketKeyIn("GPK_KSC")
.listPage(pageNumber, pageSize);
assertThat(results.size(), equalTo(4));
// Getting full page
pageNumber = 3;
pageSize = 1;
results = taskService.createTaskQuery()
.workbasketKeyIn("GPK_KSC")
.listPage(pageNumber, pageSize);
assertThat(results.size(), equalTo(1));
// Getting last results on 1 big page
pageNumber = 0;
pageSize = 100;
results = taskService.createTaskQuery()
.workbasketKeyIn("GPK_KSC")
.listPage(pageNumber, pageSize);
assertThat(results.size(), equalTo(22));
// Getting last results on multiple pages
pageNumber = 2;
pageSize = 10;
results = taskService.createTaskQuery()
.workbasketKeyIn("GPK_KSC")
.listPage(pageNumber, pageSize);
assertThat(results.size(), equalTo(2));
}
@WithAccessId(
userName = "teamlead_1",
groupNames = {"group_1"})
@Test
public void testPaginationNullAndNegativeLimitsIgnoring()
throws SQLException, NotAuthorizedException, InvalidArgumentException {
TaskService taskService = taskanaEngine.getTaskService();
// 0 limit/size = 0 results
int pageNumber = 1;
int pageSize = 0;
List<TaskSummary> results = taskService.createTaskQuery()
.workbasketKeyIn("GPK_KSC")
.listPage(pageNumber, pageSize);
assertThat(results.size(), equalTo(0));
// Negative size will be 0 = 0 results
pageNumber = 1;
pageSize = -1;
results = taskService.createTaskQuery()
.workbasketKeyIn("GPK_KSC")
.listPage(pageNumber, pageSize);
assertThat(results.size(), equalTo(0));
// Negative page = first page
pageNumber = -1;
pageSize = 10;
results = taskService.createTaskQuery()
.workbasketKeyIn("GPK_KSC")
.listPage(pageNumber, pageSize);
assertThat(results.size(), equalTo(10));
}
/**
* Testcase only for DB2 users, because H2 doesn´t throw a Exception when the offset is set to high.<br>
* Using DB2 should throw a unchecked RuntimeException for a offset which is out of bounds.
*
* @throws SQLException
* @throws NotAuthorizedException
* @throws InvalidArgumentException
*/
@Ignore
@WithAccessId(
userName = "teamlead_1",
groupNames = {"group_1"})
@Test(expected = TaskanaRuntimeException.class)
public void testPaginationThrowingExceptionWhenPageOutOfBounds()
throws SQLException, NotAuthorizedException, InvalidArgumentException {
TaskService taskService = taskanaEngine.getTaskService();
// entrypoint set outside result amount
int pageNumber = 5;
int pageSize = 10;
taskService.createTaskQuery()
.workbasketKeyIn("GPK_KSC")
.listPage(pageNumber, pageSize);
}
@WithAccessId(
userName = "teamlead_1",
groupNames = {"group_1"})
@Test
public void testCountOfTaskQuery()
throws SQLException, NotAuthorizedException, InvalidArgumentException {
// TaskService taskService = taskanaEngine.getTaskService();
// long count = taskService.createTaskQuery()
// .workbasketKeyIn("GPK_KSC")
// .count();
// assertThat(long, equalTo(21));
TaskService taskService = taskanaEngine.getTaskService();
long count = taskService.createTaskQuery()
.workbasketKeyIn("GPK_KSC")
.count();
assertThat(count, equalTo(22L));
}
@AfterClass

View File

@ -82,9 +82,8 @@ public class UpdateTaskAccTest extends AbstractAccTest {
TaskService taskService = taskanaEngine.getTaskService();
Task task = taskService.getTask("TKI:000000000000000000000000000000000000");
task.setPrimaryObjRef(null);
Task updatedTask = null;
try {
updatedTask = taskService.updateTask(task);
taskService.updateTask(task);
fail("update() should have thrown InvalidArgumentException.");
} catch (InvalidArgumentException ex) {
// nothing to do
@ -92,7 +91,7 @@ public class UpdateTaskAccTest extends AbstractAccTest {
task.setPrimaryObjRef(createObjectReference("COMPANY_A", "SYSTEM_A", "INSTANCE_A", "VNR", null));
try {
updatedTask = taskService.updateTask(task);
taskService.updateTask(task);
fail("update() should have thrown InvalidArgumentException.");
} catch (InvalidArgumentException ex) {
// nothing to do
@ -100,28 +99,28 @@ public class UpdateTaskAccTest extends AbstractAccTest {
task.setPrimaryObjRef(createObjectReference("COMPANY_A", "SYSTEM_A", "INSTANCE_A", null, "1234567"));
try {
updatedTask = taskService.updateTask(task);
taskService.updateTask(task);
fail("update() should have thrown InvalidArgumentException.");
} catch (InvalidArgumentException ex) {
// nothing to do
}
task.setPrimaryObjRef(createObjectReference("COMPANY_A", "SYSTEM_A", null, "VNR", "1234567"));
try {
updatedTask = taskService.updateTask(task);
taskService.updateTask(task);
fail("update() should have thrown InvalidArgumentException.");
} catch (InvalidArgumentException ex) {
// nothing to do
}
task.setPrimaryObjRef(createObjectReference("COMPANY_A", null, "INSTANCE_A", "VNR", "1234567"));
try {
updatedTask = taskService.updateTask(task);
taskService.updateTask(task);
fail("update() should have thrown InvalidArgumentException.");
} catch (InvalidArgumentException ex) {
// nothing to do
}
task.setPrimaryObjRef(createObjectReference(null, "SYSTEM_A", "INSTANCE_A", "VNR", "1234567"));
try {
updatedTask = taskService.updateTask(task);
taskService.updateTask(task);
fail("update() should have thrown InvalidArgumentException.");
} catch (InvalidArgumentException ex) {
// nothing to do
@ -209,7 +208,7 @@ public class UpdateTaskAccTest extends AbstractAccTest {
TaskService taskService = taskanaEngine.getTaskService();
Task task = taskService.getTask("TKI:000000000000000000000000000000000000");
((TaskImpl) task).setWorkbasketKey("USER_2_2");
Task updatedTask = taskService.updateTask(task);
taskService.updateTask(task);
}
@AfterClass

View File

@ -52,10 +52,10 @@ public class GetWorkbasketAccTest extends AbstractAccTest {
}
@WithAccessId(
userName = "user_1_1",
groupNames = {"group_1"})
@Test
public void testGetWorkbasketPermissions() {
userName = "user_1_1",
groupNames = {"group_1"})
@Test
public void testGetWorkbasketPermissions() {
WorkbasketService workbasketService = taskanaEngine.getWorkbasketService();
List<WorkbasketAuthorization> permissions = workbasketService.getPermissionsForWorkbasket("USER_1_2");
@ -71,7 +71,7 @@ public class GetWorkbasketAccTest extends AbstractAccTest {
throws SQLException, NotAuthorizedException, InvalidArgumentException, WorkbasketNotFoundException,
InvalidWorkbasketException {
WorkbasketService workbasketService = taskanaEngine.getWorkbasketService();
Workbasket workbasket = workbasketService.getWorkbasket("INVALID_ID");
workbasketService.getWorkbasket("INVALID_ID");
}
@Test(expected = NotAuthorizedException.class)
@ -79,7 +79,7 @@ public class GetWorkbasketAccTest extends AbstractAccTest {
throws SQLException, NotAuthorizedException, InvalidArgumentException, WorkbasketNotFoundException,
InvalidWorkbasketException {
WorkbasketService workbasketService = taskanaEngine.getWorkbasketService();
Workbasket workbasket = workbasketService.getWorkbasket("WBI:100000000000000000000000000000000001");
workbasketService.getWorkbasket("WBI:100000000000000000000000000000000001");
}
@AfterClass

View File

@ -220,7 +220,6 @@ public class QueryWorkbasketAccTest extends AbstractAccTest {
.orderByName()
.orderByName()
.list();
fail("WorkbasketQuery should have thrown InvalidRequestException.");
} catch (InvalidRequestException ignored) {
// nothing to do
@ -232,7 +231,6 @@ public class QueryWorkbasketAccTest extends AbstractAccTest {
.orderByKey()
.orderByKey()
.list();
fail("WorkbasketQuery should have thrown InvalidRequestException.");
} catch (InvalidRequestException ignored) {
// nothing to do
@ -244,34 +242,34 @@ public class QueryWorkbasketAccTest extends AbstractAccTest {
.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();
.ascending();
fail("WorkbasketQuery should have thrown InvalidRequestException.");
} catch (InvalidRequestException ignored) {
// nothing to do
}
try {
workbasketService.createWorkbasketQuery()
.nameLike("%Gruppenpostkorb KSC%")
@ -279,11 +277,11 @@ public class QueryWorkbasketAccTest extends AbstractAccTest {
.ascending()
.descending()
.list();
fail("WorkbasketQuery should have thrown InvalidRequestException.");
} catch (InvalidRequestException ignored) {
// nothing to do
}
try {
workbasketService.createWorkbasketQuery()
.nameLike("%Gruppenpostkorb KSC%")
@ -291,23 +289,20 @@ public class QueryWorkbasketAccTest extends AbstractAccTest {
.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
}
}
}

View File

@ -0,0 +1,177 @@
package acceptance.workbasket;
import static org.hamcrest.core.IsEqual.equalTo;
import static org.junit.Assert.assertThat;
import java.sql.SQLException;
import java.util.List;
import org.h2.store.fs.FileUtils;
import org.junit.AfterClass;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import acceptance.AbstractAccTest;
import pro.taskana.WorkbasketService;
import pro.taskana.WorkbasketSummary;
import pro.taskana.exceptions.InvalidArgumentException;
import pro.taskana.exceptions.NotAuthorizedException;
import pro.taskana.exceptions.TaskanaRuntimeException;
import pro.taskana.security.JAASRunner;
/**
* Acceptance test for all "query classifications with pagination" scenarios.
*/
@RunWith(JAASRunner.class)
public class QueryWorkbasketsWithPaginationAccTest extends AbstractAccTest {
public QueryWorkbasketsWithPaginationAccTest() {
super();
}
@Test
public void testGetFirstPageOfWorkbasketQueryWithOffset()
throws NotAuthorizedException {
WorkbasketService workbasketService = taskanaEngine.getWorkbasketService();
List<WorkbasketSummary> results = workbasketService.createWorkbasketQuery()
.domainIn("DOMAIN_A")
.list(0, 5);
assertThat(results.size(), equalTo(5));
}
@Test
public void testGetSecondPageOfWorkbasketQueryWithOffset()
throws NotAuthorizedException {
WorkbasketService workbasketService = taskanaEngine.getWorkbasketService();
List<WorkbasketSummary> results = workbasketService.createWorkbasketQuery()
.domainIn("DOMAIN_A")
.list(5, 5);
assertThat(results.size(), equalTo(5));
}
@Test
public void testListOffsetAndLimitOutOfBounds() throws NotAuthorizedException {
WorkbasketService workbasketService = taskanaEngine.getWorkbasketService();
// both will be 0, working
List<WorkbasketSummary> results = workbasketService.createWorkbasketQuery()
.domainIn("DOMAIN_A")
.list(-1, -3);
assertThat(results.size(), equalTo(0));
// limit will be 0
results = workbasketService.createWorkbasketQuery()
.domainIn("DOMAIN_A")
.list(1, -3);
assertThat(results.size(), equalTo(0));
// offset will be 0
results = workbasketService.createWorkbasketQuery()
.domainIn("DOMAIN_A")
.list(-1, 3);
assertThat(results.size(), equalTo(3));
}
@Test
public void testPaginationWithPages() throws NotAuthorizedException {
WorkbasketService workbasketService = taskanaEngine.getWorkbasketService();
// Getting full page
int pageNumber = 1;
int pageSize = 4;
List<WorkbasketSummary> results = workbasketService.createWorkbasketQuery()
.domainIn("DOMAIN_A")
.listPage(pageNumber, pageSize);
assertThat(results.size(), equalTo(4));
// Getting full page
pageNumber = 3;
pageSize = 1;
results = workbasketService.createWorkbasketQuery()
.domainIn("DOMAIN_A")
.listPage(pageNumber, pageSize);
assertThat(results.size(), equalTo(1));
// Getting last results on 1 big page
pageNumber = 0;
pageSize = 100;
results = workbasketService.createWorkbasketQuery()
.domainIn("DOMAIN_A")
.listPage(pageNumber, pageSize);
assertThat(results.size(), equalTo(13));
// Getting last results on multiple pages
pageNumber = 2;
pageSize = 5;
results = workbasketService.createWorkbasketQuery()
.domainIn("DOMAIN_A")
.listPage(pageNumber, pageSize);
assertThat(results.size(), equalTo(3));
}
@Test
public void testPaginationNullAndNegativeLimitsIgnoring()
throws NotAuthorizedException {
WorkbasketService workbasketService = taskanaEngine.getWorkbasketService();
// 0 limit/size = 0 results
int pageNumber = 1;
int pageSize = 0;
List<WorkbasketSummary> results = workbasketService.createWorkbasketQuery()
.domainIn("DOMAIN_A")
.listPage(pageNumber, pageSize);
assertThat(results.size(), equalTo(0));
// Negative size will be 0 = 0 results
pageNumber = 1;
pageSize = -1;
results = workbasketService.createWorkbasketQuery()
.domainIn("DOMAIN_A")
.listPage(pageNumber, pageSize);
assertThat(results.size(), equalTo(0));
// Negative page = first page
pageNumber = -1;
pageSize = 10;
results = workbasketService.createWorkbasketQuery()
.domainIn("DOMAIN_A")
.listPage(pageNumber, pageSize);
assertThat(results.size(), equalTo(10));
}
/**
* Testcase only for DB2 users, because H2 doesn´t throw a Exception when the offset is set to high.<br>
* Using DB2 should throw a unchecked RuntimeException for a offset which is out of bounds.
*
* @throws NotAuthorizedException
*/
@Ignore
@Test(expected = TaskanaRuntimeException.class)
public void testPaginationThrowingExceptionWhenPageOutOfBounds()
throws SQLException, NotAuthorizedException, InvalidArgumentException {
WorkbasketService workbasketService = taskanaEngine.getWorkbasketService();
// entrypoint set outside result amount
int pageNumber = 5;
int pageSize = 10;
workbasketService.createWorkbasketQuery()
.domainIn("DOMAIN_A")
.listPage(pageNumber, pageSize);
}
@Test
public void testCountOfWorkbasketQuery()
throws SQLException, NotAuthorizedException, InvalidArgumentException {
WorkbasketService workbasketService = taskanaEngine.getWorkbasketService();
long count = workbasketService.createWorkbasketQuery()
.domainIn("DOMAIN_A")
.count();
assertThat(count, equalTo(13L));
}
@AfterClass
public static void cleanUpClass() {
FileUtils.deleteRecursive("~/data", true);
}
}

View File

@ -0,0 +1,83 @@
package acceptance.workbasket;
import static org.hamcrest.core.IsEqual.equalTo;
import static org.junit.Assert.assertThat;
import java.util.List;
import org.h2.store.fs.FileUtils;
import org.junit.AfterClass;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import acceptance.AbstractAccTest;
import pro.taskana.WorkbasketService;
import pro.taskana.WorkbasketSummary;
import pro.taskana.exceptions.InvalidRequestException;
import pro.taskana.exceptions.NotAuthorizedException;
import pro.taskana.security.JAASRunner;
/**
* Acceptance test for all "query classifications with pagination" scenarios.
*/
@RunWith(JAASRunner.class)
public class WorkbasketQueryWithOrderedPaginationAccTest extends AbstractAccTest {
public WorkbasketQueryWithOrderedPaginationAccTest() {
super();
}
@Ignore
@Test
public void testGetFirstPageOfTaskQueryWithOffset()
throws NotAuthorizedException, InvalidRequestException {
WorkbasketService workbasketService = taskanaEngine.getWorkbasketService();
List<WorkbasketSummary> results = workbasketService.createWorkbasketQuery()
.domainIn("DOMAIN_A")
.orderByKey()
.ascending()
.list(0, 5);
assertThat(results.size(), equalTo(5));
assertThat(results.get(0).getKey(), equalTo("GPK_KSC"));
assertThat(results.get(4).getKey(), equalTo("key2"));
results = workbasketService.createWorkbasketQuery()
.domainIn("DOMAIN_A")
.orderByKey()
.descending()
.list(0, 5);
assertThat(results.size(), equalTo(5));
assertThat(results.get(0).getKey(), equalTo("USER_2_2"));
assertThat(results.get(4).getKey(), equalTo("TEAMLEAD_2"));
}
@Ignore
@Test
public void testGetSecondPageOfTaskQueryWithOffset()
throws NotAuthorizedException, InvalidRequestException {
WorkbasketService workbasketService = taskanaEngine.getWorkbasketService();
List<WorkbasketSummary> results = workbasketService.createWorkbasketQuery()
.domainIn("DOMAIN_A")
.orderByKey()
.ascending()
.list(5, 5);
assertThat(results.size(), equalTo(5));
assertThat(results.get(0).getKey(), equalTo("key3"));
assertThat(results.get(4).getKey(), equalTo("USER_1_1"));
results = workbasketService.createWorkbasketQuery()
.domainIn("DOMAIN_A")
.orderByKey()
.descending()
.list(5, 5);
assertThat(results.size(), equalTo(5));
assertThat(results.get(0).getKey(), equalTo("TEAMLEAD_1"));
assertThat(results.get(4).getKey(), equalTo("key3"));
}
@AfterClass
public static void cleanUpClass() {
FileUtils.deleteRecursive("~/data", true);
}
}

View File

@ -46,7 +46,6 @@ public class TaskQueryImplTest {
@Before
public void setup() {
when(taskanaEngine.getClassificationService()).thenReturn(classificationService);
when(taskanaEngine.getTaskService()).thenReturn(taskServiceMock);
taskQueryImpl = new TaskQueryImpl(taskanaEngine);
}

View File

@ -103,4 +103,9 @@ public class TestClassificationQuery implements ClassificationQuery {
public ClassificationSummary single() throws NotAuthorizedException {
return null;
}
@Override
public long count() throws NotAuthorizedException {
return 0;
}
}

View File

@ -32,7 +32,9 @@ INSERT INTO CLASSIFICATION VALUES('CLI:100000000000000000000000000000000016', 'T
INSERT INTO CLASSIFICATION VALUES('CLI:100000000000000000000000000000000015', 'T2100', '', 'MANUAL', 'TASK', 'DOMAIN_B', TRUE, CURRENT_TIMESTAMP, 'T-Vertragstermin VERA', 'T-Vertragstermin VERA', 22, 'P2D', '', 'VNR', '', '', '', '', '', '', '');
-- WITH PARENT CLASSIFICATIONS (MIXED DOMAIN) ---
-- DOMAIN_A
INSERT INTO CLASSIFICATION VALUES('CLI:200000000000000000000000000000000001', 'A12', 'L10000', 'EXTERN', 'TASK', 'DOMAIN_A', TRUE, CURRENT_TIMESTAMP, 'OLD-Leistungsfall', 'OLD-Leistungsfall', 1, 'P1D', '', 'VNR,RVNR,KOLVNR', '', '', '', '', '', '', '');
INSERT INTO CLASSIFICATION VALUES('CLI:200000000000000000000000000000000002', 'A13', 'T6310', 'AUTOMATIC', 'EXTERN', 'DOMAIN_A', TRUE, CURRENT_TIMESTAMP, 'Beratungsprotokoll', 'Beratungsprotokoll', 1, 'P1D', '', 'VNR,RVNR,KOLVNR, ANR', '', '', '', '', '', '', '');
-- DOMAIN_B
INSERT INTO CLASSIFICATION VALUES('CLI:200000000000000000000000000000000003', 'A12', 'T2100', 'MANUAL', 'TASK', 'DOMAIN_B', TRUE, CURRENT_TIMESTAMP, 'Widerruf', 'Widerruf', 1, 'P1D', '', 'VNR,RVNR,KOLVNR', '', '', '', '', '', '', '');
INSERT INTO CLASSIFICATION VALUES('CLI:200000000000000000000000000000000004', 'T21001', 'T2100', 'MANUAL', 'TASK', 'DOMAIN_B', TRUE, CURRENT_TIMESTAMP, 'Beratungsprotokoll', 'Beratungsprotokoll', 1, 'P1D', '', 'VNR,RVNR,KOLVNR, ANR', '', '', '', '', '', '', '');