Create access items extended

This commit is contained in:
Martin Rojas Miguel Angel 2018-08-28 14:12:50 +02:00 committed by Mustapha Zorgati
parent c6a40bb2a3
commit 131e11e7aa
10 changed files with 734 additions and 3 deletions

View File

@ -0,0 +1,16 @@
package pro.taskana;
/**
* Interface for WorkbasketAccessItemExtended. This interface is used to control access of users to workbaskets.
*
* @author mmr
*/
public interface WorkbasketAccessItemExtended extends WorkbasketAccessItem {
/**
* Returns the Key of the referenced workbasket.
*
* @return the workbasket key
*/
String getWorkbasketKey();
}

View File

@ -0,0 +1,105 @@
package pro.taskana;
/**
* WorkbasketAccessItemQuery for generating dynamic sql.
*/
public interface WorkbasketAccessItemExtendedQuery extends BaseQuery<WorkbasketAccessItemExtended> {
/**
* Add your unique entry workbasket key to your query as filter.
*
* @param keys
* the unique entry Keys
* @return the query
*/
WorkbasketAccessItemExtendedQuery workbasketKeyIn(String... keys);
/**
* Sort the query result by workbasket key.
*
* @param sortDirection
* Determines whether the result is sorted in ascending or descending order. If sortDirection is null,
* the result is sorted in ascending order
* @return the query
*/
WorkbasketAccessItemExtendedQuery orderByWorkbasketKey(SortDirection sortDirection);
/**
* Add your unique entry id to your query as filter.
*
* @param ids
* the unique entry IDs
* @return the query
*/
WorkbasketAccessItemExtendedQuery idIn(String... ids);
/**
* Add your workbasket id to your query.
*
* @param workbasketId
* the workbasket Id
* @return the query
*/
WorkbasketAccessItemExtendedQuery workbasketIdIn(String... workbasketId);
/**
* Add your accessIds to your query.
*
* @param accessId
* as access Ids
* @return the query
*/
WorkbasketAccessItemExtendedQuery accessIdIn(String... accessId);
/**
* Sort the query result by workbasket id.
*
* @param sortDirection
* Determines whether the result is sorted in ascending or descending order. If sortDirection is null,
* the result is sorted in ascending order
* @return the query
*/
WorkbasketAccessItemExtendedQuery orderByWorkbasketId(SortDirection sortDirection);
/**
* Sort the query result by access Id.
*
* @param sortDirection
* Determines whether the result is sorted in ascending or descending order. If sortDirection is null,
* the result is sorted in ascending order
* @return the query
*/
WorkbasketAccessItemExtendedQuery orderByAccessId(SortDirection sortDirection);
/**
* Sort the query result by Id.
*
* @param sortDirection
* Determines whether the result is sorted in ascending or descending order. If sortDirection is null,
* the result is sorted in ascending order
* @return the query
*/
WorkbasketAccessItemExtendedQuery orderById(SortDirection sortDirection);
/**
* Add keys to your query. The keys are compared case-insensitively to the keys of access items with the SQL LIKE
* operator. You may add a wildcard like '%' to search generically. If you specify multiple keys they are connected
* with an OR operator, this is, the query searches access items workbaskets whose keys are like key1 or like key2, etc.
*
* @param key
* the keys as Strings
* @return the query
*/
WorkbasketAccessItemExtendedQuery workbasketKeyLike(String... key);
/**
* Add keys to your query. The keys are compared case-insensitively to the keys of access items with the SQL LIKE
* operator. You may add a wildcard like '%' to search generically. If you specify multiple keys they are connected
* with an OR operator, this is, the query searches access items whose ids are like id1 or like id2, etc.
*
* @param ids
* the ids as Strings
* @return the query
*/
WorkbasketAccessItemExtendedQuery accessIdLike(String... ids);
}

View File

