TSK-1150 Comments from Bernd Breier

This commit is contained in:
Jörg Heffner 2020-03-12 14:04:37 +01:00
parent 3b7da72d24
commit 7d464bd6cd
16 changed files with 208 additions and 218 deletions

View File

@ -43,7 +43,7 @@ import pro.taskana.common.internal.configuration.DbSchemaCreator;
public class TaskanaEngineConfiguration {
protected static final String TASKANA_SCHEMA_VERSION =
"2.0.1"; // must match the VERSION value in table
"2.0.2"; // must match the VERSION value in table
private static final Logger LOGGER = LoggerFactory.getLogger(TaskanaEngineConfiguration.class);
private static final String USER_NAME = "sa";
private static final String USER_PASSWORD = "sa";

View File

@ -15,14 +15,12 @@ import pro.taskana.task.api.exceptions.AttachmentPersistenceException;
import pro.taskana.task.api.exceptions.InvalidOwnerException;
import pro.taskana.task.api.exceptions.InvalidStateException;
import pro.taskana.task.api.exceptions.TaskAlreadyExistException;
import pro.taskana.task.api.exceptions.TaskCommentAlreadyExistException;
import pro.taskana.task.api.exceptions.TaskCommentNotFoundException;
import pro.taskana.task.api.exceptions.TaskNotFoundException;
import pro.taskana.task.api.models.Attachment;
import pro.taskana.task.api.models.ObjectReference;
import pro.taskana.task.api.models.Task;
import pro.taskana.task.api.models.TaskComment;
import pro.taskana.task.internal.models.TaskCommentImpl;
import pro.taskana.workbasket.api.exceptions.WorkbasketNotFoundException;
/** The Task Service manages all operations on tasks. */
@ -234,6 +232,14 @@ public interface TaskService {
*/
Task newTask(String workbasketKey, String domain);
/**
* Returns a not persisted instance of {@link TaskComment}.
*
* @param taskId The id of the task to which the task comment belongs
* @return an empty new TaskComment
*/
TaskComment newTaskComment(String taskId);
/**
* Returns a not persisted instance of {@link Attachment}.
*
@ -376,13 +382,14 @@ public interface TaskService {
* @param taskComment the task comment to be created.
* @return the created task comment.
* @throws NotAuthorizedException If the current user has no authorization to create a task
* comment for the given taskId in the TaskComment.
* @throws TaskCommentAlreadyExistException If the task comment already exists.
* comment for the given taskId in the TaskComment or is not authorized to access the task.
* @throws TaskNotFoundException If the given taskId in the TaskComment does not refer to an
* existing task.
* @throws InvalidArgumentException If the given taskCommentId from the provided task comment is
* not null or empty
*/
TaskComment createTaskComment(TaskComment taskComment)
throws NotAuthorizedException, TaskCommentAlreadyExistException, TaskNotFoundException;
throws NotAuthorizedException, TaskNotFoundException, InvalidArgumentException;
/**
* Update a task comment.
@ -390,29 +397,32 @@ public interface TaskService {
* @param taskComment the task comment to be updated in the database.
* @return the updated task comment.
* @throws NotAuthorizedException If the current user has no authorization to update a task
* comment.
* comment or is not authorized to access the task.
* @throws ConcurrencyException if an attempt is made to update the task comment and another user.
* updated it already.
* @throws TaskCommentNotFoundException If the given taskCommentId in the TaskComment does not
* refer to an existing taskComment.
* @throws TaskNotFoundException If the given taskId in the TaskComment does not refer to an
* existing task.
* @throws InvalidArgumentException If the given taskCommentId from the provided task comment is
* null or empty
*/
TaskComment updateTaskComment(TaskComment taskComment)
throws NotAuthorizedException, ConcurrencyException, TaskCommentNotFoundException,
TaskNotFoundException;
TaskNotFoundException, InvalidArgumentException;
/**
* Deletes the task comment with the given Id.
*
* @param taskCommentId The id of the task comment to delete.
* @throws NotAuthorizedException If the current user has no authorization to delete a task
* comment
* comment or is not authorized to access the task.
* @throws InvalidArgumentException If the taskCommentId is null/empty
* @throws TaskCommentNotFoundException If the given taskCommentId in the TaskComment does not
* refer to an existing taskComment.
* @throws TaskNotFoundException If the given taskId in the TaskComment does not refer to an
* existing task.
* @throws InvalidArgumentException If the given taskCommentId is null or empty
*/
void deleteTaskComment(String taskCommentId)
throws NotAuthorizedException, TaskCommentNotFoundException, TaskNotFoundException,
@ -424,22 +434,27 @@ public interface TaskService {
* @param taskCommentId The id of the task comment which should be retrieved
* @throws TaskCommentNotFoundException If the given taskCommentId in the TaskComment does not
* refer to an existing taskComment.
* @throws NotAuthorizedException If the current user has no authorization to retrieve a
* taskComment from a certain task or is not authorized to access the task.
* @throws TaskNotFoundException If the given taskId in the TaskComment does not refer to an
* existing task.
* @throws InvalidArgumentException If the given taskCommentId is null or empty
*/
TaskComment getTaskComment(String taskCommentId) throws TaskCommentNotFoundException;
TaskComment getTaskComment(String taskCommentId)
throws TaskCommentNotFoundException, NotAuthorizedException, TaskNotFoundException,
InvalidArgumentException;
/**
* Retrieves a list of task comments for a given taskId.
*
* @param taskId The id of the task for which all task comments should be retrieved
* @throws TaskCommentNotFoundException If the given taskCommentId in the TaskComment does not
* refer to an existing taskComment.
* @throws NotAuthorizedException If the current user has no authorization to retrieve a
* taskComment from a certain task
* taskComment from a certain task or is not authorized to access the task.
* @throws TaskNotFoundException If the given taskId in the TaskComment does not refer to an
* existing task.
*/
List<TaskCommentImpl> getTaskComments(String taskId)
throws TaskCommentNotFoundException, NotAuthorizedException, TaskNotFoundException;
List<TaskComment> getTaskComments(String taskId)
throws NotAuthorizedException, TaskNotFoundException;
/**
* Sets the callback state on a list of tasks. Note: this method is primarily intended to be used

View File

@ -1,17 +0,0 @@
package pro.taskana.task.api.exceptions;
import pro.taskana.common.api.exceptions.TaskanaException;
/**
* Thrown when a TaskComment is going to be created, but a TaskComment with
* the same ID does already exist. The TaskComment ID should be unique.
*/
public class TaskCommentAlreadyExistException extends TaskanaException {
private static final long serialVersionUID = 1L;
public TaskCommentAlreadyExistException(String id) {
super(id);
}
}

View File

@ -33,6 +33,12 @@ public interface TaskComment {
*/
String getTextField();
/**
* Sets the text field of the task comment.
*
*/
void setTextField(String textField);
/**
* Gets the time when the task comment was created.
*
@ -47,4 +53,6 @@ public interface TaskComment {
*/
Instant getModified();
}

View File

@ -2,9 +2,11 @@ package pro.taskana.task.internal;
import java.time.Instant;
import java.util.List;
import java.util.stream.Collectors;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import pro.taskana.common.api.TaskanaRole;
import pro.taskana.common.api.exceptions.ConcurrencyException;
import pro.taskana.common.api.exceptions.InvalidArgumentException;
import pro.taskana.common.api.exceptions.NotAuthorizedException;
@ -12,7 +14,6 @@ import pro.taskana.common.api.exceptions.SystemException;
import pro.taskana.common.internal.InternalTaskanaEngine;
import pro.taskana.common.internal.security.CurrentUserContext;
import pro.taskana.common.internal.util.IdGenerator;
import pro.taskana.task.api.exceptions.TaskCommentAlreadyExistException;
import pro.taskana.task.api.exceptions.TaskCommentNotFoundException;
import pro.taskana.task.api.exceptions.TaskNotFoundException;
import pro.taskana.task.api.models.TaskComment;
@ -40,9 +41,21 @@ class TaskCommentServiceImpl {
this.taskCommentMapper = taskCommentMapper;
}
TaskComment newTaskComment(String taskId) {
LOGGER.debug("entry to newTaskComment (taskId = {})", taskId);
TaskCommentImpl taskComment = new TaskCommentImpl();
taskComment.setTaskId(taskId);
LOGGER.debug("exit from newTaskComment(), returning {}", taskComment);
return taskComment;
}
TaskComment updateTaskComment(TaskComment taskCommentToUpdate)
throws NotAuthorizedException, ConcurrencyException, TaskCommentNotFoundException,
TaskNotFoundException {
TaskNotFoundException, InvalidArgumentException {
LOGGER.debug("entry to updateTaskComment (taskComment = {})", taskCommentToUpdate);
@ -56,9 +69,10 @@ class TaskCommentServiceImpl {
taskService.getTask(taskCommentImplToUpdate.getTaskId());
if (taskCommentToUpdate.getCreator().equals(userId)) {
if (taskCommentToUpdate.getCreator().equals(userId)
|| taskanaEngine.getEngine().isUserInRole(TaskanaRole.ADMIN)) {
TaskCommentImpl oldTaskComment = getTaskComment(taskCommentImplToUpdate.getId());
TaskComment oldTaskComment = getTaskComment(taskCommentImplToUpdate.getId());
checkModifiedHasNotChanged(oldTaskComment, taskCommentImplToUpdate);
@ -81,11 +95,11 @@ class TaskCommentServiceImpl {
LOGGER.debug("exit from updateTaskComment()");
}
return taskCommentToUpdate;
return taskCommentImplToUpdate;
}
TaskComment createTaskComment(TaskComment taskCommentToCreate)
throws NotAuthorizedException, TaskCommentAlreadyExistException, TaskNotFoundException {
throws NotAuthorizedException, TaskNotFoundException, InvalidArgumentException {
LOGGER.debug("entry to setTaskComment (taskCommentToCreate = {})", taskCommentToCreate);
@ -97,9 +111,7 @@ class TaskCommentServiceImpl {
taskService.getTask(taskCommentImplToCreate.getTaskId());
if (isTaskCommentAlreadyExisting(taskCommentImplToCreate.getId())) {
throw new TaskCommentAlreadyExistException(taskCommentImplToCreate.getId());
}
validateNoneExistingTaskCommentId(taskCommentImplToCreate.getId());
initDefaultTaskCommentValues(taskCommentImplToCreate);
@ -112,7 +124,7 @@ class TaskCommentServiceImpl {
LOGGER.debug("exit from setTaskComment()");
}
return taskCommentToCreate;
return taskCommentImplToCreate;
}
void deleteTaskComment(String taskCommentId)
@ -123,24 +135,14 @@ class TaskCommentServiceImpl {
String userId = CurrentUserContext.getUserid();
validateTaskCommentId(taskCommentId);
try {
taskanaEngine.openConnection();
TaskComment taskCommentToDelete = getTaskComment(taskCommentId);
if (taskCommentToDelete != null) {
taskService.getTask(taskCommentToDelete.getTaskId());
} else {
throw new TaskCommentNotFoundException(
taskCommentId, String.format("The TaskComment with ID %s wasn't found", taskCommentId));
}
if (taskCommentToDelete.getCreator().equals(userId)) {
if (taskCommentToDelete.getCreator().equals(userId)
|| taskanaEngine.getEngine().isUserInRole(TaskanaRole.ADMIN)) {
taskCommentMapper.delete(taskCommentId);
@ -158,27 +160,25 @@ class TaskCommentServiceImpl {
}
}
List<TaskCommentImpl> getTaskComments(String taskId)
throws TaskCommentNotFoundException, NotAuthorizedException, TaskNotFoundException {
List<TaskComment> getTaskComments(String taskId)
throws NotAuthorizedException, TaskNotFoundException {
LOGGER.debug("entry to getTaskComments (taskId = {})", taskId);
List<TaskCommentImpl> result = null;
try {
taskanaEngine.openConnection();
taskService.getTask(taskId);
result = taskCommentMapper.findByTaskId(taskId);
List<TaskComment> taskComments =
taskCommentMapper.findByTaskId(taskId).stream().collect(Collectors.toList());
if (result == null || result.isEmpty()) {
throw new TaskCommentNotFoundException(
taskId, "TaskComments for TaskId " + taskId + " were not found");
if (taskComments.isEmpty()) {
LOGGER.debug("getTaskComments() found no comments for the provided taskId");
}
return result;
return taskComments;
} finally {
@ -188,12 +188,16 @@ class TaskCommentServiceImpl {
}
}
TaskCommentImpl getTaskComment(String taskCommentId) throws TaskCommentNotFoundException {
TaskComment getTaskComment(String taskCommentId)
throws TaskCommentNotFoundException, NotAuthorizedException, TaskNotFoundException,
InvalidArgumentException {
LOGGER.debug("entry to getTaskComment (taskCommentId = {})", taskCommentId);
TaskCommentImpl result = null;
verifyTaskCommentIdIsNotNullOrEmpty(taskCommentId);
try {
taskanaEngine.openConnection();
@ -205,6 +209,8 @@ class TaskCommentServiceImpl {
taskCommentId, "TaskComment for id " + taskCommentId + " was not found");
}
taskService.getTask(result.getTaskId());
return result;
} finally {
@ -216,8 +222,7 @@ class TaskCommentServiceImpl {
}
private void checkModifiedHasNotChanged(
TaskCommentImpl oldTaskComment, TaskCommentImpl taskCommentImplToUpdate)
throws ConcurrencyException {
TaskComment oldTaskComment, TaskComment taskCommentImplToUpdate) throws ConcurrencyException {
if (!oldTaskComment.getModified().equals(taskCommentImplToUpdate.getModified())) {
@ -232,17 +237,9 @@ class TaskCommentServiceImpl {
Instant now = Instant.now();
if (taskCommentImplToCreate.getId() == null || "".equals(taskCommentImplToCreate.getId())) {
taskCommentImplToCreate.setId(IdGenerator.generateWithPrefix(ID_PREFIX_TASK_COMMENT));
}
if (taskCommentImplToCreate.getModified() == null) {
taskCommentImplToCreate.setModified(now);
}
if (taskCommentImplToCreate.getCreated() == null) {
taskCommentImplToCreate.setCreated(now);
}
taskCommentImplToCreate.setId(IdGenerator.generateWithPrefix(ID_PREFIX_TASK_COMMENT));
taskCommentImplToCreate.setModified(now);
taskCommentImplToCreate.setCreated(now);
String creator = CurrentUserContext.getUserid();
if (taskanaEngine.getEngine().getConfiguration().isSecurityEnabled() && creator == null) {
@ -253,27 +250,22 @@ class TaskCommentServiceImpl {
taskCommentImplToCreate.setCreator(creator);
}
private boolean isTaskCommentAlreadyExisting(String taskCommentId) {
private void validateNoneExistingTaskCommentId(String taskCommentId)
throws InvalidArgumentException {
boolean isExisting = false;
try {
if (getTaskComment(taskCommentId) != null) {
isExisting = true;
}
} catch (Exception ex) {
LOGGER.warn(
"TaskComment-Service threw Exception while calling "
+ "mapper and searching for TaskComment.",
ex);
if (taskCommentId != null && !taskCommentId.equals("")) {
throw new InvalidArgumentException(
String.format(
"taskCommentId must be null/empty for creation, but found %s", taskCommentId));
}
return isExisting;
}
private void validateTaskCommentId(String taskCommentId) throws InvalidArgumentException {
private void verifyTaskCommentIdIsNotNullOrEmpty(String taskCommentId)
throws InvalidArgumentException {
if (taskCommentId == null || taskCommentId.isEmpty()) {
throw new InvalidArgumentException("TaskId must not be null/empty for deletion");
throw new InvalidArgumentException(
"taskCommentId must not be null/empty for retrieval/deletion");
}
}
}

View File

@ -47,7 +47,6 @@ import pro.taskana.task.api.exceptions.AttachmentPersistenceException;
import pro.taskana.task.api.exceptions.InvalidOwnerException;
import pro.taskana.task.api.exceptions.InvalidStateException;
import pro.taskana.task.api.exceptions.TaskAlreadyExistException;
import pro.taskana.task.api.exceptions.TaskCommentAlreadyExistException;
import pro.taskana.task.api.exceptions.TaskCommentNotFoundException;
import pro.taskana.task.api.exceptions.TaskNotFoundException;
import pro.taskana.task.api.exceptions.UpdateFailedException;
@ -59,7 +58,6 @@ import pro.taskana.task.api.models.TaskSummary;
import pro.taskana.task.internal.models.AttachmentImpl;
import pro.taskana.task.internal.models.AttachmentSummaryImpl;
import pro.taskana.task.internal.models.MinimalTaskSummary;
import pro.taskana.task.internal.models.TaskCommentImpl;
import pro.taskana.task.internal.models.TaskImpl;
import pro.taskana.task.internal.models.TaskSummaryImpl;
import pro.taskana.workbasket.api.WorkbasketPermission;
@ -398,6 +396,11 @@ public class TaskServiceImpl implements TaskService {
return task;
}
@Override
public TaskComment newTaskComment(String taskId) {
return taskCommentService.newTaskComment(taskId);
}
@Override
public Attachment newAttachment() {
return new AttachmentImpl();
@ -602,14 +605,14 @@ public class TaskServiceImpl implements TaskService {
@Override
public TaskComment createTaskComment(TaskComment taskComment)
throws NotAuthorizedException, TaskCommentAlreadyExistException, TaskNotFoundException {
throws NotAuthorizedException, TaskNotFoundException, InvalidArgumentException {
return taskCommentService.createTaskComment(taskComment);
}
@Override
public TaskComment updateTaskComment(TaskComment taskComment)
throws NotAuthorizedException, ConcurrencyException, TaskCommentNotFoundException,
TaskNotFoundException {
TaskNotFoundException, InvalidArgumentException {
return taskCommentService.updateTaskComment(taskComment);
}
@ -621,13 +624,15 @@ public class TaskServiceImpl implements TaskService {
}
@Override
public TaskComment getTaskComment(String taskCommentid) throws TaskCommentNotFoundException {
public TaskComment getTaskComment(String taskCommentid)
throws TaskCommentNotFoundException, NotAuthorizedException, TaskNotFoundException,
InvalidArgumentException {
return taskCommentService.getTaskComment(taskCommentid);
}
@Override
public List<TaskCommentImpl> getTaskComments(String taskId)
throws TaskCommentNotFoundException, NotAuthorizedException, TaskNotFoundException {
public List<TaskComment> getTaskComments(String taskId)
throws NotAuthorizedException, TaskNotFoundException {
return taskCommentService.getTaskComments(taskId);
}

View File

@ -7,7 +7,7 @@ CREATE TABLE TASKANA_SCHEMA_VERSION(
PRIMARY KEY (ID)
);
-- The VERSION value must match the value of TaskanaEngineConfiguration.TASKANA_SCHEMA_VERSION
INSERT INTO TASKANA_SCHEMA_VERSION (VERSION, CREATED) VALUES ('2.0.1', CURRENT_TIMESTAMP);
INSERT INTO TASKANA_SCHEMA_VERSION (VERSION, CREATED) VALUES ('2.0.2', CURRENT_TIMESTAMP);
CREATE TABLE CLASSIFICATION(
ID CHAR(40) NOT NULL,

View File

@ -9,7 +9,7 @@ CREATE TABLE TASKANA_SCHEMA_VERSION(
PRIMARY KEY (ID)
);
-- The VERSION value must match the value of TaskanaEngineConfiguration.TASKANA_SCHEMA_VERSION
INSERT INTO TASKANA_SCHEMA_VERSION (VERSION, CREATED) VALUES ('2.0.1', CURRENT_TIMESTAMP);
INSERT INTO TASKANA_SCHEMA_VERSION (VERSION, CREATED) VALUES ('2.0.2', CURRENT_TIMESTAMP);
CREATE TABLE CLASSIFICATION(
ID CHAR(40) NOT NULL,

View File

@ -9,7 +9,7 @@ CREATE TABLE TASKANA_SCHEMA_VERSION(
PRIMARY KEY (ID)
);
-- The VERSION value must match the value of TaskanaEngineConfiguration.TASKANA_SCHEMA_VERSION
INSERT INTO TASKANA_SCHEMA_VERSION (VERSION, CREATED) VALUES ('2.0.1', CURRENT_TIMESTAMP);
INSERT INTO TASKANA_SCHEMA_VERSION (VERSION, CREATED) VALUES ('2.0.2', CURRENT_TIMESTAMP);
CREATE TABLE CLASSIFICATION(
ID CHAR(40) NOT NULL,

View File

@ -2,7 +2,7 @@
SET SCHEMA %schemaName%;
INSERT INTO TASKANA_SCHEMA_VERSION (VERSION, CREATED) VALUES ('1.2.1', CURRENT_TIMESTAMP);
INSERT INTO TASKANA_SCHEMA_VERSION (VERSION, CREATED) VALUES ('2.0.2', CURRENT_TIMESTAMP);
CREATE TABLE TASK_COMMENT(
ID CHAR(40) NOT NULL,

View File

@ -2,7 +2,7 @@
SET search_path = %schemaName%;
INSERT INTO TASKANA_SCHEMA_VERSION (VERSION, CREATED) VALUES ('1.2.1', CURRENT_TIMESTAMP);
INSERT INTO TASKANA_SCHEMA_VERSION (VERSION, CREATED) VALUES ('2.0.2', CURRENT_TIMESTAMP);
CREATE TABLE TASK_COMMENT(
ID CHAR(40) NOT NULL,

View File

@ -8,14 +8,13 @@ import java.util.List;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import pro.taskana.common.api.exceptions.InvalidArgumentException;
import pro.taskana.common.api.exceptions.NotAuthorizedException;
import pro.taskana.security.JaasExtension;
import pro.taskana.security.WithAccessId;
import pro.taskana.task.api.TaskService;
import pro.taskana.task.api.exceptions.TaskCommentAlreadyExistException;
import pro.taskana.task.api.exceptions.TaskCommentNotFoundException;
import pro.taskana.task.api.exceptions.TaskNotFoundException;
import pro.taskana.task.internal.models.TaskCommentImpl;
import pro.taskana.task.api.models.TaskComment;
@ExtendWith(JaasExtension.class)
public class CreateTaskCommentAccTest extends AbstractAccTest {
@ -29,23 +28,22 @@ public class CreateTaskCommentAccTest extends AbstractAccTest {
groupNames = {"group_1"})
@Test
void testCreateTaskComment()
throws TaskCommentNotFoundException, TaskCommentAlreadyExistException, TaskNotFoundException,
NotAuthorizedException {
throws TaskNotFoundException, NotAuthorizedException, InvalidArgumentException {
TaskService taskService = taskanaEngine.getTaskService();
List<TaskCommentImpl> taskComments =
List<TaskComment> taskComments =
taskService.getTaskComments("TKI:000000000000000000000000000000000026");
assertThat(taskComments).hasSize(2);
TaskCommentImpl newTaskComment = new TaskCommentImpl();
newTaskComment.setTaskId("TKI:000000000000000000000000000000000026");
newTaskComment.setTextField("a newly created taskComment");
TaskComment taskCommentToCreate =
taskService.newTaskComment("TKI:000000000000000000000000000000000026");
taskCommentToCreate.setTextField("a newly created taskComment");
taskService.createTaskComment(newTaskComment);
taskService.createTaskComment(taskCommentToCreate);
// make sure that the new task comment was added
List<TaskCommentImpl> taskCommentsAfterInsert =
List<TaskComment> taskCommentsAfterInsert =
taskService.getTaskComments("TKI:000000000000000000000000000000000026");
assertThat(taskCommentsAfterInsert).hasSize(3);
}
@ -54,42 +52,21 @@ public class CreateTaskCommentAccTest extends AbstractAccTest {
userName = "user_1_1",
groupNames = {"group_1"})
@Test
void testCreateTaskCommentWithAlreadyExistingIdShouldFail()
throws TaskCommentNotFoundException, TaskNotFoundException, NotAuthorizedException {
void testCreateTaskCommentForNullOrNonExistingTaskIdShouldFail() {
TaskService taskService = taskanaEngine.getTaskService();
List<TaskCommentImpl> taskComments =
taskService.getTaskComments("TKI:000000000000000000000000000000000027");
assertThat(taskComments).hasSize(2);
TaskComment newTaskCommentForNonExistingTask =
taskService.newTaskComment("Definately non existing ID");
newTaskCommentForNonExistingTask.setTextField("a newly created taskComment");
TaskCommentImpl newTaskComment = new TaskCommentImpl();
newTaskComment.setTaskId("TKI:000000000000000000000000000000000027");
newTaskComment.setId("TCI:000000000000000000000000000000000000");
newTaskComment.setTextField("a newly created taskComment");
TaskComment newTaskCommentForTaskIdNull = taskService.newTaskComment(null);
newTaskCommentForTaskIdNull.setTextField("a newly created taskComment");
assertThatThrownBy(() -> taskService.createTaskComment(newTaskComment))
.isInstanceOf(TaskCommentAlreadyExistException.class);
assertThatThrownBy(() -> taskService.createTaskComment(newTaskCommentForNonExistingTask))
.isInstanceOf(TaskNotFoundException.class);
// make sure there is no new task comment
List<TaskCommentImpl> taskComments1 =
taskService.getTaskComments("TKI:000000000000000000000000000000000027");
assertThat(taskComments1).hasSize(2);
}
@WithAccessId(
userName = "user_1_1",
groupNames = {"group_1"})
@Test
void testCreateTaskCommentForNonExistingTaskShouldFail() {
TaskService taskService = taskanaEngine.getTaskService();
TaskCommentImpl newTaskComment = new TaskCommentImpl();
newTaskComment.setTaskId("Definately non existing ID");
newTaskComment.setTextField("a newly created taskComment");
assertThatThrownBy(() -> taskService.createTaskComment(newTaskComment))
assertThatThrownBy(() -> taskService.createTaskComment(newTaskCommentForTaskIdNull))
.isInstanceOf(TaskNotFoundException.class);
}
}

View File

@ -15,7 +15,7 @@ import pro.taskana.security.WithAccessId;
import pro.taskana.task.api.TaskService;
import pro.taskana.task.api.exceptions.TaskCommentNotFoundException;
import pro.taskana.task.api.exceptions.TaskNotFoundException;
import pro.taskana.task.internal.models.TaskCommentImpl;
import pro.taskana.task.api.models.TaskComment;
@ExtendWith(JaasExtension.class)
public class DeleteTaskCommentAccTest extends AbstractAccTest {
@ -34,14 +34,14 @@ public class DeleteTaskCommentAccTest extends AbstractAccTest {
TaskService taskService = taskanaEngine.getTaskService();
List<TaskCommentImpl> taskComments =
List<TaskComment> taskComments =
taskService.getTaskComments("TKI:000000000000000000000000000000000001");
assertThat(taskComments).hasSize(2);
taskService.deleteTaskComment("TCI:000000000000000000000000000000000003");
taskService.deleteTaskComment("TCI:000000000000000000000000000000000004");
// make sure the task comment was deleted
List<TaskCommentImpl> taskCommentsAfterDeletion =
List<TaskComment> taskCommentsAfterDeletion =
taskService.getTaskComments("TKI:000000000000000000000000000000000001");
assertThat(taskCommentsAfterDeletion).hasSize(1);
}
@ -51,20 +51,20 @@ public class DeleteTaskCommentAccTest extends AbstractAccTest {
groupNames = {"group_1"})
@Test
void testDeleteTaskCommentWithNoAuthorizationShouldFail()
throws TaskCommentNotFoundException, NotAuthorizedException, TaskNotFoundException {
throws NotAuthorizedException, TaskNotFoundException {
TaskService taskService = taskanaEngine.getTaskService();
List<TaskCommentImpl> taskComments =
List<TaskComment> taskComments =
taskService.getTaskComments("TKI:000000000000000000000000000000000002");
assertThat(taskComments).hasSize(2);
assertThatThrownBy(
() -> taskService.deleteTaskComment("TCI:000000000000000000000000000000000004"))
() -> taskService.deleteTaskComment("TCI:000000000000000000000000000000000005"))
.isInstanceOf(NotAuthorizedException.class);
// make sure the task comment was not deleted
List<TaskCommentImpl> taskCommentsAfterDeletion =
List<TaskComment> taskCommentsAfterDeletion =
taskService.getTaskComments("TKI:000000000000000000000000000000000002");
assertThat(taskCommentsAfterDeletion).hasSize(2);
}
@ -74,19 +74,22 @@ public class DeleteTaskCommentAccTest extends AbstractAccTest {
groupNames = {"group_1"})
@Test
void testDeleteTaskCommentWithInvalidTaskCommentIdShouldFail()
throws TaskCommentNotFoundException, NotAuthorizedException, TaskNotFoundException {
throws NotAuthorizedException, TaskNotFoundException {
TaskService taskService = taskanaEngine.getTaskService();
List<TaskCommentImpl> taskComments =
List<TaskComment> taskComments =
taskService.getTaskComments("TKI:000000000000000000000000000000000002");
assertThat(taskComments).hasSize(2);
assertThatThrownBy(() -> taskService.deleteTaskComment(""))
.isInstanceOf(InvalidArgumentException.class);
// make sure the task comment was not deleted
List<TaskCommentImpl> taskCommentsAfterDeletion =
assertThatThrownBy(() -> taskService.deleteTaskComment(null))
.isInstanceOf(InvalidArgumentException.class);
// make sure that no task comment was deleted
List<TaskComment> taskCommentsAfterDeletion =
taskService.getTaskComments("TKI:000000000000000000000000000000000002");
assertThat(taskCommentsAfterDeletion).hasSize(2);
}
@ -96,11 +99,11 @@ public class DeleteTaskCommentAccTest extends AbstractAccTest {
groupNames = {"group_1"})
@Test
void testDeleteNonExistingTaskCommentShouldFail()
throws TaskCommentNotFoundException, NotAuthorizedException, TaskNotFoundException {
throws NotAuthorizedException, TaskNotFoundException {
TaskService taskService = taskanaEngine.getTaskService();
List<TaskCommentImpl> taskComments =
List<TaskComment> taskComments =
taskService.getTaskComments("TKI:000000000000000000000000000000000002");
assertThat(taskComments).hasSize(2);
@ -108,7 +111,7 @@ public class DeleteTaskCommentAccTest extends AbstractAccTest {
.isInstanceOf(TaskCommentNotFoundException.class);
// make sure the task comment was not deleted
List<TaskCommentImpl> taskCommentsAfterDeletion =
List<TaskComment> taskCommentsAfterDeletion =
taskService.getTaskComments("TKI:000000000000000000000000000000000002");
assertThat(taskCommentsAfterDeletion).hasSize(2);
}

View File

@ -8,6 +8,7 @@ import java.util.List;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import pro.taskana.common.api.exceptions.InvalidArgumentException;
import pro.taskana.common.api.exceptions.NotAuthorizedException;
import pro.taskana.security.JaasExtension;
import pro.taskana.security.WithAccessId;
@ -15,7 +16,6 @@ import pro.taskana.task.api.TaskService;
import pro.taskana.task.api.exceptions.TaskCommentNotFoundException;
import pro.taskana.task.api.exceptions.TaskNotFoundException;
import pro.taskana.task.api.models.TaskComment;
import pro.taskana.task.internal.models.TaskCommentImpl;
@ExtendWith(JaasExtension.class)
public class GetTaskCommentAccTest extends AbstractAccTest {
@ -28,28 +28,26 @@ public class GetTaskCommentAccTest extends AbstractAccTest {
userName = "user_1_1",
groupNames = {"group_1"})
@Test
void testGetTaskComments()
throws TaskCommentNotFoundException, NotAuthorizedException, TaskNotFoundException {
void testGetTaskComments() throws NotAuthorizedException, TaskNotFoundException {
TaskService taskService = taskanaEngine.getTaskService();
taskService.getTask("TKI:000000000000000000000000000000000000");
List<TaskCommentImpl> taskComments =
List<TaskComment> taskComments =
taskService.getTaskComments("TKI:000000000000000000000000000000000000");
assertThat(taskComments).hasSize(2);
assertThat(taskComments).hasSize(3);
}
@WithAccessId(
userName = "user_1_1",
groupNames = {"group_1"})
@Test
void testGetNonExistingTaskCommentsShouldFail() {
void testGetNonExistingTaskCommentsShouldReturnEmptyList()
throws NotAuthorizedException, TaskNotFoundException {
TaskService taskService = taskanaEngine.getTaskService();
assertThatThrownBy(
() -> taskService.getTaskComments("TKI:000000000000000000000000000000000036"))
.isInstanceOf(TaskCommentNotFoundException.class);
assertThat(taskService.getTaskComments("TKI:000000000000000000000000000000000036")).isEmpty();
}
@WithAccessId(
@ -60,7 +58,8 @@ public class GetTaskCommentAccTest extends AbstractAccTest {
TaskService taskService = taskanaEngine.getTaskService();
assertThatThrownBy(() -> taskService.getTask("TKI:000000000000000000000000000000000004"))
assertThatThrownBy(
() -> taskService.getTaskComments("TKI:000000000000000000000000000000000004"))
.isInstanceOf(NotAuthorizedException.class);
}
@ -68,7 +67,9 @@ public class GetTaskCommentAccTest extends AbstractAccTest {
userName = "user_1_1",
groupNames = {"group_1"})
@Test
void testGetTaskComment() throws TaskCommentNotFoundException {
void testGetTaskComment()
throws TaskCommentNotFoundException, NotAuthorizedException, TaskNotFoundException,
InvalidArgumentException {
TaskService taskService = taskanaEngine.getTaskService();
@ -89,6 +90,15 @@ public class GetTaskCommentAccTest extends AbstractAccTest {
.isInstanceOf(TaskCommentNotFoundException.class);
}
@WithAccessId(
userName = "user_1_1",
groupNames = {"group_1"})
@Test
void testGetTaskCommentOfNotVisibleTaskShouldFail() {
TaskService taskService = taskanaEngine.getTaskService();
assertThatThrownBy(() -> taskService.getTaskComment("TCI:000000000000000000000000000000000012"))
.isInstanceOf(NotAuthorizedException.class);
}
}

View File

@ -4,19 +4,19 @@ import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import acceptance.AbstractAccTest;
import java.time.Instant;
import java.util.List;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import pro.taskana.common.api.exceptions.ConcurrencyException;
import pro.taskana.common.api.exceptions.InvalidArgumentException;
import pro.taskana.common.api.exceptions.NotAuthorizedException;
import pro.taskana.security.JaasExtension;
import pro.taskana.security.WithAccessId;
import pro.taskana.task.api.TaskService;
import pro.taskana.task.api.exceptions.TaskCommentNotFoundException;
import pro.taskana.task.api.exceptions.TaskNotFoundException;
import pro.taskana.task.internal.models.TaskCommentImpl;
import pro.taskana.task.api.models.TaskComment;
@ExtendWith(JaasExtension.class)
public class UpdateTaskCommentAccTest extends AbstractAccTest {
@ -31,26 +31,22 @@ public class UpdateTaskCommentAccTest extends AbstractAccTest {
@Test
void testUpdateTaskComment()
throws TaskCommentNotFoundException, NotAuthorizedException, ConcurrencyException,
TaskNotFoundException {
TaskNotFoundException, InvalidArgumentException {
TaskService taskService = taskanaEngine.getTaskService();
List<TaskCommentImpl> taskComments =
List<TaskComment> taskComments =
taskService.getTaskComments("TKI:000000000000000000000000000000000025");
assertThat(taskComments).hasSize(1);
assertThat(taskComments.get(0).getTextField()).isEqualTo("some text in textfield");
TaskCommentImpl taskComment = new TaskCommentImpl();
taskComment.setId("TCI:000000000000000000000000000000000002");
taskComment.setTaskId("TKI:000000000000000000000000000000000025");
TaskComment taskComment =
taskService.getTaskComment("TCI:000000000000000000000000000000000003");
taskComment.setTextField("updated textfield");
taskComment.setCreated(taskComments.get(0).getCreated());
taskComment.setModified(taskComments.get(0).getModified());
taskComment.setCreator("user_1_1");
taskService.updateTaskComment(taskComment);
List<TaskCommentImpl> taskCommentsAfterUpdate =
List<TaskComment> taskCommentsAfterUpdate =
taskService.getTaskComments("TKI:000000000000000000000000000000000025");
assertThat(taskCommentsAfterUpdate.get(0).getTextField()).isEqualTo("updated textfield");
}
@ -60,28 +56,25 @@ public class UpdateTaskCommentAccTest extends AbstractAccTest {
groupNames = {"group_1"})
@Test
void testUpdateTaskCommentWithNoAuthorizationShouldFail()
throws TaskCommentNotFoundException, NotAuthorizedException, TaskNotFoundException {
throws TaskCommentNotFoundException, NotAuthorizedException, TaskNotFoundException,
InvalidArgumentException {
TaskService taskService = taskanaEngine.getTaskService();
List<TaskCommentImpl> taskComments =
List<TaskComment> taskComments =
taskService.getTaskComments("TKI:000000000000000000000000000000000000");
assertThat(taskComments).hasSize(2);
assertThat(taskComments).hasSize(3);
assertThat(taskComments.get(1).getTextField()).isEqualTo("some other text in textfield");
TaskCommentImpl taskComment = new TaskCommentImpl();
taskComment.setId("TCI:000000000000000000000000000000000001");
taskComment.setTaskId("TKI:000000000000000000000000000000000000");
TaskComment taskComment =
taskService.getTaskComment("TCI:000000000000000000000000000000000001");
taskComment.setTextField("updated textfield");
taskComment.setCreated(taskComments.get(1).getCreated());
taskComment.setModified(taskComments.get(1).getModified());
taskComment.setCreator("user_1_1");
assertThatThrownBy(() -> taskService.updateTaskComment(taskComment))
.isInstanceOf(NotAuthorizedException.class);
// make sure the task comment wasn't updated
List<TaskCommentImpl> taskCommentsAfterUpdateAttempt =
List<TaskComment> taskCommentsAfterUpdateAttempt =
taskService.getTaskComments("TKI:000000000000000000000000000000000000");
assertThat(taskCommentsAfterUpdateAttempt.get(1).getTextField())
.isEqualTo("some other text in textfield");
@ -92,30 +85,32 @@ public class UpdateTaskCommentAccTest extends AbstractAccTest {
groupNames = {"group_1"})
@Test
void testUpdateTaskCommentWithConcurrentModificationShouldFail()
throws TaskCommentNotFoundException, NotAuthorizedException, TaskNotFoundException {
throws TaskCommentNotFoundException, NotAuthorizedException, TaskNotFoundException,
ConcurrencyException, InvalidArgumentException {
TaskService taskService = taskanaEngine.getTaskService();
List<TaskCommentImpl> taskComments =
List<TaskComment> taskComments =
taskService.getTaskComments("TKI:000000000000000000000000000000000000");
assertThat(taskComments).hasSize(2);
assertThat(taskComments.get(1).getTextField()).isEqualTo("some other text in textfield");
assertThat(taskComments).hasSize(3);
assertThat(taskComments.get(2).getTextField()).isEqualTo("some other text in textfield");
TaskCommentImpl taskComment = new TaskCommentImpl();
taskComment.setId("TCI:000000000000000000000000000000000001");
taskComment.setTaskId("TKI:000000000000000000000000000000000000");
taskComment.setTextField("updated textfield");
taskComment.setCreated(taskComments.get(1).getCreated());
taskComment.setModified(Instant.now());
taskComment.setCreator("user_1_1");
TaskComment taskCommentToUpdate =
taskService.getTaskComment("TCI:000000000000000000000000000000000002");
taskCommentToUpdate.setTextField("updated textfield");
assertThatThrownBy(() -> taskService.updateTaskComment(taskComment))
TaskComment concurrentTaskCommentToUpdate =
taskService.getTaskComment("TCI:000000000000000000000000000000000002");
concurrentTaskCommentToUpdate.setTextField("concurrently updated textfield");
taskService.updateTaskComment(taskCommentToUpdate);
assertThatThrownBy(() -> taskService.updateTaskComment(concurrentTaskCommentToUpdate))
.isInstanceOf(ConcurrencyException.class);
// make sure the task comment wasn't updated
List<TaskCommentImpl> taskCommentsAfterUpdateAttempt =
List<TaskComment> taskCommentsAfterUpdateAttempt =
taskService.getTaskComments("TKI:000000000000000000000000000000000000");
assertThat(taskCommentsAfterUpdateAttempt.get(1).getTextField())
.isEqualTo("some other text in textfield");
assertThat(taskCommentsAfterUpdateAttempt.get(2).getTextField()).isEqualTo("updated textfield");
}
}

View File

@ -3,14 +3,16 @@
-- TaskComments for GetTaskCommentAccTest + UpdateTaskCommentAccTest
INSERT INTO TASK_COMMENT VALUES('TCI:000000000000000000000000000000000000', 'TKI:000000000000000000000000000000000000', 'some text in textfield', 'user_1_1', '2018-01-29 15:55:00', '2018-01-30 15:55:00');
INSERT INTO TASK_COMMENT VALUES('TCI:000000000000000000000000000000000001', 'TKI:000000000000000000000000000000000000', 'some other text in textfield', 'user_1_1', '2018-01-29 15:55:00', '2018-01-30 15:55:00');
INSERT INTO TASK_COMMENT VALUES('TCI:000000000000000000000000000000000002', 'TKI:000000000000000000000000000000000025', 'some text in textfield', 'user_1_1', '2018-01-29 15:55:00', '2018-01-30 15:55:00');
INSERT INTO TASK_COMMENT VALUES('TCI:000000000000000000000000000000000002', 'TKI:000000000000000000000000000000000000', 'some other text in textfield', 'user_1_1', '2018-01-29 15:55:00', '2018-01-30 15:55:00');
INSERT INTO TASK_COMMENT VALUES('TCI:000000000000000000000000000000000003', 'TKI:000000000000000000000000000000000025', 'some text in textfield', 'user_1_1', '2018-01-29 15:55:00', '2018-01-30 15:55:00');
-- TaskComments for DeleteTaskCommentAccTest
INSERT INTO TASK_COMMENT VALUES('TCI:000000000000000000000000000000000003', 'TKI:000000000000000000000000000000000001', 'some text in textfield', 'user_1_1', '2018-01-29 15:55:00', '2018-01-30 15:55:00');
INSERT INTO TASK_COMMENT VALUES('TCI:000000000000000000000000000000000004', 'TKI:000000000000000000000000000000000001', 'some other text in textfield', 'user_1_1', '2018-01-29 15:55:00', '2018-01-30 15:55:00');
INSERT INTO TASK_COMMENT VALUES('TCI:000000000000000000000000000000000005', 'TKI:000000000000000000000000000000000002', 'some text in textfield', 'user_1_1', '2018-01-29 15:55:00', '2018-01-30 15:55:00');
INSERT INTO TASK_COMMENT VALUES('TCI:000000000000000000000000000000000006', 'TKI:000000000000000000000000000000000002', 'some other text in textfield', 'user_1_1', '2018-01-29 15:55:00', '2018-01-30 15:55:00');
INSERT INTO TASK_COMMENT VALUES('TCI:000000000000000000000000000000000004', 'TKI:000000000000000000000000000000000001', 'some text in textfield', 'user_1_1', '2018-01-29 15:55:00', '2018-01-30 15:55:00');
INSERT INTO TASK_COMMENT VALUES('TCI:000000000000000000000000000000000005', 'TKI:000000000000000000000000000000000001', 'some other text in textfield', 'user_1_1', '2018-01-29 15:55:00', '2018-01-30 15:55:00');
INSERT INTO TASK_COMMENT VALUES('TCI:000000000000000000000000000000000006', 'TKI:000000000000000000000000000000000002', 'some text in textfield', 'user_1_1', '2018-01-29 15:55:00', '2018-01-30 15:55:00');
INSERT INTO TASK_COMMENT VALUES('TCI:000000000000000000000000000000000007', 'TKI:000000000000000000000000000000000002', 'some other text in textfield', 'user_1_1', '2018-01-29 15:55:00', '2018-01-30 15:55:00');
-- TaskComments for CreateTaskCommentAccTest
INSERT INTO TASK_COMMENT VALUES('TCI:000000000000000000000000000000000007', 'TKI:000000000000000000000000000000000026', 'some text in textfield', 'user_1_1', '2018-01-29 15:55:00', '2018-01-30 15:55:00');
INSERT INTO TASK_COMMENT VALUES('TCI:000000000000000000000000000000000008', 'TKI:000000000000000000000000000000000026', 'some other text in textfield', 'user_1_1', '2018-01-29 15:55:00', '2018-01-30 15:55:00');
INSERT INTO TASK_COMMENT VALUES('TCI:000000000000000000000000000000000009', 'TKI:000000000000000000000000000000000027', 'some text in textfield', 'user_1_1', '2018-01-29 15:55:00', '2018-01-30 15:55:00');
INSERT INTO TASK_COMMENT VALUES('TCI:000000000000000000000000000000000010', 'TKI:000000000000000000000000000000000027', 'some other text in textfield', 'user_1_1', '2018-01-29 15:55:00', '2018-01-30 15:55:00');
INSERT INTO TASK_COMMENT VALUES('TCI:000000000000000000000000000000000008', 'TKI:000000000000000000000000000000000026', 'some text in textfield', 'user_1_1', '2018-01-29 15:55:00', '2018-01-30 15:55:00');
INSERT INTO TASK_COMMENT VALUES('TCI:000000000000000000000000000000000009', 'TKI:000000000000000000000000000000000026', 'some other text in textfield', 'user_1_1', '2018-01-29 15:55:00', '2018-01-30 15:55:00');
INSERT INTO TASK_COMMENT VALUES('TCI:000000000000000000000000000000000010', 'TKI:000000000000000000000000000000000027', 'some text in textfield', 'user_1_1', '2018-01-29 15:55:00', '2018-01-30 15:55:00');
INSERT INTO TASK_COMMENT VALUES('TCI:000000000000000000000000000000000011', 'TKI:000000000000000000000000000000000027', 'some other text in textfield', 'user_1_1', '2018-01-29 15:55:00', '2018-01-30 15:55:00');
INSERT INTO TASK_COMMENT VALUES('TCI:000000000000000000000000000000000012', 'TKI:000000000000000000000000000000000004', 'some text in textfield', 'user_1_1', '2018-01-29 15:55:00', '2018-01-30 15:55:00');