TSK-694: refactored WorkbasketAccessItemQuery + Extended

This commit is contained in:
Mustapha Zorgati 2018-09-10 19:06:49 +02:00
parent 40b2648060
commit ef703b4a40
23 changed files with 546 additions and 802 deletions

View File

@ -0,0 +1,69 @@
package pro.taskana;
/**
* AbstractWorkbasketAccessItemQuery for generating dynamic sql.
*
* @param <Q> the actual WorkbasketAccessItemQuery behind this interface class
* @param <T> the workbasket access item
*/
public interface AbstractWorkbasketAccessItemQuery<Q extends AbstractWorkbasketAccessItemQuery<Q, T>, T extends WorkbasketAccessItem>
extends BaseQuery<T> {
/**
* Add your unique entry id to your query as filter.
*
* @param ids
* the unique entry IDs
* @return the query
*/
Q idIn(String... ids);
/**
* Add your workbasket id to your query.
*
* @param workbasketId
* the workbasket Id
* @return the query
*/
Q workbasketIdIn(String... workbasketId);
/**
* Add your accessIds to your query.
*
* @param accessId
* as access Ids
* @return the query
*/
Q 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
*/
Q 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
*/
Q 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
*/
Q orderById(SortDirection sortDirection);
}

View File

@ -1,105 +0,0 @@
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

