use of pro.taskana.exceptions.InvalidStateException in project taskana by Taskana.
the class TaskServiceImplTest method testCompleteTaskNotForcedNotClaimedBefore.
@Test(expected = InvalidStateException.class)
public void testCompleteTaskNotForcedNotClaimedBefore() throws TaskNotFoundException, InvalidStateException, InvalidOwnerException, ClassificationNotFoundException, NotAuthorizedException {
final boolean isForced = false;
TaskServiceImpl cutSpy = Mockito.spy(cut);
Classification dummyClassification = createDummyClassification();
TaskImpl task = createUnitTestTask("1", "Unit Test Task 1", "1", dummyClassification);
task.setState(TaskState.READY);
task.setClaimed(null);
doReturn(task).when(cutSpy).getTask(task.getId());
try {
cutSpy.completeTask(task.getId(), isForced);
} catch (InvalidStateException e) {
verify(taskanaEngineMock, times(1)).openConnection();
verify(cutSpy, times(1)).getTask(task.getId());
verify(taskanaEngineMock, times(1)).returnConnection();
verifyNoMoreInteractions(attachmentMapperMock, taskanaEngineConfigurationMock, taskanaEngineMock, taskMapperMock, objectReferenceMapperMock, workbasketServiceMock, sqlSessionMock, classificationQueryImplMock);
throw e;
}
}
use of pro.taskana.exceptions.InvalidStateException in project taskana by Taskana.
the class DeleteTaskAccTest method testForceDeleteTaskIfNotCompleted.
@WithAccessId(userName = "user_1_2", groupNames = { "group_1", "admin" })
@Test(expected = TaskNotFoundException.class)
public void testForceDeleteTaskIfNotCompleted() throws SQLException, TaskNotFoundException, InvalidStateException, NotAuthorizedException {
TaskService taskService = taskanaEngine.getTaskService();
Task task = taskService.getTask("TKI:000000000000000000000000000000000027");
try {
taskService.deleteTask(task.getId());
fail("Should not be possible to delete claimed task without force flag");
} catch (InvalidStateException ex) {
taskService.deleteTask(task.getId(), true);
}
taskService.getTask("TKI:000000000000000000000000000000000027");
}
use of pro.taskana.exceptions.InvalidStateException in project taskana by Taskana.
the class TaskServiceImpl method cancelClaim.
@Override
public Task cancelClaim(String taskId, boolean forceUnclaim) throws TaskNotFoundException, InvalidStateException, InvalidOwnerException, NotAuthorizedException {
String userId = CurrentUserContext.getUserid();
LOGGER.debug("entry to cancelClaim(taskId = {}) with userId = {}, forceFlag = {}", taskId, userId, forceUnclaim);
TaskImpl task = null;
try {
taskanaEngine.openConnection();
task = (TaskImpl) getTask(taskId);
TaskState state = task.getState();
if (state == TaskState.COMPLETED) {
LOGGER.warn("Method cancelClaim() found that task {} is already completed. Throwing InvalidStateException", taskId);
throw new InvalidStateException("Task is already completed");
}
if (state == TaskState.CLAIMED && !forceUnclaim && !userId.equals(task.getOwner())) {
LOGGER.warn("Method cancelClaim() found that task {} is claimed by {} and forceClaim is false. Throwing InvalidOwnerException", taskId, task.getOwner());
throw new InvalidOwnerException("Task is already claimed by an other user = " + task.getOwner());
}
Instant now = Instant.now();
task.setOwner(null);
task.setModified(now);
task.setClaimed(null);
task.setRead(true);
task.setState(TaskState.READY);
taskMapper.update(task);
LOGGER.debug("Method cancelClaim() unclaimed task '{}' for user '{}'.", taskId, userId);
} finally {
taskanaEngine.returnConnection();
LOGGER.debug("exit from cancelClaim(taskId = {}) with userId = {}, forceFlag = {}", taskId, userId, forceUnclaim);
}
return task;
}
use of pro.taskana.exceptions.InvalidStateException in project taskana by Taskana.
the class TaskServiceImpl method claim.
@Override
public Task claim(String taskId, boolean forceClaim) throws TaskNotFoundException, InvalidStateException, InvalidOwnerException, NotAuthorizedException {
String userId = CurrentUserContext.getUserid();
LOGGER.debug("entry to claim(id = {}, forceClaim = {}, userId = {})", taskId, forceClaim, userId);
TaskImpl task = null;
try {
taskanaEngine.openConnection();
task = (TaskImpl) getTask(taskId);
TaskState state = task.getState();
if (state == TaskState.COMPLETED) {
LOGGER.warn("Method claim() found that task {} is already completed. Throwing InvalidStateException", taskId);
throw new InvalidStateException("Task is already completed");
}
if (state == TaskState.CLAIMED && !forceClaim && !task.getOwner().equals(userId)) {
LOGGER.warn("Method claim() found that task {} is claimed by {} and forceClaim is false. Throwing InvalidOwnerException", taskId, task.getOwner());
throw new InvalidOwnerException("You´re not the owner of this task and it is already claimed by other user " + task.getOwner());
}
Instant now = Instant.now();
task.setOwner(userId);
task.setModified(now);
task.setClaimed(now);
task.setRead(true);
task.setState(TaskState.CLAIMED);
taskMapper.update(task);
LOGGER.debug("Method claim() claimed task '{}' for user '{}'.", taskId, userId);
} finally {
taskanaEngine.returnConnection();
LOGGER.debug("exit from claim()");
}
return task;
}
use of pro.taskana.exceptions.InvalidStateException in project taskana by Taskana.
the class TaskServiceImpl method deleteTasks.
@Override
public BulkOperationResults<String, TaskanaException> deleteTasks(List<String> taskIds) throws InvalidArgumentException {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("entry to deleteTasks(tasks = {})", LoggerUtils.listToString(taskIds));
}
try {
taskanaEngine.openConnection();
if (taskIds == null) {
throw new InvalidArgumentException("TaskIds can´t be NULL as parameter for deleteTasks().");
}
BulkOperationResults<String, TaskanaException> bulkLog = new BulkOperationResults<>();
List<MinimalTaskSummary> taskSummaries = taskMapper.findExistingTasks(taskIds);
Iterator<String> taskIdIterator = taskIds.iterator();
while (taskIdIterator.hasNext()) {
String currentTaskId = taskIdIterator.next();
if (currentTaskId == null || currentTaskId.equals("")) {
bulkLog.addError("", new InvalidArgumentException("IDs with EMPTY or NULL value are not allowed."));
taskIdIterator.remove();
} else {
MinimalTaskSummary foundSummary = taskSummaries.stream().filter(taskState -> currentTaskId.equals(taskState.getTaskId())).findFirst().orElse(null);
if (foundSummary == null) {
bulkLog.addError(currentTaskId, new TaskNotFoundException(currentTaskId, "Task with id " + currentTaskId + " was not found."));
taskIdIterator.remove();
} else {
if (!TaskState.COMPLETED.equals(foundSummary.getTaskState())) {
bulkLog.addError(currentTaskId, new InvalidStateException(currentTaskId));
taskIdIterator.remove();
}
}
}
}
if (!taskIds.isEmpty()) {
taskMapper.deleteMultiple(taskIds);
}
return bulkLog;
} finally {
LOGGER.debug("exit from deleteTasks()");
taskanaEngine.returnConnection();
}
}
Aggregations