TSK-162 Implement WorkbasketService.getDistributionTargets() method

This commit is contained in:
BerndBreier 2018-01-23 10:43:40 +01:00 committed by Marcel Lengl
parent a9bb3ed377
commit c04b30d91a
17 changed files with 703 additions and 220 deletions

View File

@ -1,7 +1,6 @@
package pro.taskana; package pro.taskana;
import java.time.Instant; import java.time.Instant;
import java.util.List;
import pro.taskana.model.WorkbasketType; import pro.taskana.model.WorkbasketType;
@ -121,21 +120,6 @@ public interface Workbasket {
*/ */
String getOwner(); 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. * Return the value for the custom1 attribute.
* *
@ -262,4 +246,5 @@ public interface Workbasket {
* @return the WorkbasketSummary object for the current work basket * @return the WorkbasketSummary object for the current work basket
*/ */
WorkbasketSummary asSummary(); WorkbasketSummary asSummary();
} }

View File

@ -30,7 +30,7 @@ public interface WorkbasketQuery extends BaseQuery<WorkbasketSummary> {
* the keys as Strings * the keys as Strings
* @return the query * @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 * 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 * the names as Strings
* @return the query * @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. * 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 * the seach strings
* @return the query * @return the query
*/ */
BaseQuery<WorkbasketSummary> keyOrNameLike(String... searchString); WorkbasketQuery keyOrNameLike(String... searchString);
/** /**
* Add your domains to your query. * Add your domains to your query.

View File

@ -121,7 +121,7 @@ public interface WorkbasketService {
* @param authorization * @param authorization
* the needed Authorization * the needed Authorization
* @throws NotAuthorizedException * @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; 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. * Returns a set with all permissions of the current user at this workbasket.
* *
* @param workbasketKey * @param workbasketKey
* The key of the referenced workbasket * the key of the referenced workbasket
* @return a Set with all permissions * @return a Set with all permissions
*/ */
List<WorkbasketAuthorization> getPermissionsForWorkbasket(String workbasketKey); 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;
} }

View File