@ -1,64 +1,55 @@
package pro.taskana;
/**
* WorkbasketAccessItemQuery for generating dynamic sql.
* WorkbasketAccessItemQuery for generating dynamic SQL.
*/
public interface WorkbasketAccessItemQuery extends BaseQuery<WorkbasketAccessItem> {
public interface WorkbasketAccessItemQuery
extends AbstractWorkbasketAccessItemQuery<WorkbasketAccessItemQuery, WorkbasketAccessItem> {
/**
* Add your unique entry id to your query as filter.
*
* @param ids
* the unique entry IDs
* @return the query
* Extended version of {@link WorkbasketAccessItemQuery}.
*/
WorkbasketAccessItemQuery idIn(String... ids);
interface Extended extends AbstractWorkbasketAccessItemQuery<Extended, WorkbasketAccessItemExtended> {
/**
* Add your workbasket id to your query.
*
* @param workbasketId
* the workbasket Id
* @return the query
*/
WorkbasketAccessItemQuery workbasketIdIn(String... workbasketId);
/**
* Add your unique entry workbasket key to your query as filter.
*
* @param keys
* the unique entry Keys
* @return the query
*/
Extended workbasketKeyIn(String... keys);
/**
* Add your accessIds to your query.
*
* @param accessId
* as access Ids
* @return the query
*/
WorkbasketAccessItemQuery accessIdIn(String... accessId);
/**
* 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
*/
Extended orderByWorkbasketKey(SortDirection sortDirection);
/**
* 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
*/
WorkbasketAccessItemQuery orderByWorkbasketId(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
*/
Extended workbasketKeyLike(String... key);
/**
* 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
*/
WorkbasketAccessItemQuery 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
*/
WorkbasketAccessItemQuery 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 whose ids are like id1 or like id2, etc.
*
* @param ids
* the ids as Strings
* @return the query
*/
Extended accessIdLike(String... ids);
}
}

View File

@ -218,11 +218,11 @@ public interface WorkbasketService {
/**
* This method provides a query builder for querying the database.
*
* @return a {@link WorkbasketAccessItemExtendedQuery}
* @return a {@link WorkbasketAccessItemQuery.Extended}
* @throws NotAuthorizedException
* if the current user is not member of role BUSINESS_ADMIN or ADMIN
*/
WorkbasketAccessItemExtendedQuery createWorkbasketAccessItemExtendedQuery() throws NotAuthorizedException;
WorkbasketAccessItemQuery.Extended createWorkbasketAccessItemExtendedQuery() throws NotAuthorizedException;
/**
* Returns a new workbasket which is not persisted.

View File

@ -9,30 +9,26 @@ import org.apache.ibatis.session.RowBounds;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import pro.taskana.AbstractWorkbasketAccessItemQuery;
import pro.taskana.TaskanaEngine;
import pro.taskana.WorkbasketAccessItemExtended;
import pro.taskana.WorkbasketAccessItemExtendedQuery;
import pro.taskana.WorkbasketAccessItem;
import pro.taskana.exceptions.TaskanaRuntimeException;
import pro.taskana.impl.util.LoggerUtils;
/**
* WorkbasketAccessItemQuery for generating dynamic SQL.
* AbstractWorkbasketAccessItemQueryImpl for generating dynamic SQL.
*
* @author mmr
* @param <Q> the actual WorkbasketAccessItemQuery behind this abstract class
* @param <T> the workbasket access item
*/
public class WorkbasketAccessItemExtendedQueryImpl implements
WorkbasketAccessItemExtendedQuery {
abstract class AbstractWorkbasketAccessItemQueryImpl<Q extends AbstractWorkbasketAccessItemQuery<Q, T>, T extends WorkbasketAccessItem>
implements AbstractWorkbasketAccessItemQuery<Q, T> {
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 static final Logger LOGGER = LoggerFactory.getLogger(AbstractWorkbasketAccessItemQueryImpl.class);
private String columnName;
private String[] accessIdIn;
private String[] accessIdLike;
private String[] workbasketIdIn;
private String[] idIn;
@ -40,102 +36,61 @@ public class WorkbasketAccessItemExtendedQueryImpl implements
private List<String> orderBy;
private List<String> orderColumns;
WorkbasketAccessItemExtendedQueryImpl(TaskanaEngine taskanaEngine) {
AbstractWorkbasketAccessItemQueryImpl(TaskanaEngine taskanaEngine) {
this.taskanaEngine = (TaskanaEngineImpl) taskanaEngine;
orderBy = new ArrayList<>();
orderColumns = new ArrayList<>();
}
@Override
public WorkbasketAccessItemExtendedQuery workbasketKeyIn(String... keys) {
this.workbasketKeyIn = keys;
return this;
}
abstract Q _this();
abstract String getLinkToMapper();
abstract String getLinkToValueMapper();
@Override
public WorkbasketAccessItemExtendedQuery orderByWorkbasketKey(SortDirection sortDirection) {
return addOrderCriteria("WB.KEY", sortDirection);
}
@Override
public WorkbasketAccessItemExtendedQuery idIn(String... ids) {
public Q idIn(String... ids) {
this.idIn = ids;
return this;
return _this();
}
@Override
public WorkbasketAccessItemExtendedQuery workbasketIdIn(String... workbasketId) {
this.workbasketIdIn = workbasketId;
return this;
public Q workbasketIdIn(String... id) {
this.workbasketIdIn = id;
return _this();
}
@Override
public WorkbasketAccessItemExtendedQuery accessIdIn(String... accessId) {
public Q accessIdIn(String... accessId) {
this.accessIdIn = accessId;
WorkbasketQueryImpl.lowercaseAccessIds(this.accessIdIn);
return this;
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) {
public Q orderById(SortDirection sortDirection) {
return addOrderCriteria("ID", sortDirection);
}
@Override
public WorkbasketAccessItemExtendedQuery workbasketKeyLike(String... key) {
this.workbasketKeyLike = toUpperCopy(key);
return this;
public Q orderByWorkbasketId(SortDirection sortDirection) {
return addOrderCriteria("WORKBASKET_ID", sortDirection);
}
@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;
public Q orderByAccessId(SortDirection sortDirection) {
return addOrderCriteria("ACCESS_ID", sortDirection);
}
@Override
public List<WorkbasketAccessItemExtended> list() {
LOGGER.debug("entry to list(), this = {}", this);
List<WorkbasketAccessItemExtended> result = new ArrayList<>();
public List<T> list() {
LOGGER.debug("entry to list(), this = {}", _this());
List<T> result = new ArrayList<>();
try {
taskanaEngine.openConnection();
List<WorkbasketAccessItemExtendedImpl> foundAccessItems = taskanaEngine.getSqlSession()
.selectList(LINK_TO_MAPPER_EXTENDED, this);
result.addAll(foundAccessItems);
List<T> foundAccessItms = taskanaEngine.getSqlSession()
.selectList(getLinkToMapper(), _this());
result.addAll(foundAccessItms);
return result;
} finally {
taskanaEngine.returnConnection();
@ -148,15 +103,36 @@ public class WorkbasketAccessItemExtendedQueryImpl implements
}
@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<>();
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(getLinkToValueMapper(), _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 List<T> list(int offset, int limit) {
LOGGER.debug("entry to list(offset = {}, limit = {}), this = {}", offset, limit, _this());
List<T> 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);
List<T> foundAccessItms = taskanaEngine.getSqlSession()
.selectList(getLinkToMapper(), _this(), rowBounds);
result.addAll(foundAccessItms);
return result;
} catch (PersistenceException e) {
if (e.getMessage().contains("ERRORCODE=-4470")) {
@ -177,33 +153,12 @@ public class WorkbasketAccessItemExtendedQueryImpl implements
}
@Override
public List<String> listValues(String columnName, SortDirection sortDirection) {
LOGGER.debug("Entry to listValues(dbColumnName={}) this = {}", columnName, this);
List<String> result = null;
public T single() {
LOGGER.debug("entry to single(), this = {}", _this());
T accessItem = 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);
accessItem = taskanaEngine.getSqlSession().selectOne(getLinkToMapper(), _this());
return accessItem;
} finally {
taskanaEngine.returnConnection();
@ -213,11 +168,11 @@ public class WorkbasketAccessItemExtendedQueryImpl implements
@Override
public long count() {
LOGGER.debug("entry to count(), this = {}", this);
LOGGER.debug("entry to count(), this = {}", _this());
Long rowCount = null;
try {
taskanaEngine.openConnection();
rowCount = taskanaEngine.getSqlSession().selectOne(LINK_TO_COUNTER, this);
rowCount = taskanaEngine.getSqlSession().selectOne(LINK_TO_COUNTER, _this());
return (rowCount == null) ? 0L : rowCount;
} finally {
taskanaEngine.returnConnection();
@ -225,8 +180,15 @@ public class WorkbasketAccessItemExtendedQueryImpl implements
}
}
public String getColumnName() {
return columnName;
protected Q addOrderCriteria(String colName, SortDirection sortDirection) {
String orderByDirection = " " + (sortDirection == null ? SortDirection.ASCENDING : sortDirection);
orderBy.add(colName + orderByDirection);
orderColumns.add(colName);
return _this();
}
public String[] getIdIn() {
return this.idIn;
}
public String[] getAccessIdIn() {
@ -237,39 +199,31 @@ public class WorkbasketAccessItemExtendedQueryImpl implements
return workbasketIdIn;
}
public String[] getIdIn() {
return idIn;
public List<String> getOrderBy() {
return orderBy;
}
public List<String> getOrderColumns() {
return orderColumns;
}
public List<String> getOrderBy() {
return orderBy;
}
private WorkbasketAccessItemExtendedQuery addOrderCriteria(String colName, SortDirection sortDirection) {
String orderByDirection = " " + (sortDirection == null ? SortDirection.ASCENDING.toString() : sortDirection.toString());
orderBy.add(colName + orderByDirection);
orderColumns.add(colName);
return this;
public String getColumnName() {
return columnName;
}
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("WorkbasketAccessItemQueryImpl [idIn=");
builder.append("AbstractWorkbasketAccessItemQueryImpl [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

@ -463,7 +463,7 @@ public class ClassificationQueryImpl implements ClassificationQuery {
}
private ClassificationQuery addOrderCriteria(String columnName, SortDirection sortDirection) {
String orderByDirection = " " + (sortDirection == null ? SortDirection.ASCENDING.toString() : sortDirection.toString());
String orderByDirection = " " + (sortDirection == null ? SortDirection.ASCENDING : sortDirection);
orderBy.add(columnName + orderByDirection);
orderColumns.add(columnName);
return this;

View File

@ -211,7 +211,7 @@ public class ObjectReferenceQueryImpl implements ObjectReferenceQuery {
}
private ObjectReferenceQuery addOrderCriteria(String colName, SortDirection sortDirection) {
String orderByDirection = " " + (sortDirection == null ? SortDirection.ASCENDING.toString() : sortDirection.toString());
String orderByDirection = " " + (sortDirection == null ? SortDirection.ASCENDING : sortDirection);
orderBy.add(colName + orderByDirection);
return this;
}

View File

@ -1448,7 +1448,7 @@ public class TaskQueryImpl implements TaskQuery {
}
private TaskQuery addOrderCriteria(String columnName, SortDirection sortDirection) {
String orderByDirection = " " + (sortDirection == null ? SortDirection.ASCENDING.toString() : sortDirection.toString());
String orderByDirection = " " + (sortDirection == null ? SortDirection.ASCENDING : sortDirection);
orderBy.add(columnName + orderByDirection);
orderColumns.add(columnName);
return this;

View File

@ -1,5 +1,7 @@
package pro.taskana.impl;
import java.util.Objects;
import pro.taskana.WorkbasketAccessItemExtended;
/**
@ -20,104 +22,21 @@ public class WorkbasketAccessItemExtendedImpl extends WorkbasketAccessItemImpl i
@Override
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
result = prime * result + ((workbasketKey == null) ? 0 : workbasketKey.hashCode());
return result;
return Objects.hash(super.hashCode(), workbasketKey);
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (obj == null) {
if (!(o instanceof WorkbasketAccessItemExtendedImpl)) {
return false;
}
if (getClass() != obj.getClass()) {
if (!super.equals(o)) {
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;
WorkbasketAccessItemExtendedImpl that = (WorkbasketAccessItemExtendedImpl) o;
return Objects.equals(workbasketKey, that.workbasketKey);
}
}

View File

@ -1,222 +1,108 @@
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.WorkbasketAccessItem;
import pro.taskana.WorkbasketAccessItemExtended;
import pro.taskana.WorkbasketAccessItemQuery;
import pro.taskana.exceptions.TaskanaRuntimeException;
import pro.taskana.impl.util.LoggerUtils;
/**
* WorkbasketAccessItemQueryImpl for generating dynamic SQL.
*
* @author mmr
*/
public class WorkbasketAccessItemQueryImpl implements WorkbasketAccessItemQuery {
public class WorkbasketAccessItemQueryImpl
extends AbstractWorkbasketAccessItemQueryImpl<WorkbasketAccessItemQuery, WorkbasketAccessItem>
implements WorkbasketAccessItemQuery {
private static final String LINK_TO_MAPPER = "pro.taskana.mappings.QueryMapper.queryWorkbasketAccessItems";
private static final String LINK_TO_COUNTER = "pro.taskana.mappings.QueryMapper.countQueryWorkbasketAccessItems";
private static final String LINK_TO_VALUEMAPPER = "pro.taskana.mappings.QueryMapper.queryWorkbasketAccessItemColumnValues";
private static final Logger LOGGER = LoggerFactory.getLogger(WorkbasketQueryImpl.class);
private String columnName;
private String[] accessIdIn;
private String[] workbasketIdIn;
private String[] idIn;
private TaskanaEngineImpl taskanaEngine;
private List<String> orderBy;
private List<String> orderColumns;
private static final String LINK_TO_VALUE_MAPPER = "pro.taskana.mappings.QueryMapper.queryWorkbasketAccessItemColumnValues";
WorkbasketAccessItemQueryImpl(TaskanaEngine taskanaEngine) {
this.taskanaEngine = (TaskanaEngineImpl) taskanaEngine;
orderBy = new ArrayList<>();
orderColumns = new ArrayList<>();
super(taskanaEngine);
}
@Override
public WorkbasketAccessItemQuery idIn(String... ids) {
this.idIn = ids;
WorkbasketAccessItemQuery _this() {
return this;
}
@Override
public WorkbasketAccessItemQuery workbasketIdIn(String... id) {
this.workbasketIdIn = id;
return this;
String getLinkToMapper() {
return LINK_TO_MAPPER;
}
@Override
public WorkbasketAccessItemQuery accessIdIn(String... accessId) {
this.accessIdIn = accessId;
WorkbasketQueryImpl.lowercaseAccessIds(this.accessIdIn);
return this;
String getLinkToValueMapper() {
return LINK_TO_VALUE_MAPPER;
}
@Override
public WorkbasketAccessItemQuery orderById(SortDirection sortDirection) {
return addOrderCriteria("ID", sortDirection);
}
/**
* Extended version of {@link WorkbasketAccessItemQueryImpl}.
*/
public static class Extended
extends AbstractWorkbasketAccessItemQueryImpl<WorkbasketAccessItemQuery.Extended, WorkbasketAccessItemExtended>
implements WorkbasketAccessItemQuery.Extended {
@Override
public WorkbasketAccessItemQuery orderByWorkbasketId(SortDirection sortDirection) {
return addOrderCriteria("WORKBASKET_ID", sortDirection);
}
private static final String LINK_TO_MAPPER_EXTENDED = "pro.taskana.mappings.QueryMapper.queryWorkbasketAccessItemsExtended";
private static final String LINK_TO_VALUE_MAPPER_EXTENDED = "pro.taskana.mappings.QueryMapper.queryWorkbasketAccessItemExtendedColumnValues";
@Override
public WorkbasketAccessItemQuery orderByAccessId(SortDirection sortDirection) {
return addOrderCriteria("ACCESS_ID", sortDirection);
}
private String[] workbasketKeyIn;
private String[] workbasketKeyLike;
private String[] accessIdLike;
@Override
public List<WorkbasketAccessItem> list() {
LOGGER.debug("entry to list(), this = {}", this);
List<WorkbasketAccessItem> result = new ArrayList<>();
try {
taskanaEngine.openConnection();
List<WorkbasketAccessItemImpl> foundAccessItms = taskanaEngine.getSqlSession()
.selectList(LINK_TO_MAPPER, this);
result.addAll(foundAccessItms);
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));
}
Extended(TaskanaEngine taskanaEngine) {
super(taskanaEngine);
}
}
@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, 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
WorkbasketAccessItemQuery.Extended _this() {
return this;
}
}
@Override
public List<WorkbasketAccessItem> list(int offset, int limit) {
LOGGER.debug("entry to list(offset = {}, limit = {}), this = {}", offset, limit, this);
List<WorkbasketAccessItem> result = new ArrayList<>();
try {
taskanaEngine.openConnection();
RowBounds rowBounds = new RowBounds(offset, limit);
List<WorkbasketAccessItemImpl> foundAccessItms = taskanaEngine.getSqlSession()
.selectList(LINK_TO_MAPPER, this, rowBounds);
result.addAll(foundAccessItms);
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
String getLinkToMapper() {
return LINK_TO_MAPPER_EXTENDED;
}
}
@Override
public WorkbasketAccessItem single() {
LOGGER.debug("entry to single(), this = {}", this);
WorkbasketAccessItem accessItm = null;
try {
taskanaEngine.openConnection();
accessItm = taskanaEngine.getSqlSession().selectOne(LINK_TO_MAPPER, this);
return accessItm;
} finally {
taskanaEngine.returnConnection();
LOGGER.debug("exit from single(). Returning result {} ", accessItm);
@Override
String getLinkToValueMapper() {
return LINK_TO_VALUE_MAPPER_EXTENDED;
}
}
@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);
@Override
public WorkbasketAccessItemQuery.Extended workbasketKeyIn(String... keys) {
this.workbasketKeyIn = keys;
return this;
}
}
private WorkbasketAccessItemQuery addOrderCriteria(String colName, SortDirection sortDirection) {
String orderByDirection = " " + (sortDirection == null ? SortDirection.ASCENDING.toString() : sortDirection.toString());
orderBy.add(colName + orderByDirection);
orderColumns.add(colName);
return this;
}
@Override
public WorkbasketAccessItemQuery.Extended orderByWorkbasketKey(SortDirection sortDirection) {
return addOrderCriteria("WB.KEY", sortDirection);
}
public String[] getIdIn() {
return this.idIn;
}
@Override
public WorkbasketAccessItemQuery.Extended workbasketKeyLike(String... key) {
this.workbasketKeyLike = toUpperCopy(key);
return this;
}
public String[] getAccessIdIn() {
return accessIdIn;
}
@Override
public WorkbasketAccessItemQuery.Extended accessIdLike(String... ids) {
this.accessIdLike = toUpperCopy(ids);
return this;
}
public String[] getWorkbasketIdIn() {
return workbasketIdIn;
}
public String[] getWorkbasketKeyIn() {
return workbasketKeyIn;
}
public List<String> getOrderBy() {
return orderBy;
}
public String[] getAccessIdLike() {
return accessIdLike;
}
public List<String> getOrderColumns() {
return orderColumns;
}
public String[] getWorkbasketKeyLike() {
return workbasketKeyLike;
}
public String getColumnName() {
return columnName;
}
@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(", orderBy=");
builder.append(orderBy);
builder.append("]");
return builder.toString();
}
}

View File

@ -753,7 +753,7 @@ public class WorkbasketQueryImpl implements WorkbasketQuery {
}
private WorkbasketQuery addOrderCriteria(String colName, SortDirection sortDirection) {
String orderByDirection = " " + (sortDirection == null ? SortDirection.ASCENDING.toString() : sortDirection.toString());
String orderByDirection = " " + (sortDirection == null ? SortDirection.ASCENDING : sortDirection);
orderBy.add(colName + orderByDirection);
orderColumns.add(colName);
return this;

View File

@ -13,7 +13,6 @@ 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;
@ -232,7 +231,7 @@ public class WorkbasketServiceImpl implements WorkbasketService {
// add all
if (!newItems.isEmpty()) {
newItems.stream().forEach(item -> workbasketAccessMapper.insert(item));
newItems.forEach(item -> workbasketAccessMapper.insert(item));
}
} finally {
taskanaEngine.returnConnection();
@ -450,7 +449,7 @@ public class WorkbasketServiceImpl implements WorkbasketService {
private List<WorkbasketPermission> getPermissionsFromWorkbasketAccessItem(
WorkbasketAccessItem workbasketAccessItem) {
List<WorkbasketPermission> permissions = new ArrayList<WorkbasketPermission>();
List<WorkbasketPermission> permissions = new ArrayList<>();
if (workbasketAccessItem == null) {
return permissions;
}
@ -745,8 +744,7 @@ public class WorkbasketServiceImpl implements WorkbasketService {
long numTasksInWorkbasket = taskanaEngine.getSqlSession()
.getMapper(TaskMapper.class)
.countTasksInWorkbasket(workbasketId)
.longValue();
.countTasksInWorkbasket(workbasketId);
if (numTasksInWorkbasket > 0) {
throw new WorkbasketInUseException(
@ -772,9 +770,9 @@ public class WorkbasketServiceImpl implements WorkbasketService {
}
@Override
public WorkbasketAccessItemExtendedQuery createWorkbasketAccessItemExtendedQuery() throws NotAuthorizedException {
public WorkbasketAccessItemQuery.Extended createWorkbasketAccessItemExtendedQuery() throws NotAuthorizedException {
taskanaEngine.checkRoleMembership(TaskanaRole.ADMIN, TaskanaRole.BUSINESS_ADMIN);
return new WorkbasketAccessItemExtendedQueryImpl(this.taskanaEngine);
return new WorkbasketAccessItemQueryImpl.Extended(this.taskanaEngine);
}
}

View File

@ -7,15 +7,14 @@ import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import pro.taskana.ObjectReference;
import pro.taskana.WorkbasketAccessItemQuery;
import pro.taskana.impl.ClassificationQueryImpl;
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;
import pro.taskana.impl.WorkbasketSummaryImpl;
@ -29,6 +28,11 @@ public interface QueryMapper {
String CLASSIFICATION_FINDBYID = "pro.taskana.mappings.ClassificationMapper.findById";
String WORKBASKET_FINDSUMMARYBYKEY = "pro.taskana.mappings.WorkbasketMapper.findSummaryByKey";
static String fixColumnNames() {
return "";
}
@Select("<script> "
+ "SELECT <if test=\"joinWithAttachments\">DISTINCT</if> t.ID, t.CREATED, t.CLAIMED, t.COMPLETED, t.MODIFIED, t.PLANNED, t.DUE, t.NAME, t.CREATOR, t.DESCRIPTION, t.NOTE, t.PRIORITY, t.STATE, t.CLASSIFICATION_KEY, t.CLASSIFICATION_CATEGORY, t.CLASSIFICATION_ID, t.WORKBASKET_ID, t.DOMAIN, t.WORKBASKET_KEY, t.BUSINESS_PROCESS_ID, t.PARENT_BUSINESS_PROCESS_ID, t.OWNER, t.POR_COMPANY, t.POR_SYSTEM, t.POR_INSTANCE, t.POR_TYPE, t.POR_VALUE, t.IS_READ, t.IS_TRANSFERRED, t.CUSTOM_1, t.CUSTOM_2, t.CUSTOM_3, t.CUSTOM_4, t.CUSTOM_5, t.CUSTOM_6, t.CUSTOM_7, t.CUSTOM_8, t.CUSTOM_9, t.CUSTOM_10, t.CUSTOM_11, t.CUSTOM_12, t.CUSTOM_13, t.CUSTOM_14, t.CUSTOM_15, t.CUSTOM_16"
+ "<if test=\"addAttachmentColumnsToSelectClauseForOrdering\">"
@ -178,11 +182,6 @@ public interface QueryMapper {
@Result(property = "custom16", column = "CUSTOM_16")})
List<TaskSummaryImpl> queryTaskSummaries(TaskQueryImpl taskQuery);
static String fixColumnNames() {
return "";
}
@Select("<script> "
+ "WITH X (ID, CREATED, CLAIMED, COMPLETED, MODIFIED, PLANNED, DUE, NAME, CREATOR, DESCRIPTION, NOTE, PRIORITY, STATE, TCLASSIFICATION_KEY, "
+ "CLASSIFICATION_CATEGORY, CLASSIFICATION_ID, WORKBASKET_ID, DOMAIN, WORKBASKET_KEY, BUSINESS_PROCESS_ID, PARENT_BUSINESS_PROCESS_ID, OWNER, "
@ -609,7 +608,7 @@ public interface QueryMapper {
@Result(property = "permCustom10", column = "PERM_CUSTOM_10"),
@Result(property = "permCustom11", column = "PERM_CUSTOM_11"),
@Result(property = "permCustom12", column = "PERM_CUSTOM_12")})
List<WorkbasketAccessItemImpl> queryWorkbasketAccessItems(WorkbasketAccessItemQueryImpl accessItemQuery);
List<WorkbasketAccessItemImpl> queryWorkbasketAccessItems(WorkbasketAccessItemQuery accessItemQuery);
@Select("<script>"
+ "SELECT "
@ -651,7 +650,8 @@ public interface QueryMapper {
@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);
List<WorkbasketAccessItemExtendedImpl> queryWorkbasketAccessItemsExtended(
WorkbasketAccessItemQuery.Extended accessItemExtendedQuery);
@Select("<script> "
+ "SELECT COUNT( <if test=\"joinWithAttachments\">DISTINCT</if> t.ID) FROM TASK t "
@ -751,7 +751,6 @@ public interface QueryMapper {
+ "</script>")
Long countQueryTasks(TaskQueryImpl taskQuery);
@Select("<script> "
+ "WITH X (ID, WORKBASKET_ID) AS (SELECT <if test=\"joinWithAttachments\">DISTINCT</if> t.ID, t.WORKBASKET_ID FROM TASK t "
+ "<if test=\"joinWithAttachments\">"
@ -998,7 +997,7 @@ public interface QueryMapper {
+ "</where>"
+ "<if test=\"_databaseId == 'db2'\">with UR </if> "
+ "</script>")
Long countQueryWorkbasketAccessItems(WorkbasketAccessItemQueryImpl accessItem);
Long countQueryWorkbasketAccessItems(WorkbasketAccessItemQuery accessItem);
@Select("<script>SELECT DISTINCT ${columnName} "
+ "FROM TASK t LEFT JOIN ATTACHMENT AS a ON t.ID = a.TASK_ID "
@ -1283,7 +1282,7 @@ public interface QueryMapper {
+ "<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> queryWorkbasketAccessItemColumnValues(WorkbasketAccessItemQueryImpl accessItemQuery);
List<String> queryWorkbasketAccessItemColumnValues(WorkbasketAccessItemQuery accessItemQuery);
@Select("<script>SELECT DISTINCT ${columnName} "
+ "FROM WORKBASKET_ACCESS_LIST AS WBA LEFT JOIN WORKBASKET AS WB ON WORKBASKET_ID = WB.ID"
@ -1299,5 +1298,6 @@ public interface QueryMapper {
+ "<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);
List<String> queryWorkbasketAccessItemExtendedColumnValues(
WorkbasketAccessItemQuery.Extended accessItemExtendedQuery);
}

View File

@ -27,9 +27,6 @@ import pro.taskana.security.WithAccessId;
@RunWith(JAASRunner.class)
public class QueryWorkbasketAccessItemsAccTest extends AbstractAccTest {
private static SortDirection asc = SortDirection.ASCENDING;
private static SortDirection desc = SortDirection.DESCENDING;
public QueryWorkbasketAccessItemsAccTest() {
super();
}
@ -88,8 +85,8 @@ public class QueryWorkbasketAccessItemsAccTest extends AbstractAccTest {
WorkbasketService workbasketService = taskanaEngine.getWorkbasketService();
WorkbasketAccessItemQuery query = workbasketService.createWorkbasketAccessItemQuery()
.accessIdIn("user_1_1", "group_1")
.orderByAccessId(desc)
.orderByWorkbasketId(desc);
.orderByAccessId(SortDirection.DESCENDING)
.orderByWorkbasketId(SortDirection.DESCENDING);
List<WorkbasketAccessItem> results = query.list();
long count = query.count();
Assert.assertEquals(8L, results.size());
@ -133,8 +130,8 @@ public class QueryWorkbasketAccessItemsAccTest extends AbstractAccTest {
WorkbasketService workbasketService = taskanaEngine.getWorkbasketService();
List<WorkbasketAccessItem> results = workbasketService.createWorkbasketAccessItemQuery()
.workbasketIdIn("WBI:100000000000000000000000000000000006")
.orderByWorkbasketId(desc)
.orderByAccessId(asc)
.orderByWorkbasketId(SortDirection.DESCENDING)
.orderByAccessId(SortDirection.ASCENDING)
.list();
Assert.assertEquals(3L, results.size());
Assert.assertEquals("WAI:100000000000000000000000000000000009", results.get(0).getId());
@ -146,11 +143,11 @@ public class QueryWorkbasketAccessItemsAccTest extends AbstractAccTest {
public void testQueryForIdIn() throws NotAuthorizedException {
WorkbasketService workbasketService = taskanaEngine.getWorkbasketService();
String[] expectedIds = {"WAI:100000000000000000000000000000000001",
"WAI:100000000000000000000000000000000015",
"WAI:100000000000000000000000000000000007"};
"WAI:100000000000000000000000000000000015",
"WAI:100000000000000000000000000000000007"};
List<WorkbasketAccessItem> results = workbasketService.createWorkbasketAccessItemQuery()
.idIn(expectedIds)
.list();
.idIn(expectedIds)
.list();
for (String id : Arrays.asList(expectedIds)) {
assertTrue(results.stream().anyMatch(accessItem -> accessItem.getId().equals(id)));
}
@ -162,8 +159,8 @@ public class QueryWorkbasketAccessItemsAccTest extends AbstractAccTest {
public void testQueryForOrderById() throws NotAuthorizedException {
WorkbasketService workbasketService = taskanaEngine.getWorkbasketService();
List<WorkbasketAccessItem> results = workbasketService.createWorkbasketAccessItemQuery()
.orderById(asc)
.list();
.orderById(SortDirection.ASCENDING)
.list();
assertEquals("0000000000000000000000000000000000000900", results.get(0).getId());
assertEquals("WAI:100000000000000000000000000000000123", results.get(results.size() - 1).getId());
}

View File

@ -1,6 +1,10 @@
package pro.taskana.ldap;
import java.util.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import pro.taskana.rest.resource.AccessIdResource;
@ -17,100 +21,6 @@ public class LdapCacheTestImpl implements LdapCache {
* and {@link List<AccessIdResource>} as value (groups of which the user is a member) .
*/
private static Map<AccessIdResource, List<AccessIdResource>> users;
@Override
public List<AccessIdResource> findMatchingAccessId(String searchFor, int maxNumerOfReturnedAccessIds) {
return findAcessIdResource(searchFor, maxNumerOfReturnedAccessIds, false);
}
@Override
public List<AccessIdResource> findGroupsOfUser(String searchFor, int maxNumerOfReturnedAccessIds) {
if (users == null) {
addUsersToGroups();
}
return findAcessIdResource(searchFor, maxNumerOfReturnedAccessIds, true);
}
private List <AccessIdResource> findAcessIdResource (String searchFor, int maxNumerOfReturnedAccessIds, boolean groupMember) {
List<AccessIdResource> usersAndGroups = accessIds.stream()
.filter(t -> (t.getName().toLowerCase().contains(searchFor.toLowerCase())
|| t.getAccessId().toLowerCase().contains(searchFor.toLowerCase())))
.collect(Collectors.toList());
List<AccessIdResource> usersAndGroupsAux = new ArrayList<>(usersAndGroups);
if (groupMember) {
usersAndGroupsAux.forEach(item -> {
if (users.get(item) != null) {
usersAndGroups.addAll(users.get(item));
}
});
}
usersAndGroups.sort((AccessIdResource a, AccessIdResource b) -> {
return a.getAccessId().compareToIgnoreCase(b.getAccessId());
});
List<AccessIdResource> result = usersAndGroups.subList(0,
Math.min(usersAndGroups.size(), maxNumerOfReturnedAccessIds));
return result;
}
private void addUsersToGroups() {
List<AccessIdResource> groups = new ArrayList<>();
users = new HashMap<>();
accessIds.forEach(item -> {
if (!item.getAccessId().contains("ou=groups")) {
users.put(item, new ArrayList<>());
} else {
groups.add(item);
}
});
int groupNumber = 0;
List<AccessIdResource> group0 = new ArrayList<>(), group1 = new ArrayList<>(), group2 = new ArrayList<>(), group3 = new ArrayList<>();
for (AccessIdResource group : groups) {
switch (groupNumber) {
case 0:
group0.add(group);
break;
case 1:
group1.add(group);
break;
case 2:
group2.add(group);
break;
case 3:
group3.add(group);
break;
}
groupNumber = (groupNumber + 1) % 4;
}
int countUser = 0;
for (AccessIdResource item : accessIds) {
if (!item.getAccessId().contains("ou=groups")) {
switch (countUser) {
case 0:
users.put(item, group0);
break;
case 1:
users.put(item, group1);
break;
case 2:
users.put(item, group2);
break;
case 3:
users.put(item, group3);
break;
}
}
groupNumber = (groupNumber + 1) % 4;
}
}
private static List<AccessIdResource> accessIds = new ArrayList<>(Arrays.asList(
new AccessIdResource("Martin, Rojas Miguel Angel", "user_1_1"),
new AccessIdResource("Lengl, Marcel", "user_1_2"),
@ -371,4 +281,98 @@ public class LdapCacheTestImpl implements LdapCache {
new AccessIdResource("haftpflicht", "cn=haftpflicht,ou=groups,o=TaskanaTest"),
new AccessIdResource("bauspar", "cn=bauspar,ou=groups,o=TaskanaTest")));
}
@Override
public List<AccessIdResource> findMatchingAccessId(String searchFor, int maxNumerOfReturnedAccessIds) {
return findAcessIdResource(searchFor, maxNumerOfReturnedAccessIds, false);
}
@Override
public List<AccessIdResource> findGroupsOfUser(String searchFor, int maxNumerOfReturnedAccessIds) {
if (users == null) {
addUsersToGroups();
}
return findAcessIdResource(searchFor, maxNumerOfReturnedAccessIds, true);
}
private List<AccessIdResource> findAcessIdResource(String searchFor, int maxNumerOfReturnedAccessIds,
boolean groupMember) {
List<AccessIdResource> usersAndGroups = accessIds.stream()
.filter(t -> (t.getName().toLowerCase().contains(searchFor.toLowerCase())
|| t.getAccessId().toLowerCase().contains(searchFor.toLowerCase())))
.collect(Collectors.toList());
List<AccessIdResource> usersAndGroupsAux = new ArrayList<>(usersAndGroups);
if (groupMember) {
usersAndGroupsAux.forEach(item -> {
if (users.get(item) != null) {
usersAndGroups.addAll(users.get(item));
}
});
}
usersAndGroups.sort((AccessIdResource a, AccessIdResource b) -> {
return a.getAccessId().compareToIgnoreCase(b.getAccessId());
});
List<AccessIdResource> result = usersAndGroups.subList(0,
Math.min(usersAndGroups.size(), maxNumerOfReturnedAccessIds));
return result;
}
private void addUsersToGroups() {
List<AccessIdResource> groups = new ArrayList<>();
users = new HashMap<>();
accessIds.forEach(item -> {
if (!item.getAccessId().contains("ou=groups")) {
users.put(item, new ArrayList<>());
} else {
groups.add(item);
}
});
int groupNumber = 0;
List<AccessIdResource> group0 = new ArrayList<>(), group1 = new ArrayList<>(), group2 = new ArrayList<>(), group3 = new ArrayList<>();
for (AccessIdResource group : groups) {
switch (groupNumber) {
case 0:
group0.add(group);
break;
case 1:
group1.add(group);
break;
case 2:
group2.add(group);
break;
case 3:
group3.add(group);
break;
}
groupNumber = (groupNumber + 1) % 4;
}
int countUser = 0;
for (AccessIdResource item : accessIds) {
if (!item.getAccessId().contains("ou=groups")) {
switch (countUser) {
case 0:
users.put(item, group0);
break;
case 1:
users.put(item, group1);
break;
case 2:
users.put(item, group2);
break;
case 3:
users.put(item, group3);
break;
}
}
groupNumber = (groupNumber + 1) % 4;
}
}
}

View File

@ -1,5 +1,10 @@
package pro.taskana.ldap;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.naming.directory.SearchControls;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@ -12,15 +17,12 @@ import org.springframework.ldap.filter.EqualsFilter;
import org.springframework.ldap.filter.OrFilter;
import org.springframework.ldap.filter.WhitespaceWildcardsFilter;
import org.springframework.stereotype.Component;
import pro.taskana.exceptions.InvalidArgumentException;
import pro.taskana.exceptions.SystemException;
import pro.taskana.impl.util.LoggerUtils;
import pro.taskana.rest.resource.AccessIdResource;
import javax.annotation.PostConstruct;
import javax.naming.directory.SearchControls;
import java.util.List;
/**
* Class for Ldap access.
*
@ -31,14 +33,12 @@ public class LdapClient {
public static final String TASKANA_USE_LDAP_PROP_NAME = "taskana.ldap.useLdap";
private static final Logger LOGGER = LoggerFactory.getLogger(LdapClient.class);
private static final String CN = "cn";
private boolean active = false;
@Autowired
private Environment env;
@Autowired(required = false)
private LdapTemplate ldapTemplate;
private String userSearchBase;
private String userSearchFilterName;
private String userSearchFilterValue;
@ -52,8 +52,6 @@ public class LdapClient {
private String groupsOfUser;
private int minSearchForLength;
private int maxNumberOfReturnedAccessIds;
private static final String CN = "cn";
private String message;
@PostConstruct
@ -134,7 +132,7 @@ public class LdapClient {
LOGGER.debug("entry to searchUsersAndGroups(name = {})", name);
if (!active) {
throw new SystemException(
"LdapClient was called but is not active due to missing configuration: " + message);
"LdapClient was called but is not active due to missing configuration: " + message);
}
testMinSearchForLength(name);
@ -146,7 +144,7 @@ public class LdapClient {
List<AccessIdResource> result = users.subList(0, Math.min(users.size(), maxNumberOfReturnedAccessIds));
LOGGER.debug("exit from searchUsersAndGroups(name = {}). Returning {} users and groups: {}", name, users.size(),
LoggerUtils.listToString(result));
LoggerUtils.listToString(result));
return result;
}
@ -155,7 +153,7 @@ public class LdapClient {
LOGGER.debug("entry to searchUsersByName(name = {}).", name);
if (!active) {
throw new SystemException(
"LdapClient was called but is not active due to missing configuration: " + message);
"LdapClient was called but is not active due to missing configuration: " + message);
}
testMinSearchForLength(name);
@ -169,12 +167,12 @@ public class LdapClient {
andFilter.and(orFilter);
String[] userAttributesToReturn = {getUserFirstnameAttribute(), getUserLastnameAttribute(),
getUserIdAttribute()};
getUserIdAttribute()};
final List<AccessIdResource> accessIds = ldapTemplate.search(getUserSearchBase(), andFilter.encode(),
SearchControls.SUBTREE_SCOPE, userAttributesToReturn, new UserContextMapper());
SearchControls.SUBTREE_SCOPE, userAttributesToReturn, new UserContextMapper());
LOGGER.debug("exit from searchUsersByName. Retrieved the following users: {}.",
LoggerUtils.listToString(accessIds));
LoggerUtils.listToString(accessIds));
return accessIds;
}
@ -183,7 +181,7 @@ public class LdapClient {
LOGGER.debug("entry to searchGroupsByName(name = {}).", name);
if (!active) {
throw new SystemException(
"LdapClient was called but is not active due to missing configuration: " + message);
"LdapClient was called but is not active due to missing configuration: " + message);
}
testMinSearchForLength(name);
@ -204,9 +202,9 @@ public class LdapClient {
}
final List<AccessIdResource> accessIds = ldapTemplate.search(getGroupSearchBase(), andFilter.encode(),
SearchControls.SUBTREE_SCOPE, groupAttributesToReturn, new GroupContextMapper());
SearchControls.SUBTREE_SCOPE, groupAttributesToReturn, new GroupContextMapper());
LOGGER.debug("Exit from searchGroupsByName. Retrieved the following groups: {}",
LoggerUtils.listToString(accessIds));
LoggerUtils.listToString(accessIds));
return accessIds;
}
@ -215,7 +213,7 @@ public class LdapClient {
LOGGER.debug("entry to searchGroupsofUsersIsMember(name = {}).", name);
if (!active) {
throw new SystemException(
"LdapClient was called but is not active due to missing configuration: " + message);
"LdapClient was called but is not active due to missing configuration: " + message);
}
testMinSearchForLength(name);
@ -226,9 +224,9 @@ public class LdapClient {
String[] userAttributesToReturn = {getUserIdAttribute(), getGroupNameAttribute()};
final List<AccessIdResource> accessIds = ldapTemplate.search(getGroupSearchBase(), andFilter.encode(),
SearchControls.SUBTREE_SCOPE, userAttributesToReturn, new GroupContextMapper());
SearchControls.SUBTREE_SCOPE, userAttributesToReturn, new GroupContextMapper());
LOGGER.debug("exit from searchGroupsofUsersIsMember. Retrieved the following users: {}.",
LoggerUtils.listToString(accessIds));
LoggerUtils.listToString(accessIds));
return accessIds;
}
@ -236,7 +234,7 @@ public class LdapClient {
private void testMinSearchForLength(final String name) throws InvalidArgumentException {
if (name == null || name.length() < minSearchForLength) {
throw new InvalidArgumentException("searchFor string " + name + " is too short. Minimum Length = "
+ getMinSearchForLength());
+ getMinSearchForLength());
}
}

View File

@ -1,5 +1,9 @@
package pro.taskana.rest;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.hateoas.PagedResources;
import org.springframework.hateoas.config.EnableHypermediaSupport;
@ -10,19 +14,16 @@ import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import pro.taskana.BaseQuery;
import pro.taskana.WorkbasketAccessItemExtended;
import pro.taskana.WorkbasketAccessItemExtendedQuery;
import pro.taskana.WorkbasketAccessItemQuery;
import pro.taskana.WorkbasketService;
import pro.taskana.exceptions.InvalidArgumentException;
import pro.taskana.exceptions.NotAuthorizedException;
import pro.taskana.rest.resource.WorkbasketAccesItemExtendedResource;
import pro.taskana.rest.resource.assembler.WorkbasketAccessItemExtendedAssembler;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
/**
* Controller for Workbasket access.
*/
@ -49,10 +50,10 @@ public class WorkbasketAccessItemController extends AbstractPagingController {
@GetMapping
public ResponseEntity<PagedResources<WorkbasketAccesItemExtendedResource>> getWorkbasketAccessItems(
@RequestParam MultiValueMap<String, String> params)
throws NotAuthorizedException, InvalidArgumentException {
@RequestParam MultiValueMap<String, String> params)
throws NotAuthorizedException, InvalidArgumentException {
WorkbasketAccessItemExtendedQuery query = workbasketService.createWorkbasketAccessItemExtendedQuery();
WorkbasketAccessItemQuery.Extended query = workbasketService.createWorkbasketAccessItemExtendedQuery();
query = getAccessIds(query, params);
query = applyFilterParams(query, params);
query = applySortingParams(query, params);
@ -69,7 +70,7 @@ public class WorkbasketAccessItemController extends AbstractPagingController {
long totalElements = query.count();
pageMetadata = initPageMetadata(pageSize, page, totalElements);
workbasketAccessItemsExtended = query.listPage((int) pageMetadata.getNumber(),
(int) pageMetadata.getSize());
(int) pageMetadata.getSize());
} else if (page == null && pageSize == null) {
// not paging
workbasketAccessItemsExtended = query.list();
@ -78,14 +79,15 @@ public class WorkbasketAccessItemController extends AbstractPagingController {
}
WorkbasketAccessItemExtendedAssembler assembler = new WorkbasketAccessItemExtendedAssembler();
PagedResources<WorkbasketAccesItemExtendedResource> pagedResources = assembler.toResources(workbasketAccessItemsExtended,
pageMetadata);
PagedResources<WorkbasketAccesItemExtendedResource> pagedResources = assembler.toResources(
workbasketAccessItemsExtended,
pageMetadata);
return new ResponseEntity<>(pagedResources, HttpStatus.OK);
}
private WorkbasketAccessItemExtendedQuery getAccessIds(WorkbasketAccessItemExtendedQuery query,
MultiValueMap<String, String> params) throws InvalidArgumentException {
private WorkbasketAccessItemQuery.Extended getAccessIds(WorkbasketAccessItemQuery.Extended query,
MultiValueMap<String, String> params) throws InvalidArgumentException {
if (params.containsKey(ACCESS_IDS)) {
String[] accessIds = extractVerticalBarSeparatedFields(params.get(ACCESS_IDS));
query.accessIdIn(accessIds);
@ -94,8 +96,8 @@ public class WorkbasketAccessItemController extends AbstractPagingController {
return query;
}
private WorkbasketAccessItemExtendedQuery applyFilterParams(WorkbasketAccessItemExtendedQuery query,
MultiValueMap<String, String> params) throws InvalidArgumentException {
private WorkbasketAccessItemQuery.Extended applyFilterParams(WorkbasketAccessItemQuery.Extended query,
MultiValueMap<String, String> params) throws InvalidArgumentException {
if (params.containsKey(WORKBASKET_KEY)) {
String[] keys = extractCommaSeparatedFields(params.get(WORKBASKET_KEY));
query.workbasketKeyIn(keys);
@ -117,8 +119,9 @@ public class WorkbasketAccessItemController extends AbstractPagingController {
return query;
}
private WorkbasketAccessItemExtendedQuery applySortingParams(WorkbasketAccessItemExtendedQuery query, MultiValueMap<String, String> params)
throws IllegalArgumentException {
private WorkbasketAccessItemQuery.Extended applySortingParams(WorkbasketAccessItemQuery.Extended query,
MultiValueMap<String, String> params)
throws IllegalArgumentException {
// sorting
String sortBy = params.getFirst(SORT_BY);
if (sortBy != null) {

View File

@ -1,5 +1,9 @@
package pro.taskana.rest;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.hateoas.PagedResources;
import org.springframework.hateoas.PagedResources.PageMetadata;
@ -10,19 +14,40 @@ import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.MultiValueMap;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import pro.taskana.BaseQuery.SortDirection;
import pro.taskana.*;
import pro.taskana.exceptions.*;
import pro.taskana.Workbasket;
import pro.taskana.WorkbasketAccessItem;
import pro.taskana.WorkbasketPermission;
import pro.taskana.WorkbasketQuery;
import pro.taskana.WorkbasketService;
import pro.taskana.WorkbasketSummary;
import pro.taskana.WorkbasketType;
import pro.taskana.exceptions.DomainNotFoundException;
import pro.taskana.exceptions.InvalidArgumentException;
import pro.taskana.exceptions.InvalidWorkbasketException;
import pro.taskana.exceptions.NotAuthorizedException;
import pro.taskana.exceptions.WorkbasketAlreadyExistException;
import pro.taskana.exceptions.WorkbasketInUseException;
import pro.taskana.exceptions.WorkbasketNotFoundException;
import pro.taskana.rest.resource.DistributionTargetResource;
import pro.taskana.rest.resource.WorkbasketAccessItemResource;
import pro.taskana.rest.resource.WorkbasketResource;
import pro.taskana.rest.resource.WorkbasketSummaryResource;
import pro.taskana.rest.resource.assembler.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import pro.taskana.rest.resource.assembler.DistributionTargetListAssembler;
import pro.taskana.rest.resource.assembler.WorkbasketAccessItemAssembler;
import pro.taskana.rest.resource.assembler.WorkbasketAccessItemListAssembler;
import pro.taskana.rest.resource.assembler.WorkbasketAssembler;
import pro.taskana.rest.resource.assembler.WorkbasketSummaryResourcesAssembler;
/**
* Controller for all {@link Workbasket} related endpoints.
@ -69,7 +94,7 @@ public class WorkbasketController extends AbstractPagingController {
@GetMapping
@Transactional(readOnly = true, rollbackFor = Exception.class)
public ResponseEntity<PagedResources<WorkbasketSummaryResource>> getWorkbaskets(
@RequestParam MultiValueMap<String, String> params) throws InvalidArgumentException {
@RequestParam MultiValueMap<String, String> params) throws InvalidArgumentException {
WorkbasketQuery query = workbasketService.createWorkbasketQuery();
query = applySortingParams(query, params);
@ -87,7 +112,7 @@ public class WorkbasketController extends AbstractPagingController {
long totalElements = query.count();
pageMetadata = initPageMetadata(pageSize, page, totalElements);
workbasketSummaries = query.listPage((int) pageMetadata.getNumber(),
(int) pageMetadata.getSize());
(int) pageMetadata.getSize());
} else if (page == null && pageSize == null) {
// not paging
workbasketSummaries = query.list();
@ -97,7 +122,7 @@ public class WorkbasketController extends AbstractPagingController {
WorkbasketSummaryResourcesAssembler assembler = new WorkbasketSummaryResourcesAssembler();
PagedResources<WorkbasketSummaryResource> pagedResources = assembler.toResources(workbasketSummaries,
pageMetadata);
pageMetadata);
return new ResponseEntity<>(pagedResources, HttpStatus.OK);
}
@ -105,7 +130,7 @@ public class WorkbasketController extends AbstractPagingController {
@GetMapping(path = "/{workbasketId}")
@Transactional(readOnly = true, rollbackFor = Exception.class)
public ResponseEntity<WorkbasketResource> getWorkbasket(@PathVariable(value = "workbasketId") String workbasketId)
throws WorkbasketNotFoundException, NotAuthorizedException {
throws WorkbasketNotFoundException, NotAuthorizedException {
ResponseEntity<WorkbasketResource> result;
Workbasket workbasket = workbasketService.getWorkbasket(workbasketId);
result = new ResponseEntity<>(workbasketAssembler.toResource(workbasket), HttpStatus.OK);
@ -115,7 +140,7 @@ public class WorkbasketController extends AbstractPagingController {
@DeleteMapping(path = "/{workbasketId}")
@Transactional(rollbackFor = Exception.class)
public ResponseEntity<?> deleteWorkbasket(@PathVariable(value = "workbasketId") String workbasketId)
throws WorkbasketNotFoundException, NotAuthorizedException, WorkbasketInUseException, InvalidArgumentException {
throws WorkbasketNotFoundException, NotAuthorizedException, WorkbasketInUseException, InvalidArgumentException {
ResponseEntity<?> result = ResponseEntity.status(HttpStatus.NO_CONTENT).build();
workbasketService.deleteWorkbasket(workbasketId);
return result;
@ -124,8 +149,8 @@ public class WorkbasketController extends AbstractPagingController {
@PostMapping
@Transactional(rollbackFor = Exception.class)
public ResponseEntity<WorkbasketResource> createWorkbasket(@RequestBody WorkbasketResource workbasketResource)
throws InvalidWorkbasketException, NotAuthorizedException, WorkbasketAlreadyExistException,
WorkbasketNotFoundException, DomainNotFoundException {
throws InvalidWorkbasketException, NotAuthorizedException, WorkbasketAlreadyExistException,
WorkbasketNotFoundException, DomainNotFoundException {
Workbasket workbasket = workbasketAssembler.toModel(workbasketResource);
workbasket = workbasketService.createWorkbasket(workbasket);
return new ResponseEntity<>(workbasketAssembler.toResource(workbasket), HttpStatus.CREATED);
@ -134,9 +159,9 @@ public class WorkbasketController extends AbstractPagingController {
@PutMapping(path = "/{workbasketId}")
@Transactional(rollbackFor = Exception.class)
public ResponseEntity<WorkbasketResource> updateWorkbasket(
@PathVariable(value = "workbasketId") String workbasketId,
@RequestBody WorkbasketResource workbasketResource)
throws InvalidWorkbasketException, WorkbasketNotFoundException, NotAuthorizedException {
@PathVariable(value = "workbasketId") String workbasketId,
@RequestBody WorkbasketResource workbasketResource)
throws InvalidWorkbasketException, WorkbasketNotFoundException, NotAuthorizedException {
ResponseEntity<WorkbasketResource> result;
if (workbasketId.equals(workbasketResource.workbasketId)) {
Workbasket workbasket = workbasketAssembler.toModel(workbasketResource);
@ -144,9 +169,9 @@ public class WorkbasketController extends AbstractPagingController {
result = ResponseEntity.ok(workbasketAssembler.toResource(workbasket));
} else {
throw new InvalidWorkbasketException(
"Target-WB-ID('" + workbasketId
+ "') is not identical with the WB-ID of to object which should be updated. ID=('"
+ workbasketResource.getId() + "')");
"Target-WB-ID('" + workbasketId
+ "') is not identical with the WB-ID of to object which should be updated. ID=('"
+ workbasketResource.getId() + "')");
}
return result;
@ -155,14 +180,14 @@ public class WorkbasketController extends AbstractPagingController {
@GetMapping(path = "/{workbasketId}/workbasketAccessItems")
@Transactional(readOnly = true, rollbackFor = Exception.class)
public ResponseEntity<Resources<WorkbasketAccessItemResource>> getWorkbasketAccessItems(
@PathVariable(value = "workbasketId") String workbasketId)
throws NotAuthorizedException, WorkbasketNotFoundException {
@PathVariable(value = "workbasketId") String workbasketId)
throws NotAuthorizedException, WorkbasketNotFoundException {
ResponseEntity<Resources<WorkbasketAccessItemResource>> result;
List<WorkbasketAccessItem> accessItems = workbasketService.getWorkbasketAccessItems(workbasketId);
Resources<WorkbasketAccessItemResource> accessItemListResource = accessItemListAssembler
.toResource(workbasketId, accessItems);
.toResource(workbasketId, accessItems);
result = new ResponseEntity<>(accessItemListResource, HttpStatus.OK);
return result;
}
@ -170,9 +195,9 @@ public class WorkbasketController extends AbstractPagingController {
@PutMapping(value = "/{workbasketId}/workbasketAccessItems")
@Transactional(rollbackFor = Exception.class)
public ResponseEntity<Resources<WorkbasketAccessItemResource>> setWorkbasketAccessItems(
@PathVariable(value = "workbasketId") String workbasketId,
@RequestBody List<WorkbasketAccessItemResource> workbasketAccessResourceItems)
throws NotAuthorizedException, InvalidArgumentException, WorkbasketNotFoundException {
@PathVariable(value = "workbasketId") String workbasketId,
@RequestBody List<WorkbasketAccessItemResource> workbasketAccessResourceItems)
throws NotAuthorizedException, InvalidArgumentException, WorkbasketNotFoundException {
if (workbasketAccessResourceItems == null) {
throw new InvalidArgumentException("Can´t create something with NULL body-value.");
}
@ -183,7 +208,7 @@ public class WorkbasketController extends AbstractPagingController {
List<WorkbasketAccessItem> updatedWbAccessItems = workbasketService.getWorkbasketAccessItems(workbasketId);
Resources<WorkbasketAccessItemResource> accessItemListResource = accessItemListAssembler
.toResource(workbasketId, updatedWbAccessItems);
.toResource(workbasketId, updatedWbAccessItems);
return new ResponseEntity<>(accessItemListResource, HttpStatus.OK);
}
@ -191,13 +216,13 @@ public class WorkbasketController extends AbstractPagingController {
@GetMapping(path = "/{workbasketId}/distribution-targets")
@Transactional(readOnly = true, rollbackFor = Exception.class)
public ResponseEntity<Resources<DistributionTargetResource>> getDistributionTargets(
@PathVariable(value = "workbasketId") String workbasketId)
throws WorkbasketNotFoundException, NotAuthorizedException {
@PathVariable(value = "workbasketId") String workbasketId)
throws WorkbasketNotFoundException, NotAuthorizedException {
ResponseEntity<Resources<DistributionTargetResource>> result;
List<WorkbasketSummary> distributionTargets = workbasketService.getDistributionTargets(workbasketId);
Resources<DistributionTargetResource> distributionTargetListResource = distributionTargetListAssembler
.toResource(workbasketId, distributionTargets);
.toResource(workbasketId, distributionTargets);
result = new ResponseEntity<>(distributionTargetListResource, HttpStatus.OK);
return result;
}
@ -205,13 +230,13 @@ public class WorkbasketController extends AbstractPagingController {
@PutMapping(path = "/{workbasketId}/distribution-targets")
@Transactional(rollbackFor = Exception.class)
public ResponseEntity<Resources<DistributionTargetResource>> setDistributionTargetsForWorkbasketId(
@PathVariable(value = "workbasketId") String sourceWorkbasketId,
@RequestBody List<String> targetWorkbasketIds) throws WorkbasketNotFoundException, NotAuthorizedException {
@PathVariable(value = "workbasketId") String sourceWorkbasketId,
@RequestBody List<String> targetWorkbasketIds) throws WorkbasketNotFoundException, NotAuthorizedException {
workbasketService.setDistributionTargets(sourceWorkbasketId, targetWorkbasketIds);
List<WorkbasketSummary> distributionTargets = workbasketService.getDistributionTargets(sourceWorkbasketId);
Resources<DistributionTargetResource> distributionTargetListResource = distributionTargetListAssembler
.toResource(sourceWorkbasketId, distributionTargets);
.toResource(sourceWorkbasketId, distributionTargets);
return new ResponseEntity<>(distributionTargetListResource, HttpStatus.OK);
}
@ -219,8 +244,8 @@ public class WorkbasketController extends AbstractPagingController {
@DeleteMapping(path = "/distribution-targets/{workbasketId}")
@Transactional(rollbackFor = Exception.class)
public ResponseEntity<Resources<DistributionTargetResource>> removeDistributionTargetForWorkbasketId(
@PathVariable(value = "workbasketId") String targetWorkbasketId)
throws WorkbasketNotFoundException, NotAuthorizedException {
@PathVariable(value = "workbasketId") String targetWorkbasketId)
throws WorkbasketNotFoundException, NotAuthorizedException {
List<WorkbasketSummary> sourceWorkbaskets = workbasketService.getDistributionSources(targetWorkbasketId);
for (WorkbasketSummary source : sourceWorkbaskets) {
workbasketService.removeDistributionTarget(source.getId(), targetWorkbasketId);
@ -230,7 +255,7 @@ public class WorkbasketController extends AbstractPagingController {
}
private WorkbasketQuery applySortingParams(WorkbasketQuery query, MultiValueMap<String, String> params)
throws IllegalArgumentException {
throws IllegalArgumentException {
// sorting
String sortBy = params.getFirst(SORT_BY);
if (sortBy != null) {
@ -266,7 +291,7 @@ public class WorkbasketController extends AbstractPagingController {
}
private WorkbasketQuery applyFilterParams(WorkbasketQuery query,
MultiValueMap<String, String> params) throws InvalidArgumentException {
MultiValueMap<String, String> params) throws InvalidArgumentException {
if (params.containsKey(NAME)) {
String[] names = extractCommaSeparatedFields(params.get(NAME));
query.nameIn(names);

View File

@ -1,18 +1,19 @@
package pro.taskana.rest.resource.assembler;
import static org.springframework.hateoas.mvc.ControllerLinkBuilder.linkTo;
import static pro.taskana.rest.resource.assembler.AbstractRessourcesAssembler.getBuilderForOriginalUri;
import java.util.List;
import org.springframework.hateoas.Link;
import org.springframework.hateoas.PagedResources;
import org.springframework.hateoas.PagedResources.PageMetadata;
import org.springframework.web.util.UriComponentsBuilder;
import pro.taskana.ClassificationSummary;
import pro.taskana.rest.ClassificationController;
import pro.taskana.rest.resource.ClassificationSummaryResource;
import java.util.List;
import static org.springframework.hateoas.mvc.ControllerLinkBuilder.linkTo;
import static pro.taskana.rest.resource.assembler.AbstractRessourcesAssembler.getBuilderForOriginalUri;
/**
* @author HH
*/

View File

@ -1,8 +1,12 @@
package pro.taskana.rest.resource.assembler;
import static org.springframework.hateoas.mvc.ControllerLinkBuilder.linkTo;
import static org.springframework.hateoas.mvc.ControllerLinkBuilder.methodOn;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import pro.taskana.WorkbasketAccessItem;
import pro.taskana.WorkbasketService;
import pro.taskana.exceptions.NotAuthorizedException;
@ -11,9 +15,6 @@ import pro.taskana.impl.WorkbasketAccessItemImpl;
import pro.taskana.rest.WorkbasketController;
import pro.taskana.rest.resource.WorkbasketAccessItemResource;
import static org.springframework.hateoas.mvc.ControllerLinkBuilder.linkTo;
import static org.springframework.hateoas.mvc.ControllerLinkBuilder.methodOn;
/**
* Transforms {@link WorkbasketAccessItem} to its resource counterpart {@link WorkbasketAccessItemResource} and vice
* versa.
@ -25,7 +26,7 @@ public class WorkbasketAccessItemAssembler {
private WorkbasketService workbasketService;
public WorkbasketAccessItemResource toResource(WorkbasketAccessItem wbAccItem)
throws NotAuthorizedException, WorkbasketNotFoundException {
throws NotAuthorizedException, WorkbasketNotFoundException {
WorkbasketAccessItemResource resource = new WorkbasketAccessItemResource();
BeanUtils.copyProperties(wbAccItem, resource);
// property is named different, so it needs to be set by hand
@ -36,7 +37,7 @@ public class WorkbasketAccessItemAssembler {
public WorkbasketAccessItem toModel(WorkbasketAccessItemResource wbAccItemRecource) {
WorkbasketAccessItemImpl wbAccItemModel = (WorkbasketAccessItemImpl) workbasketService.newWorkbasketAccessItem(
wbAccItemRecource.workbasketId, wbAccItemRecource.accessId);
wbAccItemRecource.workbasketId, wbAccItemRecource.accessId);
BeanUtils.copyProperties(wbAccItemRecource, wbAccItemModel);
wbAccItemModel.setId(wbAccItemRecource.accessItemId);
@ -44,11 +45,11 @@ public class WorkbasketAccessItemAssembler {
}
private WorkbasketAccessItemResource addLinks(WorkbasketAccessItemResource resource, WorkbasketAccessItem wbAccItem)
throws NotAuthorizedException, WorkbasketNotFoundException {
throws NotAuthorizedException, WorkbasketNotFoundException {
resource.add(
linkTo(methodOn(WorkbasketController.class).getWorkbasket(wbAccItem.getWorkbasketId()))
.withRel("workbasket"));
linkTo(methodOn(WorkbasketController.class).getWorkbasket(wbAccItem.getWorkbasketId()))
.withRel("workbasket"));
return resource;
}
}

View File

@ -1,20 +1,21 @@
package pro.taskana.rest.resource.assembler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.hateoas.Resources;
import org.springframework.stereotype.Component;
import pro.taskana.WorkbasketAccessItem;
import pro.taskana.exceptions.NotAuthorizedException;
import pro.taskana.exceptions.WorkbasketNotFoundException;
import pro.taskana.rest.WorkbasketController;
import pro.taskana.rest.resource.WorkbasketAccessItemResource;
import static org.springframework.hateoas.mvc.ControllerLinkBuilder.linkTo;
import static org.springframework.hateoas.mvc.ControllerLinkBuilder.methodOn;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import static org.springframework.hateoas.mvc.ControllerLinkBuilder.linkTo;
import static org.springframework.hateoas.mvc.ControllerLinkBuilder.methodOn;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.hateoas.Resources;
import org.springframework.stereotype.Component;
import pro.taskana.WorkbasketAccessItem;
import pro.taskana.exceptions.NotAuthorizedException;
import pro.taskana.exceptions.WorkbasketNotFoundException;
import pro.taskana.rest.WorkbasketController;
import pro.taskana.rest.resource.WorkbasketAccessItemResource;
/**
* Mapper to convert from a list of WorkbasketAccessItem to a WorkbasketAccessItemResource.
@ -26,7 +27,7 @@ public class WorkbasketAccessItemListAssembler {
private WorkbasketAccessItemAssembler workbasketAccessItemAssembler;
public Resources<WorkbasketAccessItemResource> toResource(String workbasketId,
Collection<WorkbasketAccessItem> accessItems) throws NotAuthorizedException, WorkbasketNotFoundException {
Collection<WorkbasketAccessItem> accessItems) throws NotAuthorizedException, WorkbasketNotFoundException {
List<WorkbasketAccessItemResource> resourceList = new ArrayList<>();
for (WorkbasketAccessItem accessItem : accessItems) {
resourceList.add(workbasketAccessItemAssembler.toResource(accessItem));
@ -35,11 +36,11 @@ public class WorkbasketAccessItemListAssembler {
Resources<WorkbasketAccessItemResource> accessItemListResource = new Resources<>(resourceList);
accessItemListResource
.add(linkTo(methodOn(WorkbasketController.class).getWorkbasketAccessItems(workbasketId))
.withSelfRel());
.add(linkTo(methodOn(WorkbasketController.class).getWorkbasketAccessItems(workbasketId))
.withSelfRel());
accessItemListResource
.add(linkTo(methodOn(WorkbasketController.class).getWorkbasket(workbasketId))
.withRel("workbasket"));
.add(linkTo(methodOn(WorkbasketController.class).getWorkbasket(workbasketId))
.withRel("workbasket"));
return accessItemListResource;
}

View File

@ -1,8 +1,14 @@
package pro.taskana.rest.resource.assembler;
import static org.springframework.hateoas.mvc.ControllerLinkBuilder.linkTo;
import static org.springframework.hateoas.mvc.ControllerLinkBuilder.methodOn;
import java.time.Instant;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import pro.taskana.Workbasket;
import pro.taskana.WorkbasketService;
import pro.taskana.exceptions.NotAuthorizedException;
@ -11,11 +17,6 @@ import pro.taskana.impl.WorkbasketImpl;
import pro.taskana.rest.WorkbasketController;
import pro.taskana.rest.resource.WorkbasketResource;
import java.time.Instant;
import static org.springframework.hateoas.mvc.ControllerLinkBuilder.linkTo;
import static org.springframework.hateoas.mvc.ControllerLinkBuilder.methodOn;
/**
* Transforms {@link Workbasket} to its resource counterpart {@link WorkbasketResource} and vice versa.
*/
@ -47,15 +48,15 @@ public class WorkbasketAssembler {
}
private WorkbasketResource addLinks(WorkbasketResource resource, Workbasket wb)
throws NotAuthorizedException, WorkbasketNotFoundException {
throws NotAuthorizedException, WorkbasketNotFoundException {
resource.add(linkTo(methodOn(WorkbasketController.class).getWorkbasket(wb.getId())).withSelfRel());
resource.add(linkTo(methodOn(WorkbasketController.class).getDistributionTargets(wb.getId()))
.withRel("distributionTargets"));
.withRel("distributionTargets"));
resource.add(linkTo(methodOn(WorkbasketController.class).getWorkbasketAccessItems(wb.getId()))
.withRel("accessItems"));
.withRel("accessItems"));
resource.add(linkTo(WorkbasketController.class).withRel("allWorkbaskets"));
resource.add(linkTo(methodOn(WorkbasketController.class).removeDistributionTargetForWorkbasketId(wb.getId()))
.withRel("removeDistributionTargets"));
.withRel("removeDistributionTargets"));
return resource;
}
}

View File

@ -1,18 +1,19 @@
package pro.taskana.rest.resource.assembler;
import static org.springframework.hateoas.mvc.ControllerLinkBuilder.linkTo;
import static pro.taskana.rest.resource.assembler.AbstractRessourcesAssembler.getBuilderForOriginalUri;
import java.util.List;
import org.springframework.hateoas.Link;
import org.springframework.hateoas.PagedResources;
import org.springframework.hateoas.PagedResources.PageMetadata;
import org.springframework.web.util.UriComponentsBuilder;
import pro.taskana.WorkbasketSummary;
import pro.taskana.rest.WorkbasketController;
import pro.taskana.rest.resource.WorkbasketSummaryResource;
import java.util.List;
import static org.springframework.hateoas.mvc.ControllerLinkBuilder.linkTo;
import static pro.taskana.rest.resource.assembler.AbstractRessourcesAssembler.getBuilderForOriginalUri;
/**
* @author HH
*/