TSK-377 provide meaningful response for duplicate key exception

This commit is contained in:
BerndBreier 2018-03-12 15:34:25 +01:00 committed by Holger Hagen
parent e0c0246101
commit 3498df039a
15 changed files with 181 additions and 72 deletions

View File

@ -21,6 +21,7 @@ import pro.taskana.exceptions.InvalidWorkbasketException;
import pro.taskana.exceptions.NotAuthorizedException;
import pro.taskana.exceptions.TaskAlreadyExistException;
import pro.taskana.exceptions.TaskNotFoundException;
import pro.taskana.exceptions.WorkbasketAlreadyExistException;
import pro.taskana.exceptions.WorkbasketNotFoundException;
import pro.taskana.impl.ObjectReference;
@ -38,7 +39,7 @@ public class TaskanaRestTest {
@GET
public Response startTask() throws NotAuthorizedException, WorkbasketNotFoundException,
ClassificationNotFoundException, ClassificationAlreadyExistException, InvalidWorkbasketException,
TaskAlreadyExistException, InvalidArgumentException {
TaskAlreadyExistException, InvalidArgumentException, WorkbasketAlreadyExistException {
Workbasket workbasket = taskanaEjb.getWorkbasketService().newWorkbasket("key", "cdiDomain");
workbasket.setName("wb");
workbasket.setType(WorkbasketType.PERSONAL);

View File

@ -5,6 +5,7 @@ import java.util.List;
import pro.taskana.exceptions.InvalidArgumentException;
import pro.taskana.exceptions.InvalidWorkbasketException;
import pro.taskana.exceptions.NotAuthorizedException;
import pro.taskana.exceptions.WorkbasketAlreadyExistException;
import pro.taskana.exceptions.WorkbasketInUseException;
import pro.taskana.exceptions.WorkbasketNotFoundException;
@ -53,9 +54,11 @@ public interface WorkbasketService {
* If a required property of the Workbasket is not set.
* @throws NotAuthorizedException
* if the current user is not member of role BUSINESS_ADMIN or ADMIN
* @throws WorkbasketAlreadyExistException
* if the workbasket exists already
*/
Workbasket createWorkbasket(Workbasket workbasket)
throws InvalidWorkbasketException, NotAuthorizedException;
throws InvalidWorkbasketException, NotAuthorizedException, WorkbasketAlreadyExistException;
/**
* Update a Workbasket.

View File

@ -245,6 +245,13 @@ public class TaskanaEngineImpl implements TaskanaEngine {
if (isUserInRole(roles)) {
return;
} else {
if (LOGGER.isErrorEnabled()) {
String accessIds = LoggerUtils.listToString(CurrentUserContext.getAccessIds());
String rolesAsString = Arrays.toString(roles);
LOGGER.error("Throwing NotAuthorizedException because accessIds {} are not member of roles {}",
accessIds,
rolesAsString);
}
throw new NotAuthorizedException("current user is not member of role(s) " + Arrays.toString(roles));
}
}

View File

@ -23,6 +23,7 @@ import pro.taskana.exceptions.InvalidArgumentException;
import pro.taskana.exceptions.InvalidWorkbasketException;
import pro.taskana.exceptions.NotAuthorizedException;
import pro.taskana.exceptions.SystemException;
import pro.taskana.exceptions.WorkbasketAlreadyExistException;
import pro.taskana.exceptions.WorkbasketInUseException;
import pro.taskana.exceptions.WorkbasketNotFoundException;
import pro.taskana.impl.util.IdGenerator;
@ -71,7 +72,9 @@ public class WorkbasketServiceImpl implements WorkbasketService {
throw new WorkbasketNotFoundException(workbasketId,
"Workbasket with id " + workbasketId + " was not found.");
}
this.checkAuthorization(workbasketId, WorkbasketPermission.READ);
if (!taskanaEngine.isUserInRole(TaskanaRole.ADMIN, TaskanaRole.BUSINESS_ADMIN)) {
this.checkAuthorization(workbasketId, WorkbasketPermission.READ);
}
return result;
} finally {
taskanaEngine.returnConnection();
@ -94,7 +97,9 @@ public class WorkbasketServiceImpl implements WorkbasketService {
throw new WorkbasketNotFoundException(workbasketKey, domain,
"Workbasket with key " + workbasketKey + " and domain " + domain + " was not found.");
}
this.checkAuthorization(workbasketKey, domain, WorkbasketPermission.READ);
if (!taskanaEngine.isUserInRole(TaskanaRole.ADMIN, TaskanaRole.BUSINESS_ADMIN)) {
this.checkAuthorization(workbasketKey, domain, WorkbasketPermission.READ);
}
return result;
} finally {
taskanaEngine.returnConnection();
@ -130,7 +135,7 @@ public class WorkbasketServiceImpl implements WorkbasketService {
@Override
public Workbasket createWorkbasket(Workbasket newWorkbasket)
throws InvalidWorkbasketException, NotAuthorizedException {
throws InvalidWorkbasketException, NotAuthorizedException, WorkbasketAlreadyExistException {
LOGGER.debug("entry to createtWorkbasket(workbasket)", newWorkbasket);
taskanaEngine.checkRoleMembership(TaskanaRole.BUSINESS_ADMIN, TaskanaRole.ADMIN);
WorkbasketImpl workbasket = (WorkbasketImpl) newWorkbasket;
@ -139,6 +144,15 @@ public class WorkbasketServiceImpl implements WorkbasketService {
Instant now = Instant.now();
workbasket.setCreated(now);
workbasket.setModified(now);
Workbasket existingWorkbasket = workbasketMapper.findByKeyAndDomain(newWorkbasket.getKey(),
newWorkbasket.getDomain());
if (existingWorkbasket != null) {
LOGGER.error(
"createWorkbasket failed because Workbasket with key {} and domain {} already exists. Throwing WorkbasketAlreadyExistsException.",
newWorkbasket.getKey(), newWorkbasket.getDomain());
throw new WorkbasketAlreadyExistException(existingWorkbasket);
}
if (workbasket.getId() == null || workbasket.getId().isEmpty()) {
workbasket.setId(IdGenerator.generateWithPrefix(ID_PREFIX_WORKBASKET));
}
@ -191,6 +205,8 @@ public class WorkbasketServiceImpl implements WorkbasketService {
accessItem.setId(IdGenerator.generateWithPrefix(ID_PREFIX_WORKBASKET_AUTHORIZATION));
if (workbasketAccessItem.getId() == null || workbasketAccessItem.getAccessId() == null
|| workbasketAccessItem.getWorkbasketId() == null) {
LOGGER.error(
"createWorkbasketAccessItem failed because id, accessId or workbasketId is null. Throwing InvalidArgumentException.");
throw new InvalidArgumentException(
"Checking the preconditions of the current WorkbasketAccessItem failed. WorkbasketAccessItem="
+ workbasketAccessItem.toString());
@ -219,10 +235,16 @@ public class WorkbasketServiceImpl implements WorkbasketService {
for (WorkbasketAccessItem workbasketAccessItem : wbAccessItems) {
WorkbasketAccessItemImpl wbAccessItemImpl = (WorkbasketAccessItemImpl) workbasketAccessItem;
if (wbAccessItemImpl.getWorkbasketId() == null) {
LOGGER.error(
"setWorkbasketAccessItem failed because WorkbasketAccessItem {} has a null workbasketId. Throwing InvalidArgumentException.",
workbasketAccessItem);
throw new InvalidArgumentException(
"Checking the preconditions of the current WorkbasketAccessItem failed - WBID is NULL. WorkbasketAccessItem="
+ workbasketAccessItem.toString());
} else if (!wbAccessItemImpl.getWorkbasketId().equals(workbasketId)) {
LOGGER.error(
"setWorkbasketAccessItem failed because WorkbasketAccessItem {} does not refer to workbasket {}. Throwing InvalidArgumentException.",
workbasketAccessItem, workbasketId);
throw new InvalidArgumentException(
"Checking the preconditions of the current WorkbasketAccessItem failed - the WBID does not match. Target-WBID='"
+ workbasketId + "' WorkbasketAccessItem="
@ -277,6 +299,8 @@ public class WorkbasketServiceImpl implements WorkbasketService {
public void checkAuthorization(String workbasketId,
WorkbasketPermission workbasketPermission) throws NotAuthorizedException, WorkbasketNotFoundException {
if (workbasketMapper.findById(workbasketId) == null) {
LOGGER.error("Throwing WorkbasketNotFoundException because workbasket with id {} does not exist",
workbasketId);
throw new WorkbasketNotFoundException(workbasketId,
"Workbasket with id " + workbasketId + " was not found.");
}
@ -288,6 +312,9 @@ public class WorkbasketServiceImpl implements WorkbasketService {
WorkbasketPermission workbasketPermission)
throws NotAuthorizedException, WorkbasketNotFoundException {
if (workbasketMapper.findByKeyAndDomain(workbasketKey, domain) == null) {
LOGGER.error(
"Throwing WorkbasketNotFoundException because workbasket with key {} and domain {} does not exist",
workbasketKey, domain);
throw new WorkbasketNotFoundException(workbasketKey, domain,
"Workbasket with key " + workbasketKey + " and domain " + domain + " was not found");
}
@ -446,7 +473,9 @@ public class WorkbasketServiceImpl implements WorkbasketService {
taskanaEngine.openConnection();
// check that source workbasket exists
getWorkbasket(workbasketId);
checkAuthorization(workbasketId, WorkbasketPermission.READ);
if (!taskanaEngine.isUserInRole(TaskanaRole.ADMIN, TaskanaRole.BUSINESS_ADMIN)) {
checkAuthorization(workbasketId, WorkbasketPermission.READ);
}
List<WorkbasketSummaryImpl> distributionTargets = workbasketMapper
.findByDistributionTargets(workbasketId);
result.addAll(distributionTargets);
@ -470,7 +499,9 @@ public class WorkbasketServiceImpl implements WorkbasketService {
taskanaEngine.openConnection();
// check that source workbasket exists
Workbasket workbasket = getWorkbasket(workbasketKey, domain);
checkAuthorization(workbasket.getId(), WorkbasketPermission.READ);
if (!taskanaEngine.isUserInRole(TaskanaRole.ADMIN, TaskanaRole.BUSINESS_ADMIN)) {
checkAuthorization(workbasket.getId(), WorkbasketPermission.READ);
}
List<WorkbasketSummaryImpl> distributionTargets = workbasketMapper
.findByDistributionTargets(workbasket.getId());
result.addAll(distributionTargets);
@ -495,7 +526,9 @@ public class WorkbasketServiceImpl implements WorkbasketService {
taskanaEngine.openConnection();
// check that source workbasket exists
getWorkbasket(workbasketId);
checkAuthorization(workbasketId, WorkbasketPermission.READ);
if (!taskanaEngine.isUserInRole(TaskanaRole.ADMIN, TaskanaRole.BUSINESS_ADMIN)) {
checkAuthorization(workbasketId, WorkbasketPermission.READ);
}
List<WorkbasketSummaryImpl> distributionSources = workbasketMapper
.findDistributionSources(workbasketId);
result.addAll(distributionSources);
@ -519,7 +552,9 @@ public class WorkbasketServiceImpl implements WorkbasketService {
taskanaEngine.openConnection();
// check that source workbasket exists
Workbasket workbasket = getWorkbasket(workbasketKey, domain);
checkAuthorization(workbasket.getId(), WorkbasketPermission.READ);
if (!taskanaEngine.isUserInRole(TaskanaRole.ADMIN, TaskanaRole.BUSINESS_ADMIN)) {
checkAuthorization(workbasket.getId(), WorkbasketPermission.READ);
}
List<WorkbasketSummaryImpl> distributionSources = workbasketMapper
.findDistributionSources(workbasket.getId());
result.addAll(distributionSources);
@ -547,7 +582,6 @@ public class WorkbasketServiceImpl implements WorkbasketService {
taskanaEngine.openConnection();
// check existence of source workbasket
WorkbasketImpl sourceWorkbasket = (WorkbasketImpl) getWorkbasket(sourceWorkbasketId);
checkAuthorization(sourceWorkbasketId, WorkbasketPermission.READ);
distributionTargetMapper.deleteAllDistributionTargetsBySourceId(sourceWorkbasketId);
sourceWorkbasket.setModified(Instant.now());
@ -616,7 +650,6 @@ public class WorkbasketServiceImpl implements WorkbasketService {
try {
taskanaEngine.openConnection();
// don't check existence of source / target workbasket to enable cleanup even if the db is corrupted
checkAuthorization(sourceWorkbasketId, WorkbasketPermission.READ);
// check whether the target is set as target
int numberOfDistTargets = distributionTargetMapper.getNumberOfDistributionTargets(sourceWorkbasketId,
targetWorkbasketId);
@ -692,6 +725,13 @@ public class WorkbasketServiceImpl implements WorkbasketService {
if (workbasketPermission == null) {
throw new SystemException("checkAuthorization was called with an invalid parameter combination");
}
// Skip permission check is security is not enabled
if (!taskanaEngine.getConfiguration().isSecurityEnabled()) {
LOGGER.debug("Skipping permissions check since security is disabled.");
return;
}
if (taskanaEngine.isUserInRole(TaskanaRole.ADMIN)) {
LOGGER.debug("Skipping permissions check since user is in role ADMIN.");
return;
@ -700,12 +740,6 @@ public class WorkbasketServiceImpl implements WorkbasketService {
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 {}",
@ -723,13 +757,27 @@ public class WorkbasketServiceImpl implements WorkbasketService {
.findByWorkbasketAndAccessIdAndAuthorizationsById(workbasketId, accessIds,
workbasketPermission.name());
} else {
LOGGER.error(
"Throwing SystemException because an internal error occurred. Workbasket key and id were null in checkAuthorization");
throw new SystemException(
"checkAuthorizationImpl was called with both workbasketKey and workbasketId set to null");
}
if (accessItems.isEmpty()) {
throw new NotAuthorizedException("Not authorized. Permission '" + workbasketPermission.name()
+ "' on workbasket '" + workbasketKey + "' is needed.");
if (workbasketId != null) {
LOGGER.error(
"AccessIds {} do not have permission {} on workbasket with id {}. Throwing NotAuthorizedException.",
LoggerUtils.listToString(accessIds), workbasketPermission.name(), workbasketId);
throw new NotAuthorizedException("Not authorized. Permission '" + workbasketPermission.name()
+ "' on workbasket '" + workbasketId + "' is needed.");
} else {
LOGGER.error(
"AccessIds {} do not have permission {} on workbasket with key {} and domain {}. Throwing NotAuthorizedException.",
LoggerUtils.listToString(accessIds), workbasketPermission.name(), workbasketKey, domain);
throw new NotAuthorizedException("Not authorized. Permission '" + workbasketPermission.name()
+ "' on workbasket with key '" + workbasketKey + "' and domain '" + domain
+ "' is needed.");
}
}
isAuthorized = true;

View File

@ -32,7 +32,7 @@ public final class LoggerUtils {
StringBuilder builder = new StringBuilder();
builder.append("[");
for (T t : list) {
builder.append(t.toString());
builder.append(String.valueOf(t));
builder.append(";\n");
}
builder.append("]");

View File

@ -17,6 +17,7 @@ import pro.taskana.WorkbasketType;
import pro.taskana.exceptions.InvalidArgumentException;
import pro.taskana.exceptions.InvalidWorkbasketException;
import pro.taskana.exceptions.NotAuthorizedException;
import pro.taskana.exceptions.WorkbasketAlreadyExistException;
import pro.taskana.exceptions.WorkbasketNotFoundException;
import pro.taskana.security.JAASRunner;
import pro.taskana.security.WithAccessId;
@ -37,7 +38,7 @@ public class CreateWorkbasketAccTest extends AbstractAccTest {
@Test
public void testCreateWorkbasket()
throws SQLException, NotAuthorizedException, InvalidArgumentException, WorkbasketNotFoundException,
InvalidWorkbasketException {
InvalidWorkbasketException, WorkbasketAlreadyExistException {
WorkbasketService workbasketService = taskanaEngine.getWorkbasketService();
int before = workbasketService.createWorkbasketQuery().domainIn("DOMAIN_A").list().size();
@ -65,7 +66,7 @@ public class CreateWorkbasketAccTest extends AbstractAccTest {
@Test(expected = NotAuthorizedException.class)
public void testCreateWorkbasketNotAuthorized()
throws SQLException, NotAuthorizedException, InvalidArgumentException, WorkbasketNotFoundException,
InvalidWorkbasketException {
InvalidWorkbasketException, WorkbasketAlreadyExistException {
WorkbasketService workbasketService = taskanaEngine.getWorkbasketService();
Workbasket workbasket = workbasketService.newWorkbasket("key3", "novatec");
@ -82,7 +83,7 @@ public class CreateWorkbasketAccTest extends AbstractAccTest {
groupNames = {"businessadmin"})
@Test
public void testCreateWorkbasketWithMissingRequiredField()
throws WorkbasketNotFoundException, NotAuthorizedException {
throws WorkbasketNotFoundException, NotAuthorizedException, WorkbasketAlreadyExistException {
WorkbasketService workbasketService = taskanaEngine.getWorkbasketService();
Workbasket workbasket = workbasketService.newWorkbasket(null, "novatec");

View File

@ -123,7 +123,7 @@ public class DistributionTargetsAccTest extends AbstractAccTest {
}
@WithAccessId(
userName = "user_3_1", groupNames = {"businessadmin"})
userName = "user_3_1", groupNames = {"group_1"})
@Test
public void testDistributionTargetCallsFailWithNotAuthorizedException()
throws NotAuthorizedException, WorkbasketNotFoundException {

View File

@ -37,6 +37,7 @@ import pro.taskana.configuration.TaskanaEngineConfiguration;
import pro.taskana.exceptions.InvalidArgumentException;
import pro.taskana.exceptions.InvalidWorkbasketException;
import pro.taskana.exceptions.NotAuthorizedException;
import pro.taskana.exceptions.WorkbasketAlreadyExistException;
import pro.taskana.exceptions.WorkbasketInUseException;
import pro.taskana.exceptions.WorkbasketNotFoundException;
import pro.taskana.mappings.DistributionTargetMapper;
@ -98,6 +99,7 @@ public class WorkbasketServiceImplTest {
verify(workbasketMapperMock, times(1)).findById(wbId);
verify(cutSpy, times(1)).checkAuthorization(wb.getId(), authorization);
verify(taskanaEngineImplMock, times(1)).returnConnection();
verify(taskanaEngineImplMock, times(1)).isUserInRole(any());
verifyNoMoreInteractions(taskQueryMock, taskServiceMock, workbasketMapperMock, workbasketAccessMapperMock,
distributionTargetMapperMock,
taskanaEngineImplMock, taskanaEngineConfigurationMock);
@ -138,6 +140,7 @@ public class WorkbasketServiceImplTest {
verify(workbasketMapperMock, times(1)).findById(wbId);
verify(cutSpy, times(1)).checkAuthorization(wb.getId(), authorization);
verify(taskanaEngineImplMock, times(1)).returnConnection();
verify(taskanaEngineImplMock, times(1)).isUserInRole(any());
verifyNoMoreInteractions(taskQueryMock, taskServiceMock, workbasketMapperMock, workbasketAccessMapperMock,
distributionTargetMapperMock,
taskanaEngineImplMock, taskanaEngineConfigurationMock);
@ -160,6 +163,7 @@ public class WorkbasketServiceImplTest {
verify(workbasketMapperMock, times(1)).findByKeyAndDomain(wbKey, "domain");
verify(cutSpy, times(1)).checkAuthorization(wbKey, "domain", authorization);
verify(taskanaEngineImplMock, times(1)).returnConnection();
verify(taskanaEngineImplMock, times(1)).isUserInRole(any());
verifyNoMoreInteractions(taskQueryMock, taskServiceMock, workbasketMapperMock, workbasketAccessMapperMock,
distributionTargetMapperMock,
taskanaEngineImplMock, taskanaEngineConfigurationMock);
@ -200,6 +204,7 @@ public class WorkbasketServiceImplTest {
verify(cutSpy, times(1)).checkAuthorization(wbKey, "test", authorization);
verify(workbasketMapperMock, times(1)).findByKeyAndDomain(wbKey, "test");
verify(taskanaEngineImplMock, times(1)).returnConnection();
verify(taskanaEngineImplMock, times(1)).isUserInRole(any());
verifyNoMoreInteractions(taskQueryMock, taskServiceMock, workbasketMapperMock, workbasketAccessMapperMock,
distributionTargetMapperMock,
taskanaEngineImplMock, taskanaEngineConfigurationMock);
@ -208,7 +213,7 @@ public class WorkbasketServiceImplTest {
@Test
public void testCreateWorkbasket_InvalidWorkbasketCases()
throws WorkbasketNotFoundException, NotAuthorizedException {
throws WorkbasketNotFoundException, NotAuthorizedException, WorkbasketAlreadyExistException {
WorkbasketImpl wb = new WorkbasketImpl();
int serviceCalls = 1;
@ -216,11 +221,13 @@ public class WorkbasketServiceImplTest {
try {
wb.setId(null);
wb.setKey(null);
doReturn(null).when(workbasketMapperMock).findByKeyAndDomain(any(), any());
cutSpy.createWorkbasket(wb);
} catch (InvalidWorkbasketException ex) {
verify(taskanaEngineImplMock, times(serviceCalls)).openConnection();
verify(taskanaEngineImplMock, times(serviceCalls)).returnConnection();
verify(taskanaEngineImplMock, times(serviceCalls)).checkRoleMembership(any());
verify(workbasketMapperMock, times(serviceCalls)).findByKeyAndDomain(any(), any());
verifyNoMoreInteractions(taskQueryMock, taskServiceMock, workbasketMapperMock, workbasketAccessMapperMock,
distributionTargetMapperMock,
taskanaEngineImplMock, taskanaEngineConfigurationMock);
@ -238,6 +245,7 @@ public class WorkbasketServiceImplTest {
verify(taskanaEngineImplMock, times(serviceCalls)).openConnection();
verify(taskanaEngineImplMock, times(serviceCalls)).returnConnection();
verify(taskanaEngineImplMock, times(serviceCalls)).checkRoleMembership(any());
verify(workbasketMapperMock, times(serviceCalls)).findByKeyAndDomain(any(), any());
verifyNoMoreInteractions(taskQueryMock, taskServiceMock, workbasketMapperMock, workbasketAccessMapperMock,
distributionTargetMapperMock,
taskanaEngineImplMock, taskanaEngineConfigurationMock);
@ -256,6 +264,7 @@ public class WorkbasketServiceImplTest {
verify(taskanaEngineImplMock, times(serviceCalls)).openConnection();
verify(taskanaEngineImplMock, times(serviceCalls)).returnConnection();
verify(taskanaEngineImplMock, times(serviceCalls)).checkRoleMembership(any());
verify(workbasketMapperMock, times(serviceCalls)).findByKeyAndDomain(any(), any());
verifyNoMoreInteractions(taskQueryMock, taskServiceMock, workbasketMapperMock, workbasketAccessMapperMock,
distributionTargetMapperMock,
taskanaEngineImplMock, taskanaEngineConfigurationMock);
@ -273,6 +282,7 @@ public class WorkbasketServiceImplTest {
verify(taskanaEngineImplMock, times(serviceCalls)).openConnection();
verify(taskanaEngineImplMock, times(serviceCalls)).returnConnection();
verify(taskanaEngineImplMock, times(serviceCalls)).checkRoleMembership(any());
verify(workbasketMapperMock, times(serviceCalls)).findByKeyAndDomain(any(), any());
verifyNoMoreInteractions(taskQueryMock, taskServiceMock, workbasketMapperMock, workbasketAccessMapperMock,
distributionTargetMapperMock,
taskanaEngineImplMock, taskanaEngineConfigurationMock);
@ -291,6 +301,7 @@ public class WorkbasketServiceImplTest {
verify(taskanaEngineImplMock, times(serviceCalls)).openConnection();
verify(taskanaEngineImplMock, times(serviceCalls)).returnConnection();
verify(taskanaEngineImplMock, times(serviceCalls)).checkRoleMembership(any());
verify(workbasketMapperMock, times(serviceCalls)).findByKeyAndDomain(any(), any());
verifyNoMoreInteractions(taskQueryMock, taskServiceMock, workbasketMapperMock, workbasketAccessMapperMock,
distributionTargetMapperMock,
taskanaEngineImplMock, taskanaEngineConfigurationMock);
@ -309,6 +320,7 @@ public class WorkbasketServiceImplTest {
verify(taskanaEngineImplMock, times(serviceCalls)).openConnection();
verify(taskanaEngineImplMock, times(serviceCalls)).returnConnection();
verify(taskanaEngineImplMock, times(serviceCalls)).checkRoleMembership(any());
verify(workbasketMapperMock, times(serviceCalls)).findByKeyAndDomain(any(), any());
verifyNoMoreInteractions(taskQueryMock, taskServiceMock, workbasketMapperMock, workbasketAccessMapperMock,
distributionTargetMapperMock,
taskanaEngineImplMock, taskanaEngineConfigurationMock);
@ -321,7 +333,8 @@ public class WorkbasketServiceImplTest {
@Test
public void testCreateWorkbasket_WithoutDistibutionTargets()
throws WorkbasketNotFoundException, NotAuthorizedException, InvalidWorkbasketException {
throws WorkbasketNotFoundException, NotAuthorizedException, InvalidWorkbasketException,
WorkbasketAlreadyExistException {
WorkbasketImpl expectedWb = createTestWorkbasket(null, "Key-1");
doNothing().when(workbasketMapperMock).insert(expectedWb);
doReturn(expectedWb).when(workbasketMapperMock).findById(any());
@ -331,15 +344,16 @@ public class WorkbasketServiceImplTest {
Workbasket actualWb = cutSpy.createWorkbasket(expectedWb);
cutSpy.setDistributionTargets(expectedWb.getId(), null);
verify(taskanaEngineImplMock, times(5)).openConnection();
verify(taskanaEngineImplMock, times(2)).getConfiguration();
verify(taskanaEngineConfigurationMock, times(2)).isSecurityEnabled();
verify(taskanaEngineImplMock, times(3)).openConnection();
verify(taskanaEngineImplMock, times(1)).getConfiguration();
verify(taskanaEngineConfigurationMock, times(1)).isSecurityEnabled();
verify(workbasketMapperMock, times(1)).insert(expectedWb);
verify(workbasketMapperMock, times(3)).findById(expectedWb.getId());
verify(workbasketMapperMock, times(1)).findByKeyAndDomain(any(), any());
verify(workbasketMapperMock, times(2)).findById(expectedWb.getId());
verify(workbasketMapperMock, times(1)).update(any());
verify(taskanaEngineImplMock, times(5)).returnConnection();
verify(taskanaEngineImplMock, times(3)).returnConnection();
verify(taskanaEngineImplMock, times(2)).checkRoleMembership(any());
verify(taskanaEngineImplMock, times(2)).isUserInRole(any());
verify(taskanaEngineImplMock, times(1)).isUserInRole(any());
verify(distributionTargetMapperMock, times(1)).deleteAllDistributionTargetsBySourceId(any());
verifyNoMoreInteractions(taskQueryMock, taskServiceMock, workbasketMapperMock, workbasketAccessMapperMock,
distributionTargetMapperMock,
@ -352,30 +366,25 @@ public class WorkbasketServiceImplTest {
@Test
public void testCreateWorkbasket_WithDistibutionTargets()
throws WorkbasketNotFoundException, NotAuthorizedException, InvalidWorkbasketException {
throws WorkbasketNotFoundException, NotAuthorizedException, InvalidWorkbasketException,
WorkbasketAlreadyExistException {
final int distTargetAmount = 2;
WorkbasketImpl expectedWb = createTestWorkbasket(null, "Key-1");
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(5)).openConnection();
verify(taskanaEngineImplMock, times(1)).getConfiguration();
verify(taskanaEngineConfigurationMock, times(1)).isSecurityEnabled();
verify(taskanaEngineImplMock, times(4)).openConnection();
verify(workbasketMapperMock, times(3)).insert(any());
verify(cutSpy, times(distTargetAmount + 1)).getWorkbasket(any());
verify(distributionTargetMapperMock, times(1)).deleteAllDistributionTargetsBySourceId(any());
verify(distributionTargetMapperMock, times(distTargetAmount)).insert(any(), any());
verify(workbasketMapperMock, times(1)).findById(any());
verify(workbasketMapperMock, times(3)).findByKeyAndDomain(any(), any());
verify(workbasketMapperMock, times(1)).update(any());
verify(taskanaEngineImplMock, times(5)).returnConnection();
verify(taskanaEngineImplMock, times(4)).returnConnection();
verify(taskanaEngineImplMock, times(4)).checkRoleMembership(any());
verify(taskanaEngineImplMock, times(1)).isUserInRole(any());
verifyNoMoreInteractions(taskQueryMock, taskServiceMock, workbasketMapperMock, workbasketAccessMapperMock,
distributionTargetMapperMock,
taskanaEngineImplMock, taskanaEngineConfigurationMock);
@ -387,7 +396,8 @@ public class WorkbasketServiceImplTest {
@Test(expected = WorkbasketNotFoundException.class)
public void testCreateWorkbasket_DistibutionTargetNotExisting()
throws WorkbasketNotFoundException, NotAuthorizedException, InvalidWorkbasketException {
throws WorkbasketNotFoundException, NotAuthorizedException, InvalidWorkbasketException,
WorkbasketAlreadyExistException {
WorkbasketImpl expectedWb = createTestWorkbasket("ID-1", "Key-1");
doNothing().when(workbasketMapperMock).insert(expectedWb);
@ -402,6 +412,7 @@ public class WorkbasketServiceImplTest {
verify(taskanaEngineImplMock, times(3)).openConnection();
verify(workbasketMapperMock, times(1)).insert(expectedWb);
verify(workbasketMapperMock, times(1)).findById(any());
verify(workbasketMapperMock, times(1)).findByKeyAndDomain(any(), any());
verify(cutSpy, times(1)).getWorkbasket(any());
verify(taskanaEngineImplMock, times(3)).returnConnection();
verify(taskanaEngineImplMock, times(2)).checkRoleMembership(any());
@ -416,7 +427,7 @@ public class WorkbasketServiceImplTest {
@Ignore
@Test(expected = WorkbasketNotFoundException.class)
public void testCreateWorkbasket_NotCreated()
throws WorkbasketNotFoundException, NotAuthorizedException, InvalidWorkbasketException {
throws Exception {
WorkbasketImpl expectedWb = createTestWorkbasket(null, "Key-1");
doNothing().when(workbasketMapperMock).insert(expectedWb);
doThrow(WorkbasketNotFoundException.class).when(workbasketMapperMock).findById(any());
@ -553,7 +564,8 @@ public class WorkbasketServiceImplTest {
}
private List<String> createTestDistributionTargets(int amount)
throws WorkbasketNotFoundException, InvalidWorkbasketException, NotAuthorizedException {
throws WorkbasketNotFoundException, InvalidWorkbasketException, NotAuthorizedException,
WorkbasketAlreadyExistException {
List<String> distributionsTargets = new ArrayList<>();
amount = (amount < 0) ? 0 : amount;
for (int i = 0; i < amount; i++) {

View File

@ -40,6 +40,7 @@ import pro.taskana.exceptions.NotAuthorizedException;
import pro.taskana.exceptions.SystemException;
import pro.taskana.exceptions.TaskAlreadyExistException;
import pro.taskana.exceptions.TaskNotFoundException;
import pro.taskana.exceptions.WorkbasketAlreadyExistException;
import pro.taskana.exceptions.WorkbasketNotFoundException;
import pro.taskana.impl.ClassificationImpl;
import pro.taskana.impl.JunitHelper;
@ -96,7 +97,7 @@ public class TaskServiceImplIntAutocommitTest {
public void testStart() throws FileNotFoundException, SQLException, TaskNotFoundException,
WorkbasketNotFoundException, NotAuthorizedException, ClassificationNotFoundException,
ClassificationAlreadyExistException, TaskAlreadyExistException, InvalidWorkbasketException,
InvalidArgumentException {
InvalidArgumentException, WorkbasketAlreadyExistException {
Workbasket wb = workbasketService.newWorkbasket("workbasket", "novatec");
wb.setName("workbasket");
wb.setType(WorkbasketType.GROUP);
@ -122,7 +123,8 @@ public class TaskServiceImplIntAutocommitTest {
public void testStartTransactionFail()
throws FileNotFoundException, SQLException, TaskNotFoundException, NotAuthorizedException,
WorkbasketNotFoundException, ClassificationNotFoundException, ClassificationAlreadyExistException,
TaskAlreadyExistException, InvalidWorkbasketException, InvalidArgumentException {
TaskAlreadyExistException, InvalidWorkbasketException, InvalidArgumentException,
WorkbasketAlreadyExistException {
Workbasket wb = workbasketService.newWorkbasket("wb1k1", "novatec");
wb.setName("sdf");
wb.setType(WorkbasketType.GROUP);
@ -151,7 +153,8 @@ public class TaskServiceImplIntAutocommitTest {
public void testCreateTaskInTaskanaWithDefaultDb()
throws FileNotFoundException, SQLException, TaskNotFoundException, NotAuthorizedException,
WorkbasketNotFoundException, ClassificationNotFoundException, ClassificationAlreadyExistException,
TaskAlreadyExistException, InvalidWorkbasketException, InvalidArgumentException {
TaskAlreadyExistException, InvalidWorkbasketException, InvalidArgumentException,
WorkbasketAlreadyExistException {
DBCleaner cleaner = new DBCleaner();
cleaner.clearDb(TaskanaEngineConfiguration.createDefaultDataSource(), false);
TaskanaEngineConfiguration taskanaEngineConfiguration = new TaskanaEngineConfiguration(null, false, false);
@ -179,7 +182,8 @@ public class TaskServiceImplIntAutocommitTest {
@Test
public void should_ReturnList_when_BuilderIsUsed() throws SQLException, NotAuthorizedException,
WorkbasketNotFoundException, ClassificationNotFoundException, ClassificationAlreadyExistException,
TaskAlreadyExistException, InvalidWorkbasketException, InvalidArgumentException, SystemException {
TaskAlreadyExistException, InvalidWorkbasketException, InvalidArgumentException, SystemException,
WorkbasketAlreadyExistException {
Workbasket wb = workbasketService.newWorkbasket("key", "novatec");
wb.setName("workbasket");
wb.setType(WorkbasketType.GROUP);
@ -216,7 +220,7 @@ public class TaskServiceImplIntAutocommitTest {
public void shouldTransferTaskToOtherWorkbasket()
throws WorkbasketNotFoundException, ClassificationNotFoundException, NotAuthorizedException,
ClassificationAlreadyExistException, TaskNotFoundException, InterruptedException, TaskAlreadyExistException,
InvalidWorkbasketException, InvalidArgumentException {
InvalidWorkbasketException, InvalidArgumentException, WorkbasketAlreadyExistException {
Workbasket sourceWB;
Workbasket destinationWB;
WorkbasketImpl wb;
@ -281,7 +285,8 @@ public class TaskServiceImplIntAutocommitTest {
@Test
public void shouldNotTransferByFailingSecurity() throws WorkbasketNotFoundException,
ClassificationNotFoundException, NotAuthorizedException, ClassificationAlreadyExistException, SQLException,
TaskNotFoundException, TaskAlreadyExistException, InvalidWorkbasketException, InvalidArgumentException {
TaskNotFoundException, TaskAlreadyExistException, InvalidWorkbasketException, InvalidArgumentException,
WorkbasketAlreadyExistException {
final String user = CurrentUserContext.getUserid();
// Set up Security for this Test
@ -368,7 +373,7 @@ public class TaskServiceImplIntAutocommitTest {
public void testWithPrimaryObjectRef() throws FileNotFoundException, SQLException, TaskNotFoundException,
WorkbasketNotFoundException, NotAuthorizedException, ClassificationNotFoundException,
ClassificationAlreadyExistException, TaskAlreadyExistException, InvalidWorkbasketException,
InvalidArgumentException {
InvalidArgumentException, WorkbasketAlreadyExistException {
Workbasket wb = workbasketService.newWorkbasket("workbasket", "novatec");
wb.setName("workbasket");
wb.setType(WorkbasketType.GROUP);

View File

@ -44,6 +44,7 @@ import pro.taskana.exceptions.NotAuthorizedException;
import pro.taskana.exceptions.SystemException;
import pro.taskana.exceptions.TaskAlreadyExistException;
import pro.taskana.exceptions.TaskNotFoundException;
import pro.taskana.exceptions.WorkbasketAlreadyExistException;
import pro.taskana.exceptions.WorkbasketNotFoundException;
import pro.taskana.impl.ClassificationImpl;
import pro.taskana.impl.ClassificationServiceImpl;
@ -103,7 +104,8 @@ public class TaskServiceImplIntExplicitTest {
public void testStartTransactionFail()
throws FileNotFoundException, SQLException, TaskNotFoundException, NotAuthorizedException,
WorkbasketNotFoundException, ClassificationNotFoundException, ClassificationAlreadyExistException,
TaskAlreadyExistException, InvalidWorkbasketException, InvalidArgumentException {
TaskAlreadyExistException, InvalidWorkbasketException, InvalidArgumentException,
WorkbasketAlreadyExistException {
Connection connection = dataSource.getConnection();
taskanaEngineImpl.setConnection(connection);
@ -138,7 +140,8 @@ public class TaskServiceImplIntExplicitTest {
public void testCreateTask()
throws FileNotFoundException, SQLException, TaskNotFoundException, NotAuthorizedException,
WorkbasketNotFoundException, ClassificationNotFoundException, ClassificationAlreadyExistException,
TaskAlreadyExistException, InvalidWorkbasketException, InvalidArgumentException {
TaskAlreadyExistException, InvalidWorkbasketException, InvalidArgumentException,
WorkbasketAlreadyExistException {
Connection connection = dataSource.getConnection();
taskanaEngineImpl.setConnection(connection);
@ -169,7 +172,8 @@ public class TaskServiceImplIntExplicitTest {
public void testCreateTaskInTaskanaWithDefaultDb()
throws FileNotFoundException, SQLException, TaskNotFoundException, NotAuthorizedException,
WorkbasketNotFoundException, ClassificationNotFoundException, ClassificationAlreadyExistException,
TaskAlreadyExistException, InvalidWorkbasketException, InvalidArgumentException {
TaskAlreadyExistException, InvalidWorkbasketException, InvalidArgumentException,
WorkbasketAlreadyExistException {
DataSource ds = TaskanaEngineConfiguration.createDefaultDataSource();
DBCleaner cleaner = new DBCleaner();
cleaner.clearDb(ds, false);
@ -207,7 +211,8 @@ public class TaskServiceImplIntExplicitTest {
@Test
public void testCreateTaskWithPlannedAndName() throws SQLException, NotAuthorizedException,
WorkbasketNotFoundException, ClassificationNotFoundException, ClassificationAlreadyExistException,
TaskAlreadyExistException, InvalidWorkbasketException, InvalidArgumentException {
TaskAlreadyExistException, InvalidWorkbasketException, InvalidArgumentException,
WorkbasketAlreadyExistException {
Connection connection = dataSource.getConnection();
taskanaEngineImpl.setConnection(connection);
@ -275,7 +280,7 @@ public class TaskServiceImplIntExplicitTest {
public void createTaskShouldThrowWorkbasketNotFoundException()
throws NotAuthorizedException, WorkbasketNotFoundException, ClassificationNotFoundException, SQLException,
ClassificationAlreadyExistException, TaskAlreadyExistException, InvalidWorkbasketException,
InvalidArgumentException {
InvalidArgumentException, WorkbasketAlreadyExistException {
Connection connection = dataSource.getConnection();
taskanaEngineImpl.setConnection(connection);
@ -291,7 +296,7 @@ public class TaskServiceImplIntExplicitTest {
public void createManualTaskShouldThrowClassificationNotFoundException()
throws NotAuthorizedException, WorkbasketNotFoundException, ClassificationNotFoundException, SQLException,
ClassificationAlreadyExistException, TaskAlreadyExistException, InvalidWorkbasketException,
InvalidArgumentException {
InvalidArgumentException, WorkbasketAlreadyExistException {
Connection connection = dataSource.getConnection();
taskanaEngineImpl.setConnection(connection);
@ -318,7 +323,8 @@ public class TaskServiceImplIntExplicitTest {
@Test
public void should_ReturnList_when_BuilderIsUsed() throws SQLException, NotAuthorizedException,
WorkbasketNotFoundException, ClassificationNotFoundException, ClassificationAlreadyExistException,
TaskAlreadyExistException, InvalidWorkbasketException, InvalidArgumentException, SystemException {
TaskAlreadyExistException, InvalidWorkbasketException, InvalidArgumentException, SystemException,
WorkbasketAlreadyExistException {
Connection connection = dataSource.getConnection();
taskanaEngineImpl.setConnection(connection);
@ -363,7 +369,7 @@ public class TaskServiceImplIntExplicitTest {
public void shouldTransferTaskToOtherWorkbasket()
throws WorkbasketNotFoundException, ClassificationNotFoundException, NotAuthorizedException,
ClassificationAlreadyExistException, TaskNotFoundException, InterruptedException, TaskAlreadyExistException,
SQLException, InvalidWorkbasketException, InvalidArgumentException {
SQLException, InvalidWorkbasketException, InvalidArgumentException, WorkbasketAlreadyExistException {
Workbasket sourceWB;
Workbasket destinationWB;
WorkbasketImpl wb;
@ -440,7 +446,8 @@ public class TaskServiceImplIntExplicitTest {
@Test
public void shouldNotTransferByFailingSecurity() throws WorkbasketNotFoundException,
ClassificationNotFoundException, NotAuthorizedException, ClassificationAlreadyExistException, SQLException,
TaskNotFoundException, TaskAlreadyExistException, InvalidWorkbasketException, InvalidArgumentException {
TaskNotFoundException, TaskAlreadyExistException, InvalidWorkbasketException, InvalidArgumentException,
WorkbasketAlreadyExistException {
final String user = "User";
// Set up Security for this Test
@ -523,7 +530,8 @@ public class TaskServiceImplIntExplicitTest {
}
private Task generateDummyTask() throws ClassificationAlreadyExistException, ClassificationNotFoundException,
WorkbasketNotFoundException, InvalidWorkbasketException, NotAuthorizedException {
WorkbasketNotFoundException, InvalidWorkbasketException, NotAuthorizedException,
WorkbasketAlreadyExistException {
WorkbasketImpl workbasket = (WorkbasketImpl) workbasketService.newWorkbasket("wb", "novatec");
workbasket.setName("wb");
workbasket.setId("1"); // set id manually for authorization tests

View File

@ -34,6 +34,7 @@ import pro.taskana.configuration.TaskanaEngineConfiguration;
import pro.taskana.exceptions.InvalidArgumentException;
import pro.taskana.exceptions.InvalidWorkbasketException;
import pro.taskana.exceptions.NotAuthorizedException;
import pro.taskana.exceptions.WorkbasketAlreadyExistException;
import pro.taskana.exceptions.WorkbasketNotFoundException;
import pro.taskana.impl.TaskanaEngineImpl;
import pro.taskana.impl.TaskanaEngineProxyForTest;
@ -88,7 +89,7 @@ public class WorkbasketServiceImplIntAutocommitTest {
@Test
public void testSelectWorkbasket()
throws WorkbasketNotFoundException, NotAuthorizedException, InvalidWorkbasketException,
InvalidArgumentException {
InvalidArgumentException, WorkbasketAlreadyExistException {
String id = IdGenerator.generateWithPrefix("TWB");
Workbasket workbasket = createTestWorkbasket(id, "key0", "novatec", "Superbasket", WorkbasketType.GROUP);
workbasket = workBasketService.createWorkbasket(workbasket);
@ -107,7 +108,7 @@ public class WorkbasketServiceImplIntAutocommitTest {
@Test
public void testSelectWorkbasketWithDistribution()
throws WorkbasketNotFoundException, NotAuthorizedException, InvalidWorkbasketException,
InvalidArgumentException {
InvalidArgumentException, WorkbasketAlreadyExistException {
String id = IdGenerator.generateWithPrefix("TWB");
Workbasket wbDist1 = createTestWorkbasket(id, "key0", "novatec", "Superbasket", WorkbasketType.GROUP);
wbDist1 = workBasketService.createWorkbasket(wbDist1);

View File

@ -28,6 +28,7 @@ import pro.taskana.configuration.TaskanaEngineConfiguration;
import pro.taskana.exceptions.InvalidArgumentException;
import pro.taskana.exceptions.InvalidWorkbasketException;
import pro.taskana.exceptions.NotAuthorizedException;
import pro.taskana.exceptions.WorkbasketAlreadyExistException;
import pro.taskana.exceptions.WorkbasketNotFoundException;
import pro.taskana.impl.TaskanaEngineImpl;
import pro.taskana.impl.WorkbasketImpl;
@ -75,7 +76,7 @@ public class WorkbasketServiceImplIntExplicitTest {
@Test
public void testSelectWorkbasket()
throws WorkbasketNotFoundException, NotAuthorizedException, SQLException, InvalidWorkbasketException,
InvalidArgumentException {
InvalidArgumentException, WorkbasketAlreadyExistException {
Connection connection = dataSource.getConnection();
taskanaEngineImpl.setConnection(connection);
workBasketService = taskanaEngine.getWorkbasketService();
@ -96,7 +97,7 @@ public class WorkbasketServiceImplIntExplicitTest {
@Test(expected = NotAuthorizedException.class)
public void testGetWorkbasketFail()
throws WorkbasketNotFoundException, SQLException, InvalidWorkbasketException, NotAuthorizedException,
InvalidArgumentException {
InvalidArgumentException, WorkbasketAlreadyExistException {
Connection connection = dataSource.getConnection();
taskanaEngineImpl.setConnection(connection);
workBasketService = taskanaEngine.getWorkbasketService();
@ -113,7 +114,7 @@ public class WorkbasketServiceImplIntExplicitTest {
@Test
public void testSelectWorkbasketWithDistribution()
throws WorkbasketNotFoundException, NotAuthorizedException, SQLException, InvalidWorkbasketException,
InvalidArgumentException {
InvalidArgumentException, WorkbasketAlreadyExistException {
Connection connection = dataSource.getConnection();
taskanaEngineImpl.setConnection(connection);
workBasketService = taskanaEngine.getWorkbasketService();

View File

@ -13,6 +13,7 @@ import pro.taskana.Workbasket;
import pro.taskana.WorkbasketType;
import pro.taskana.exceptions.InvalidWorkbasketException;
import pro.taskana.exceptions.NotAuthorizedException;
import pro.taskana.exceptions.WorkbasketAlreadyExistException;
import pro.taskana.exceptions.WorkbasketNotFoundException;
import pro.taskana.impl.WorkbasketImpl;
import pro.taskana.impl.util.IdGenerator;
@ -52,7 +53,8 @@ public class TaskanaTestController {
@Transactional(rollbackFor = Exception.class)
@RequestMapping("/transaction")
public @ResponseBody String transaction(@RequestParam(value = "rollback", defaultValue = "false") String rollback)
throws WorkbasketNotFoundException, InvalidWorkbasketException, NotAuthorizedException {
throws WorkbasketNotFoundException, InvalidWorkbasketException, NotAuthorizedException,
WorkbasketAlreadyExistException {
taskanaEngine.getWorkbasketService().createWorkbasket(createWorkBasket("key", "workbasket"));
int workbaskets = getWorkbaskets();
@ -67,7 +69,8 @@ public class TaskanaTestController {
@RequestMapping("/transaction-many")
public @ResponseBody String transactionMany(
@RequestParam(value = "rollback", defaultValue = "false") String rollback)
throws WorkbasketNotFoundException, InvalidWorkbasketException, NotAuthorizedException {
throws WorkbasketNotFoundException, InvalidWorkbasketException, NotAuthorizedException,
WorkbasketAlreadyExistException {
taskanaEngine.getWorkbasketService().createWorkbasket(createWorkBasket("key1", "workbasket1"));
taskanaEngine.getWorkbasketService().createWorkbasket(createWorkBasket("key2", "workbasket2"));
taskanaEngine.getWorkbasketService().createWorkbasket(createWorkBasket("key3", "workbasket3"));
@ -83,7 +86,8 @@ public class TaskanaTestController {
@RequestMapping("/geschbuch")
public @ResponseBody String transactionGeschbuch(
@RequestParam(value = "rollback", defaultValue = "false") String rollback)
throws WorkbasketNotFoundException, InvalidWorkbasketException, NotAuthorizedException {
throws WorkbasketNotFoundException, InvalidWorkbasketException, NotAuthorizedException,
WorkbasketAlreadyExistException {
taskanaEngine.getWorkbasketService().createWorkbasket(createWorkBasket("key1", "workbasket1"));
taskanaEngine.getWorkbasketService().createWorkbasket(createWorkBasket("key2", "workbasket2"));

View File

@ -34,6 +34,7 @@ import pro.taskana.WorkbasketType;
import pro.taskana.exceptions.InvalidArgumentException;
import pro.taskana.exceptions.InvalidWorkbasketException;
import pro.taskana.exceptions.NotAuthorizedException;
import pro.taskana.exceptions.WorkbasketAlreadyExistException;
import pro.taskana.exceptions.WorkbasketInUseException;
import pro.taskana.exceptions.WorkbasketNotFoundException;
import pro.taskana.rest.resource.DistributionTargetResource;
@ -104,6 +105,7 @@ public class WorkbasketController {
.toResource(workbasketSummaries);
return new ResponseEntity<>(workbasketListResource, HttpStatus.OK);
} catch (InvalidArgumentException ex) {
TransactionInterceptor.currentTransactionStatus().setRollbackOnly();
return new ResponseEntity<>(HttpStatus.PRECONDITION_FAILED);
}
}
@ -149,8 +151,7 @@ public class WorkbasketController {
@PostMapping
@Transactional(rollbackFor = Exception.class)
public ResponseEntity<WorkbasketResource> createWorkbasket(@RequestBody WorkbasketResource workbasketResource)
throws NotAuthorizedException {
public ResponseEntity<WorkbasketResource> createWorkbasket(@RequestBody WorkbasketResource workbasketResource) {
try {
Workbasket workbasket = workbasketMapper.toModel(workbasketResource);
workbasket = workbasketService.createWorkbasket(workbasket);
@ -158,6 +159,12 @@ public class WorkbasketController {
} catch (InvalidWorkbasketException e) {
TransactionInterceptor.currentTransactionStatus().setRollbackOnly();
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
} catch (WorkbasketAlreadyExistException e) {
TransactionInterceptor.currentTransactionStatus().setRollbackOnly();
return new ResponseEntity<>(HttpStatus.CONFLICT);
} catch (NotAuthorizedException e) {
TransactionInterceptor.currentTransactionStatus().setRollbackOnly();
return new ResponseEntity<>(HttpStatus.UNAUTHORIZED);
}
}
@ -219,6 +226,7 @@ public class WorkbasketController {
workbasketAccessItem = workbasketService.createWorkbasketAccessItem(workbasketAccessItem);
return new ResponseEntity<>(workbasketAccessItemMapper.toResource(workbasketAccessItem), HttpStatus.OK);
} catch (InvalidArgumentException e) {
TransactionInterceptor.currentTransactionStatus().setRollbackOnly();
return new ResponseEntity<>(HttpStatus.PRECONDITION_FAILED);
}
}
@ -234,6 +242,7 @@ public class WorkbasketController {
workbasketAccessItem = workbasketService.updateWorkbasketAccessItem(workbasketAccessItem);
return new ResponseEntity<>(workbasketAccessItemMapper.toResource(workbasketAccessItem), HttpStatus.OK);
} catch (InvalidArgumentException | NotAuthorizedException e) {
TransactionInterceptor.currentTransactionStatus().setRollbackOnly();
return new ResponseEntity<>(HttpStatus.PRECONDITION_FAILED);
}
}
@ -256,6 +265,7 @@ public class WorkbasketController {
}
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
} catch (InvalidArgumentException | NullPointerException e) {
TransactionInterceptor.currentTransactionStatus().setRollbackOnly();
return new ResponseEntity<>(HttpStatus.PRECONDITION_FAILED);
}
}
@ -280,8 +290,10 @@ public class WorkbasketController {
.toResource(workbasketId, distributionTargets);
result = new ResponseEntity<>(distributionTargetListResource, HttpStatus.OK);
} catch (WorkbasketNotFoundException e) {
TransactionInterceptor.currentTransactionStatus().setRollbackOnly();
result = new ResponseEntity<>(HttpStatus.NOT_FOUND);
} catch (NotAuthorizedException e) {
TransactionInterceptor.currentTransactionStatus().setRollbackOnly();
result = new ResponseEntity<>(HttpStatus.UNAUTHORIZED);
}
return result;
@ -297,8 +309,10 @@ public class WorkbasketController {
workbasketService.setDistributionTargets(sourceWorkbasketId, targetWorkbasketIds);
result = ResponseEntity.status(HttpStatus.NO_CONTENT).build();
} catch (WorkbasketNotFoundException e) {
TransactionInterceptor.currentTransactionStatus().setRollbackOnly();
result = ResponseEntity.status(HttpStatus.NOT_FOUND).build();
} catch (NotAuthorizedException e) {
TransactionInterceptor.currentTransactionStatus().setRollbackOnly();
result = ResponseEntity.status(HttpStatus.UNAUTHORIZED).build();
}
return result;

View File

@ -26,6 +26,7 @@ import pro.taskana.WorkbasketSummary;
import pro.taskana.exceptions.InvalidArgumentException;
import pro.taskana.exceptions.InvalidWorkbasketException;
import pro.taskana.exceptions.NotAuthorizedException;
import pro.taskana.exceptions.WorkbasketAlreadyExistException;
import pro.taskana.exceptions.WorkbasketNotFoundException;
import pro.taskana.rest.resource.WorkbasketAccessItemResource;
import pro.taskana.rest.resource.WorkbasketDefinition;
@ -155,6 +156,9 @@ public class WorkbasketDefinitionController {
} catch (InvalidArgumentException e) {
TransactionInterceptor.currentTransactionStatus().setRollbackOnly();
return new ResponseEntity<>(HttpStatus.PRECONDITION_FAILED);
} catch (WorkbasketAlreadyExistException e) {
TransactionInterceptor.currentTransactionStatus().setRollbackOnly();
return new ResponseEntity<>(HttpStatus.CONFLICT);
}
}