@ -87,6 +87,17 @@ public interface WorkbasketService {
*/
WorkbasketAccessItem newWorkbasketAccessItem(String workbasketId, String accessId);
/**
* Returns a new WorkbasketAccessItemExtended which is not persisted.
*
* @param workbasketId
* the workbasket id used to identify the referenced workbasket
* @param accessId
* the group id or user id for which access is controlled
* @return new WorkbasketAccessItem
*/
WorkbasketAccessItemExtended newWorkbasketAccessItemExtended(String workbasketId, String accessId);
/**
* Create and persist a new {@link WorkbasketAccessItem} with a WorkbasketId, an accessId and permissions.
*
@ -204,6 +215,15 @@ public interface WorkbasketService {
*/
WorkbasketAccessItemQuery createWorkbasketAccessItemQuery() throws NotAuthorizedException;
/**
* This method provides a query builder for querying the database.
*
* @return a {@link WorkbasketAccessItemExtendedQuery}
* @throws NotAuthorizedException
* if the current user is not member of role BUSINESS_ADMIN or ADMIN
*/
WorkbasketAccessItemExtendedQuery createWorkbasketAccessItemExtendedQuery() throws NotAuthorizedException;
/**
* Returns a new workbasket which is not persisted.
*

View File

@ -0,0 +1,123 @@
package pro.taskana.impl;
import pro.taskana.WorkbasketAccessItemExtended;
/**
* WorkbasketAccessItemExtendedImpl Entity.
*/
public class WorkbasketAccessItemExtendedImpl extends WorkbasketAccessItemImpl implements WorkbasketAccessItemExtended {
private String workbasketKey;
@Override
public String getWorkbasketKey() {
return workbasketKey;
}
public void setWorkbasketKey(String workbasketKey) {
this.workbasketKey = workbasketKey;
}
@Override
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
result = prime * result + ((workbasketKey == null) ? 0 : workbasketKey.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
WorkbasketAccessItemExtendedImpl other = (WorkbasketAccessItemExtendedImpl) obj;
if (getAccessId() == null) {
if (other.getAccessId() != null) {
return false;
}
} else if (!getAccessId().equals(other.getAccessId())) {
return false;
}
if (getId() == null) {
if (other.getId() != null) {
return false;
}
} else if (!getId().equals(other.getId())) {
return false;
}
if (isPermAppend() != other.isPermAppend()) {
return false;
}
if (isPermCustom1() != other.isPermCustom1()) {
return false;
}
if (isPermCustom10() != other.isPermCustom10()) {
return false;
}
if (isPermCustom11() != other.isPermCustom11()) {
return false;
}
if (isPermCustom12() != other.isPermCustom12()) {
return false;
}
if (isPermCustom2() != other.isPermCustom2()) {
return false;
}
if (isPermCustom3() != other.isPermCustom3()) {
return false;
}
if (isPermCustom4() != other.isPermCustom4()) {
return false;
}
if (isPermCustom5() != other.isPermCustom5()) {
return false;
}
if (isPermCustom6() != other.isPermCustom6()) {
return false;
}
if (isPermCustom7() != other.isPermCustom7()) {
return false;
}
if (isPermCustom8() != other.isPermCustom8()) {
return false;
}
if (isPermCustom9() != other.isPermCustom9()) {
return false;
}
if (isPermDistribute() != other.isPermDistribute()) {
return false;
}
if (isPermOpen() != other.isPermOpen()) {
return false;
}
if (isPermRead() != other.isPermRead()) {
return false;
}
if (isPermTransfer() != other.isPermTransfer()) {
return false;
}
if (getWorkbasketId() == null) {
if (other.getWorkbasketId() != null) {
return false;
}
} else if (!getWorkbasketId().equals(other.getWorkbasketId())) {
return false;
}
if (getWorkbasketKey() == null) {
if (other.getWorkbasketKey() != null) {
return false;
}
} else if (!getWorkbasketKey().equals(other.getWorkbasketKey())) {
return false;
}
return true;
}
}

View File

@ -0,0 +1,290 @@
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;
import pro.taskana.TaskanaEngine;
import pro.taskana.WorkbasketAccessItemExtended;
import pro.taskana.WorkbasketAccessItemExtendedQuery;
import pro.taskana.exceptions.TaskanaRuntimeException;
import pro.taskana.impl.util.LoggerUtils;
/**
* WorkbasketAccessItemQuery for generating dynamic SQL.
*
* @author mmr
*/
public class WorkbasketAccessItemExtendedQueryImpl implements
WorkbasketAccessItemExtendedQuery {
private static final String LINK_TO_COUNTER = "pro.taskana.mappings.QueryMapper.countQueryWorkbasketAccessItems";
private static final String LINK_TO_MAPPER_EXTENDED = "pro.taskana.mappings.QueryMapper.queryWorkbasketAccessItemsExtended";
private static final String LINK_TO_VALUEMAPPER_EXTENDED = "pro.taskana.mappings.QueryMapper.queryWorkbasketAccessItemExtendedColumnValues";
private static final Logger LOGGER = LoggerFactory.getLogger(WorkbasketAccessItemExtended.class);
private String[] workbasketKeyIn;
private String[] workbasketKeyLike;
private String columnName;
private String[] accessIdIn;
private String[] accessIdLike;
private String[] workbasketIdIn;
private String[] idIn;
private TaskanaEngineImpl taskanaEngine;
private List<String> orderBy;
private List<String> orderColumns;
WorkbasketAccessItemExtendedQueryImpl(TaskanaEngine taskanaEngine) {
this.taskanaEngine = (TaskanaEngineImpl) taskanaEngine;
orderBy = new ArrayList<>();
orderColumns = new ArrayList<>();
}
@Override
public WorkbasketAccessItemExtendedQuery workbasketKeyIn(String... keys) {
this.workbasketKeyIn = keys;
return this;
}
@Override
public WorkbasketAccessItemExtendedQuery orderByWorkbasketKey(SortDirection sortDirection) {
return addOrderCriteria("WB.KEY", sortDirection);
}
@Override
public WorkbasketAccessItemExtendedQuery idIn(String... ids) {
this.idIn = ids;
return this;
}
@Override
public WorkbasketAccessItemExtendedQuery workbasketIdIn(String... workbasketId) {
this.workbasketIdIn = workbasketId;
return this;
}
@Override
public WorkbasketAccessItemExtendedQuery accessIdIn(String... accessId) {
this.accessIdIn = accessId;
WorkbasketQueryImpl.lowercaseAccessIds(this.accessIdIn);
return this;
}
@Override
public WorkbasketAccessItemExtendedQuery orderByWorkbasketId(SortDirection sortDirection) {
return addOrderCriteria("WORKBASKET_ID", sortDirection);
}
@Override
public WorkbasketAccessItemExtendedQuery orderByAccessId(SortDirection sortDirection) {
return addOrderCriteria("ACCESS_ID", sortDirection);
}
@Override
public WorkbasketAccessItemExtendedQuery orderById(SortDirection sortDirection) {
return addOrderCriteria("ID", sortDirection);
}
@Override
public WorkbasketAccessItemExtendedQuery workbasketKeyLike(String... key) {
this.workbasketKeyLike = toUpperCopy(key);
return this;
}
@Override
public WorkbasketAccessItemExtendedQuery accessIdLike(String... ids) {
this.accessIdLike = toUpperCopy(ids);
return this;
}
public String[] getWorkbasketKeyIn() {
return workbasketKeyIn;
}
public void setWorkbasketKeyIn(String[] workbasketKeyIn) {
this.workbasketKeyIn = workbasketKeyIn;
}
public String[] getAccessIdLike() {
return accessIdLike;
}
public void setAccessIdLike(String[] accessIdLike) {
this.accessIdLike = accessIdLike;
}
public String[] getWorkbasketKeyLike() {
return workbasketKeyLike;
}
public void setWorkbasketKeyLike(String[] workbasketKeyLike) {
this.workbasketKeyLike = workbasketKeyLike;
}
@Override
public List<WorkbasketAccessItemExtended> list() {
LOGGER.debug("entry to list(), this = {}", this);
List<WorkbasketAccessItemExtended> result = new ArrayList<>();
try {
taskanaEngine.openConnection();
List<WorkbasketAccessItemExtendedImpl> foundAccessItems = taskanaEngine.getSqlSession()
.selectList(LINK_TO_MAPPER_EXTENDED, this);
result.addAll(foundAccessItems);
return result;
} finally {
taskanaEngine.returnConnection();
if (LOGGER.isDebugEnabled()) {
int numberOfResultObjects = result == null ? 0 : result.size();
LOGGER.debug("exit from list(). Returning {} resulting Objects: {} ", numberOfResultObjects,
LoggerUtils.listToString(result));
}
}
}
@Override
public List<WorkbasketAccessItemExtended> list(int offset, int limit) {
LOGGER.debug("entry to list(offset = {}, limit = {}), this = {}", offset, limit, this);
List<WorkbasketAccessItemExtended> result = new ArrayList<>();
try {
taskanaEngine.openConnection();
RowBounds rowBounds = new RowBounds(offset, limit);
List<WorkbasketAccessItemExtended> foundAccessItems = taskanaEngine.getSqlSession()
.selectList(LINK_TO_MAPPER_EXTENDED, this, rowBounds);
result.addAll(foundAccessItems);
return result;
} catch (PersistenceException e) {
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 {
taskanaEngine.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));
}
}
}
@Override
public List<String> listValues(String columnName, SortDirection sortDirection) {
LOGGER.debug("Entry to listValues(dbColumnName={}) this = {}", columnName, this);
List<String> result = null;
try {
taskanaEngine.openConnection();
this.columnName = columnName;
this.orderBy.clear();
this.addOrderCriteria(columnName, sortDirection);
result = taskanaEngine.getSqlSession().selectList(LINK_TO_VALUEMAPPER_EXTENDED, this);
return result;
} finally {
taskanaEngine.returnConnection();
if (LOGGER.isDebugEnabled()) {
int numberOfResultObjects = result == null ? 0 : result.size();
LOGGER.debug("Exit from listValues. Returning {} resulting Objects: {} ", numberOfResultObjects,
LoggerUtils.listToString(result));
}
}
}
@Override
public WorkbasketAccessItemExtended single() {
LOGGER.debug("entry to single(), this = {}", this);
WorkbasketAccessItemExtended accessItem = null;
try {
taskanaEngine.openConnection();
accessItem = taskanaEngine.getSqlSession().selectOne(LINK_TO_MAPPER_EXTENDED, this);
return accessItem;
} finally {
taskanaEngine.returnConnection();
LOGGER.debug("exit from single(). Returning result {} ", accessItem);
}
}
@Override
public long count() {
LOGGER.debug("entry to count(), this = {}", this);
Long rowCount = null;
try {
taskanaEngine.openConnection();
rowCount = taskanaEngine.getSqlSession().selectOne(LINK_TO_COUNTER, this);
return (rowCount == null) ? 0L : rowCount;
} finally {
taskanaEngine.returnConnection();
LOGGER.debug("exit from count(). Returning result {} ", rowCount);
}
}
public String getColumnName() {
return columnName;
}
public String[] getAccessIdIn() {
return accessIdIn;
}
public String[] getWorkbasketIdIn() {
return workbasketIdIn;
}
public String[] getIdIn() {
return idIn;
}
public List<String> getOrderColumns() {
return orderColumns;
}
public List<String> getOrderBy() {
return orderBy;
}
private WorkbasketAccessItemExtendedQuery addOrderCriteria(String colName, SortDirection sortDirection) {
String orderByDirection = " ASC";
if (sortDirection != null && SortDirection.DESCENDING.equals(sortDirection)) {
orderByDirection = " DESC";
}
orderBy.add(colName + orderByDirection);
orderColumns.add(colName);
return this;
}
static String[] toUpperCopy(String... source) {
if (source == null || source.length == 0) {
return null;
} else {
String[] target = new String[source.length];
for (int i = 0; i < source.length; i++) {
target[i] = source[i].toUpperCase();
}
return target;
}
}
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("WorkbasketAccessItemQueryImpl [idIn=");
builder.append(Arrays.toString(idIn));
builder.append(", accessIdIn=");
builder.append(Arrays.toString(accessIdIn));
builder.append(", workbasketIdIn=");
builder.append(Arrays.toString(workbasketIdIn));
builder.append(", workbasketKeyIn=");
builder.append(Arrays.toString(workbasketKeyIn));
builder.append(", orderBy=");
builder.append(orderBy);
builder.append("]");
return builder.toString();
}
}