@ -518,7 +518,7 @@ public class TaskServiceImpl implements TaskService {
for (TaskSummaryImpl task : taskSummaries) { for (TaskSummaryImpl task : taskSummaries) {
String workbasketKey = task.getWorkbasketSummaryImpl().getKey(); 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() WorkbasketSummary aWorkbasket = workbaskets.stream()
.filter(x -> workbasketKey != null && workbasketKey.equals(x.getKey())) .filter(x -> workbasketKey != null && workbasketKey.equals(x.getKey()))
.findFirst() .findFirst()

View File

@ -1,8 +1,6 @@
package pro.taskana.impl; package pro.taskana.impl;
import java.time.Instant; import java.time.Instant;
import java.util.ArrayList;
import java.util.List;
import pro.taskana.Workbasket; import pro.taskana.Workbasket;
import pro.taskana.WorkbasketSummary; import pro.taskana.WorkbasketSummary;
@ -22,7 +20,6 @@ public class WorkbasketImpl implements Workbasket {
private String owner; private String owner;
private String domain; private String domain;
private WorkbasketType type; private WorkbasketType type;
private List<WorkbasketSummary> distributionTargets = new ArrayList<>();
private String custom1; private String custom1;
private String custom2; private String custom2;
private String custom3; private String custom3;
@ -122,16 +119,6 @@ public class WorkbasketImpl implements Workbasket {
this.type = type; this.type = type;
} }
@Override
public List<WorkbasketSummary> getDistributionTargets() {
return distributionTargets;
}
@Override
public void setDistributionTargets(List<WorkbasketSummary> distributionTargets) {
this.distributionTargets = distributionTargets;
}
@Override @Override
public String getCustom1() { public String getCustom1() {
return custom1; return custom1;
@ -229,6 +216,60 @@ public class WorkbasketImpl implements Workbasket {
return result; 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 @Override
public String toString() { public String toString() {
StringBuilder builder = new StringBuilder(); StringBuilder builder = new StringBuilder();
@ -250,8 +291,6 @@ public class WorkbasketImpl implements Workbasket {
builder.append(domain); builder.append(domain);
builder.append(", type="); builder.append(", type=");
builder.append(type); builder.append(type);
builder.append(", distributionTargets=");
builder.append(distributionTargets);
builder.append(", custom1="); builder.append(", custom1=");
builder.append(custom1); builder.append(custom1);
builder.append(", custom2="); builder.append(", custom2=");

View File

@ -8,7 +8,6 @@ import org.apache.ibatis.session.RowBounds;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import pro.taskana.BaseQuery;
import pro.taskana.TaskanaEngine; import pro.taskana.TaskanaEngine;
import pro.taskana.WorkbasketQuery; import pro.taskana.WorkbasketQuery;
import pro.taskana.WorkbasketSummary; import pro.taskana.WorkbasketSummary;
@ -75,19 +74,19 @@ public class WorkbasketQueryImpl implements WorkbasketQuery {
} }
@Override @Override
public BaseQuery<WorkbasketSummary> nameLike(String... names) { public WorkbasketQuery nameLike(String... names) {
this.nameLike = toUpperCopy(names); this.nameLike = toUpperCopy(names);
return this; return this;
} }
@Override @Override
public BaseQuery<WorkbasketSummary> keyLike(String... keys) { public WorkbasketQuery keyLike(String... keys) {
this.keyLike = toUpperCopy(keys); this.keyLike = toUpperCopy(keys);
return this; return this;
} }
@Override @Override
public BaseQuery<WorkbasketSummary> keyOrNameLike(String... keysOrNames) { public WorkbasketQuery keyOrNameLike(String... keysOrNames) {
this.keyOrNameLike = toUpperCopy(keysOrNames); this.keyOrNameLike = toUpperCopy(keysOrNames);
return this; return this;
} }

View File

@ -16,6 +16,7 @@ import pro.taskana.WorkbasketService;
import pro.taskana.WorkbasketSummary; import pro.taskana.WorkbasketSummary;
import pro.taskana.exceptions.InvalidWorkbasketException; import pro.taskana.exceptions.InvalidWorkbasketException;
import pro.taskana.exceptions.NotAuthorizedException; import pro.taskana.exceptions.NotAuthorizedException;
import pro.taskana.exceptions.SystemException;
import pro.taskana.exceptions.WorkbasketNotFoundException; import pro.taskana.exceptions.WorkbasketNotFoundException;
import pro.taskana.impl.util.IdGenerator; import pro.taskana.impl.util.IdGenerator;
import pro.taskana.impl.util.LoggerUtils; 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 Logger LOGGER = LoggerFactory.getLogger(WorkbasketServiceImpl.class);
private static final String ID_PREFIX_WORKBASKET = "WBI"; private static final String ID_PREFIX_WORKBASKET = "WBI";
private static final String ID_PREFIX_WORKBASKET_AUTHORIZATION = "WAI"; private static final String ID_PREFIX_WORKBASKET_AUTHORIZATION = "WAI";
private TaskanaEngine taskanaEngine; private TaskanaEngineImpl taskanaEngine;
private TaskanaEngineImpl taskanaEngineImpl;
private WorkbasketMapper workbasketMapper; private WorkbasketMapper workbasketMapper;
private DistributionTargetMapper distributionTargetMapper; private DistributionTargetMapper distributionTargetMapper;
private WorkbasketAccessMapper workbasketAccessMapper; private WorkbasketAccessMapper workbasketAccessMapper;
@ -45,8 +45,7 @@ public class WorkbasketServiceImpl implements WorkbasketService {
public WorkbasketServiceImpl(TaskanaEngine taskanaEngine, WorkbasketMapper workbasketMapper, public WorkbasketServiceImpl(TaskanaEngine taskanaEngine, WorkbasketMapper workbasketMapper,
DistributionTargetMapper distributionTargetMapper, WorkbasketAccessMapper workbasketAccessMapper) { DistributionTargetMapper distributionTargetMapper, WorkbasketAccessMapper workbasketAccessMapper) {
this.taskanaEngine = taskanaEngine; this.taskanaEngine = (TaskanaEngineImpl) taskanaEngine;
this.taskanaEngineImpl = (TaskanaEngineImpl) taskanaEngine;
this.workbasketMapper = workbasketMapper; this.workbasketMapper = workbasketMapper;
this.distributionTargetMapper = distributionTargetMapper; this.distributionTargetMapper = distributionTargetMapper;
this.workbasketAccessMapper = workbasketAccessMapper; this.workbasketAccessMapper = workbasketAccessMapper;
@ -58,7 +57,7 @@ public class WorkbasketServiceImpl implements WorkbasketService {
LOGGER.debug("entry to getWorkbasket(workbasketId = {})", workbasketId); LOGGER.debug("entry to getWorkbasket(workbasketId = {})", workbasketId);
Workbasket result = null; Workbasket result = null;
try { try {
taskanaEngineImpl.openConnection(); taskanaEngine.openConnection();
result = workbasketMapper.findById(workbasketId); result = workbasketMapper.findById(workbasketId);
if (result == null) { if (result == null) {
LOGGER.error( LOGGER.error(
@ -69,7 +68,7 @@ public class WorkbasketServiceImpl implements WorkbasketService {
this.checkAuthorization(result.getKey(), WorkbasketAuthorization.READ); this.checkAuthorization(result.getKey(), WorkbasketAuthorization.READ);
return result; return result;
} finally { } finally {
taskanaEngineImpl.returnConnection(); taskanaEngine.returnConnection();
LOGGER.debug("exit from getWorkbasket(workbasketId). Returning result {} ", result); 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); LOGGER.debug("entry to getWorkbasketByKey(workbasketKey = {})", workbasketKey);
Workbasket result = null; Workbasket result = null;
try { try {
taskanaEngineImpl.openConnection(); taskanaEngine.openConnection();
result = workbasketMapper.findByKey(workbasketKey); result = workbasketMapper.findByKey(workbasketKey);
if (result == null) { if (result == null) {
LOGGER.error( LOGGER.error(
@ -91,7 +90,7 @@ public class WorkbasketServiceImpl implements WorkbasketService {
this.checkAuthorization(workbasketKey, WorkbasketAuthorization.READ); this.checkAuthorization(workbasketKey, WorkbasketAuthorization.READ);
return result; return result;
} finally { } finally {
taskanaEngineImpl.returnConnection(); taskanaEngine.returnConnection();
LOGGER.debug("exit from getWorkbasket(workbasketId). Returning result {} ", result); LOGGER.debug("exit from getWorkbasket(workbasketId). Returning result {} ", result);
} }
} }
@ -103,7 +102,7 @@ public class WorkbasketServiceImpl implements WorkbasketService {
} }
List<WorkbasketSummary> result = null; List<WorkbasketSummary> result = null;
try { try {
taskanaEngineImpl.openConnection(); taskanaEngine.openConnection();
// use a set to avoid duplicates // use a set to avoid duplicates
Set<WorkbasketSummary> workbaskets = new HashSet<>(); Set<WorkbasketSummary> workbaskets = new HashSet<>();
for (String accessId : CurrentUserContext.getAccessIds()) { for (String accessId : CurrentUserContext.getAccessIds()) {
@ -113,7 +112,7 @@ public class WorkbasketServiceImpl implements WorkbasketService {
result.addAll(workbaskets); result.addAll(workbaskets);
return result; return result;
} finally { } finally {
taskanaEngineImpl.returnConnection(); taskanaEngine.returnConnection();
if (LOGGER.isDebugEnabled()) { if (LOGGER.isDebugEnabled()) {
int numberOfResultObjects = result == null ? 0 : result.size(); int numberOfResultObjects = result == null ? 0 : result.size();
LOGGER.debug("exit from getWorkbaskets(permissions). Returning {} resulting Objects: {} ", LOGGER.debug("exit from getWorkbaskets(permissions). Returning {} resulting Objects: {} ",
@ -127,14 +126,14 @@ public class WorkbasketServiceImpl implements WorkbasketService {
LOGGER.debug("entry to getWorkbaskets()"); LOGGER.debug("entry to getWorkbaskets()");
List<WorkbasketSummary> workbaskets = new ArrayList<>(); List<WorkbasketSummary> workbaskets = new ArrayList<>();
try { try {
taskanaEngineImpl.openConnection(); taskanaEngine.openConnection();
List<WorkbasketSummaryImpl> workbasketImpls = workbasketMapper.findAll(); List<WorkbasketSummaryImpl> workbasketImpls = workbasketMapper.findAll();
for (WorkbasketSummaryImpl workbasketSummaryImpl : workbasketImpls) { for (WorkbasketSummaryImpl workbasketSummaryImpl : workbasketImpls) {
workbaskets.add(workbasketSummaryImpl); workbaskets.add(workbasketSummaryImpl);
} }
return workbaskets; return workbaskets;
} finally { } finally {
taskanaEngineImpl.returnConnection(); taskanaEngine.returnConnection();
if (LOGGER.isDebugEnabled()) { if (LOGGER.isDebugEnabled()) {
int numberOfResultObjects = workbaskets == null ? 0 : workbaskets.size(); int numberOfResultObjects = workbaskets == null ? 0 : workbaskets.size();
LOGGER.debug("exit from getWorkbaskets(). Returning {} resulting Objects: {} ", numberOfResultObjects, LOGGER.debug("exit from getWorkbaskets(). Returning {} resulting Objects: {} ", numberOfResultObjects,
@ -150,7 +149,7 @@ public class WorkbasketServiceImpl implements WorkbasketService {
Workbasket result = null; Workbasket result = null;
WorkbasketImpl workbasket = (WorkbasketImpl) newWorkbasket; WorkbasketImpl workbasket = (WorkbasketImpl) newWorkbasket;
try { try {
taskanaEngineImpl.openConnection(); taskanaEngine.openConnection();
Instant now = Instant.now(); Instant now = Instant.now();
workbasket.setCreated(now); workbasket.setCreated(now);
workbasket.setModified(now); workbasket.setModified(now);
@ -161,19 +160,10 @@ public class WorkbasketServiceImpl implements WorkbasketService {
workbasketMapper.insert(workbasket); workbasketMapper.insert(workbasket);
LOGGER.debug("Method createWorkbasket() created Workbasket '{}'", 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()); result = workbasketMapper.findById(workbasket.getId());
return result; return result;
} finally { } finally {
taskanaEngineImpl.returnConnection(); taskanaEngine.returnConnection();
LOGGER.debug("exit from createWorkbasket(workbasket). Returning result {} ", result); LOGGER.debug("exit from createWorkbasket(workbasket). Returning result {} ", result);
} }
} }
@ -186,33 +176,14 @@ public class WorkbasketServiceImpl implements WorkbasketService {
Workbasket result = null; Workbasket result = null;
WorkbasketImpl workbasket = (WorkbasketImpl) workbasketToUpdate; WorkbasketImpl workbasket = (WorkbasketImpl) workbasketToUpdate;
try { try {
taskanaEngineImpl.openConnection(); taskanaEngine.openConnection();
workbasket.setModified(Instant.now()); workbasket.setModified(Instant.now());
workbasketMapper.update(workbasket); workbasketMapper.update(workbasket);
LOGGER.debug("Method updateWorkbasket() updated workbasket '{}'", workbasket.getId()); 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()); result = workbasketMapper.findById(workbasket.getId());
return result; return result;
} finally { } finally {
taskanaEngineImpl.returnConnection(); taskanaEngine.returnConnection();
LOGGER.debug("exit from updateWorkbasket(). Returning result {} ", result); LOGGER.debug("exit from updateWorkbasket(). Returning result {} ", result);
} }
} }
@ -221,14 +192,14 @@ public class WorkbasketServiceImpl implements WorkbasketService {
public WorkbasketAccessItem createWorkbasketAuthorization(WorkbasketAccessItem workbasketAccessItem) { public WorkbasketAccessItem createWorkbasketAuthorization(WorkbasketAccessItem workbasketAccessItem) {
LOGGER.debug("entry to createWorkbasketAuthorization(workbasketAccessItem = {})", workbasketAccessItem); LOGGER.debug("entry to createWorkbasketAuthorization(workbasketAccessItem = {})", workbasketAccessItem);
try { try {
taskanaEngineImpl.openConnection(); taskanaEngine.openConnection();
workbasketAccessItem.setId(IdGenerator.generateWithPrefix(ID_PREFIX_WORKBASKET_AUTHORIZATION)); workbasketAccessItem.setId(IdGenerator.generateWithPrefix(ID_PREFIX_WORKBASKET_AUTHORIZATION));
workbasketAccessMapper.insert(workbasketAccessItem); workbasketAccessMapper.insert(workbasketAccessItem);
LOGGER.debug("Method createWorkbasketAuthorization() created workbaskteAccessItem {}", LOGGER.debug("Method createWorkbasketAuthorization() created workbaskteAccessItem {}",
workbasketAccessItem); workbasketAccessItem);
return workbasketAccessItem; return workbasketAccessItem;
} finally { } finally {
taskanaEngineImpl.returnConnection(); taskanaEngine.returnConnection();
LOGGER.debug("exit from createWorkbasketAuthorization(workbasketAccessItem). Returning result {}", LOGGER.debug("exit from createWorkbasketAuthorization(workbasketAccessItem). Returning result {}",
workbasketAccessItem); workbasketAccessItem);
} }
@ -239,11 +210,11 @@ public class WorkbasketServiceImpl implements WorkbasketService {
LOGGER.debug("entry to getWorkbasketAuthorization(id = {})", id); LOGGER.debug("entry to getWorkbasketAuthorization(id = {})", id);
WorkbasketAccessItem result = null; WorkbasketAccessItem result = null;
try { try {
taskanaEngineImpl.openConnection(); taskanaEngine.openConnection();
result = workbasketAccessMapper.findById(id); result = workbasketAccessMapper.findById(id);
return result; return result;
} finally { } finally {
taskanaEngineImpl.returnConnection(); taskanaEngine.returnConnection();
LOGGER.debug("exit from getWorkbasketAuthorization(id). Returning result {}", result); LOGGER.debug("exit from getWorkbasketAuthorization(id). Returning result {}", result);
} }
} }
@ -252,11 +223,11 @@ public class WorkbasketServiceImpl implements WorkbasketService {
public void deleteWorkbasketAuthorization(String id) { public void deleteWorkbasketAuthorization(String id) {
LOGGER.debug("entry to deleteWorkbasketAuthorization(id = {})", id); LOGGER.debug("entry to deleteWorkbasketAuthorization(id = {})", id);
try { try {
taskanaEngineImpl.openConnection(); taskanaEngine.openConnection();
workbasketAccessMapper.delete(id); workbasketAccessMapper.delete(id);
LOGGER.debug("Method deleteWorkbasketAuthorization() deleted workbasketAccessItem wit Id {}", id); LOGGER.debug("Method deleteWorkbasketAuthorization() deleted workbasketAccessItem wit Id {}", id);
} finally { } finally {
taskanaEngineImpl.returnConnection(); taskanaEngine.returnConnection();
LOGGER.debug("exit from deleteWorkbasketAuthorization(id)."); LOGGER.debug("exit from deleteWorkbasketAuthorization(id).");
} }
} }
@ -266,11 +237,11 @@ public class WorkbasketServiceImpl implements WorkbasketService {
LOGGER.debug("entry to getAllAuthorizations()"); LOGGER.debug("entry to getAllAuthorizations()");
List<WorkbasketAccessItem> result = null; List<WorkbasketAccessItem> result = null;
try { try {
taskanaEngineImpl.openConnection(); taskanaEngine.openConnection();
result = workbasketAccessMapper.findAll(); result = workbasketAccessMapper.findAll();
return result; return result;
} finally { } finally {
taskanaEngineImpl.returnConnection(); taskanaEngine.returnConnection();
if (LOGGER.isDebugEnabled()) { if (LOGGER.isDebugEnabled()) {
int numberOfResultObjects = result == null ? 0 : result.size(); int numberOfResultObjects = result == null ? 0 : result.size();
LOGGER.debug("exit from getAllAuthorizations(). Returning {} resulting Objects: {} ", LOGGER.debug("exit from getAllAuthorizations(). Returning {} resulting Objects: {} ",
@ -282,49 +253,21 @@ public class WorkbasketServiceImpl implements WorkbasketService {
@Override @Override
public void checkAuthorization(String workbasketKey, WorkbasketAuthorization workbasketAuthorization) public void checkAuthorization(String workbasketKey, WorkbasketAuthorization workbasketAuthorization)
throws NotAuthorizedException { 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(); checkAuthorization(workbasketKey, null, workbasketAuthorization);
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);
}
} }
@Override @Override
public WorkbasketAccessItem updateWorkbasketAuthorization(WorkbasketAccessItem workbasketAccessItem) { public WorkbasketAccessItem updateWorkbasketAuthorization(WorkbasketAccessItem workbasketAccessItem) {
LOGGER.debug("entry to updateWorkbasketAuthorization(workbasketAccessItem = {}", workbasketAccessItem); LOGGER.debug("entry to updateWorkbasketAuthorization(workbasketAccessItem = {}", workbasketAccessItem);
try { try {
taskanaEngineImpl.openConnection(); taskanaEngine.openConnection();
workbasketAccessMapper.update(workbasketAccessItem); workbasketAccessMapper.update(workbasketAccessItem);
LOGGER.debug("Method updateWorkbasketAuthorization() updated workbasketAccessItem {}", LOGGER.debug("Method updateWorkbasketAuthorization() updated workbasketAccessItem {}",
workbasketAccessItem); workbasketAccessItem);
return workbasketAccessItem; return workbasketAccessItem;
} finally { } finally {
taskanaEngineImpl.returnConnection(); taskanaEngine.returnConnection();
LOGGER.debug("exit from updateWorkbasketAuthorization(workbasketAccessItem). Returning {}", LOGGER.debug("exit from updateWorkbasketAuthorization(workbasketAccessItem). Returning {}",
workbasketAccessItem); workbasketAccessItem);
} }
@ -335,11 +278,11 @@ public class WorkbasketServiceImpl implements WorkbasketService {
LOGGER.debug("entry to getWorkbasketAuthorizations(workbasketId = {})", workbasketKey); LOGGER.debug("entry to getWorkbasketAuthorizations(workbasketId = {})", workbasketKey);
List<WorkbasketAccessItem> result = null; List<WorkbasketAccessItem> result = null;
try { try {
taskanaEngineImpl.openConnection(); taskanaEngine.openConnection();
result = workbasketAccessMapper.findByWorkbasketKey(workbasketKey); result = workbasketAccessMapper.findByWorkbasketKey(workbasketKey);
return result; return result;
} finally { } finally {
taskanaEngineImpl.returnConnection(); taskanaEngine.returnConnection();
if (LOGGER.isDebugEnabled()) { if (LOGGER.isDebugEnabled()) {
int numberOfResultObjects = result == null ? 0 : result.size(); int numberOfResultObjects = result == null ? 0 : result.size();
LOGGER.debug("exit from getWorkbasketAuthorizations(workbasketId). Returning {} resulting Objects: {} ", LOGGER.debug("exit from getWorkbasketAuthorizations(workbasketId). Returning {} resulting Objects: {} ",
@ -351,7 +294,8 @@ public class WorkbasketServiceImpl implements WorkbasketService {
@Override @Override
public List<WorkbasketAuthorization> getPermissionsForWorkbasket(String workbasketKey) { public List<WorkbasketAuthorization> getPermissionsForWorkbasket(String workbasketKey) {
List<WorkbasketAuthorization> permissions = new ArrayList<>(); List<WorkbasketAuthorization> permissions = new ArrayList<>();
WorkbasketAccessItem wbAcc = workbasketAccessMapper.findByWorkbasketAndAccessId(workbasketKey, CurrentUserContext.getAccessIds()); WorkbasketAccessItem wbAcc = workbasketAccessMapper.findByWorkbasketAndAccessId(workbasketKey,
CurrentUserContext.getAccessIds());
this.addWorkbasketAccessItemValuesToPermissionSet(wbAcc, permissions); this.addWorkbasketAccessItemValuesToPermissionSet(wbAcc, permissions);
return 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()) { if (workbasketAccessItem.isPermOpen()) {
permissions.add(WorkbasketAuthorization.OPEN); permissions.add(WorkbasketAuthorization.OPEN);
} }
@ -425,4 +370,190 @@ public class WorkbasketServiceImpl implements WorkbasketService {
public Workbasket newWorkbasket() { public Workbasket newWorkbasket() {
return new WorkbasketImpl(); 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);
}
}
} }

View File

@ -6,6 +6,7 @@ import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert; import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select; import org.apache.ibatis.annotations.Select;
/** /**
* This class is the mybatis mapping of distribution targets. * 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}") @Select("SELECT TARGET_ID FROM DISTRIBUTION_TARGETS WHERE SOURCE_ID = #{sourceId}")
List<String> findBySourceId(@Param("sourceId") String 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>") @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); 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);
} }

View File

@ -169,4 +169,43 @@ public interface WorkbasketAccessMapper {
List<WorkbasketAccessItem> findByWorkbasketAndAccessIdAndAuthorization( List<WorkbasketAccessItem> findByWorkbasketAndAccessIdAndAuthorization(
@Param("workbasketKey") String workbasketKey, @Param("accessIds") List<String> accessIds, @Param("workbasketKey") String workbasketKey, @Param("accessIds") List<String> accessIds,
@Param("authorization") String authorization); @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);
} }

View File

@ -4,14 +4,12 @@ import java.util.List;
import org.apache.ibatis.annotations.Delete; import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert; import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Many;
import org.apache.ibatis.annotations.Options; import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result; import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results; import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select; import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update; import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.mapping.FetchType;
import pro.taskana.impl.WorkbasketImpl; import pro.taskana.impl.WorkbasketImpl;
import pro.taskana.impl.WorkbasketSummaryImpl; import pro.taskana.impl.WorkbasketSummaryImpl;
@ -32,8 +30,6 @@ public interface WorkbasketMapper {
@Result(property = "type", column = "TYPE"), @Result(property = "type", column = "TYPE"),
@Result(property = "description", column = "DESCRIPTION"), @Result(property = "description", column = "DESCRIPTION"),
@Result(property = "owner", column = "OWNER"), @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 = "custom1", column = "CUSTOM_1"),
@Result(property = "custom2", column = "CUSTOM_2"), @Result(property = "custom2", column = "CUSTOM_2"),
@Result(property = "custom3", column = "CUSTOM_3"), @Result(property = "custom3", column = "CUSTOM_3"),
@ -54,8 +50,6 @@ public interface WorkbasketMapper {
@Result(property = "type", column = "TYPE"), @Result(property = "type", column = "TYPE"),
@Result(property = "description", column = "DESCRIPTION"), @Result(property = "description", column = "DESCRIPTION"),
@Result(property = "owner", column = "OWNER"), @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 = "custom1", column = "CUSTOM_1"),
@Result(property = "custom2", column = "CUSTOM_2"), @Result(property = "custom2", column = "CUSTOM_2"),
@Result(property = "custom3", column = "CUSTOM_3"), @Result(property = "custom3", column = "CUSTOM_3"),

View File

@ -36,10 +36,14 @@ public abstract class AbstractAccTest {
resetDb(); resetDb();
} }
public static void resetDb() throws SQLException { public static void resetDb(boolean... dropTables) throws SQLException {
DataSource dataSource = TaskanaEngineConfigurationTest.getDataSource(); DataSource dataSource = TaskanaEngineConfigurationTest.getDataSource();
DBCleaner cleaner = new DBCleaner(); DBCleaner cleaner = new DBCleaner();
if (dropTables == null || dropTables.length == 0) {
cleaner.clearDb(dataSource, true); cleaner.clearDb(dataSource, true);
} else {
cleaner.clearDb(dataSource, dropTables[0]);
}
dataSource = TaskanaEngineConfigurationTest.getDataSource(); dataSource = TaskanaEngineConfigurationTest.getDataSource();
taskanaEngineConfiguration = new TaskanaEngineConfiguration(dataSource, false); taskanaEngineConfiguration = new TaskanaEngineConfiguration(dataSource, false);
taskanaEngine = taskanaEngineConfiguration.buildTaskanaEngine(); taskanaEngine = taskanaEngineConfiguration.buildTaskanaEngine();

View File

@ -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);
}
}

View File

@ -120,6 +120,7 @@ public class ClassificationServiceImplTest {
verify(classificationMapperMock, times(1)).insert(any()); verify(classificationMapperMock, times(1)).insert(any());
verify(taskanaEngineImplMock, times(2)).returnConnection(); verify(taskanaEngineImplMock, times(2)).returnConnection();
verifyNoMoreInteractions(classificationMapperMock, taskanaEngineImplMock, classificationQueryImplMock); verifyNoMoreInteractions(classificationMapperMock, taskanaEngineImplMock, classificationQueryImplMock);
Thread.sleep(15);
assertThat(classification.getCreated().toString().substring(0, 10), equalTo(todaysDate)); assertThat(classification.getCreated().toString().substring(0, 10), equalTo(todaysDate));
assertFalse(classification.getCreated().isAfter(Instant.now())); assertFalse(classification.getCreated().isAfter(Instant.now()));
assertTrue(classification.getCreated().isAfter(beforeTimestamp)); assertTrue(classification.getCreated().isAfter(beforeTimestamp));

View File

@ -13,6 +13,7 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions; import static org.mockito.Mockito.verifyNoMoreInteractions;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.List; import java.util.List;
import org.junit.Before; import org.junit.Before;
@ -26,7 +27,6 @@ import org.mockito.Spy;
import org.mockito.junit.MockitoJUnitRunner; import org.mockito.junit.MockitoJUnitRunner;
import pro.taskana.Workbasket; import pro.taskana.Workbasket;
import pro.taskana.WorkbasketSummary;
import pro.taskana.configuration.TaskanaEngineConfiguration; import pro.taskana.configuration.TaskanaEngineConfiguration;
import pro.taskana.exceptions.InvalidWorkbasketException; import pro.taskana.exceptions.InvalidWorkbasketException;
import pro.taskana.exceptions.NotAuthorizedException; import pro.taskana.exceptions.NotAuthorizedException;
@ -292,16 +292,22 @@ public class WorkbasketServiceImplTest {
public void testCreateWorkbasket_WithoutDistibutionTargets() public void testCreateWorkbasket_WithoutDistibutionTargets()
throws WorkbasketNotFoundException, NotAuthorizedException, InvalidWorkbasketException { throws WorkbasketNotFoundException, NotAuthorizedException, InvalidWorkbasketException {
WorkbasketImpl expectedWb = createTestWorkbasket(null, "Key-1"); WorkbasketImpl expectedWb = createTestWorkbasket(null, "Key-1");
expectedWb.setDistributionTargets(null);
doNothing().when(workbasketMapperMock).insert(expectedWb); doNothing().when(workbasketMapperMock).insert(expectedWb);
doReturn(expectedWb).when(workbasketMapperMock).findById(any()); doReturn(expectedWb).when(workbasketMapperMock).findById(any());
doReturn(taskanaEngineConfigurationMock).when(taskanaEngineImplMock).getConfiguration();
doReturn(false).when(taskanaEngineConfigurationMock).isSecurityEnabled();
Workbasket actualWb = cutSpy.createWorkbasket(expectedWb); 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)).insert(expectedWb);
verify(workbasketMapperMock, times(1)).findById(expectedWb.getId()); verify(workbasketMapperMock, times(2)).findById(expectedWb.getId());
verify(taskanaEngineImplMock, times(1)).returnConnection(); verify(workbasketMapperMock, times(1)).update(any());
verify(taskanaEngineImplMock, times(5)).returnConnection();
verify(distributionTargetMapperMock, times(1)).deleteAllDistributionTargets(any());
verifyNoMoreInteractions(workbasketMapperMock, workbasketAccessMapperMock, distributionTargetMapperMock, verifyNoMoreInteractions(workbasketMapperMock, workbasketAccessMapperMock, distributionTargetMapperMock,
taskanaEngineImplMock, taskanaEngineConfigurationMock); taskanaEngineImplMock, taskanaEngineConfigurationMock);
assertThat(actualWb.getId(), not(equalTo(null))); assertThat(actualWb.getId(), not(equalTo(null)));
@ -315,19 +321,25 @@ public class WorkbasketServiceImplTest {
throws WorkbasketNotFoundException, NotAuthorizedException, InvalidWorkbasketException { throws WorkbasketNotFoundException, NotAuthorizedException, InvalidWorkbasketException {
final int distTargetAmount = 2; final int distTargetAmount = 2;
WorkbasketImpl expectedWb = createTestWorkbasket(null, "Key-1"); WorkbasketImpl expectedWb = createTestWorkbasket(null, "Key-1");
expectedWb.setDistributionTargets(createTestDistributionTargets(distTargetAmount));
doNothing().when(workbasketMapperMock).insert(expectedWb); doNothing().when(workbasketMapperMock).insert(expectedWb);
doReturn(expectedWb).when(cutSpy).getWorkbasket(any()); doReturn(expectedWb).when(cutSpy).getWorkbasket(any());
doReturn(expectedWb).when(workbasketMapperMock).findById(any()); doReturn(expectedWb).when(workbasketMapperMock).findById(any());
doReturn(taskanaEngineConfigurationMock).when(taskanaEngineImplMock).getConfiguration();
doReturn(false).when(taskanaEngineConfigurationMock).isSecurityEnabled();
Workbasket actualWb = cutSpy.createWorkbasket(expectedWb); Workbasket actualWb = cutSpy.createWorkbasket(expectedWb);
cutSpy.setDistributionTargets(expectedWb.getId(), createTestDistributionTargets(distTargetAmount));
verify(taskanaEngineImplMock, times(1)).openConnection(); verify(taskanaEngineImplMock, times(5)).openConnection();
verify(workbasketMapperMock, times(1)).insert(expectedWb); verify(taskanaEngineImplMock, times(1)).getConfiguration();
verify(cutSpy, times(distTargetAmount)).getWorkbasket(any()); 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(distributionTargetMapperMock, times(distTargetAmount)).insert(any(), any());
verify(workbasketMapperMock, times(1)).findById(expectedWb.getId()); verify(workbasketMapperMock, times(3)).findById(any());
verify(taskanaEngineImplMock, times(1)).returnConnection(); verify(workbasketMapperMock, times(1)).update(any());
verify(taskanaEngineImplMock, times(5)).returnConnection();
verifyNoMoreInteractions(workbasketMapperMock, workbasketAccessMapperMock, distributionTargetMapperMock, verifyNoMoreInteractions(workbasketMapperMock, workbasketAccessMapperMock, distributionTargetMapperMock,
taskanaEngineImplMock, taskanaEngineConfigurationMock); taskanaEngineImplMock, taskanaEngineConfigurationMock);
assertThat(actualWb.getId(), not(equalTo(null))); assertThat(actualWb.getId(), not(equalTo(null)));
@ -341,18 +353,21 @@ public class WorkbasketServiceImplTest {
throws WorkbasketNotFoundException, NotAuthorizedException, InvalidWorkbasketException { throws WorkbasketNotFoundException, NotAuthorizedException, InvalidWorkbasketException {
final int distTargetAmount = 5; final int distTargetAmount = 5;
WorkbasketImpl expectedWb = createTestWorkbasket("ID-1", "Key-1"); WorkbasketImpl expectedWb = createTestWorkbasket("ID-1", "Key-1");
expectedWb.setDistributionTargets(createTestDistributionTargets(distTargetAmount));
doNothing().when(workbasketMapperMock).insert(expectedWb); doNothing().when(workbasketMapperMock).insert(expectedWb);
doThrow(WorkbasketNotFoundException.class).when(cutSpy)
.getWorkbasket(expectedWb.getDistributionTargets().get(0).getId());
try { try {
cutSpy.createWorkbasket(expectedWb); 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) { } catch (WorkbasketNotFoundException e) {
verify(taskanaEngineImplMock, times(1)).openConnection(); verify(taskanaEngineImplMock, times(3)).openConnection();
verify(workbasketMapperMock, times(1)).insert(expectedWb); verify(workbasketMapperMock, times(1)).insert(expectedWb);
verify(workbasketMapperMock, times(2)).findById(any());
verify(cutSpy, times(1)).getWorkbasket(any()); verify(cutSpy, times(1)).getWorkbasket(any());
verify(taskanaEngineImplMock, times(1)).returnConnection(); verify(taskanaEngineImplMock, times(3)).returnConnection();
verifyNoMoreInteractions(workbasketMapperMock, workbasketAccessMapperMock, distributionTargetMapperMock, verifyNoMoreInteractions(workbasketMapperMock, workbasketAccessMapperMock, distributionTargetMapperMock,
taskanaEngineImplMock, taskanaEngineConfigurationMock); taskanaEngineImplMock, taskanaEngineConfigurationMock);
throw e; throw e;
@ -365,7 +380,6 @@ public class WorkbasketServiceImplTest {
public void testCreateWorkbasket_NotCreated() public void testCreateWorkbasket_NotCreated()
throws WorkbasketNotFoundException, NotAuthorizedException, InvalidWorkbasketException { throws WorkbasketNotFoundException, NotAuthorizedException, InvalidWorkbasketException {
WorkbasketImpl expectedWb = createTestWorkbasket(null, "Key-1"); WorkbasketImpl expectedWb = createTestWorkbasket(null, "Key-1");
expectedWb.setDistributionTargets(null);
doNothing().when(workbasketMapperMock).insert(expectedWb); doNothing().when(workbasketMapperMock).insert(expectedWb);
doThrow(WorkbasketNotFoundException.class).when(workbasketMapperMock).findById(any()); doThrow(WorkbasketNotFoundException.class).when(workbasketMapperMock).findById(any());
@ -393,11 +407,14 @@ public class WorkbasketServiceImplTest {
return workbasket; return workbasket;
} }
private List<WorkbasketSummary> createTestDistributionTargets(int amount) { private List<String> createTestDistributionTargets(int amount)
List<WorkbasketSummary> distributionsTargets = new ArrayList<>(); throws WorkbasketNotFoundException, InvalidWorkbasketException, NotAuthorizedException {
List<String> distributionsTargets = new ArrayList<>();
amount = (amount < 0) ? 0 : amount; amount = (amount < 0) ? 0 : amount;
for (int i = 0; i < amount; i++) { 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; return distributionsTargets;
} }

View File

@ -1,7 +1,5 @@
package pro.taskana.impl.integration; package pro.taskana.impl.integration;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
@ -9,6 +7,7 @@ import java.sql.SQLException;
import java.time.Duration; import java.time.Duration;
import java.time.Instant; import java.time.Instant;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.List; import java.util.List;
import javax.security.auth.login.LoginException; import javax.security.auth.login.LoginException;
@ -58,16 +57,13 @@ public class WorkbasketServiceImplIntAutocommitTest {
private static final int SLEEP_TIME = 100; private static final int SLEEP_TIME = 100;
private static final int THREE = 3; 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; static int counter = 0;
private DataSource dataSource; private DataSource dataSource;
private TaskanaEngineConfiguration taskanaEngineConfiguration; private TaskanaEngineConfiguration taskanaEngineConfiguration;
private TaskanaEngine taskanaEngine; private TaskanaEngine taskanaEngine;
private TaskanaEngineImpl taskanaEngineImpl; private TaskanaEngineImpl taskanaEngineImpl;
private WorkbasketService workBasketService; private WorkbasketService workBasketService;
private Instant now;
@BeforeClass @BeforeClass
public static void resetDb() throws SQLException { public static void resetDb() throws SQLException {
@ -86,6 +82,7 @@ public class WorkbasketServiceImplIntAutocommitTest {
workBasketService = taskanaEngine.getWorkbasketService(); workBasketService = taskanaEngine.getWorkbasketService();
DBCleaner cleaner = new DBCleaner(); DBCleaner cleaner = new DBCleaner();
cleaner.clearDb(dataSource, false); cleaner.clearDb(dataSource, false);
now = Instant.now();
} }
@Test @Test
@ -165,18 +162,17 @@ public class WorkbasketServiceImplIntAutocommitTest {
Workbasket wbDist2 = createTestWorkbasket(id, "key1", "novatec", "Megabasket", WorkbasketType.GROUP); Workbasket wbDist2 = createTestWorkbasket(id, "key1", "novatec", "Megabasket", WorkbasketType.GROUP);
wbDist2 = workBasketService.createWorkbasket(wbDist2); wbDist2 = workBasketService.createWorkbasket(wbDist2);
createWorkbasketWithSecurity(wbDist2, "Elena", true, true, false, false); createWorkbasketWithSecurity(wbDist2, "Elena", true, true, false, false);
id = IdGenerator.generateWithPrefix("TWB"); id = IdGenerator.generateWithPrefix("TWB");
Workbasket workbasket = createTestWorkbasket(id, "key2", "novatec", "Hyperbasket", WorkbasketType.GROUP); 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); workbasket = workBasketService.createWorkbasket(workbasket);
List<String> distributionTargets = new ArrayList<>(Arrays.asList(wbDist1.getId(), wbDist2.getId()));
createWorkbasketWithSecurity(workbasket, "Elena", true, true, false, false); createWorkbasketWithSecurity(workbasket, "Elena", true, true, false, false);
workBasketService.setDistributionTargets(workbasket.getId(), distributionTargets);
Workbasket foundWorkbasket = workBasketService.getWorkbasket(workbasket.getId()); Workbasket foundWorkbasket = workBasketService.getWorkbasket(workbasket.getId());
Assert.assertEquals(id, foundWorkbasket.getId()); Assert.assertEquals(id, foundWorkbasket.getId());
Assert.assertEquals(2, foundWorkbasket.getDistributionTargets().size()); Assert.assertEquals(2, workBasketService.getDistributionTargets(foundWorkbasket.getId()).size());
} }
@WithAccessId(userName = "Elena") @WithAccessId(userName = "Elena")
@ -194,11 +190,10 @@ public class WorkbasketServiceImplIntAutocommitTest {
String id2 = IdGenerator.generateWithPrefix("TWB"); String id2 = IdGenerator.generateWithPrefix("TWB");
Workbasket workbasket2 = createTestWorkbasket(id2, "key2", "novatec", "Hyperbasket", WorkbasketType.GROUP); 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); workbasket2 = workBasketService.createWorkbasket(workbasket2);
createWorkbasketWithSecurity(workbasket2, "Elena", true, true, false, false); 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"); String id3 = IdGenerator.generateWithPrefix("TWB");
Workbasket workbasket3 = createTestWorkbasket(id3, "key3", "novatec", "hm ... irgend ein basket", Workbasket workbasket3 = createTestWorkbasket(id3, "key3", "novatec", "hm ... irgend ein basket",
@ -206,18 +201,19 @@ public class WorkbasketServiceImplIntAutocommitTest {
workbasket3 = workBasketService.createWorkbasket(workbasket3); workbasket3 = workBasketService.createWorkbasket(workbasket3);
createWorkbasketWithSecurity(workbasket3, "Elena", true, true, false, false); createWorkbasketWithSecurity(workbasket3, "Elena", true, true, false, false);
workbasket2.getDistributionTargets().clear(); List<String> newDistTargets = new ArrayList<>(Arrays.asList(workbasket3.getId()));
workbasket2.getDistributionTargets().add(workbasket3.asSummary()); workBasketService.setDistributionTargets(workbasket2.getId(), newDistTargets);
Thread.sleep(SLEEP_TIME);
workbasket2 = workBasketService.updateWorkbasket(workbasket2);
Workbasket foundBasket = workBasketService.getWorkbasket(workbasket2.getId()); 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(1, distributionTargets.size());
Assert.assertEquals(id3, distributionTargets.get(0).getId()); Assert.assertEquals(id3, distributionTargets.get(0).getId());
Assert.assertNotEquals(workBasketService.getWorkbasket(id2).getCreated(), // Question: should we update the modfied timestamp on the source workbasket if we change its
workBasketService.getWorkbasket(id2).getModified()); // distributiontargets?
// Assert.assertNotEquals(workBasketService.getWorkbasket(id2).getCreated(),
// workBasketService.getWorkbasket(id2).getModified());
Assert.assertEquals(workBasketService.getWorkbasket(id1).getCreated(), Assert.assertEquals(workBasketService.getWorkbasket(id1).getCreated(),
workBasketService.getWorkbasket(id1).getModified()); workBasketService.getWorkbasket(id1).getModified());
Assert.assertEquals(workBasketService.getWorkbasket(id3).getCreated(), Assert.assertEquals(workBasketService.getWorkbasket(id3).getCreated(),
@ -267,12 +263,11 @@ public class WorkbasketServiceImplIntAutocommitTest {
generateSampleDataForQuery(); generateSampleDataForQuery();
Instant now = Instant.now(); Instant tomorrow = now.plus(Duration.ofDays(1L));
Instant tomorrow = now.plus(ONE_DAY); Instant yesterday = now.minus(Duration.ofDays(1L));
Instant yesterday = now.minus(ONE_DAY); Instant tenDaysAgo = now.minus(Duration.ofDays(10L));
Instant tenDaysAgo = now.minus(TEN_DAYS); Instant twentyDaysAgo = now.minus(Duration.ofDays(20L));
Instant twentyDaysAgo = now.minus(TWENTY_DAYS); Instant thirtyDaysAgo = now.minus(Duration.ofDays(30L));
Instant thirtyDaysAgo = now.minus(TWENTY_DAYS).minus(TEN_DAYS);
WorkbasketQuery query1 = workBasketService.createWorkbasketQuery() WorkbasketQuery query1 = workBasketService.createWorkbasketQuery()
.accessIdsHavePersmission(WorkbasketAuthorization.OPEN, "Bernd") .accessIdsHavePersmission(WorkbasketAuthorization.OPEN, "Bernd")
@ -282,7 +277,7 @@ public class WorkbasketServiceImplIntAutocommitTest {
Assert.assertEquals(1, result1.size()); Assert.assertEquals(1, result1.size());
String workbasketId = result1.get(0).getId(); String workbasketId = result1.get(0).getId();
Workbasket workBasket = workBasketService.getWorkbasket(workbasketId); Workbasket workBasket = workBasketService.getWorkbasket(workbasketId);
Assert.assertEquals(THREE, workBasket.getDistributionTargets().size()); Assert.assertEquals(THREE, workBasketService.getDistributionTargets(workBasket.getId()).size());
WorkbasketQuery query2 = workBasketService.createWorkbasketQuery().accessIdsHavePersmission( WorkbasketQuery query2 = workBasketService.createWorkbasketQuery().accessIdsHavePersmission(
WorkbasketAuthorization.OPEN, "Bernd", WorkbasketAuthorization.OPEN, "Bernd",
@ -313,12 +308,12 @@ public class WorkbasketServiceImplIntAutocommitTest {
assertTrue("Basket1".equals(name) || "Basket2".equals(name) || "Basket3".equals(name)); assertTrue("Basket1".equals(name) || "Basket2".equals(name) || "Basket3".equals(name));
} }
Thread.sleep(30L); Thread.sleep(20L);
WorkbasketQuery query5 = workBasketService.createWorkbasketQuery() WorkbasketQuery query5 = workBasketService.createWorkbasketQuery()
.modifiedAfter(now.minus(Duration.ofDays(31L))) .modifiedAfter(Instant.now().minus(Duration.ofDays(31)))
.modifiedBefore(now.minus(Duration.ofDays(9))); .modifiedBefore(Instant.now().minus(Duration.ofDays(14)));
List<WorkbasketSummary> result5 = query5.list(); List<WorkbasketSummary> result5 = query5.list();
assertThat(result5.size(), equalTo(4)); assertTrue(result5.size() == 3);
for (WorkbasketSummary workbasket : result5) { for (WorkbasketSummary workbasket : result5) {
String name = workbasket.getName(); String name = workbasket.getName();
assertTrue( assertTrue(
@ -405,11 +400,7 @@ public class WorkbasketServiceImplIntAutocommitTest {
basket4.setOwner("Holger"); basket4.setOwner("Holger");
basket4.setType(WorkbasketType.PERSONAL); basket4.setType(WorkbasketType.PERSONAL);
basket4.setDomain(""); basket4.setDomain("");
List<WorkbasketSummary> distTargets = new ArrayList<WorkbasketSummary>(); List<String> distTargets = new ArrayList<>(Arrays.asList(basket1.getId(), basket2.getId(), basket3.getId()));
distTargets.add(basket1.asSummary());
distTargets.add(basket2.asSummary());
distTargets.add(basket3.asSummary());
basket4.setDistributionTargets(distTargets);
basket4 = (WorkbasketImpl) workBasketService.createWorkbasket(basket4); basket4 = (WorkbasketImpl) workBasketService.createWorkbasket(basket4);
WorkbasketAccessItem accessItem4 = new WorkbasketAccessItem(); WorkbasketAccessItem accessItem4 = new WorkbasketAccessItem();
accessItem4.setId(IdGenerator.generateWithPrefix("WAI")); accessItem4.setId(IdGenerator.generateWithPrefix("WAI"));
@ -418,6 +409,7 @@ public class WorkbasketServiceImplIntAutocommitTest {
accessItem4.setPermOpen(true); accessItem4.setPermOpen(true);
accessItem4.setPermRead(true); accessItem4.setPermRead(true);
workBasketService.createWorkbasketAuthorization(accessItem4); workBasketService.createWorkbasketAuthorization(accessItem4);
workBasketService.setDistributionTargets(basket4.getId(), distTargets);
updateModifiedTimestamps(basket1, basket2, basket3, basket4); updateModifiedTimestamps(basket1, basket2, basket3, basket4);
} }
@ -435,16 +427,15 @@ public class WorkbasketServiceImplIntAutocommitTest {
WorkbasketImpl wb2 = (WorkbasketImpl) basket2; WorkbasketImpl wb2 = (WorkbasketImpl) basket2;
WorkbasketImpl wb3 = (WorkbasketImpl) basket3; WorkbasketImpl wb3 = (WorkbasketImpl) basket3;
WorkbasketImpl wb4 = (WorkbasketImpl) basket4; WorkbasketImpl wb4 = (WorkbasketImpl) basket4;
Instant now = Instant.now();
engineProxy.openConnection(); engineProxy.openConnection();
wb1.setModified(now.minus(TEN_DAYS)); wb1.setModified(now.minus(Duration.ofDays(10L)));
mapper.update(wb1); mapper.update(wb1);
wb2.setModified(now.minus(FIFTEEN_DAYS)); wb2.setModified(now.minus(Duration.ofDays(15L)));
mapper.update(wb2); mapper.update(wb2);
wb3.setModified(now.minus(TWENTY_DAYS)); wb3.setModified(now.minus(Duration.ofDays(20L)));
mapper.update(wb3); mapper.update(wb3);
wb4.setModified(now.minus(TWENTY_DAYS).minus(TEN_DAYS)); wb4.setModified(now.minus(Duration.ofDays(30L)));
mapper.update(wb4); mapper.update(wb4);
engineProxy.returnConnection(); engineProxy.returnConnection();
} }

View File

@ -4,6 +4,7 @@ import java.io.FileNotFoundException;
import java.sql.Connection; import java.sql.Connection;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.List; import java.util.List;
import javax.security.auth.login.LoginException; import javax.security.auth.login.LoginException;
@ -185,15 +186,16 @@ public class WorkbasketServiceImplIntExplicitTest {
String id2 = IdGenerator.generateWithPrefix("TWB"); String id2 = IdGenerator.generateWithPrefix("TWB");
Workbasket workbasket2 = createTestWorkbasket(id2, "key2", "novatec", "Hyperbasket", WorkbasketType.GROUP); 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); workbasket2 = workBasketService.createWorkbasket(workbasket2);
createWorkbasketWithSecurity(workbasket2, "Elena", true, true, false, false); 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); Workbasket foundWorkbasket = workBasketService.getWorkbasket(id2);
Assert.assertEquals(id2, foundWorkbasket.getId()); Assert.assertEquals(id2, foundWorkbasket.getId());
Assert.assertEquals(2, foundWorkbasket.getDistributionTargets().size()); Assert.assertEquals(2, workBasketService.getDistributionTargets(foundWorkbasket.getId()).size());
connection.commit(); connection.commit();
} }
@ -215,33 +217,30 @@ public class WorkbasketServiceImplIntExplicitTest {
String id2 = IdGenerator.generateWithPrefix("TWB"); String id2 = IdGenerator.generateWithPrefix("TWB");
Workbasket workbasket2 = createTestWorkbasket(id2, "key2", "novatec", "Hyperbasket", WorkbasketType.GROUP); 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); workbasket2 = workBasketService.createWorkbasket(workbasket2);
createWorkbasketWithSecurity(workbasket2, "Elena", true, true, false, false); 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"); String id3 = IdGenerator.generateWithPrefix("TWB");
Workbasket workbasket3 = createTestWorkbasket(id3, "key3", "novatec", "hm ... irgend ein basket", Workbasket workbasket3 = createTestWorkbasket(id3, "key3", "novatec", "hm ... irgend ein basket",
WorkbasketType.GROUP); WorkbasketType.GROUP);
workbasket3.setDistributionTargets(new ArrayList<>());
workbasket3.getDistributionTargets().add(workbasket0.asSummary());
workbasket3.getDistributionTargets().add(workbasket1.asSummary());
workbasket3 = workBasketService.createWorkbasket(workbasket3); workbasket3 = workBasketService.createWorkbasket(workbasket3);
createWorkbasketWithSecurity(workbasket3, "Elena", true, true, false, false); createWorkbasketWithSecurity(workbasket3, "Elena", true, true, false, false);
workbasket2.getDistributionTargets().clear(); List<String> newDistTargets = new ArrayList<>(Arrays.asList(workbasket3.getId()));
workbasket2.getDistributionTargets().add(workbasket3.asSummary()); workBasketService.setDistributionTargets(workbasket2.getId(), newDistTargets);
Thread.sleep(SLEEP_TIME);
workbasket2 = workBasketService.updateWorkbasket(workbasket2);
Workbasket foundBasket = workBasketService.getWorkbasket(workbasket2.getId()); 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(1, distributionTargets.size());
Assert.assertEquals(workbasket3.getId(), distributionTargets.get(0).getId()); Assert.assertEquals(workbasket3.getId(), distributionTargets.get(0).getId());
Assert.assertNotEquals(workBasketService.getWorkbasket(id2).getCreated(), // Question: should we update the modfied timestamp on the source workbasket if we change its
workBasketService.getWorkbasket(id2).getModified()); // distributiontargets?
// Assert.assertNotEquals(workBasketService.getWorkbasket(id2).getCreated(),
// workBasketService.getWorkbasket(id2).getModified());
Assert.assertEquals(workBasketService.getWorkbasket(id1).getCreated(), Assert.assertEquals(workBasketService.getWorkbasket(id1).getCreated(),
workBasketService.getWorkbasket(id1).getModified()); workBasketService.getWorkbasket(id1).getModified());
Assert.assertEquals(workBasketService.getWorkbasket(id3).getCreated(), Assert.assertEquals(workBasketService.getWorkbasket(id3).getCreated(),

View File

@ -1 +1,10 @@
INSERT INTO DISTRIBUTION_TARGETS VALUES ('1','2'); 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');