TSK-162 Implement WorkbasketService.getDistributionTargets() method
This commit is contained in:
parent
a9bb3ed377
commit
c04b30d91a
|
@ -1,7 +1,6 @@
|
|||
package pro.taskana;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.List;
|
||||
|
||||
import pro.taskana.model.WorkbasketType;
|
||||
|
||||
|
@ -121,21 +120,6 @@ public interface Workbasket {
|
|||
*/
|
||||
String getOwner();
|
||||
|
||||
/**
|
||||
* Returns a list of all distribution targets.
|
||||
*
|
||||
* @return distributionTargets
|
||||
*/
|
||||
List<WorkbasketSummary> getDistributionTargets();
|
||||
|
||||
/**
|
||||
* Sets the list of distribution targets for this workbasket.
|
||||
*
|
||||
* @param distributionTargets
|
||||
* the distribution targets of the workbasket
|
||||
*/
|
||||
void setDistributionTargets(List<WorkbasketSummary> distributionTargets);
|
||||
|
||||
/**
|
||||
* Return the value for the custom1 attribute.
|
||||
*
|
||||
|
@ -262,4 +246,5 @@ public interface Workbasket {
|
|||
* @return the WorkbasketSummary object for the current work basket
|
||||
*/
|
||||
WorkbasketSummary asSummary();
|
||||
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@ public interface WorkbasketQuery extends BaseQuery<WorkbasketSummary> {
|
|||
* the keys as Strings
|
||||
* @return the query
|
||||
*/
|
||||
BaseQuery<WorkbasketSummary> keyLike(String... key);
|
||||
WorkbasketQuery keyLike(String... key);
|
||||
|
||||
/**
|
||||
* Add your names to your query. The names are compared case-insensitively to the names of workbaskets
|
||||
|
@ -51,7 +51,7 @@ public interface WorkbasketQuery extends BaseQuery<WorkbasketSummary> {
|
|||
* the names as Strings
|
||||
* @return the query
|
||||
*/
|
||||
BaseQuery<WorkbasketSummary> nameLike(String... name);
|
||||
WorkbasketQuery nameLike(String... name);
|
||||
|
||||
/**
|
||||
* Add search strings to your query that are searched case-insensitively in the key and name fields of workbaskets.
|
||||
|
@ -63,7 +63,7 @@ public interface WorkbasketQuery extends BaseQuery<WorkbasketSummary> {
|
|||
* the seach strings
|
||||
* @return the query
|
||||
*/
|
||||
BaseQuery<WorkbasketSummary> keyOrNameLike(String... searchString);
|
||||
WorkbasketQuery keyOrNameLike(String... searchString);
|
||||
|
||||
/**
|
||||
* Add your domains to your query.
|
||||
|
|
|
@ -121,7 +121,7 @@ public interface WorkbasketService {
|
|||
* @param authorization
|
||||
* the needed Authorization
|
||||
* @throws NotAuthorizedException
|
||||
* if the current user has not the requested authorization fot the specified workbasket
|
||||
* if the current user has not the requested authorization for the specified workbasket
|
||||
*/
|
||||
void checkAuthorization(String workbasketKey, WorkbasketAuthorization authorization) throws NotAuthorizedException;
|
||||
|
||||
|
@ -171,9 +171,68 @@ public interface WorkbasketService {
|
|||
* Returns a set with all permissions of the current user at this workbasket.
|
||||
*
|
||||
* @param workbasketKey
|
||||
* The key of the referenced workbasket
|
||||
* the key of the referenced workbasket
|
||||
* @return a Set with all permissions
|
||||
*/
|
||||
List<WorkbasketAuthorization> getPermissionsForWorkbasket(String workbasketKey);
|
||||
|
||||
/**
|
||||
* Returns the distribution targets for a given workbasket.
|
||||
*
|
||||
* @param workbasketId
|
||||
* the id of the workbasket for which the distribution targets are to be retrieved
|
||||
* @return the distribution targets of the specified workbasket
|
||||
* @throws NotAuthorizedException
|
||||
* if the current user has no read permission for the specified workbasket
|
||||
* @throws WorkbasketNotFoundException
|
||||
* if the workbasket doesn't exist
|
||||
*/
|
||||
List<WorkbasketSummary> getDistributionTargets(String workbasketId)
|
||||
throws NotAuthorizedException, WorkbasketNotFoundException;
|
||||
|
||||
/**
|
||||
* Set the distribution targets for a workbasket.
|
||||
*
|
||||
* @param sourceWorkbasketId
|
||||
* the id of the source workbasket for which the distribution targets are to be set
|
||||
* @param targetWorkbasketIds
|
||||
* a list of the ids of the target workbaskets
|
||||
* @throws NotAuthorizedException
|
||||
* if the current used doesn't have READ permission for the source workbasket
|
||||
* @throws WorkbasketNotFoundException
|
||||
* if either the source workbasket or any of the target workbaskets don't exist
|
||||
*/
|
||||
void setDistributionTargets(String sourceWorkbasketId, List<String> targetWorkbasketIds)
|
||||
throws NotAuthorizedException, WorkbasketNotFoundException;
|
||||
|
||||
/**
|
||||
* Add a distribution target to a workbasket. If the specified distribution target exists already, the method
|
||||
* silently returns without doing anything.
|
||||
*
|
||||
* @param sourceWorkbasketId
|
||||
* the id of the source workbasket
|
||||
* @param targetWorkbasketId
|
||||
* the id of the target workbasket
|
||||
* @throws NotAuthorizedException
|
||||
* if the current user doesn't have READ permission for the source workbasket
|
||||
* @throws WorkbasketNotFoundException
|
||||
* if either the source workbasket or the target workbasket doesn't exist
|
||||
*/
|
||||
void addDistributionTarget(String sourceWorkbasketId, String targetWorkbasketId)
|
||||
throws NotAuthorizedException, WorkbasketNotFoundException;
|
||||
|
||||
/**
|
||||
* Remove a distribution target from a workbasket. If the the specified distribution target doesn't exist, the
|
||||
* method silently returns without doing anything.
|
||||
*
|
||||
* @param sourceWorkbasketId
|
||||
* The id of the source workbasket
|
||||
* @param targetWorkbasketId
|
||||
* The id of the target workbasket
|
||||
* @throws NotAuthorizedException
|
||||
* If the current user doesn't have READ permission for the source workbasket
|
||||
*/
|
||||
void removeDistributionTarget(String sourceWorkbasketId, String targetWorkbasketId)
|
||||
throws NotAuthorizedException;
|
||||
|
||||
}
|
||||
|
|
|
@ -518,7 +518,7 @@ public class TaskServiceImpl implements TaskService {
|
|||
for (TaskSummaryImpl task : taskSummaries) {
|
||||
String workbasketKey = task.getWorkbasketSummaryImpl().getKey();
|
||||
|
||||
// find the appropriate classification from the query result
|
||||
// find the appropriate workbasket from the query result
|
||||
WorkbasketSummary aWorkbasket = workbaskets.stream()
|
||||
.filter(x -> workbasketKey != null && workbasketKey.equals(x.getKey()))
|
||||
.findFirst()
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
package pro.taskana.impl;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import pro.taskana.Workbasket;
|
||||
import pro.taskana.WorkbasketSummary;
|
||||
|
@ -22,7 +20,6 @@ public class WorkbasketImpl implements Workbasket {
|
|||
private String owner;
|
||||
private String domain;
|
||||
private WorkbasketType type;
|
||||
private List<WorkbasketSummary> distributionTargets = new ArrayList<>();
|
||||
private String custom1;
|
||||
private String custom2;
|
||||
private String custom3;
|
||||
|
@ -122,16 +119,6 @@ public class WorkbasketImpl implements Workbasket {
|
|||
this.type = type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<WorkbasketSummary> getDistributionTargets() {
|
||||
return distributionTargets;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDistributionTargets(List<WorkbasketSummary> distributionTargets) {
|
||||
this.distributionTargets = distributionTargets;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCustom1() {
|
||||
return custom1;
|
||||
|
@ -229,6 +216,60 @@ public class WorkbasketImpl implements Workbasket {
|
|||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((domain == null) ? 0 : domain.hashCode());
|
||||
result = prime * result + ((id == null) ? 0 : id.hashCode());
|
||||
result = prime * result + ((key == null) ? 0 : key.hashCode());
|
||||
result = prime * result + ((name == null) ? 0 : name.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
if (!(obj instanceof WorkbasketImpl)) {
|
||||
return false;
|
||||
}
|
||||
WorkbasketImpl other = (WorkbasketImpl) obj;
|
||||
if (domain == null) {
|
||||
if (other.domain != null) {
|
||||
return false;
|
||||
}
|
||||
} else if (!domain.equals(other.domain)) {
|
||||
return false;
|
||||
}
|
||||
if (id == null) {
|
||||
if (other.id != null) {
|
||||
return false;
|
||||
}
|
||||
} else if (!id.equals(other.id)) {
|
||||
return false;
|
||||
}
|
||||
if (key == null) {
|
||||
if (other.key != null) {
|
||||
return false;
|
||||
}
|
||||
} else if (!key.equals(other.key)) {
|
||||
return false;
|
||||
}
|
||||
if (name == null) {
|
||||
if (other.name != null) {
|
||||
return false;
|
||||
}
|
||||
} else if (!name.equals(other.name)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
|
@ -250,8 +291,6 @@ public class WorkbasketImpl implements Workbasket {
|
|||
builder.append(domain);
|
||||
builder.append(", type=");
|
||||
builder.append(type);
|
||||
builder.append(", distributionTargets=");
|
||||
builder.append(distributionTargets);
|
||||
builder.append(", custom1=");
|
||||
builder.append(custom1);
|
||||
builder.append(", custom2=");
|
||||
|
|
|
@ -8,7 +8,6 @@ import org.apache.ibatis.session.RowBounds;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import pro.taskana.BaseQuery;
|
||||
import pro.taskana.TaskanaEngine;
|
||||
import pro.taskana.WorkbasketQuery;
|
||||
import pro.taskana.WorkbasketSummary;
|
||||
|
@ -75,19 +74,19 @@ public class WorkbasketQueryImpl implements WorkbasketQuery {
|
|||
}
|
||||
|
||||
@Override
|
||||
public BaseQuery<WorkbasketSummary> nameLike(String... names) {
|
||||
public WorkbasketQuery nameLike(String... names) {
|
||||
this.nameLike = toUpperCopy(names);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseQuery<WorkbasketSummary> keyLike(String... keys) {
|
||||
public WorkbasketQuery keyLike(String... keys) {
|
||||
this.keyLike = toUpperCopy(keys);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseQuery<WorkbasketSummary> keyOrNameLike(String... keysOrNames) {
|
||||
public WorkbasketQuery keyOrNameLike(String... keysOrNames) {
|
||||
this.keyOrNameLike = toUpperCopy(keysOrNames);
|
||||
return this;
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@ import pro.taskana.WorkbasketService;
|
|||
import pro.taskana.WorkbasketSummary;
|
||||
import pro.taskana.exceptions.InvalidWorkbasketException;
|
||||
import pro.taskana.exceptions.NotAuthorizedException;
|
||||
import pro.taskana.exceptions.SystemException;
|
||||
import pro.taskana.exceptions.WorkbasketNotFoundException;
|
||||
import pro.taskana.impl.util.IdGenerator;
|
||||
import pro.taskana.impl.util.LoggerUtils;
|
||||
|
@ -34,8 +35,7 @@ public class WorkbasketServiceImpl implements WorkbasketService {
|
|||
private static final Logger LOGGER = LoggerFactory.getLogger(WorkbasketServiceImpl.class);
|
||||
private static final String ID_PREFIX_WORKBASKET = "WBI";
|
||||
private static final String ID_PREFIX_WORKBASKET_AUTHORIZATION = "WAI";
|
||||
private TaskanaEngine taskanaEngine;
|
||||
private TaskanaEngineImpl taskanaEngineImpl;
|
||||
private TaskanaEngineImpl taskanaEngine;
|
||||
private WorkbasketMapper workbasketMapper;
|
||||
private DistributionTargetMapper distributionTargetMapper;
|
||||
private WorkbasketAccessMapper workbasketAccessMapper;
|
||||
|
@ -45,8 +45,7 @@ public class WorkbasketServiceImpl implements WorkbasketService {
|
|||
|
||||
public WorkbasketServiceImpl(TaskanaEngine taskanaEngine, WorkbasketMapper workbasketMapper,
|
||||
DistributionTargetMapper distributionTargetMapper, WorkbasketAccessMapper workbasketAccessMapper) {
|
||||
this.taskanaEngine = taskanaEngine;
|
||||
this.taskanaEngineImpl = (TaskanaEngineImpl) taskanaEngine;
|
||||
this.taskanaEngine = (TaskanaEngineImpl) taskanaEngine;
|
||||
this.workbasketMapper = workbasketMapper;
|
||||
this.distributionTargetMapper = distributionTargetMapper;
|
||||
this.workbasketAccessMapper = workbasketAccessMapper;
|
||||
|
@ -58,7 +57,7 @@ public class WorkbasketServiceImpl implements WorkbasketService {
|
|||
LOGGER.debug("entry to getWorkbasket(workbasketId = {})", workbasketId);
|
||||
Workbasket result = null;
|
||||
try {
|
||||
taskanaEngineImpl.openConnection();
|
||||
taskanaEngine.openConnection();
|
||||
result = workbasketMapper.findById(workbasketId);
|
||||
if (result == null) {
|
||||
LOGGER.error(
|
||||
|
@ -69,7 +68,7 @@ public class WorkbasketServiceImpl implements WorkbasketService {
|
|||
this.checkAuthorization(result.getKey(), WorkbasketAuthorization.READ);
|
||||
return result;
|
||||
} finally {
|
||||
taskanaEngineImpl.returnConnection();
|
||||
taskanaEngine.returnConnection();
|
||||
LOGGER.debug("exit from getWorkbasket(workbasketId). Returning result {} ", result);
|
||||
}
|
||||
}
|
||||
|
@ -80,7 +79,7 @@ public class WorkbasketServiceImpl implements WorkbasketService {
|
|||
LOGGER.debug("entry to getWorkbasketByKey(workbasketKey = {})", workbasketKey);
|
||||
Workbasket result = null;
|
||||
try {
|
||||
taskanaEngineImpl.openConnection();
|
||||
taskanaEngine.openConnection();
|
||||
result = workbasketMapper.findByKey(workbasketKey);
|
||||
if (result == null) {
|
||||
LOGGER.error(
|
||||
|
@ -91,7 +90,7 @@ public class WorkbasketServiceImpl implements WorkbasketService {
|
|||
this.checkAuthorization(workbasketKey, WorkbasketAuthorization.READ);
|
||||
return result;
|
||||
} finally {
|
||||
taskanaEngineImpl.returnConnection();
|
||||
taskanaEngine.returnConnection();
|
||||
LOGGER.debug("exit from getWorkbasket(workbasketId). Returning result {} ", result);
|
||||
}
|
||||
}
|
||||
|
@ -103,7 +102,7 @@ public class WorkbasketServiceImpl implements WorkbasketService {
|
|||
}
|
||||
List<WorkbasketSummary> result = null;
|
||||
try {
|
||||
taskanaEngineImpl.openConnection();
|
||||
taskanaEngine.openConnection();
|
||||
// use a set to avoid duplicates
|
||||
Set<WorkbasketSummary> workbaskets = new HashSet<>();
|
||||
for (String accessId : CurrentUserContext.getAccessIds()) {
|
||||
|
@ -113,7 +112,7 @@ public class WorkbasketServiceImpl implements WorkbasketService {
|
|||
result.addAll(workbaskets);
|
||||
return result;
|
||||
} finally {
|
||||
taskanaEngineImpl.returnConnection();
|
||||
taskanaEngine.returnConnection();
|
||||
if (LOGGER.isDebugEnabled()) {
|
||||
int numberOfResultObjects = result == null ? 0 : result.size();
|
||||
LOGGER.debug("exit from getWorkbaskets(permissions). Returning {} resulting Objects: {} ",
|
||||
|
@ -127,14 +126,14 @@ public class WorkbasketServiceImpl implements WorkbasketService {
|
|||
LOGGER.debug("entry to getWorkbaskets()");
|
||||
List<WorkbasketSummary> workbaskets = new ArrayList<>();
|
||||
try {
|
||||
taskanaEngineImpl.openConnection();
|
||||
taskanaEngine.openConnection();
|
||||
List<WorkbasketSummaryImpl> workbasketImpls = workbasketMapper.findAll();
|
||||
for (WorkbasketSummaryImpl workbasketSummaryImpl : workbasketImpls) {
|
||||
workbaskets.add(workbasketSummaryImpl);
|
||||
}
|
||||
return workbaskets;
|
||||
} finally {
|
||||
taskanaEngineImpl.returnConnection();
|
||||
taskanaEngine.returnConnection();
|
||||
if (LOGGER.isDebugEnabled()) {
|
||||
int numberOfResultObjects = workbaskets == null ? 0 : workbaskets.size();
|
||||
LOGGER.debug("exit from getWorkbaskets(). Returning {} resulting Objects: {} ", numberOfResultObjects,
|
||||
|
@ -150,7 +149,7 @@ public class WorkbasketServiceImpl implements WorkbasketService {
|
|||
Workbasket result = null;
|
||||
WorkbasketImpl workbasket = (WorkbasketImpl) newWorkbasket;
|
||||
try {
|
||||
taskanaEngineImpl.openConnection();
|
||||
taskanaEngine.openConnection();
|
||||
Instant now = Instant.now();
|
||||
workbasket.setCreated(now);
|
||||
workbasket.setModified(now);
|
||||
|
@ -161,19 +160,10 @@ public class WorkbasketServiceImpl implements WorkbasketService {
|
|||
|
||||
workbasketMapper.insert(workbasket);
|
||||
LOGGER.debug("Method createWorkbasket() created Workbasket '{}'", workbasket);
|
||||
if (workbasket.getDistributionTargets() != null) {
|
||||
for (WorkbasketSummary distributionTarget : workbasket.getDistributionTargets()) {
|
||||
// validate that all distribution targets exist
|
||||
this.getWorkbasket(distributionTarget.getId());
|
||||
distributionTargetMapper.insert(workbasket.getId(), distributionTarget.getId());
|
||||
LOGGER.debug("Method createWorkbasket() created distributiontarget for source '{}' and target {}",
|
||||
workbasket.getId(), distributionTarget.getId());
|
||||
}
|
||||
}
|
||||
result = workbasketMapper.findById(workbasket.getId());
|
||||
return result;
|
||||
} finally {
|
||||
taskanaEngineImpl.returnConnection();
|
||||
taskanaEngine.returnConnection();
|
||||
LOGGER.debug("exit from createWorkbasket(workbasket). Returning result {} ", result);
|
||||
}
|
||||
}
|
||||
|
@ -186,33 +176,14 @@ public class WorkbasketServiceImpl implements WorkbasketService {
|
|||
Workbasket result = null;
|
||||
WorkbasketImpl workbasket = (WorkbasketImpl) workbasketToUpdate;
|
||||
try {
|
||||
taskanaEngineImpl.openConnection();
|
||||
taskanaEngine.openConnection();
|
||||
workbasket.setModified(Instant.now());
|
||||
workbasketMapper.update(workbasket);
|
||||
LOGGER.debug("Method updateWorkbasket() updated workbasket '{}'", workbasket.getId());
|
||||
List<String> oldDistributionTargets = distributionTargetMapper.findBySourceId(workbasket.getId());
|
||||
List<WorkbasketSummary> newDistributionTargets = workbasket.getDistributionTargets();
|
||||
for (WorkbasketSummary distributionTarget : newDistributionTargets) {
|
||||
if (!oldDistributionTargets.contains(distributionTarget.getId())) {
|
||||
// check that old distribution target exists
|
||||
getWorkbasket(distributionTarget.getId());
|
||||
distributionTargetMapper.insert(workbasket.getId(), distributionTarget.getId());
|
||||
LOGGER.debug("Method updateWorkbasket() created distributionTarget for '{}' and '{}'",
|
||||
workbasket.getId(), distributionTarget.getId());
|
||||
} else {
|
||||
oldDistributionTargets.remove(distributionTarget.getId());
|
||||
}
|
||||
}
|
||||
distributionTargetMapper.deleteMultiple(workbasket.getId(), oldDistributionTargets);
|
||||
if (LOGGER.isInfoEnabled()) {
|
||||
LOGGER.debug(
|
||||
"Method updateWorkbasket() deleted distributionTargets for '{}' and old distribution targets {}",
|
||||
workbasket.getId(), LoggerUtils.listToString(oldDistributionTargets));
|
||||
}
|
||||
result = workbasketMapper.findById(workbasket.getId());
|
||||
return result;
|
||||
} finally {
|
||||
taskanaEngineImpl.returnConnection();
|
||||
taskanaEngine.returnConnection();
|
||||
LOGGER.debug("exit from updateWorkbasket(). Returning result {} ", result);
|
||||
}
|
||||
}
|
||||
|
@ -221,14 +192,14 @@ public class WorkbasketServiceImpl implements WorkbasketService {
|
|||
public WorkbasketAccessItem createWorkbasketAuthorization(WorkbasketAccessItem workbasketAccessItem) {
|
||||
LOGGER.debug("entry to createWorkbasketAuthorization(workbasketAccessItem = {})", workbasketAccessItem);
|
||||
try {
|
||||
taskanaEngineImpl.openConnection();
|
||||
taskanaEngine.openConnection();
|
||||
workbasketAccessItem.setId(IdGenerator.generateWithPrefix(ID_PREFIX_WORKBASKET_AUTHORIZATION));
|
||||
workbasketAccessMapper.insert(workbasketAccessItem);
|
||||
LOGGER.debug("Method createWorkbasketAuthorization() created workbaskteAccessItem {}",
|
||||
workbasketAccessItem);
|
||||
return workbasketAccessItem;
|
||||
} finally {
|
||||
taskanaEngineImpl.returnConnection();
|
||||
taskanaEngine.returnConnection();
|
||||
LOGGER.debug("exit from createWorkbasketAuthorization(workbasketAccessItem). Returning result {}",
|
||||
workbasketAccessItem);
|
||||
}
|
||||
|
@ -239,11 +210,11 @@ public class WorkbasketServiceImpl implements WorkbasketService {
|
|||
LOGGER.debug("entry to getWorkbasketAuthorization(id = {})", id);
|
||||
WorkbasketAccessItem result = null;
|
||||
try {
|
||||
taskanaEngineImpl.openConnection();
|
||||
taskanaEngine.openConnection();
|
||||
result = workbasketAccessMapper.findById(id);
|
||||
return result;
|
||||
} finally {
|
||||
taskanaEngineImpl.returnConnection();
|
||||
taskanaEngine.returnConnection();
|
||||
LOGGER.debug("exit from getWorkbasketAuthorization(id). Returning result {}", result);
|
||||
}
|
||||
}
|
||||
|
@ -252,11 +223,11 @@ public class WorkbasketServiceImpl implements WorkbasketService {
|
|||
public void deleteWorkbasketAuthorization(String id) {
|
||||
LOGGER.debug("entry to deleteWorkbasketAuthorization(id = {})", id);
|
||||
try {
|
||||
taskanaEngineImpl.openConnection();
|
||||
taskanaEngine.openConnection();
|
||||
workbasketAccessMapper.delete(id);
|
||||
LOGGER.debug("Method deleteWorkbasketAuthorization() deleted workbasketAccessItem wit Id {}", id);
|
||||
} finally {
|
||||
taskanaEngineImpl.returnConnection();
|
||||
taskanaEngine.returnConnection();
|
||||
LOGGER.debug("exit from deleteWorkbasketAuthorization(id).");
|
||||
}
|
||||
}
|
||||
|
@ -266,11 +237,11 @@ public class WorkbasketServiceImpl implements WorkbasketService {
|
|||
LOGGER.debug("entry to getAllAuthorizations()");
|
||||
List<WorkbasketAccessItem> result = null;
|
||||
try {
|
||||
taskanaEngineImpl.openConnection();
|
||||
taskanaEngine.openConnection();
|
||||
result = workbasketAccessMapper.findAll();
|
||||
return result;
|
||||
} finally {
|
||||
taskanaEngineImpl.returnConnection();
|
||||
taskanaEngine.returnConnection();
|
||||
if (LOGGER.isDebugEnabled()) {
|
||||
int numberOfResultObjects = result == null ? 0 : result.size();
|
||||
LOGGER.debug("exit from getAllAuthorizations(). Returning {} resulting Objects: {} ",
|
||||
|
@ -282,49 +253,21 @@ public class WorkbasketServiceImpl implements WorkbasketService {
|
|||
@Override
|
||||
public void checkAuthorization(String workbasketKey, WorkbasketAuthorization workbasketAuthorization)
|
||||
throws NotAuthorizedException {
|
||||
LOGGER.debug("entry to checkAuthorization(workbasketId = {}, workbasketAuthorization = {})", workbasketKey,
|
||||
workbasketAuthorization);
|
||||
boolean isAuthorized = false;
|
||||
try {
|
||||
taskanaEngineImpl.openConnection();
|
||||
// Skip permission check is security is not enabled
|
||||
if (!taskanaEngine.getConfiguration().isSecurityEnabled()) {
|
||||
LOGGER.debug("Skipping permissions check since security is disabled.");
|
||||
isAuthorized = true;
|
||||
return;
|
||||
}
|
||||
|
||||
List<String> accessIds = CurrentUserContext.getAccessIds();
|
||||
LOGGER.debug("checkAuthorization: Verifying that {} has the permission {} on workbasket {}",
|
||||
CurrentUserContext.getUserid(), workbasketAuthorization.name(), workbasketKey);
|
||||
|
||||
List<WorkbasketAccessItem> accessItems = workbasketAccessMapper
|
||||
.findByWorkbasketAndAccessIdAndAuthorization(workbasketKey, accessIds, workbasketAuthorization.name());
|
||||
|
||||
if (accessItems.size() <= 0) {
|
||||
throw new NotAuthorizedException("Not authorized. Authorization '" + workbasketAuthorization.name()
|
||||
+ "' on workbasket '" + workbasketKey + "' is needed.");
|
||||
}
|
||||
|
||||
isAuthorized = true;
|
||||
|
||||
} finally {
|
||||
taskanaEngineImpl.returnConnection();
|
||||
LOGGER.debug("exit from checkAuthorization(). User is authorized = {}.", isAuthorized);
|
||||
}
|
||||
checkAuthorization(workbasketKey, null, workbasketAuthorization);
|
||||
}
|
||||
|
||||
@Override
|
||||
public WorkbasketAccessItem updateWorkbasketAuthorization(WorkbasketAccessItem workbasketAccessItem) {
|
||||
LOGGER.debug("entry to updateWorkbasketAuthorization(workbasketAccessItem = {}", workbasketAccessItem);
|
||||
try {
|
||||
taskanaEngineImpl.openConnection();
|
||||
taskanaEngine.openConnection();
|
||||
workbasketAccessMapper.update(workbasketAccessItem);
|
||||
LOGGER.debug("Method updateWorkbasketAuthorization() updated workbasketAccessItem {}",
|
||||
workbasketAccessItem);
|
||||
return workbasketAccessItem;
|
||||
} finally {
|
||||
taskanaEngineImpl.returnConnection();
|
||||
taskanaEngine.returnConnection();
|
||||
LOGGER.debug("exit from updateWorkbasketAuthorization(workbasketAccessItem). Returning {}",
|
||||
workbasketAccessItem);
|
||||
}
|
||||
|
@ -335,11 +278,11 @@ public class WorkbasketServiceImpl implements WorkbasketService {
|
|||
LOGGER.debug("entry to getWorkbasketAuthorizations(workbasketId = {})", workbasketKey);
|
||||
List<WorkbasketAccessItem> result = null;
|
||||
try {
|
||||
taskanaEngineImpl.openConnection();
|
||||
taskanaEngine.openConnection();
|
||||
result = workbasketAccessMapper.findByWorkbasketKey(workbasketKey);
|
||||
return result;
|
||||
} finally {
|
||||
taskanaEngineImpl.returnConnection();
|
||||
taskanaEngine.returnConnection();
|
||||
if (LOGGER.isDebugEnabled()) {
|
||||
int numberOfResultObjects = result == null ? 0 : result.size();
|
||||
LOGGER.debug("exit from getWorkbasketAuthorizations(workbasketId). Returning {} resulting Objects: {} ",
|
||||
|
@ -351,7 +294,8 @@ public class WorkbasketServiceImpl implements WorkbasketService {
|
|||
@Override
|
||||
public List<WorkbasketAuthorization> getPermissionsForWorkbasket(String workbasketKey) {
|
||||
List<WorkbasketAuthorization> permissions = new ArrayList<>();
|
||||
WorkbasketAccessItem wbAcc = workbasketAccessMapper.findByWorkbasketAndAccessId(workbasketKey, CurrentUserContext.getAccessIds());
|
||||
WorkbasketAccessItem wbAcc = workbasketAccessMapper.findByWorkbasketAndAccessId(workbasketKey,
|
||||
CurrentUserContext.getAccessIds());
|
||||
this.addWorkbasketAccessItemValuesToPermissionSet(wbAcc, permissions);
|
||||
return permissions;
|
||||
}
|
||||
|
@ -379,7 +323,8 @@ public class WorkbasketServiceImpl implements WorkbasketService {
|
|||
}
|
||||
}
|
||||
|
||||
private void addWorkbasketAccessItemValuesToPermissionSet(WorkbasketAccessItem workbasketAccessItem, List<WorkbasketAuthorization> permissions) {
|
||||
private void addWorkbasketAccessItemValuesToPermissionSet(WorkbasketAccessItem workbasketAccessItem,
|
||||
List<WorkbasketAuthorization> permissions) {
|
||||
if (workbasketAccessItem.isPermOpen()) {
|
||||
permissions.add(WorkbasketAuthorization.OPEN);
|
||||
}
|
||||
|
@ -425,4 +370,190 @@ public class WorkbasketServiceImpl implements WorkbasketService {
|
|||
public Workbasket newWorkbasket() {
|
||||
return new WorkbasketImpl();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<WorkbasketSummary> getDistributionTargets(String workbasketId)
|
||||
throws NotAuthorizedException, WorkbasketNotFoundException {
|
||||
LOGGER.debug("entry to getDistributionTargets(workbasketId = {})", workbasketId);
|
||||
List<WorkbasketSummary> result = new ArrayList<>();
|
||||
try {
|
||||
taskanaEngine.openConnection();
|
||||
// check that source workbasket exists
|
||||
getWorkbasket(workbasketId);
|
||||
checkAuthorizationByWorkbasketId(workbasketId, WorkbasketAuthorization.READ);
|
||||
List<WorkbasketSummaryImpl> distributionTargets = workbasketMapper
|
||||
.findByDistributionTargets(workbasketId);
|
||||
result.addAll(distributionTargets);
|
||||
return result;
|
||||
} finally {
|
||||
taskanaEngine.returnConnection();
|
||||
if (LOGGER.isDebugEnabled()) {
|
||||
int numberOfResultObjects = result == null ? 0 : result.size();
|
||||
LOGGER.debug("exit from getDistributionTargets(workbasketId). Returning {} resulting Objects: {} ",
|
||||
numberOfResultObjects, LoggerUtils.listToString(result));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDistributionTargets(String sourceWorkbasketId, List<String> targetWorkbasketIds)
|
||||
throws WorkbasketNotFoundException, NotAuthorizedException {
|
||||
if (LOGGER.isDebugEnabled()) {
|
||||
LOGGER.debug("entry to setDistributionTargets(sourceWorkbasketId = {}, targetWorkazketIds = {})",
|
||||
sourceWorkbasketId,
|
||||
LoggerUtils.listToString(targetWorkbasketIds));
|
||||
}
|
||||
try {
|
||||
taskanaEngine.openConnection();
|
||||
// check existence of source workbasket
|
||||
WorkbasketImpl sourceWorkbasket = (WorkbasketImpl) getWorkbasket(sourceWorkbasketId);
|
||||
checkAuthorizationByWorkbasketId(sourceWorkbasketId, WorkbasketAuthorization.READ);
|
||||
distributionTargetMapper.deleteAllDistributionTargets(sourceWorkbasketId);
|
||||
|
||||
sourceWorkbasket.setModified(Instant.now());
|
||||
workbasketMapper.update(sourceWorkbasket);
|
||||
|
||||
if (targetWorkbasketIds != null) {
|
||||
for (String targetId : targetWorkbasketIds) {
|
||||
// check for existence of target workbasket
|
||||
getWorkbasket(targetId);
|
||||
distributionTargetMapper.insert(sourceWorkbasketId, targetId);
|
||||
LOGGER.debug(
|
||||
"Method setDistributionTargets() created distributiontarget for source '{}' and target {}",
|
||||
sourceWorkbasketId, targetId);
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
taskanaEngine.returnConnection();
|
||||
if (LOGGER.isDebugEnabled()) {
|
||||
LOGGER.debug("setDistributionTargets set {} distribution targets to source workbasket {} ",
|
||||
targetWorkbasketIds.size(), sourceWorkbasketId);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addDistributionTarget(String sourceWorkbasketId, String targetWorkbasketId)
|
||||
throws NotAuthorizedException, WorkbasketNotFoundException {
|
||||
LOGGER.debug("entry to addDistributionTarget(sourceWorkbasketId = {}, targetWorkbasketId = {})",
|
||||
sourceWorkbasketId, targetWorkbasketId);
|
||||
try {
|
||||
taskanaEngine.openConnection();
|
||||
// check existence of source workbasket
|
||||
WorkbasketImpl sourceWorkbasket = (WorkbasketImpl) getWorkbasket(sourceWorkbasketId);
|
||||
// check esistence of target workbasket
|
||||
getWorkbasket(targetWorkbasketId);
|
||||
checkAuthorizationByWorkbasketId(sourceWorkbasketId, WorkbasketAuthorization.READ);
|
||||
// check whether the target is already set as target
|
||||
int numOfDistTargets = distributionTargetMapper.getNumberOfDistributionTargets(sourceWorkbasketId,
|
||||
targetWorkbasketId);
|
||||
if (numOfDistTargets > 0) {
|
||||
LOGGER.debug(
|
||||
"addDistributionTarget detected that the specified distribution target exists already. Doing nothing...");
|
||||
} else {
|
||||
distributionTargetMapper.insert(sourceWorkbasketId, targetWorkbasketId);
|
||||
LOGGER.debug("addDistributionTarget inserted distribution target sourceId = {}, targetId = {}",
|
||||
sourceWorkbasketId, targetWorkbasketId);
|
||||
sourceWorkbasket.setModified(Instant.now());
|
||||
workbasketMapper.update(sourceWorkbasket);
|
||||
}
|
||||
|
||||
} finally {
|
||||
taskanaEngine.returnConnection();
|
||||
LOGGER.debug("exit from addDistributionTarget");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeDistributionTarget(String sourceWorkbasketId, String targetWorkbasketId)
|
||||
throws NotAuthorizedException {
|
||||
LOGGER.debug("entry to removeDistributionTarget(sourceWorkbasketId = {}, targetWorkbasketId = {})",
|
||||
sourceWorkbasketId, targetWorkbasketId);
|
||||
try {
|
||||
taskanaEngine.openConnection();
|
||||
// don't check existence of source / target workbasket to enable cleanup even if the db is corrupted
|
||||
checkAuthorizationByWorkbasketId(sourceWorkbasketId, WorkbasketAuthorization.READ);
|
||||
// check whether the target is set as target
|
||||
int numberOfDistTargets = distributionTargetMapper.getNumberOfDistributionTargets(sourceWorkbasketId,
|
||||
targetWorkbasketId);
|
||||
if (numberOfDistTargets > 0) {
|
||||
distributionTargetMapper.delete(sourceWorkbasketId, targetWorkbasketId);
|
||||
LOGGER.debug("removeDistributionTarget deleted distribution target sourceId = {}, targetId = {}",
|
||||
sourceWorkbasketId, targetWorkbasketId);
|
||||
|
||||
try {
|
||||
WorkbasketImpl sourceWorkbasket = (WorkbasketImpl) getWorkbasket(sourceWorkbasketId);
|
||||
sourceWorkbasket.setModified(Instant.now());
|
||||
workbasketMapper.update(sourceWorkbasket);
|
||||
} catch (WorkbasketNotFoundException e) {
|
||||
LOGGER.debug(
|
||||
"removeDistributionTarget found that the source workbasket {} doesn't exist. Ignoring the request... ",
|
||||
sourceWorkbasketId);
|
||||
}
|
||||
|
||||
} else {
|
||||
LOGGER.debug(
|
||||
"removeDistributionTarget detected that the specified distribution target doesn't exist. Doing nothing...");
|
||||
}
|
||||
} finally {
|
||||
taskanaEngine.returnConnection();
|
||||
LOGGER.debug("exit from addDistributionTarget");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void checkAuthorizationByWorkbasketId(String workbasketId,
|
||||
WorkbasketAuthorization workbasketAuthorization) throws NotAuthorizedException {
|
||||
checkAuthorization(null, workbasketId, workbasketAuthorization);
|
||||
}
|
||||
|
||||
private void checkAuthorization(String workbasketKey, String workbasketId,
|
||||
WorkbasketAuthorization workbasketAuthorization)
|
||||
throws NotAuthorizedException {
|
||||
LOGGER.debug("entry to checkAuthorization(workbasketId = {}, workbasketAuthorization = {})", workbasketKey,
|
||||
workbasketAuthorization);
|
||||
boolean isAuthorized = false;
|
||||
try {
|
||||
taskanaEngine.openConnection();
|
||||
// Skip permission check is security is not enabled
|
||||
if (!taskanaEngine.getConfiguration().isSecurityEnabled()) {
|
||||
LOGGER.debug("Skipping permissions check since security is disabled.");
|
||||
isAuthorized = true;
|
||||
return;
|
||||
}
|
||||
|
||||
List<String> accessIds = CurrentUserContext.getAccessIds();
|
||||
LOGGER.debug("checkAuthorization: Verifying that {} has the permission {} on workbasket {}",
|
||||
CurrentUserContext.getUserid(), workbasketAuthorization.name(), workbasketKey);
|
||||
|
||||
List<WorkbasketAccessItem> accessItems;
|
||||
|
||||
if (workbasketKey != null) {
|
||||
accessItems = workbasketAccessMapper
|
||||
.findByWorkbasketAndAccessIdAndAuthorization(workbasketKey, accessIds,
|
||||
workbasketAuthorization.name());
|
||||
} else if (workbasketId != null) {
|
||||
accessItems = workbasketAccessMapper
|
||||
.findByWorkbasketAndAccessIdAndAuthorizationsById(workbasketId, accessIds,
|
||||
workbasketAuthorization.name());
|
||||
} else {
|
||||
throw new SystemException(
|
||||
"checkAuthorizationImpl was called with both workbasketKey and workbasketId set to null");
|
||||
}
|
||||
|
||||
if (accessItems.size() <= 0) {
|
||||
throw new NotAuthorizedException("Not authorized. Authorization '" + workbasketAuthorization.name()
|
||||
+ "' on workbasket '" + workbasketKey + "' is needed.");
|
||||
}
|
||||
|
||||
isAuthorized = true;
|
||||
|
||||
} finally {
|
||||
taskanaEngine.returnConnection();
|
||||
LOGGER.debug("exit from checkAuthorization(). User is authorized = {}.", isAuthorized);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ import org.apache.ibatis.annotations.Delete;
|
|||
import org.apache.ibatis.annotations.Insert;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
|
||||
/**
|
||||
* This class is the mybatis mapping of distribution targets.
|
||||
*/
|
||||
|
@ -20,6 +21,12 @@ public interface DistributionTargetMapper {
|
|||
@Select("SELECT TARGET_ID FROM DISTRIBUTION_TARGETS WHERE SOURCE_ID = #{sourceId}")
|
||||
List<String> findBySourceId(@Param("sourceId") String sourceId);
|
||||
|
||||
@Select("SELECT count(*) FROM DISTRIBUTION_TARGETS WHERE SOURCE_ID = #{sourceId} AND TARGET_ID = #{targetId}")
|
||||
int getNumberOfDistributionTargets(@Param("sourceId") String sourceId, @Param("targetId") String targetId);
|
||||
|
||||
@Delete("<script>DELETE FROM DISTRIBUTION_TARGETS WHERE SOURCE_ID = #{sourceId} AND TARGET_ID IN (<foreach item='target' collection='targetId' separator=',' > #{target} </foreach>)</script>")
|
||||
void deleteMultiple(@Param("sourceId") String sourceId, @Param("targetId") List<String> targetId);
|
||||
|
||||
@Delete("DELETE FROM DISTRIBUTION_TARGETS WHERE SOURCE_ID = #{sourceId}")
|
||||
void deleteAllDistributionTargets(@Param("sourceId") String sourceId);
|
||||
}
|
||||
|
|
|
@ -169,4 +169,43 @@ public interface WorkbasketAccessMapper {
|
|||
List<WorkbasketAccessItem> findByWorkbasketAndAccessIdAndAuthorization(
|
||||
@Param("workbasketKey") String workbasketKey, @Param("accessIds") List<String> accessIds,
|
||||
@Param("authorization") String authorization);
|
||||
@Select("<script>SELECT A.ID, A.WORKBASKET_KEY, A.ACCESS_ID, A.PERM_READ, A.PERM_OPEN, A.PERM_APPEND, A.PERM_TRANSFER, A.PERM_DISTRIBUTE, A.PERM_CUSTOM_1, A.PERM_CUSTOM_2, A.PERM_CUSTOM_3, A.PERM_CUSTOM_4, A.PERM_CUSTOM_5, A.PERM_CUSTOM_6, A.PERM_CUSTOM_7, A.PERM_CUSTOM_8 "
|
||||
+ "FROM WORKBASKET_ACCESS_LIST AS A "
|
||||
+ "LEFT JOIN WORKBASKET AS W ON A.WORKBASKET_KEY = W.KEY "
|
||||
+ "WHERE W.ID = #{workbasketId} "
|
||||
+ "AND A.ACCESS_ID IN(<foreach item='item' collection='accessIds' separator=',' >#{item}</foreach>)"
|
||||
+ "AND <if test=\"authorization == 'OPEN'\">PERM_OPEN</if>"
|
||||
+ "<if test=\"authorization == 'READ'\">PERM_READ</if>"
|
||||
+ "<if test=\"authorization == 'APPEND'\">PERM_APPEND</if>"
|
||||
+ "<if test=\"authorization == 'TRANSFER'\">PERM_TRANSFER</if>"
|
||||
+ "<if test=\"authorization == 'DISTRIBUTE'\">PERM_DISTRIBUTE</if>"
|
||||
+ "<if test=\"authorization == 'CUSTOM_1'\">PERM_CUSTOM_1</if>"
|
||||
+ "<if test=\"authorization == 'CUSTOM_2'\">PERM_CUSTOM_2</if>"
|
||||
+ "<if test=\"authorization == 'CUSTOM_3'\">PERM_CUSTOM_3</if>"
|
||||
+ "<if test=\"authorization == 'CUSTOM_4'\">PERM_CUSTOM_4</if>"
|
||||
+ "<if test=\"authorization == 'CUSTOM_5'\">PERM_CUSTOM_5</if>"
|
||||
+ "<if test=\"authorization == 'CUSTOM_6'\">PERM_CUSTOM_6</if>"
|
||||
+ "<if test=\"authorization == 'CUSTOM_7'\">PERM_CUSTOM_7</if>"
|
||||
+ "<if test=\"authorization == 'CUSTOM_8'\">PERM_CUSTOM_8</if> = 1</script>")
|
||||
@Results(value = {
|
||||
@Result(property = "id", column = "ID"),
|
||||
@Result(property = "workbasketKey", column = "WORKBASKET_KEY"),
|
||||
@Result(property = "accessId", column = "ACCESS_ID"),
|
||||
@Result(property = "permRead", column = "PERM_READ"),
|
||||
@Result(property = "permOpen", column = "PERM_OPEN"),
|
||||
@Result(property = "permAppend", column = "PERM_APPEND"),
|
||||
@Result(property = "permTransfer", column = "PERM_TRANSFER"),
|
||||
@Result(property = "permDistribute", column = "PERM_DISTRIBUTE"),
|
||||
@Result(property = "permCustom1", column = "PERM_CUSTOM_1"),
|
||||
@Result(property = "permCustom2", column = "PERM_CUSTOM_2"),
|
||||
@Result(property = "permCustom3", column = "PERM_CUSTOM_3"),
|
||||
@Result(property = "permCustom4", column = "PERM_CUSTOM_4"),
|
||||
@Result(property = "permCustom5", column = "PERM_CUSTOM_5"),
|
||||
@Result(property = "permCustom6", column = "PERM_CUSTOM_6"),
|
||||
@Result(property = "permCustom7", column = "PERM_CUSTOM_7"),
|
||||
@Result(property = "permCustom8", column = "PERM_CUSTOM_8")})
|
||||
List<WorkbasketAccessItem> findByWorkbasketAndAccessIdAndAuthorizationsById(
|
||||
@Param("workbasketId") String workbasketId, @Param("accessIds") List<String> accessIds,
|
||||
@Param("authorization") String authorization);
|
||||
|
||||
}
|
||||
|
|
|
@ -4,14 +4,12 @@ import java.util.List;
|
|||
|
||||
import org.apache.ibatis.annotations.Delete;
|
||||
import org.apache.ibatis.annotations.Insert;
|
||||
import org.apache.ibatis.annotations.Many;
|
||||
import org.apache.ibatis.annotations.Options;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Result;
|
||||
import org.apache.ibatis.annotations.Results;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
import org.apache.ibatis.annotations.Update;
|
||||
import org.apache.ibatis.mapping.FetchType;
|
||||
|
||||
import pro.taskana.impl.WorkbasketImpl;
|
||||
import pro.taskana.impl.WorkbasketSummaryImpl;
|
||||
|
@ -32,8 +30,6 @@ public interface WorkbasketMapper {
|
|||
@Result(property = "type", column = "TYPE"),
|
||||
@Result(property = "description", column = "DESCRIPTION"),
|
||||
@Result(property = "owner", column = "OWNER"),
|
||||
@Result(property = "distributionTargets", column = "ID", javaType = List.class,
|
||||
many = @Many(fetchType = FetchType.DEFAULT, select = "findByDistributionTargets")),
|
||||
@Result(property = "custom1", column = "CUSTOM_1"),
|
||||
@Result(property = "custom2", column = "CUSTOM_2"),
|
||||
@Result(property = "custom3", column = "CUSTOM_3"),
|
||||
|
@ -41,7 +37,7 @@ public interface WorkbasketMapper {
|
|||
@Result(property = "orgLevel1", column = "ORG_LEVEL_1"),
|
||||
@Result(property = "orgLevel2", column = "ORG_LEVEL_2"),
|
||||
@Result(property = "orgLevel3", column = "ORG_LEVEL_3"),
|
||||
@Result(property = "orgLevel4", column = "ORG_LEVEL_4") })
|
||||
@Result(property = "orgLevel4", column = "ORG_LEVEL_4")})
|
||||
WorkbasketImpl findById(@Param("id") String id);
|
||||
|
||||
@Select("SELECT ID, KEY, CREATED, MODIFIED, NAME, DOMAIN, TYPE, DESCRIPTION, OWNER, CUSTOM_1 ,CUSTOM_2 ,CUSTOM_3 ,CUSTOM_4 ,ORG_LEVEL_1 ,ORG_LEVEL_2 ,ORG_LEVEL_3 ,ORG_LEVEL_4 FROM WORKBASKET WHERE KEY = #{key}")
|
||||
|
@ -54,8 +50,6 @@ public interface WorkbasketMapper {
|
|||
@Result(property = "type", column = "TYPE"),
|
||||
@Result(property = "description", column = "DESCRIPTION"),
|
||||
@Result(property = "owner", column = "OWNER"),
|
||||
@Result(property = "distributionTargets", column = "ID", javaType = List.class,
|
||||
many = @Many(fetchType = FetchType.DEFAULT, select = "findByDistributionTargets")),
|
||||
@Result(property = "custom1", column = "CUSTOM_1"),
|
||||
@Result(property = "custom2", column = "CUSTOM_2"),
|
||||
@Result(property = "custom3", column = "CUSTOM_3"),
|
||||
|
@ -64,7 +58,7 @@ public interface WorkbasketMapper {
|
|||
@Result(property = "orgLevel1", column = "ORG_LEVEL_1"),
|
||||
@Result(property = "orgLevel2", column = "ORG_LEVEL_2"),
|
||||
@Result(property = "orgLevel3", column = "ORG_LEVEL_3"),
|
||||
@Result(property = "orgLevel4", column = "ORG_LEVEL_4") })
|
||||
@Result(property = "orgLevel4", column = "ORG_LEVEL_4")})
|
||||
WorkbasketImpl findByKey(@Param("key") String key);
|
||||
|
||||
@Select("SELECT * FROM WORKBASKET WHERE id IN (SELECT TARGET_ID FROM DISTRIBUTION_TARGETS WHERE SOURCE_ID = #{id})")
|
||||
|
@ -80,7 +74,7 @@ public interface WorkbasketMapper {
|
|||
@Result(property = "orgLevel1", column = "ORG_LEVEL_1"),
|
||||
@Result(property = "orgLevel2", column = "ORG_LEVEL_2"),
|
||||
@Result(property = "orgLevel3", column = "ORG_LEVEL_3"),
|
||||
@Result(property = "orgLevel4", column = "ORG_LEVEL_4") })
|
||||
@Result(property = "orgLevel4", column = "ORG_LEVEL_4")})
|
||||
List<WorkbasketSummaryImpl> findByDistributionTargets(@Param("id") String id);
|
||||
|
||||
@Select("SELECT ID, KEY, NAME, DESCRIPTION, OWNER, DOMAIN, TYPE, ORG_LEVEL_1, ORG_LEVEL_2, ORG_LEVEL_3, ORG_LEVEL_4 FROM WORKBASKET WHERE key = #{key}")
|
||||
|
@ -111,7 +105,7 @@ public interface WorkbasketMapper {
|
|||
@Result(property = "orgLevel1", column = "ORG_LEVEL_1"),
|
||||
@Result(property = "orgLevel2", column = "ORG_LEVEL_2"),
|
||||
@Result(property = "orgLevel3", column = "ORG_LEVEL_3"),
|
||||
@Result(property = "orgLevel4", column = "ORG_LEVEL_4") })
|
||||
@Result(property = "orgLevel4", column = "ORG_LEVEL_4")})
|
||||
List<WorkbasketSummaryImpl> findAll();
|
||||
|
||||
@Select("<script>SELECT W.ID, W.KEY, W.NAME, W.DESCRIPTION, W.OWNER, W.DOMAIN, W.TYPE, W.ORG_LEVEL_1, W.ORG_LEVEL_2, W.ORG_LEVEL_3, W.ORG_LEVEL_4 FROM WORKBASKET AS W "
|
||||
|
@ -145,7 +139,7 @@ public interface WorkbasketMapper {
|
|||
@Result(property = "orgLevel1", column = "ORG_LEVEL_1"),
|
||||
@Result(property = "orgLevel2", column = "ORG_LEVEL_2"),
|
||||
@Result(property = "orgLevel3", column = "ORG_LEVEL_3"),
|
||||
@Result(property = "orgLevel4", column = "ORG_LEVEL_4") })
|
||||
@Result(property = "orgLevel4", column = "ORG_LEVEL_4")})
|
||||
List<WorkbasketSummaryImpl> findByPermission(@Param("authorizations") List<WorkbasketAuthorization> authorizations,
|
||||
@Param("accessId") String accessId);
|
||||
|
||||
|
|
|
@ -36,10 +36,14 @@ public abstract class AbstractAccTest {
|
|||
resetDb();
|
||||
}
|
||||
|
||||
public static void resetDb() throws SQLException {
|
||||
public static void resetDb(boolean... dropTables) throws SQLException {
|
||||
DataSource dataSource = TaskanaEngineConfigurationTest.getDataSource();
|
||||
DBCleaner cleaner = new DBCleaner();
|
||||
cleaner.clearDb(dataSource, true);
|
||||
if (dropTables == null || dropTables.length == 0) {
|
||||
cleaner.clearDb(dataSource, true);
|
||||
} else {
|
||||
cleaner.clearDb(dataSource, dropTables[0]);
|
||||
}
|
||||
dataSource = TaskanaEngineConfigurationTest.getDataSource();
|
||||
taskanaEngineConfiguration = new TaskanaEngineConfiguration(dataSource, false);
|
||||
taskanaEngine = taskanaEngineConfiguration.buildTaskanaEngine();
|
||||
|
|
|
@ -0,0 +1,209 @@
|
|||
package acceptance.workbasket;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.h2.store.fs.FileUtils;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import acceptance.AbstractAccTest;
|
||||
import pro.taskana.Workbasket;
|
||||
import pro.taskana.WorkbasketService;
|
||||
import pro.taskana.WorkbasketSummary;
|
||||
import pro.taskana.exceptions.InvalidWorkbasketException;
|
||||
import pro.taskana.exceptions.NotAuthorizedException;
|
||||
import pro.taskana.exceptions.WorkbasketNotFoundException;
|
||||
import pro.taskana.security.JAASRunner;
|
||||
import pro.taskana.security.WithAccessId;
|
||||
|
||||
/**
|
||||
* Acceptance test for all "get workbasket" scenarios.
|
||||
*/
|
||||
@RunWith(JAASRunner.class)
|
||||
public class DistributionTargetsAccTest extends AbstractAccTest {
|
||||
|
||||
public DistributionTargetsAccTest() {
|
||||
super();
|
||||
}
|
||||
|
||||
@WithAccessId(
|
||||
userName = "user_1_1",
|
||||
groupNames = {"teamlead_1"})
|
||||
@Test
|
||||
public void testGetDistributionTargetsSucceeds() throws NotAuthorizedException, WorkbasketNotFoundException {
|
||||
WorkbasketService workbasketService = taskanaEngine.getWorkbasketService();
|
||||
WorkbasketSummary workbasketSummary = workbasketService.createWorkbasketQuery()
|
||||
.keyIn("GPK_KSC")
|
||||
.single();
|
||||
|
||||
List<WorkbasketSummary> retrievedDistributionTargets = workbasketService
|
||||
.getDistributionTargets(workbasketSummary.getId());
|
||||
|
||||
Assert.assertEquals(4, retrievedDistributionTargets.size());
|
||||
List<String> expectedTargetIds = new ArrayList<>(
|
||||
Arrays.asList("WBI:100000000000000000000000000000000002", "WBI:100000000000000000000000000000000003",
|
||||
"WBI:100000000000000000000000000000000004", "WBI:100000000000000000000000000000000005"));
|
||||
|
||||
for (WorkbasketSummary wbSummary : retrievedDistributionTargets) {
|
||||
Assert.assertTrue(expectedTargetIds.contains(wbSummary.getId()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@WithAccessId(
|
||||
userName = "user_1_1",
|
||||
groupNames = {"teamlead_1", "group_1", "group_2"})
|
||||
@Test
|
||||
public void testDistributionTargetCallsWithNonExistingWorkbaskets()
|
||||
throws NotAuthorizedException, WorkbasketNotFoundException {
|
||||
WorkbasketService workbasketService = taskanaEngine.getWorkbasketService();
|
||||
String existingWb = "WBI:100000000000000000000000000000000001";
|
||||
String nonExistingWb = "WBI:100000000000000000000000000000000xx1";
|
||||
|
||||
try {
|
||||
workbasketService.getDistributionTargets("WBI:100000000000000000000000000000000xx1");
|
||||
Assert.assertTrue("This line of code should not be reached", false);
|
||||
} catch (WorkbasketNotFoundException ex) {
|
||||
// nothing to do
|
||||
}
|
||||
|
||||
try {
|
||||
List<String> distributionTargets = new ArrayList<>(
|
||||
Arrays.asList(nonExistingWb));
|
||||
workbasketService.setDistributionTargets(existingWb, distributionTargets);
|
||||
Assert.assertTrue("This line of code should not be reached", false);
|
||||
} catch (WorkbasketNotFoundException ex) {
|
||||
// nothing to do
|
||||
}
|
||||
|
||||
try {
|
||||
workbasketService.addDistributionTarget(existingWb, nonExistingWb);
|
||||
Assert.assertTrue("This line of code should not be reached", false);
|
||||
} catch (WorkbasketNotFoundException ex) {
|
||||
// nothing to do
|
||||
}
|
||||
|
||||
int beforeCount = workbasketService.getDistributionTargets(existingWb).size();
|
||||
workbasketService.removeDistributionTarget(existingWb, nonExistingWb);
|
||||
int afterCount = workbasketService.getDistributionTargets(existingWb).size();
|
||||
|
||||
Assert.assertEquals(afterCount, beforeCount);
|
||||
|
||||
}
|
||||
|
||||
@WithAccessId(
|
||||
userName = "user_3_1")
|
||||
@Test
|
||||
public void testDistributionTargetCallsFailWithNotAuthorizedException()
|
||||
throws NotAuthorizedException, WorkbasketNotFoundException {
|
||||
WorkbasketService workbasketService = taskanaEngine.getWorkbasketService();
|
||||
String existingWb = "WBI:100000000000000000000000000000000001";
|
||||
|
||||
try {
|
||||
workbasketService.getDistributionTargets(existingWb);
|
||||
Assert.assertTrue("This line of code should not be reached", false);
|
||||
} catch (NotAuthorizedException ex) {
|
||||
// nothing to do
|
||||
}
|
||||
|
||||
try {
|
||||
List<String> distributionTargets = new ArrayList<>(
|
||||
Arrays.asList("WBI:100000000000000000000000000000000002"));
|
||||
workbasketService.setDistributionTargets(existingWb, distributionTargets);
|
||||
Assert.assertTrue("This line of code should not be reached", false);
|
||||
} catch (NotAuthorizedException ex) {
|
||||
// nothing to do
|
||||
}
|
||||
|
||||
try {
|
||||
workbasketService.addDistributionTarget(existingWb,
|
||||
"WBI:100000000000000000000000000000000002");
|
||||
Assert.assertTrue("This line of code should not be reached", false);
|
||||
} catch (NotAuthorizedException ex) {
|
||||
// nothing to do
|
||||
}
|
||||
|
||||
try {
|
||||
workbasketService.removeDistributionTarget(existingWb,
|
||||
"WBI:100000000000000000000000000000000002");
|
||||
Assert.assertTrue("This line of code should not be reached", false);
|
||||
} catch (NotAuthorizedException ex) {
|
||||
// nothing to do
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@WithAccessId(
|
||||
userName = "user_2_2",
|
||||
groupNames = {"group_1", "group_2"})
|
||||
@Test
|
||||
public void testAddAndRemoveDistributionTargets()
|
||||
throws NotAuthorizedException, WorkbasketNotFoundException, InvalidWorkbasketException {
|
||||
WorkbasketService workbasketService = taskanaEngine.getWorkbasketService();
|
||||
Workbasket workbasket = workbasketService.getWorkbasketByKey("GPK_KSC_1");
|
||||
|
||||
List<WorkbasketSummary> distributionTargets = workbasketService.getDistributionTargets(workbasket.getId());
|
||||
Assert.assertEquals(4, distributionTargets.size());
|
||||
|
||||
// add a new distribution target
|
||||
Workbasket newTarget = workbasketService.getWorkbasketByKey("GPK_B_KSC_2");
|
||||
workbasketService.addDistributionTarget(workbasket.getId(), newTarget.getId());
|
||||
|
||||
distributionTargets = workbasketService.getDistributionTargets(workbasket.getId());
|
||||
Assert.assertEquals(5, distributionTargets.size());
|
||||
|
||||
// remove the new target
|
||||
workbasketService.removeDistributionTarget(workbasket.getId(), newTarget.getId());
|
||||
distributionTargets = workbasketService.getDistributionTargets(workbasket.getId());
|
||||
Assert.assertEquals(4, distributionTargets.size());
|
||||
|
||||
// remove the new target again Question: should this throw an exception?
|
||||
workbasketService.removeDistributionTarget(workbasket.getId(), newTarget.getId());
|
||||
distributionTargets = workbasketService.getDistributionTargets(workbasket.getId());
|
||||
Assert.assertEquals(4, distributionTargets.size());
|
||||
|
||||
}
|
||||
|
||||
@WithAccessId(
|
||||
userName = "user_2_2",
|
||||
groupNames = {"group_1", "group_2"})
|
||||
@Test
|
||||
public void testSetDistributionTargets()
|
||||
throws NotAuthorizedException, WorkbasketNotFoundException, InvalidWorkbasketException, SQLException {
|
||||
WorkbasketService workbasketService = taskanaEngine.getWorkbasketService();
|
||||
|
||||
Workbasket sourceWorkbasket = workbasketService.getWorkbasketByKey("GPK_KSC_1");
|
||||
|
||||
List<WorkbasketSummary> initialDistributionTargets = workbasketService
|
||||
.getDistributionTargets(sourceWorkbasket.getId());
|
||||
Assert.assertEquals(4, initialDistributionTargets.size());
|
||||
|
||||
List<WorkbasketSummary> newDistributionTargets = workbasketService.createWorkbasketQuery()
|
||||
.keyIn("USER_1_1", "GPK_B_KSC_1")
|
||||
.list();
|
||||
Assert.assertEquals(2, newDistributionTargets.size());
|
||||
|
||||
List<String> newDistributionTargetIds = newDistributionTargets.stream().map(t -> t.getId()).collect(
|
||||
Collectors.toList());
|
||||
|
||||
workbasketService.setDistributionTargets(sourceWorkbasket.getId(), newDistributionTargetIds);
|
||||
List<WorkbasketSummary> changedTargets = workbasketService.getDistributionTargets(sourceWorkbasket.getId());
|
||||
Assert.assertEquals(2, changedTargets.size());
|
||||
|
||||
// reset DB to original state
|
||||
resetDb(false);
|
||||
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void cleanUpClass() {
|
||||
FileUtils.deleteRecursive("~/data", true);
|
||||
}
|
||||
|
||||
}
|
|
@ -120,6 +120,7 @@ public class ClassificationServiceImplTest {
|
|||
verify(classificationMapperMock, times(1)).insert(any());
|
||||
verify(taskanaEngineImplMock, times(2)).returnConnection();
|
||||
verifyNoMoreInteractions(classificationMapperMock, taskanaEngineImplMock, classificationQueryImplMock);
|
||||
Thread.sleep(15);
|
||||
assertThat(classification.getCreated().toString().substring(0, 10), equalTo(todaysDate));
|
||||
assertFalse(classification.getCreated().isAfter(Instant.now()));
|
||||
assertTrue(classification.getCreated().isAfter(beforeTimestamp));
|
||||
|
|
|
@ -13,6 +13,7 @@ import static org.mockito.Mockito.verify;
|
|||
import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Before;
|
||||
|
@ -26,7 +27,6 @@ import org.mockito.Spy;
|
|||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
import pro.taskana.Workbasket;
|
||||
import pro.taskana.WorkbasketSummary;
|
||||
import pro.taskana.configuration.TaskanaEngineConfiguration;
|
||||
import pro.taskana.exceptions.InvalidWorkbasketException;
|
||||
import pro.taskana.exceptions.NotAuthorizedException;
|
||||
|
@ -292,16 +292,22 @@ public class WorkbasketServiceImplTest {
|
|||
public void testCreateWorkbasket_WithoutDistibutionTargets()
|
||||
throws WorkbasketNotFoundException, NotAuthorizedException, InvalidWorkbasketException {
|
||||
WorkbasketImpl expectedWb = createTestWorkbasket(null, "Key-1");
|
||||
expectedWb.setDistributionTargets(null);
|
||||
doNothing().when(workbasketMapperMock).insert(expectedWb);
|
||||
doReturn(expectedWb).when(workbasketMapperMock).findById(any());
|
||||
doReturn(taskanaEngineConfigurationMock).when(taskanaEngineImplMock).getConfiguration();
|
||||
doReturn(false).when(taskanaEngineConfigurationMock).isSecurityEnabled();
|
||||
|
||||
Workbasket actualWb = cutSpy.createWorkbasket(expectedWb);
|
||||
cutSpy.setDistributionTargets(expectedWb.getId(), null);
|
||||
|
||||
verify(taskanaEngineImplMock, times(1)).openConnection();
|
||||
verify(taskanaEngineImplMock, times(5)).openConnection();
|
||||
verify(taskanaEngineImplMock, times(2)).getConfiguration();
|
||||
verify(taskanaEngineConfigurationMock, times(2)).isSecurityEnabled();
|
||||
verify(workbasketMapperMock, times(1)).insert(expectedWb);
|
||||
verify(workbasketMapperMock, times(1)).findById(expectedWb.getId());
|
||||
verify(taskanaEngineImplMock, times(1)).returnConnection();
|
||||
verify(workbasketMapperMock, times(2)).findById(expectedWb.getId());
|
||||
verify(workbasketMapperMock, times(1)).update(any());
|
||||
verify(taskanaEngineImplMock, times(5)).returnConnection();
|
||||
verify(distributionTargetMapperMock, times(1)).deleteAllDistributionTargets(any());
|
||||
verifyNoMoreInteractions(workbasketMapperMock, workbasketAccessMapperMock, distributionTargetMapperMock,
|
||||
taskanaEngineImplMock, taskanaEngineConfigurationMock);
|
||||
assertThat(actualWb.getId(), not(equalTo(null)));
|
||||
|
@ -315,19 +321,25 @@ public class WorkbasketServiceImplTest {
|
|||
throws WorkbasketNotFoundException, NotAuthorizedException, InvalidWorkbasketException {
|
||||
final int distTargetAmount = 2;
|
||||
WorkbasketImpl expectedWb = createTestWorkbasket(null, "Key-1");
|
||||
expectedWb.setDistributionTargets(createTestDistributionTargets(distTargetAmount));
|
||||
doNothing().when(workbasketMapperMock).insert(expectedWb);
|
||||
doReturn(expectedWb).when(cutSpy).getWorkbasket(any());
|
||||
doReturn(expectedWb).when(workbasketMapperMock).findById(any());
|
||||
doReturn(taskanaEngineConfigurationMock).when(taskanaEngineImplMock).getConfiguration();
|
||||
doReturn(false).when(taskanaEngineConfigurationMock).isSecurityEnabled();
|
||||
|
||||
Workbasket actualWb = cutSpy.createWorkbasket(expectedWb);
|
||||
cutSpy.setDistributionTargets(expectedWb.getId(), createTestDistributionTargets(distTargetAmount));
|
||||
|
||||
verify(taskanaEngineImplMock, times(1)).openConnection();
|
||||
verify(workbasketMapperMock, times(1)).insert(expectedWb);
|
||||
verify(cutSpy, times(distTargetAmount)).getWorkbasket(any());
|
||||
verify(taskanaEngineImplMock, times(5)).openConnection();
|
||||
verify(taskanaEngineImplMock, times(1)).getConfiguration();
|
||||
verify(taskanaEngineConfigurationMock, times(1)).isSecurityEnabled();
|
||||
verify(workbasketMapperMock, times(3)).insert(any());
|
||||
verify(cutSpy, times(distTargetAmount + 1)).getWorkbasket(any());
|
||||
verify(distributionTargetMapperMock, times(1)).deleteAllDistributionTargets(any());
|
||||
verify(distributionTargetMapperMock, times(distTargetAmount)).insert(any(), any());
|
||||
verify(workbasketMapperMock, times(1)).findById(expectedWb.getId());
|
||||
verify(taskanaEngineImplMock, times(1)).returnConnection();
|
||||
verify(workbasketMapperMock, times(3)).findById(any());
|
||||
verify(workbasketMapperMock, times(1)).update(any());
|
||||
verify(taskanaEngineImplMock, times(5)).returnConnection();
|
||||
verifyNoMoreInteractions(workbasketMapperMock, workbasketAccessMapperMock, distributionTargetMapperMock,
|
||||
taskanaEngineImplMock, taskanaEngineConfigurationMock);
|
||||
assertThat(actualWb.getId(), not(equalTo(null)));
|
||||
|
@ -341,18 +353,21 @@ public class WorkbasketServiceImplTest {
|
|||
throws WorkbasketNotFoundException, NotAuthorizedException, InvalidWorkbasketException {
|
||||
final int distTargetAmount = 5;
|
||||
WorkbasketImpl expectedWb = createTestWorkbasket("ID-1", "Key-1");
|
||||
expectedWb.setDistributionTargets(createTestDistributionTargets(distTargetAmount));
|
||||
doNothing().when(workbasketMapperMock).insert(expectedWb);
|
||||
doThrow(WorkbasketNotFoundException.class).when(cutSpy)
|
||||
.getWorkbasket(expectedWb.getDistributionTargets().get(0).getId());
|
||||
|
||||
try {
|
||||
cutSpy.createWorkbasket(expectedWb);
|
||||
String id1 = "4711";
|
||||
List<String> destinations = new ArrayList<>(Arrays.asList(id1));
|
||||
cutSpy.setDistributionTargets(expectedWb.getId(), destinations);
|
||||
doThrow(WorkbasketNotFoundException.class).when(cutSpy).getDistributionTargets(expectedWb.getId()).get(0);
|
||||
|
||||
} catch (WorkbasketNotFoundException e) {
|
||||
verify(taskanaEngineImplMock, times(1)).openConnection();
|
||||
verify(taskanaEngineImplMock, times(3)).openConnection();
|
||||
verify(workbasketMapperMock, times(1)).insert(expectedWb);
|
||||
verify(workbasketMapperMock, times(2)).findById(any());
|
||||
verify(cutSpy, times(1)).getWorkbasket(any());
|
||||
verify(taskanaEngineImplMock, times(1)).returnConnection();
|
||||
verify(taskanaEngineImplMock, times(3)).returnConnection();
|
||||
verifyNoMoreInteractions(workbasketMapperMock, workbasketAccessMapperMock, distributionTargetMapperMock,
|
||||
taskanaEngineImplMock, taskanaEngineConfigurationMock);
|
||||
throw e;
|
||||
|
@ -365,7 +380,6 @@ public class WorkbasketServiceImplTest {
|
|||
public void testCreateWorkbasket_NotCreated()
|
||||
throws WorkbasketNotFoundException, NotAuthorizedException, InvalidWorkbasketException {
|
||||
WorkbasketImpl expectedWb = createTestWorkbasket(null, "Key-1");
|
||||
expectedWb.setDistributionTargets(null);
|
||||
doNothing().when(workbasketMapperMock).insert(expectedWb);
|
||||
doThrow(WorkbasketNotFoundException.class).when(workbasketMapperMock).findById(any());
|
||||
|
||||
|
@ -393,11 +407,14 @@ public class WorkbasketServiceImplTest {
|
|||
return workbasket;
|
||||
}
|
||||
|
||||
private List<WorkbasketSummary> createTestDistributionTargets(int amount) {
|
||||
List<WorkbasketSummary> distributionsTargets = new ArrayList<>();
|
||||
private List<String> createTestDistributionTargets(int amount)
|
||||
throws WorkbasketNotFoundException, InvalidWorkbasketException, NotAuthorizedException {
|
||||
List<String> distributionsTargets = new ArrayList<>();
|
||||
amount = (amount < 0) ? 0 : amount;
|
||||
for (int i = 0; i < amount; i++) {
|
||||
distributionsTargets.add(createTestWorkbasket("WB-ID-" + i, "WB-KEY-" + i).asSummary());
|
||||
WorkbasketImpl wb = createTestWorkbasket("WB-ID-" + i, "WB-KEY-" + i);
|
||||
cutSpy.createWorkbasket(wb);
|
||||
distributionsTargets.add(wb.getId());
|
||||
}
|
||||
return distributionsTargets;
|
||||
}
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
package pro.taskana.impl.integration;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.equalTo;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
|
@ -9,6 +7,7 @@ import java.sql.SQLException;
|
|||
import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import javax.security.auth.login.LoginException;
|
||||
|
@ -58,16 +57,13 @@ public class WorkbasketServiceImplIntAutocommitTest {
|
|||
|
||||
private static final int SLEEP_TIME = 100;
|
||||
private static final int THREE = 3;
|
||||
private static final Duration ONE_DAY = Duration.ofDays(1L);
|
||||
private static final Duration TEN_DAYS = Duration.ofDays(10L);
|
||||
private static final Duration FIFTEEN_DAYS = Duration.ofDays(15L);
|
||||
private static final Duration TWENTY_DAYS = Duration.ofDays(20L);
|
||||
static int counter = 0;
|
||||
private DataSource dataSource;
|
||||
private TaskanaEngineConfiguration taskanaEngineConfiguration;
|
||||
private TaskanaEngine taskanaEngine;
|
||||
private TaskanaEngineImpl taskanaEngineImpl;
|
||||
private WorkbasketService workBasketService;
|
||||
private Instant now;
|
||||
|
||||
@BeforeClass
|
||||
public static void resetDb() throws SQLException {
|
||||
|
@ -86,6 +82,7 @@ public class WorkbasketServiceImplIntAutocommitTest {
|
|||
workBasketService = taskanaEngine.getWorkbasketService();
|
||||
DBCleaner cleaner = new DBCleaner();
|
||||
cleaner.clearDb(dataSource, false);
|
||||
now = Instant.now();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -165,18 +162,17 @@ public class WorkbasketServiceImplIntAutocommitTest {
|
|||
Workbasket wbDist2 = createTestWorkbasket(id, "key1", "novatec", "Megabasket", WorkbasketType.GROUP);
|
||||
wbDist2 = workBasketService.createWorkbasket(wbDist2);
|
||||
createWorkbasketWithSecurity(wbDist2, "Elena", true, true, false, false);
|
||||
|
||||
id = IdGenerator.generateWithPrefix("TWB");
|
||||
Workbasket workbasket = createTestWorkbasket(id, "key2", "novatec", "Hyperbasket", WorkbasketType.GROUP);
|
||||
workbasket.setDistributionTargets(new ArrayList<>());
|
||||
workbasket.getDistributionTargets().add(wbDist1.asSummary());
|
||||
workbasket.getDistributionTargets().add(wbDist2.asSummary());
|
||||
workbasket = workBasketService.createWorkbasket(workbasket);
|
||||
List<String> distributionTargets = new ArrayList<>(Arrays.asList(wbDist1.getId(), wbDist2.getId()));
|
||||
createWorkbasketWithSecurity(workbasket, "Elena", true, true, false, false);
|
||||
workBasketService.setDistributionTargets(workbasket.getId(), distributionTargets);
|
||||
|
||||
Workbasket foundWorkbasket = workBasketService.getWorkbasket(workbasket.getId());
|
||||
Assert.assertEquals(id, foundWorkbasket.getId());
|
||||
Assert.assertEquals(2, foundWorkbasket.getDistributionTargets().size());
|
||||
Assert.assertEquals(2, workBasketService.getDistributionTargets(foundWorkbasket.getId()).size());
|
||||
|
||||
}
|
||||
|
||||
@WithAccessId(userName = "Elena")
|
||||
|
@ -194,11 +190,10 @@ public class WorkbasketServiceImplIntAutocommitTest {
|
|||
|
||||
String id2 = IdGenerator.generateWithPrefix("TWB");
|
||||
Workbasket workbasket2 = createTestWorkbasket(id2, "key2", "novatec", "Hyperbasket", WorkbasketType.GROUP);
|
||||
workbasket2.setDistributionTargets(new ArrayList<>());
|
||||
workbasket2.getDistributionTargets().add(workbasket0.asSummary());
|
||||
workbasket2.getDistributionTargets().add(workbasket1.asSummary());
|
||||
workbasket2 = workBasketService.createWorkbasket(workbasket2);
|
||||
createWorkbasketWithSecurity(workbasket2, "Elena", true, true, false, false);
|
||||
List<String> distTargets = new ArrayList<>(Arrays.asList(workbasket0.getId(), workbasket1.getId()));
|
||||
workBasketService.setDistributionTargets(workbasket2.getId(), distTargets);
|
||||
|
||||
String id3 = IdGenerator.generateWithPrefix("TWB");
|
||||
Workbasket workbasket3 = createTestWorkbasket(id3, "key3", "novatec", "hm ... irgend ein basket",
|
||||
|
@ -206,18 +201,19 @@ public class WorkbasketServiceImplIntAutocommitTest {
|
|||
workbasket3 = workBasketService.createWorkbasket(workbasket3);
|
||||
createWorkbasketWithSecurity(workbasket3, "Elena", true, true, false, false);
|
||||
|
||||
workbasket2.getDistributionTargets().clear();
|
||||
workbasket2.getDistributionTargets().add(workbasket3.asSummary());
|
||||
Thread.sleep(SLEEP_TIME);
|
||||
workbasket2 = workBasketService.updateWorkbasket(workbasket2);
|
||||
List<String> newDistTargets = new ArrayList<>(Arrays.asList(workbasket3.getId()));
|
||||
workBasketService.setDistributionTargets(workbasket2.getId(), newDistTargets);
|
||||
|
||||
Workbasket foundBasket = workBasketService.getWorkbasket(workbasket2.getId());
|
||||
|
||||
List<WorkbasketSummary> distributionTargets = foundBasket.getDistributionTargets();
|
||||
List<WorkbasketSummary> distributionTargets = workBasketService.getDistributionTargets(foundBasket.getId());
|
||||
|
||||
Assert.assertEquals(1, distributionTargets.size());
|
||||
Assert.assertEquals(id3, distributionTargets.get(0).getId());
|
||||
Assert.assertNotEquals(workBasketService.getWorkbasket(id2).getCreated(),
|
||||
workBasketService.getWorkbasket(id2).getModified());
|
||||
// Question: should we update the modfied timestamp on the source workbasket if we change its
|
||||
// distributiontargets?
|
||||
// Assert.assertNotEquals(workBasketService.getWorkbasket(id2).getCreated(),
|
||||
// workBasketService.getWorkbasket(id2).getModified());
|
||||
Assert.assertEquals(workBasketService.getWorkbasket(id1).getCreated(),
|
||||
workBasketService.getWorkbasket(id1).getModified());
|
||||
Assert.assertEquals(workBasketService.getWorkbasket(id3).getCreated(),
|
||||
|
@ -267,12 +263,11 @@ public class WorkbasketServiceImplIntAutocommitTest {
|
|||
|
||||
generateSampleDataForQuery();
|
||||
|
||||
Instant now = Instant.now();
|
||||
Instant tomorrow = now.plus(ONE_DAY);
|
||||
Instant yesterday = now.minus(ONE_DAY);
|
||||
Instant tenDaysAgo = now.minus(TEN_DAYS);
|
||||
Instant twentyDaysAgo = now.minus(TWENTY_DAYS);
|
||||
Instant thirtyDaysAgo = now.minus(TWENTY_DAYS).minus(TEN_DAYS);
|
||||
Instant tomorrow = now.plus(Duration.ofDays(1L));
|
||||
Instant yesterday = now.minus(Duration.ofDays(1L));
|
||||
Instant tenDaysAgo = now.minus(Duration.ofDays(10L));
|
||||
Instant twentyDaysAgo = now.minus(Duration.ofDays(20L));
|
||||
Instant thirtyDaysAgo = now.minus(Duration.ofDays(30L));
|
||||
|
||||
WorkbasketQuery query1 = workBasketService.createWorkbasketQuery()
|
||||
.accessIdsHavePersmission(WorkbasketAuthorization.OPEN, "Bernd")
|
||||
|
@ -282,7 +277,7 @@ public class WorkbasketServiceImplIntAutocommitTest {
|
|||
Assert.assertEquals(1, result1.size());
|
||||
String workbasketId = result1.get(0).getId();
|
||||
Workbasket workBasket = workBasketService.getWorkbasket(workbasketId);
|
||||
Assert.assertEquals(THREE, workBasket.getDistributionTargets().size());
|
||||
Assert.assertEquals(THREE, workBasketService.getDistributionTargets(workBasket.getId()).size());
|
||||
|
||||
WorkbasketQuery query2 = workBasketService.createWorkbasketQuery().accessIdsHavePersmission(
|
||||
WorkbasketAuthorization.OPEN, "Bernd",
|
||||
|
@ -313,12 +308,12 @@ public class WorkbasketServiceImplIntAutocommitTest {
|
|||
assertTrue("Basket1".equals(name) || "Basket2".equals(name) || "Basket3".equals(name));
|
||||
}
|
||||
|
||||
Thread.sleep(30L);
|
||||
Thread.sleep(20L);
|
||||
WorkbasketQuery query5 = workBasketService.createWorkbasketQuery()
|
||||
.modifiedAfter(now.minus(Duration.ofDays(31L)))
|
||||
.modifiedBefore(now.minus(Duration.ofDays(9)));
|
||||
.modifiedAfter(Instant.now().minus(Duration.ofDays(31)))
|
||||
.modifiedBefore(Instant.now().minus(Duration.ofDays(14)));
|
||||
List<WorkbasketSummary> result5 = query5.list();
|
||||
assertThat(result5.size(), equalTo(4));
|
||||
assertTrue(result5.size() == 3);
|
||||
for (WorkbasketSummary workbasket : result5) {
|
||||
String name = workbasket.getName();
|
||||
assertTrue(
|
||||
|
@ -405,11 +400,7 @@ public class WorkbasketServiceImplIntAutocommitTest {
|
|||
basket4.setOwner("Holger");
|
||||
basket4.setType(WorkbasketType.PERSONAL);
|
||||
basket4.setDomain("");
|
||||
List<WorkbasketSummary> distTargets = new ArrayList<WorkbasketSummary>();
|
||||
distTargets.add(basket1.asSummary());
|
||||
distTargets.add(basket2.asSummary());
|
||||
distTargets.add(basket3.asSummary());
|
||||
basket4.setDistributionTargets(distTargets);
|
||||
List<String> distTargets = new ArrayList<>(Arrays.asList(basket1.getId(), basket2.getId(), basket3.getId()));
|
||||
basket4 = (WorkbasketImpl) workBasketService.createWorkbasket(basket4);
|
||||
WorkbasketAccessItem accessItem4 = new WorkbasketAccessItem();
|
||||
accessItem4.setId(IdGenerator.generateWithPrefix("WAI"));
|
||||
|
@ -418,6 +409,7 @@ public class WorkbasketServiceImplIntAutocommitTest {
|
|||
accessItem4.setPermOpen(true);
|
||||
accessItem4.setPermRead(true);
|
||||
workBasketService.createWorkbasketAuthorization(accessItem4);
|
||||
workBasketService.setDistributionTargets(basket4.getId(), distTargets);
|
||||
|
||||
updateModifiedTimestamps(basket1, basket2, basket3, basket4);
|
||||
}
|
||||
|
@ -435,16 +427,15 @@ public class WorkbasketServiceImplIntAutocommitTest {
|
|||
WorkbasketImpl wb2 = (WorkbasketImpl) basket2;
|
||||
WorkbasketImpl wb3 = (WorkbasketImpl) basket3;
|
||||
WorkbasketImpl wb4 = (WorkbasketImpl) basket4;
|
||||
Instant now = Instant.now();
|
||||
|
||||
engineProxy.openConnection();
|
||||
wb1.setModified(now.minus(TEN_DAYS));
|
||||
wb1.setModified(now.minus(Duration.ofDays(10L)));
|
||||
mapper.update(wb1);
|
||||
wb2.setModified(now.minus(FIFTEEN_DAYS));
|
||||
wb2.setModified(now.minus(Duration.ofDays(15L)));
|
||||
mapper.update(wb2);
|
||||
wb3.setModified(now.minus(TWENTY_DAYS));
|
||||
wb3.setModified(now.minus(Duration.ofDays(20L)));
|
||||
mapper.update(wb3);
|
||||
wb4.setModified(now.minus(TWENTY_DAYS).minus(TEN_DAYS));
|
||||
wb4.setModified(now.minus(Duration.ofDays(30L)));
|
||||
mapper.update(wb4);
|
||||
engineProxy.returnConnection();
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ import java.io.FileNotFoundException;
|
|||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import javax.security.auth.login.LoginException;
|
||||
|
@ -185,15 +186,16 @@ public class WorkbasketServiceImplIntExplicitTest {
|
|||
|
||||
String id2 = IdGenerator.generateWithPrefix("TWB");
|
||||
Workbasket workbasket2 = createTestWorkbasket(id2, "key2", "novatec", "Hyperbasket", WorkbasketType.GROUP);
|
||||
workbasket2.setDistributionTargets(new ArrayList<>());
|
||||
workbasket2.getDistributionTargets().add(workbasket0.asSummary());
|
||||
workbasket2.getDistributionTargets().add(workbasket1.asSummary());
|
||||
//
|
||||
workbasket2 = workBasketService.createWorkbasket(workbasket2);
|
||||
createWorkbasketWithSecurity(workbasket2, "Elena", true, true, false, false);
|
||||
|
||||
List<String> distributionTargets = new ArrayList<>(Arrays.asList(workbasket0.getId(), workbasket1.getId()));
|
||||
workBasketService.setDistributionTargets(workbasket2.getId(), distributionTargets);
|
||||
|
||||
Workbasket foundWorkbasket = workBasketService.getWorkbasket(id2);
|
||||
Assert.assertEquals(id2, foundWorkbasket.getId());
|
||||
Assert.assertEquals(2, foundWorkbasket.getDistributionTargets().size());
|
||||
Assert.assertEquals(2, workBasketService.getDistributionTargets(foundWorkbasket.getId()).size());
|
||||
connection.commit();
|
||||
}
|
||||
|
||||
|
@ -215,33 +217,30 @@ public class WorkbasketServiceImplIntExplicitTest {
|
|||
|
||||
String id2 = IdGenerator.generateWithPrefix("TWB");
|
||||
Workbasket workbasket2 = createTestWorkbasket(id2, "key2", "novatec", "Hyperbasket", WorkbasketType.GROUP);
|
||||
workbasket2.setDistributionTargets(new ArrayList<>());
|
||||
workbasket2.getDistributionTargets().add(workbasket0.asSummary());
|
||||
workbasket2.getDistributionTargets().add(workbasket1.asSummary());
|
||||
workbasket2 = workBasketService.createWorkbasket(workbasket2);
|
||||
createWorkbasketWithSecurity(workbasket2, "Elena", true, true, false, false);
|
||||
|
||||
List<String> distTargets = new ArrayList<>(Arrays.asList(workbasket0.getId(), workbasket1.getId()));
|
||||
workBasketService.setDistributionTargets(workbasket2.getId(), distTargets);
|
||||
|
||||
String id3 = IdGenerator.generateWithPrefix("TWB");
|
||||
Workbasket workbasket3 = createTestWorkbasket(id3, "key3", "novatec", "hm ... irgend ein basket",
|
||||
WorkbasketType.GROUP);
|
||||
workbasket3.setDistributionTargets(new ArrayList<>());
|
||||
workbasket3.getDistributionTargets().add(workbasket0.asSummary());
|
||||
workbasket3.getDistributionTargets().add(workbasket1.asSummary());
|
||||
workbasket3 = workBasketService.createWorkbasket(workbasket3);
|
||||
createWorkbasketWithSecurity(workbasket3, "Elena", true, true, false, false);
|
||||
|
||||
workbasket2.getDistributionTargets().clear();
|
||||
workbasket2.getDistributionTargets().add(workbasket3.asSummary());
|
||||
Thread.sleep(SLEEP_TIME);
|
||||
workbasket2 = workBasketService.updateWorkbasket(workbasket2);
|
||||
List<String> newDistTargets = new ArrayList<>(Arrays.asList(workbasket3.getId()));
|
||||
workBasketService.setDistributionTargets(workbasket2.getId(), newDistTargets);
|
||||
|
||||
Workbasket foundBasket = workBasketService.getWorkbasket(workbasket2.getId());
|
||||
|
||||
List<WorkbasketSummary> distributionTargets = foundBasket.getDistributionTargets();
|
||||
List<WorkbasketSummary> distributionTargets = workBasketService.getDistributionTargets(foundBasket.getId());
|
||||
Assert.assertEquals(1, distributionTargets.size());
|
||||
Assert.assertEquals(workbasket3.getId(), distributionTargets.get(0).getId());
|
||||
Assert.assertNotEquals(workBasketService.getWorkbasket(id2).getCreated(),
|
||||
workBasketService.getWorkbasket(id2).getModified());
|
||||
// Question: should we update the modfied timestamp on the source workbasket if we change its
|
||||
// distributiontargets?
|
||||
// Assert.assertNotEquals(workBasketService.getWorkbasket(id2).getCreated(),
|
||||
// workBasketService.getWorkbasket(id2).getModified());
|
||||
Assert.assertEquals(workBasketService.getWorkbasket(id1).getCreated(),
|
||||
workBasketService.getWorkbasket(id1).getModified());
|
||||
Assert.assertEquals(workBasketService.getWorkbasket(id3).getCreated(),
|
||||
|
|
|
@ -1 +1,10 @@
|
|||
INSERT INTO DISTRIBUTION_TARGETS VALUES ('1','2');
|
||||
INSERT INTO DISTRIBUTION_TARGETS VALUES ('WBI:100000000000000000000000000000000001','WBI:100000000000000000000000000000000002');
|
||||
INSERT INTO DISTRIBUTION_TARGETS VALUES ('WBI:100000000000000000000000000000000001','WBI:100000000000000000000000000000000003');
|
||||
INSERT INTO DISTRIBUTION_TARGETS VALUES ('WBI:100000000000000000000000000000000001','WBI:100000000000000000000000000000000004');
|
||||
INSERT INTO DISTRIBUTION_TARGETS VALUES ('WBI:100000000000000000000000000000000001','WBI:100000000000000000000000000000000005');
|
||||
INSERT INTO DISTRIBUTION_TARGETS VALUES ('WBI:100000000000000000000000000000000002','WBI:100000000000000000000000000000000003');
|
||||
INSERT INTO DISTRIBUTION_TARGETS VALUES ('WBI:100000000000000000000000000000000002','WBI:100000000000000000000000000000000004');
|
||||
INSERT INTO DISTRIBUTION_TARGETS VALUES ('WBI:100000000000000000000000000000000002','WBI:100000000000000000000000000000000006');
|
||||
INSERT INTO DISTRIBUTION_TARGETS VALUES ('WBI:100000000000000000000000000000000002','WBI:100000000000000000000000000000000007');
|
||||
INSERT INTO DISTRIBUTION_TARGETS VALUES ('WBI:100000000000000000000000000000000007','WBI:100000000000000000000000000000000001');
|
||||
|
|
Loading…
Reference in New Issue