View File

@ -4,7 +4,7 @@ import pro.taskana.WorkbasketAccessItem;
import pro.taskana.configuration.TaskanaEngineConfiguration;
/**
* WorkbasketAccessItem Entity.
* WorkbasketAccessItemImpl Entity.
*/
public class WorkbasketAccessItemImpl implements WorkbasketAccessItem {

View File

@ -16,9 +16,9 @@ import pro.taskana.exceptions.TaskanaRuntimeException;
import pro.taskana.impl.util.LoggerUtils;
/**
* WorkbasketAccessItemQuery for generating dynamic SQL.
* WorkbasketAccessItemQueryImpl for generating dynamic SQL.
*
* @author bbr
* @author mmr
*/
public class WorkbasketAccessItemQueryImpl implements WorkbasketAccessItemQuery {

View File

@ -12,6 +12,8 @@ import pro.taskana.TaskanaEngine;
import pro.taskana.TaskanaRole;
import pro.taskana.Workbasket;
import pro.taskana.WorkbasketAccessItem;
import pro.taskana.WorkbasketAccessItemExtended;
import pro.taskana.WorkbasketAccessItemExtendedQuery;
import pro.taskana.WorkbasketAccessItemQuery;
import pro.taskana.WorkbasketPermission;
import pro.taskana.WorkbasketQuery;
@ -157,6 +159,14 @@ public class WorkbasketServiceImpl implements WorkbasketService {
return accessItem;
}
@Override
public WorkbasketAccessItemExtended newWorkbasketAccessItemExtended(String workbasketId, String accessId) {
WorkbasketAccessItemExtendedImpl accessItem = new WorkbasketAccessItemExtendedImpl();
accessItem.setWorkbasketId(workbasketId);
accessItem.setAccessId(accessId);
return accessItem;
}
@Override
public WorkbasketAccessItem createWorkbasketAccessItem(WorkbasketAccessItem workbasketAccessItem)
throws InvalidArgumentException, NotAuthorizedException, WorkbasketNotFoundException {
@ -761,4 +771,10 @@ public class WorkbasketServiceImpl implements WorkbasketService {
return new WorkbasketAccessItemQueryImpl(this.taskanaEngine);
}
@Override
public WorkbasketAccessItemExtendedQuery createWorkbasketAccessItemExtendedQuery() throws NotAuthorizedException {
taskanaEngine.checkRoleMembership(TaskanaRole.ADMIN, TaskanaRole.BUSINESS_ADMIN);
return new WorkbasketAccessItemExtendedQueryImpl(this.taskanaEngine);
}
}

View File

@ -12,6 +12,8 @@ import pro.taskana.impl.ClassificationSummaryImpl;
import pro.taskana.impl.ObjectReferenceQueryImpl;
import pro.taskana.impl.TaskQueryImpl;
import pro.taskana.impl.TaskSummaryImpl;
import pro.taskana.impl.WorkbasketAccessItemExtendedImpl;
import pro.taskana.impl.WorkbasketAccessItemExtendedQueryImpl;
import pro.taskana.impl.WorkbasketAccessItemImpl;
import pro.taskana.impl.WorkbasketAccessItemQueryImpl;
import pro.taskana.impl.WorkbasketQueryImpl;
@ -609,6 +611,48 @@ public interface QueryMapper {
@Result(property = "permCustom12", column = "PERM_CUSTOM_12")})
List<WorkbasketAccessItemImpl> queryWorkbasketAccessItems(WorkbasketAccessItemQueryImpl accessItemQuery);
@Select("<script>"
+ "SELECT "
+ "WBA.ID, WORKBASKET_ID, WB.KEY, ACCESS_ID, ACCESS_NAME, 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, PERM_CUSTOM_9, PERM_CUSTOM_10, PERM_CUSTOM_11, PERM_CUSTOM_12 "
+ "from WORKBASKET_ACCESS_LIST AS WBA LEFT JOIN WORKBASKET AS WB ON WORKBASKET_ID = WB.ID"
+ "<where>"
+ "<if test='idIn != null'>AND ID IN(<foreach item='item' collection='idIn' separator=',' >#{item}</foreach>)</if> "
+ "<if test='workbasketIdIn != null'>AND WORKBASKET_ID IN(<foreach item='item' collection='workbasketIdIn' separator=',' >#{item}</foreach>)</if> "
+ "<if test='workbasketKeyIn != null'>AND WB.KEY IN(<foreach item='item' collection='workbasketKeyIn' separator=',' >#{item}</foreach>)</if> "
+ "<if test='workbasketKeyLike != null'>AND (<foreach item='item' collection='workbasketKeyLike' separator=' OR '>UPPER(WB.KEY) LIKE #{item}</foreach>)</if> "
+ "<if test='accessIdIn != null'>AND ACCESS_ID IN(<foreach item='item' collection='accessIdIn' separator=',' >#{item}</foreach>) </if> "
+ "<if test='accessIdLike != null'>AND (<foreach item='item' collection='accessIdLike' separator=' OR '>UPPER(ACCESS_ID) LIKE #{item}</foreach>)</if> "
+ "<if test='!orderColumns.isEmpty()'>AND (<foreach item='item' collection='orderColumns' separator='OR ' >${item} IS NOT NULL </foreach>)</if> "
+ "</where>"
+ "<if test='!orderBy.isEmpty()'>ORDER BY <foreach item='orderItem' collection='orderBy' separator=',' >${orderItem}</foreach></if> "
+ "<if test=\"_databaseId == 'db2'\">with UR </if> "
+ "</script>")
@Results({
@Result(property = "id", column = "ID"),
@Result(property = "workbasketId", column = "WORKBASKET_ID"),
@Result(property = "workbasketKey", column = "KEY"),
@Result(property = "accessId", column = "ACCESS_ID"),
@Result(property = "accessName", column = "ACCESS_NAME"),
@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"),
@Result(property = "permCustom9", column = "PERM_CUSTOM_9"),
@Result(property = "permCustom10", column = "PERM_CUSTOM_10"),
@Result(property = "permCustom11", column = "PERM_CUSTOM_11"),
@Result(property = "permCustom12", column = "PERM_CUSTOM_12")})
List<WorkbasketAccessItemExtendedImpl> queryWorkbasketAccessItemsExtended(WorkbasketAccessItemExtendedQueryImpl accessItemExtendedQuery);
@Select("<script> "
+ "SELECT COUNT( <if test=\"joinWithAttachments\">DISTINCT</if> t.ID) FROM TASK t "
+ "<if test=\"joinWithAttachments\">"
@ -1240,4 +1284,20 @@ public interface QueryMapper {
+ "<if test=\"_databaseId == 'db2'\">with UR </if> "
+ "</script>")
List<String> queryWorkbasketAccessItemColumnValues(WorkbasketAccessItemQueryImpl accessItemQuery);
@Select("<script>SELECT DISTINCT ${columnName} "
+ "FROM WORKBASKET_ACCESS_LIST AS WBA LEFT JOIN WORKBASKET AS WB ON WORKBASKET_ID = WB.ID"
+ "<where>"
+ "<if test='!orderBy.isEmpty()'>${columnName} IS NOT NULL</if> "
+ "<if test='idIn != null'>AND WBA.ID IN(<foreach item='item' collection='idIn' separator=',' >#{item}</foreach>)</if> "
+ "<if test='workbasketIdIn != null'>AND WORKBASKET_ID IN(<foreach item='item' collection='workbasketIdIn' separator=',' >#{item}</foreach>)</if> "
+ "<if test='workbasketKeyIn != null'>AND WB.KEY IN(<foreach item='item' collection='workbasketKeyIn' separator=',' >#{item}</foreach>)</if> "
+ "<if test='workbasketKeyLike != null'>AND (<foreach item='item' collection='workbasketKeyLike' separator=' OR '>UPPER(WB.KEY) LIKE #{item}</foreach>)</if> "
+ "<if test='accessIdIn != null'>AND ACCESS_ID IN(<foreach item='item' collection='accessIdIn' separator=',' >#{item}</foreach>) </if> "
+ "<if test='accessIdLike != null'>AND (<foreach item='item' collection='accessIdLike' separator=' OR '>UPPER(ACCESS_ID) LIKE #{item}</foreach>)</if> "
+ "</where>"
+ "<if test='!orderBy.isEmpty()'>ORDER BY <foreach item='orderItem' collection='orderBy' separator=',' >${orderItem}</foreach></if> "
+ "<if test=\"_databaseId == 'db2'\">with UR </if> "
+ "</script>")
List<String> queryWorkbasketAccessItemExtendedColumnValues(WorkbasketAccessItemExtendedQueryImpl accessItemExtendedQuery);
}

View File

@ -0,0 +1,101 @@
package acceptance.workbasket;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import java.util.List;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import acceptance.AbstractAccTest;
import pro.taskana.BaseQuery.SortDirection;
import pro.taskana.WorkbasketAccessItemExtended;
import pro.taskana.WorkbasketService;
import pro.taskana.exceptions.NotAuthorizedException;
import pro.taskana.security.JAASRunner;
import pro.taskana.security.WithAccessId;
/**
* Acceptance test for all "query access items extended for workbaskets" scenarios.
*/
@RunWith(JAASRunner.class)
public class QueryWorkbasketAccessItemsExtendedAccTest extends AbstractAccTest {
private static SortDirection asc = SortDirection.ASCENDING;
private static SortDirection desc = SortDirection.DESCENDING;
public QueryWorkbasketAccessItemsExtendedAccTest() {
super();
}
@WithAccessId(
userName = "dummy",
groupNames = {"businessadmin"})
@Test
public void testQueryWorkbasketAccessItemExtendedValuesForColumnName() throws NotAuthorizedException {
WorkbasketService workbasketService = taskanaEngine.getWorkbasketService();
List<String> columnValueList = workbasketService.createWorkbasketAccessItemExtendedQuery()
.listValues("WORKBASKET_ID", null);
assertNotNull(columnValueList);
assertEquals(24, columnValueList.size());
columnValueList = workbasketService.createWorkbasketAccessItemExtendedQuery()
.listValues("ACCESS_ID", null);
assertNotNull(columnValueList);
assertEquals(9, columnValueList.size());
columnValueList = workbasketService.createWorkbasketAccessItemExtendedQuery()
.listValues("WB.KEY", null);
assertNotNull(columnValueList);
assertEquals(24, columnValueList.size());
long countEntries = workbasketService.createWorkbasketAccessItemExtendedQuery().count();
assertTrue(columnValueList.size() < countEntries); // DISTINCT
}
@WithAccessId(
userName = "dummy",
groupNames = {"businessadmin"})
@Test
public void testQueryAccessItemsForAccessIds()
throws NotAuthorizedException {
WorkbasketService workbasketService = taskanaEngine.getWorkbasketService();
List<WorkbasketAccessItemExtended> results = workbasketService.createWorkbasketAccessItemExtendedQuery()
.accessIdIn("user_1_1", "group_1")
.list();
Assert.assertEquals(8L, results.size());
}
@WithAccessId(
userName = "dummy",
groupNames = {"businessadmin"})
@Test
public void testQueryAccessItemsForAccessIdsWorkbasketKeyLike()
throws NotAuthorizedException {
WorkbasketService workbasketService = taskanaEngine.getWorkbasketService();
List<WorkbasketAccessItemExtended> results = workbasketService.createWorkbasketAccessItemExtendedQuery()
.workbasketKeyLike("GPK_KSC%")
.list();
Assert.assertEquals(4L, results.size());
}
@WithAccessId(
userName = "dummy",
groupNames = {"businessadmin"})
@Test
public void testQueryAccessItemsForAccessIdsWorkbasketKeyLikeAndOrderAsc()
throws NotAuthorizedException {
WorkbasketService workbasketService = taskanaEngine.getWorkbasketService();
List<WorkbasketAccessItemExtended> results = workbasketService.createWorkbasketAccessItemExtendedQuery()
.workbasketKeyLike("GPK_KSC%")
.orderByWorkbasketKey(SortDirection.ASCENDING)
.list();
Assert.assertEquals(4L, results.size());
Assert.assertEquals("GPK_KSC", results.get(0).getWorkbasketKey());
Assert.assertEquals("GPK_KSC_2", results.get(3).getWorkbasketKey());
}
}