TSK-1150 Java-API for the administration of comments for tasks

This commit is contained in:
Jörg Heffner 2020-03-03 11:42:18 +01:00
parent d574cfa06f
commit 3b7da72d24
25 changed files with 1206 additions and 70 deletions

View File

@ -43,7 +43,7 @@ import pro.taskana.common.internal.configuration.DbSchemaCreator;
public class TaskanaEngineConfiguration {
protected static final String TASKANA_SCHEMA_VERSION =
"1.2.1"; // must match the VERSION value in table
"2.0.1"; // 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";
@ -485,7 +485,7 @@ public class TaskanaEngineConfiguration {
this.schemaName = this.schemaName.toUpperCase();
}
} catch (SQLException ex) {
LOGGER.error("Caught {} when attempting to initialize the schema name", ex);
LOGGER.error("Caught exception when attempting to initialize the schema name", ex);
}
LOGGER.debug("Using schema name {}", this.getSchemaName());

View File

@ -52,6 +52,7 @@ import pro.taskana.spi.history.internal.HistoryEventProducer;
import pro.taskana.task.api.TaskService;
import pro.taskana.task.internal.AttachmentMapper;
import pro.taskana.task.internal.ObjectReferenceMapper;
import pro.taskana.task.internal.TaskCommentMapper;
import pro.taskana.task.internal.TaskMapper;
import pro.taskana.task.internal.TaskQueryMapper;
import pro.taskana.task.internal.TaskRoutingManager;
@ -98,6 +99,7 @@ public class TaskanaEngineImpl implements TaskanaEngine {
return new TaskServiceImpl(
internalTaskanaEngineImpl,
session.getMapper(TaskMapper.class),
session.getMapper(TaskCommentMapper.class),
session.getMapper(AttachmentMapper.class));
}
@ -258,6 +260,7 @@ public class TaskanaEngineImpl implements TaskanaEngine {
configuration.addMapper(ObjectReferenceMapper.class);
configuration.addMapper(WorkbasketQueryMapper.class);
configuration.addMapper(TaskQueryMapper.class);
configuration.addMapper(TaskCommentMapper.class);
configuration.addMapper(ClassificationQueryMapper.class);
configuration.addMapper(AttachmentMapper.class);
configuration.addMapper(JobMapper.class);

View File

@ -15,10 +15,14 @@ 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. */
@ -366,6 +370,77 @@ public interface TaskService {
List<String> updateTasks(List<String> taskIds, Map<String, String> customFieldsToUpdate)
throws InvalidArgumentException;
/**
* Create a task comment.
*
* @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.
* @throws TaskNotFoundException If the given taskId in the TaskComment does not refer to an
* existing task.
*/
TaskComment createTaskComment(TaskComment taskComment)
throws NotAuthorizedException, TaskCommentAlreadyExistException, TaskNotFoundException;
/**
* Update a task comment.
*
* @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.
* @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.
*/
TaskComment updateTaskComment(TaskComment taskComment)
throws NotAuthorizedException, ConcurrencyException, TaskCommentNotFoundException,
TaskNotFoundException;
/**
* 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
* @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.
*/
void deleteTaskComment(String taskCommentId)
throws NotAuthorizedException, TaskCommentNotFoundException, TaskNotFoundException,
InvalidArgumentException;
/**
* Retrieves a task comment for a given taskCommentId.
*
* @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.
*/
TaskComment getTaskComment(String taskCommentId) throws TaskCommentNotFoundException;
/**
* 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
* @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;
/**
* Sets the callback state on a list of tasks. Note: this method is primarily intended to be used
* by the TaskanaAdapter
@ -392,7 +467,7 @@ public interface TaskService {
* affected by this method. On each task, the corresponding due date is set according to the due
* dates in the classification() of the task and the task's attachments.
*
* @param planned the new 'PLANNED" property of the tasks
* @param planned the new 'PLANNED" property of the tasks
* @param taskIds the IDs of the tasks on which the new planned property is to be set.
* @return the result of the operations with Id and Exception for each failed task update.
*/

View File

@ -0,0 +1,17 @@
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

@ -0,0 +1,14 @@
package pro.taskana.task.api.exceptions;
import pro.taskana.common.api.exceptions.NotFoundException;
/** This exception will be thrown if a specific task comment is not in the database. */
public class TaskCommentNotFoundException extends NotFoundException {
private static final long serialVersionUID = 1L;
public TaskCommentNotFoundException(String id, String msg) {
super(id, msg);
}
}

View File

@ -0,0 +1,50 @@
package pro.taskana.task.api.models;
import java.time.Instant;
/** TaskComment-Interface to specify TaskComment Attributes. */
public interface TaskComment {
/**
* Gets the id of the task comment.
*
* @return taskId
*/
String getId();
/**
* Gets the id of the associated task.
*
* @return taskId
*/
String getTaskId();
/**
* Gets the name of the task comment-creator.
*
* @return creator
*/
String getCreator();
/**
* Gets the text field of the task comment.
*
* @return textField
*/
String getTextField();
/**
* Gets the time when the task comment was created.
*
* @return the created Instant
*/
Instant getCreated();
/**
* Gets the time when the task comment was last modified.
*
* @return the last modified Instant
*/
Instant getModified();
}

View File

@ -0,0 +1,63 @@
package pro.taskana.task.internal;
import java.util.List;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import pro.taskana.task.internal.models.TaskCommentImpl;
public interface TaskCommentMapper {
@Insert(
"INSERT INTO TASK_COMMENT (ID, TASK_ID, TEXT_FIELD, CREATOR, CREATED, MODIFIED) "
+ "VALUES (#{taskComment.id}, #{taskComment.taskId}, #{taskComment.textField},"
+ " #{taskComment.creator}, #{taskComment.created}, #{taskComment.modified})")
void insert(@Param("taskComment") TaskCommentImpl taskComment);
@Update(
"UPDATE TASK_COMMENT SET MODIFIED = #{modified}, TEXT_FIELD = #{textField} "
+ "WHERE ID = #{id}")
void update(TaskCommentImpl taskCommentImpl);
@Delete("DELETE FROM TASK_COMMENT WHERE ID = #{taskCommentId}")
void delete(String taskCommentId);
@Select(
"<script> SELECT ID, TASK_ID, TEXT_FIELD, CREATOR, CREATED, MODIFIED"
+ " FROM TASK_COMMENT "
+ "WHERE TASK_ID = #{taskId} "
+ "<if test=\"_databaseId == 'db2'\">with UR </if> "
+ "</script>")
@Results(
value = {
@Result(property = "id", column = "ID"),
@Result(property = "taskId", column = "TASK_ID"),
@Result(property = "textField", column = "TEXT_FIELD"),
@Result(property = "creator", column = "CREATOR"),
@Result(property = "created", column = "CREATED"),
@Result(property = "modified", column = "MODIFIED"),
})
List<TaskCommentImpl> findByTaskId(@Param("taskId") String taskId);
@Select(
"<script> SELECT ID, TASK_ID, TEXT_FIELD, CREATOR, CREATED, MODIFIED"
+ " FROM TASK_COMMENT "
+ "WHERE ID = #{taskCommentId} "
+ "<if test=\"_databaseId == 'db2'\">with UR </if> "
+ "</script>")
@Results(
value = {
@Result(property = "id", column = "ID"),
@Result(property = "taskId", column = "TASK_ID"),
@Result(property = "textField", column = "TEXT_FIELD"),
@Result(property = "creator", column = "CREATOR"),
@Result(property = "created", column = "CREATED"),
@Result(property = "modified", column = "MODIFIED"),
})
TaskCommentImpl findById(@Param("taskCommentId") String taskCommentId);
}

View File

@ -0,0 +1,279 @@
package pro.taskana.task.internal;
import java.time.Instant;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import pro.taskana.common.api.exceptions.ConcurrencyException;
import pro.taskana.common.api.exceptions.InvalidArgumentException;
import pro.taskana.common.api.exceptions.NotAuthorizedException;
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;
import pro.taskana.task.internal.models.TaskCommentImpl;
class TaskCommentServiceImpl {
private static final Logger LOGGER = LoggerFactory.getLogger(TaskCommentServiceImpl.class);
private static final String NOT_AUTHORIZED =
" Not authorized, TaskComment creator and current user must match. TaskComment creator is ";
private static final String BUT_CURRENT_USER_IS = " but current user is ";
private static final String ID_PREFIX_TASK_COMMENT = "TCI";
private InternalTaskanaEngine taskanaEngine;
private TaskServiceImpl taskService;
private TaskCommentMapper taskCommentMapper;
TaskCommentServiceImpl(
InternalTaskanaEngine taskanaEngine,
TaskCommentMapper taskCommentMapper,
TaskServiceImpl taskService) {
super();
this.taskanaEngine = taskanaEngine;
this.taskService = taskService;
this.taskCommentMapper = taskCommentMapper;
}
TaskComment updateTaskComment(TaskComment taskCommentToUpdate)
throws NotAuthorizedException, ConcurrencyException, TaskCommentNotFoundException,
TaskNotFoundException {
LOGGER.debug("entry to updateTaskComment (taskComment = {})", taskCommentToUpdate);
String userId = CurrentUserContext.getUserid();
TaskCommentImpl taskCommentImplToUpdate = (TaskCommentImpl) taskCommentToUpdate;
try {
taskanaEngine.openConnection();
taskService.getTask(taskCommentImplToUpdate.getTaskId());
if (taskCommentToUpdate.getCreator().equals(userId)) {
TaskCommentImpl oldTaskComment = getTaskComment(taskCommentImplToUpdate.getId());
checkModifiedHasNotChanged(oldTaskComment, taskCommentImplToUpdate);
taskCommentImplToUpdate.setModified(Instant.now());
taskCommentMapper.update(taskCommentImplToUpdate);
LOGGER.debug(
"Method updateTaskComment() updated taskComment '{}' for user '{}'.",
taskCommentImplToUpdate.getId(),
userId);
} else {
throw new NotAuthorizedException(
NOT_AUTHORIZED + taskCommentImplToUpdate.getCreator() + BUT_CURRENT_USER_IS + userId,
userId);
}
} finally {
taskanaEngine.returnConnection();
LOGGER.debug("exit from updateTaskComment()");
}
return taskCommentToUpdate;
}
TaskComment createTaskComment(TaskComment taskCommentToCreate)
throws NotAuthorizedException, TaskCommentAlreadyExistException, TaskNotFoundException {
LOGGER.debug("entry to setTaskComment (taskCommentToCreate = {})", taskCommentToCreate);
TaskCommentImpl taskCommentImplToCreate = (TaskCommentImpl) taskCommentToCreate;
try {
taskanaEngine.openConnection();
taskService.getTask(taskCommentImplToCreate.getTaskId());
if (isTaskCommentAlreadyExisting(taskCommentImplToCreate.getId())) {
throw new TaskCommentAlreadyExistException(taskCommentImplToCreate.getId());
}
initDefaultTaskCommentValues(taskCommentImplToCreate);
taskCommentMapper.insert(taskCommentImplToCreate);
} finally {
taskanaEngine.returnConnection();
LOGGER.debug("exit from setTaskComment()");
}
return taskCommentToCreate;
}
void deleteTaskComment(String taskCommentId)
throws NotAuthorizedException, TaskCommentNotFoundException, TaskNotFoundException,
InvalidArgumentException {
LOGGER.debug("entry to deleteTaskComment (taskComment = {}", taskCommentId);
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)) {
taskCommentMapper.delete(taskCommentId);
LOGGER.debug("taskComment {} deleted", taskCommentToDelete.getId());
} else {
throw new NotAuthorizedException(
NOT_AUTHORIZED + taskCommentToDelete.getCreator() + BUT_CURRENT_USER_IS + userId,
userId);
}
} finally {
taskanaEngine.returnConnection();
LOGGER.debug("exit from deleteTaskComment()");
}
}
List<TaskCommentImpl> getTaskComments(String taskId)
throws TaskCommentNotFoundException, NotAuthorizedException, TaskNotFoundException {
LOGGER.debug("entry to getTaskComments (taskId = {})", taskId);
List<TaskCommentImpl> result = null;
try {
taskanaEngine.openConnection();
taskService.getTask(taskId);
result = taskCommentMapper.findByTaskId(taskId);
if (result == null || result.isEmpty()) {
throw new TaskCommentNotFoundException(
taskId, "TaskComments for TaskId " + taskId + " were not found");
}
return result;
} finally {
taskanaEngine.returnConnection();
LOGGER.debug("exit from getTaskComments()");
}
}
TaskCommentImpl getTaskComment(String taskCommentId) throws TaskCommentNotFoundException {
LOGGER.debug("entry to getTaskComment (taskCommentId = {})", taskCommentId);
TaskCommentImpl result = null;
try {
taskanaEngine.openConnection();
result = taskCommentMapper.findById(taskCommentId);
if (result == null) {
throw new TaskCommentNotFoundException(
taskCommentId, "TaskComment for id " + taskCommentId + " was not found");
}
return result;
} finally {
taskanaEngine.returnConnection();
LOGGER.debug("exit from getTaskComment()");
}
}
private void checkModifiedHasNotChanged(
TaskCommentImpl oldTaskComment, TaskCommentImpl taskCommentImplToUpdate)
throws ConcurrencyException {
if (!oldTaskComment.getModified().equals(taskCommentImplToUpdate.getModified())) {
throw new ConcurrencyException(
"The current TaskComment has been modified while editing. "
+ "The values can not be updated. TaskComment "
+ taskCommentImplToUpdate.toString());
}
}
private void initDefaultTaskCommentValues(TaskCommentImpl taskCommentImplToCreate) {
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);
}
String creator = CurrentUserContext.getUserid();
if (taskanaEngine.getEngine().getConfiguration().isSecurityEnabled() && creator == null) {
throw new SystemException(
"TaskanaSecurity is enabled, but the current UserId is"
+ " NULL while creating a TaskComment.");
}
taskCommentImplToCreate.setCreator(creator);
}
private boolean isTaskCommentAlreadyExisting(String taskCommentId) {
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);
}
return isExisting;
}
private void validateTaskCommentId(String taskCommentId) throws InvalidArgumentException {
if (taskCommentId == null || taskCommentId.isEmpty()) {
throw new InvalidArgumentException("TaskId must not be null/empty for deletion");
}
}
}

View File

@ -47,15 +47,19 @@ 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;
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.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;
@ -101,11 +105,13 @@ public class TaskServiceImpl implements TaskService {
private AttachmentMapper attachmentMapper;
private HistoryEventProducer historyEventProducer;
private TaskTransferrer taskTransferrer;
private TaskCommentServiceImpl taskCommentService;
private ServiceLevelHandler serviceLevelHander;
public TaskServiceImpl(
InternalTaskanaEngine taskanaEngine,
TaskMapper taskMapper,
TaskCommentMapper taskCommentMapper,
AttachmentMapper attachmentMapper) {
super();
try {
@ -121,6 +127,7 @@ public class TaskServiceImpl implements TaskService {
this.classificationService = taskanaEngine.getEngine().getClassificationService();
this.historyEventProducer = taskanaEngine.getHistoryEventProducer();
this.taskTransferrer = new TaskTransferrer(taskanaEngine, taskMapper, this);
this.taskCommentService = new TaskCommentServiceImpl(taskanaEngine, taskCommentMapper, this);
this.serviceLevelHander = new ServiceLevelHandler(taskanaEngine, taskMapper, attachmentMapper);
}
@ -268,7 +275,7 @@ public class TaskServiceImpl implements TaskService {
}
@Override
public Task getTask(String id) throws TaskNotFoundException, NotAuthorizedException {
public Task getTask(String id) throws NotAuthorizedException, TaskNotFoundException {
LOGGER.debug("entry to getTaskById(id = {})", id);
TaskImpl resultTask = null;
try {
@ -593,6 +600,38 @@ public class TaskServiceImpl implements TaskService {
}
}
@Override
public TaskComment createTaskComment(TaskComment taskComment)
throws NotAuthorizedException, TaskCommentAlreadyExistException, TaskNotFoundException {
return taskCommentService.createTaskComment(taskComment);
}
@Override
public TaskComment updateTaskComment(TaskComment taskComment)
throws NotAuthorizedException, ConcurrencyException, TaskCommentNotFoundException,
TaskNotFoundException {
return taskCommentService.updateTaskComment(taskComment);
}
@Override
public void deleteTaskComment(String taskCommentId)
throws NotAuthorizedException, TaskCommentNotFoundException, TaskNotFoundException,
InvalidArgumentException {
taskCommentService.deleteTaskComment(taskCommentId);
}
@Override
public TaskComment getTaskComment(String taskCommentid) throws TaskCommentNotFoundException {
return taskCommentService.getTaskComment(taskCommentid);
}
@Override
public List<TaskCommentImpl> getTaskComments(String taskId)
throws TaskCommentNotFoundException, NotAuthorizedException, TaskNotFoundException {
return taskCommentService.getTaskComments(taskId);
}
@Override
public BulkOperationResults<String, TaskanaException> setCallbackStateForTasks(
List<String> externalIds, CallbackState state) {
@ -792,25 +831,6 @@ public class TaskServiceImpl implements TaskService {
LOGGER.debug("exit from removeNonExistingTasksFromTaskIdList()");
}
private Duration calculateDuration(
PrioDurationHolder prioDurationFromAttachments,
ClassificationSummary newClassificationSummary) {
if (newClassificationSummary.getServiceLevel() == null) {
return null;
}
Duration minDuration = prioDurationFromAttachments.getLeft();
Duration durationFromClassification =
Duration.parse(newClassificationSummary.getServiceLevel());
if (minDuration != null) {
if (minDuration.compareTo(durationFromClassification) > 0) {
minDuration = durationFromClassification;
}
} else {
minDuration = durationFromClassification;
}
return minDuration;
}
List<TaskSummary> augmentTaskSummariesByContainedSummaries(List<TaskSummaryImpl> taskSummaries) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug(
@ -845,6 +865,25 @@ public class TaskServiceImpl implements TaskService {
return result;
}
private Duration calculateDuration(
PrioDurationHolder prioDurationFromAttachments,
ClassificationSummary newClassificationSummary) {
if (newClassificationSummary.getServiceLevel() == null) {
return null;
}
Duration minDuration = prioDurationFromAttachments.getLeft();
Duration durationFromClassification =
Duration.parse(newClassificationSummary.getServiceLevel());
if (minDuration != null) {
if (minDuration.compareTo(durationFromClassification) > 0) {
minDuration = durationFromClassification;
}
} else {
minDuration = durationFromClassification;
}
return minDuration;
}
private BulkOperationResults<String, TaskanaException> addExceptionsForTasksWhoseOwnerWasNotSet(
String owner, List<MinimalTaskSummary> existingMinimalTaskSummaries) {
BulkOperationResults<String, TaskanaException> bulkLog = new BulkOperationResults<>();
@ -1230,7 +1269,8 @@ public class TaskServiceImpl implements TaskService {
CallbackState state = CallbackState.valueOf(value);
task.setCallbackState(state);
} catch (Exception e) {
LOGGER.warn("Attempted to determine callback state from {} and caught {}", value, e);
LOGGER.warn(
"Attempted to determine callback state from {} and caught exception", value, e);
throw new InvalidArgumentException(
"Attempted to set callback state for task " + task.getId(), e);
}

View File

@ -0,0 +1,123 @@
package pro.taskana.task.internal.models;
import java.time.Instant;
import java.util.Objects;
import pro.taskana.task.api.models.TaskComment;
public class TaskCommentImpl implements TaskComment {
private String id;
private String taskId;
private String textField;
private String creator;
private Instant created;
private Instant modified;
@Override
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
@Override
public String getTaskId() {
return taskId;
}
public void setTaskId(String taskId) {
this.taskId = taskId;
}
@Override
public String getCreator() {
return creator;
}
public void setCreator(String creator) {
this.creator = creator;
}
public String getTextField() {
return textField;
}
@Override
public Instant getCreated() {
return created;
}
public void setCreated(Instant created) {
this.created = created;
}
@Override
public Instant getModified() {
return modified;
}
public void setModified(Instant modified) {
this.modified = modified;
}
public void setTextField(String textField) {
this.textField = textField;
}
protected boolean canEqual(Object other) {
return (other instanceof TaskCommentImpl);
}
@Override
public int hashCode() {
return Objects.hash(
id,
taskId,
textField,
creator,
created,
modified);
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (!(obj instanceof TaskCommentImpl)) {
return false;
}
TaskCommentImpl other = (TaskCommentImpl) obj;
if (!other.canEqual(this)) {
return false;
}
return Objects.equals(id, other.getId())
&& Objects.equals(taskId, other.getTaskId())
&& Objects.equals(textField, other.getTextField())
&& Objects.equals(creator, other.getCreator())
&& Objects.equals(created, other.getCreated())
&& Objects.equals(modified, other.getModified());
}
@Override
public String toString() {
return "TaskCommentImpl [id="
+ id
+ ", taskId="
+ taskId
+ ", textField="
+ textField
+ ", creator="
+ creator
+ ", created="
+ created
+ ", modified="
+ modified
+ "]";
}
}

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 ('1.2.1', CURRENT_TIMESTAMP);
INSERT INTO TASKANA_SCHEMA_VERSION (VERSION, CREATED) VALUES ('2.0.1', CURRENT_TIMESTAMP);
CREATE TABLE CLASSIFICATION(
ID CHAR(40) NOT NULL,
@ -177,6 +177,17 @@ CREATE TABLE ATTACHMENT(
CONSTRAINT ATT_CLASS FOREIGN KEY (CLASSIFICATION_ID) REFERENCES CLASSIFICATION ON DELETE NO ACTION
);
CREATE TABLE TASK_COMMENT(
ID CHAR(40) NOT NULL,
TASK_ID CHAR(40) NOT NULL,
TEXT_FIELD VARCHAR(1024) NULL,
CREATOR VARCHAR(32) NULL,
CREATED TIMESTAMP NULL,
MODIFIED TIMESTAMP NULL,
PRIMARY KEY (ID),
CONSTRAINT COMMENT_TASK FOREIGN KEY (TASK_ID) REFERENCES TASK ON DELETE CASCADE
);
CREATE TABLE SCHEDULED_JOB(
JOB_ID INTEGER NOT NULL,
PRIORITY INTEGER 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 ('1.2.1', CURRENT_TIMESTAMP);
INSERT INTO TASKANA_SCHEMA_VERSION (VERSION, CREATED) VALUES ('2.0.1', CURRENT_TIMESTAMP);
CREATE TABLE CLASSIFICATION(
ID CHAR(40) NOT NULL,
@ -179,6 +179,17 @@ CREATE TABLE ATTACHMENT(
CONSTRAINT ATT_CLASS FOREIGN KEY (CLASSIFICATION_ID) REFERENCES CLASSIFICATION ON DELETE NO ACTION
);
CREATE TABLE TASK_COMMENT(
ID CHAR(40) NOT NULL,
TASK_ID CHAR(40) NOT NULL,
TEXT_FIELD VARCHAR(1024) NULL,
CREATOR VARCHAR(32) NULL,
CREATED TIMESTAMP NULL,
MODIFIED TIMESTAMP NULL,
PRIMARY KEY (ID),
CONSTRAINT COMMENT_TASK FOREIGN KEY (TASK_ID) REFERENCES TASK ON DELETE CASCADE
);
CREATE TABLE SCHEDULED_JOB(
JOB_ID INTEGER NOT NULL,
PRIORITY INTEGER 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 ('1.2.1', CURRENT_TIMESTAMP);
INSERT INTO TASKANA_SCHEMA_VERSION (VERSION, CREATED) VALUES ('2.0.1', CURRENT_TIMESTAMP);
CREATE TABLE CLASSIFICATION(
ID CHAR(40) NOT NULL,
@ -179,6 +179,17 @@ CREATE TABLE ATTACHMENT(
CONSTRAINT ATT_CLASS FOREIGN KEY (CLASSIFICATION_ID) REFERENCES CLASSIFICATION ON DELETE NO ACTION
);
CREATE TABLE TASK_COMMENT(
ID CHAR(40) NOT NULL,
TASK_ID CHAR(40) NOT NULL,
TEXT_FIELD VARCHAR(1024) NULL,
CREATOR VARCHAR(32) NULL,
CREATED TIMESTAMP NULL,
MODIFIED TIMESTAMP NULL,
PRIMARY KEY (ID),
CONSTRAINT COMMENT_TASK FOREIGN KEY (TASK_ID) REFERENCES TASK ON DELETE CASCADE
);
CREATE TABLE SCHEDULED_JOB(
JOB_ID INTEGER NOT NULL,
PRIORITY INTEGER NULL,

View File

@ -0,0 +1,16 @@
-- this script adds a TASK_COMMENT table and updates the table TASKANA_SCHEMA_VERSION.
SET SCHEMA %schemaName%;
INSERT INTO TASKANA_SCHEMA_VERSION (VERSION, CREATED) VALUES ('1.2.1', CURRENT_TIMESTAMP);
CREATE TABLE TASK_COMMENT(
ID CHAR(40) NOT NULL,
TASK_ID CHAR(40) NOT NULL,
TEXT_FIELD VARCHAR(1024) NULL,
CREATOR VARCHAR(32) NULL,
CREATED TIMESTAMP NULL,
MODIFIED TIMESTAMP NULL,
PRIMARY KEY (ID),
CONSTRAINT COMMENT_TASK FOREIGN KEY (TASK_ID) REFERENCES TASK ON DELETE CASCADE
);

View File

@ -0,0 +1,16 @@
-- this script adds a TASK_COMMENT table and updates the table TASKANA_SCHEMA_VERSION.
SET search_path = %schemaName%;
INSERT INTO TASKANA_SCHEMA_VERSION (VERSION, CREATED) VALUES ('1.2.1', CURRENT_TIMESTAMP);
CREATE TABLE TASK_COMMENT(
ID CHAR(40) NOT NULL,
TASK_ID CHAR(40) NOT NULL,
TEXT_FIELD VARCHAR(1024) NULL,
CREATOR VARCHAR(32) NULL,
CREATED TIMESTAMP NULL,
MODIFIED TIMESTAMP NULL,
PRIMARY KEY (ID),
CONSTRAINT COMMENT_TASK FOREIGN KEY (TASK_ID) REFERENCES TASK ON DELETE CASCADE
);

View File

@ -0,0 +1,95 @@
package acceptance.task;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import acceptance.AbstractAccTest;
import java.util.List;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
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;
@ExtendWith(JaasExtension.class)
public class CreateTaskCommentAccTest extends AbstractAccTest {
CreateTaskCommentAccTest() {
super();
}
@WithAccessId(
userName = "user_1_1",
groupNames = {"group_1"})
@Test
void testCreateTaskComment()
throws TaskCommentNotFoundException, TaskCommentAlreadyExistException, TaskNotFoundException,
NotAuthorizedException {
TaskService taskService = taskanaEngine.getTaskService();
List<TaskCommentImpl> taskComments =
taskService.getTaskComments("TKI:000000000000000000000000000000000026");
assertThat(taskComments).hasSize(2);
TaskCommentImpl newTaskComment = new TaskCommentImpl();
newTaskComment.setTaskId("TKI:000000000000000000000000000000000026");
newTaskComment.setTextField("a newly created taskComment");
taskService.createTaskComment(newTaskComment);
// make sure that the new task comment was added
List<TaskCommentImpl> taskCommentsAfterInsert =
taskService.getTaskComments("TKI:000000000000000000000000000000000026");
assertThat(taskCommentsAfterInsert).hasSize(3);
}
@WithAccessId(
userName = "user_1_1",
groupNames = {"group_1"})
@Test
void testCreateTaskCommentWithAlreadyExistingIdShouldFail()
throws TaskCommentNotFoundException, TaskNotFoundException, NotAuthorizedException {
TaskService taskService = taskanaEngine.getTaskService();
List<TaskCommentImpl> taskComments =
taskService.getTaskComments("TKI:000000000000000000000000000000000027");
assertThat(taskComments).hasSize(2);
TaskCommentImpl newTaskComment = new TaskCommentImpl();
newTaskComment.setTaskId("TKI:000000000000000000000000000000000027");
newTaskComment.setId("TCI:000000000000000000000000000000000000");
newTaskComment.setTextField("a newly created taskComment");
assertThatThrownBy(() -> taskService.createTaskComment(newTaskComment))
.isInstanceOf(TaskCommentAlreadyExistException.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))
.isInstanceOf(TaskNotFoundException.class);
}
}

View File

@ -0,0 +1,115 @@
package acceptance.task;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import acceptance.AbstractAccTest;
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.TaskCommentNotFoundException;
import pro.taskana.task.api.exceptions.TaskNotFoundException;
import pro.taskana.task.internal.models.TaskCommentImpl;
@ExtendWith(JaasExtension.class)
public class DeleteTaskCommentAccTest extends AbstractAccTest {
DeleteTaskCommentAccTest() {
super();
}
@WithAccessId(
userName = "user_1_1",
groupNames = {"group_1"})
@Test
void testDeleteTaskComment()
throws TaskCommentNotFoundException, NotAuthorizedException, TaskNotFoundException,
InvalidArgumentException {
TaskService taskService = taskanaEngine.getTaskService();
List<TaskCommentImpl> taskComments =
taskService.getTaskComments("TKI:000000000000000000000000000000000001");
assertThat(taskComments).hasSize(2);
taskService.deleteTaskComment("TCI:000000000000000000000000000000000003");
// make sure the task comment was deleted
List<TaskCommentImpl> taskCommentsAfterDeletion =
taskService.getTaskComments("TKI:000000000000000000000000000000000001");
assertThat(taskCommentsAfterDeletion).hasSize(1);
}
@WithAccessId(
userName = "user_1_2",
groupNames = {"group_1"})
@Test
void testDeleteTaskCommentWithNoAuthorizationShouldFail()
throws TaskCommentNotFoundException, NotAuthorizedException, TaskNotFoundException {
TaskService taskService = taskanaEngine.getTaskService();
List<TaskCommentImpl> taskComments =
taskService.getTaskComments("TKI:000000000000000000000000000000000002");
assertThat(taskComments).hasSize(2);
assertThatThrownBy(
() -> taskService.deleteTaskComment("TCI:000000000000000000000000000000000004"))
.isInstanceOf(NotAuthorizedException.class);
// make sure the task comment was not deleted
List<TaskCommentImpl> taskCommentsAfterDeletion =
taskService.getTaskComments("TKI:000000000000000000000000000000000002");
assertThat(taskCommentsAfterDeletion).hasSize(2);
}
@WithAccessId(
userName = "user_1_1",
groupNames = {"group_1"})
@Test
void testDeleteTaskCommentWithInvalidTaskCommentIdShouldFail()
throws TaskCommentNotFoundException, NotAuthorizedException, TaskNotFoundException {
TaskService taskService = taskanaEngine.getTaskService();
List<TaskCommentImpl> 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 =
taskService.getTaskComments("TKI:000000000000000000000000000000000002");
assertThat(taskCommentsAfterDeletion).hasSize(2);
}
@WithAccessId(
userName = "user_1_1",
groupNames = {"group_1"})
@Test
void testDeleteNonExistingTaskCommentShouldFail()
throws TaskCommentNotFoundException, NotAuthorizedException, TaskNotFoundException {
TaskService taskService = taskanaEngine.getTaskService();
List<TaskCommentImpl> taskComments =
taskService.getTaskComments("TKI:000000000000000000000000000000000002");
assertThat(taskComments).hasSize(2);
assertThatThrownBy(() -> taskService.deleteTaskComment("non existing task comment id"))
.isInstanceOf(TaskCommentNotFoundException.class);
// make sure the task comment was not deleted
List<TaskCommentImpl> taskCommentsAfterDeletion =
taskService.getTaskComments("TKI:000000000000000000000000000000000002");
assertThat(taskCommentsAfterDeletion).hasSize(2);
}
}

View File

@ -0,0 +1,94 @@
package acceptance.task;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import acceptance.AbstractAccTest;
import java.util.List;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
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.api.models.TaskComment;
import pro.taskana.task.internal.models.TaskCommentImpl;
@ExtendWith(JaasExtension.class)
public class GetTaskCommentAccTest extends AbstractAccTest {
GetTaskCommentAccTest() {
super();
}
@WithAccessId(
userName = "user_1_1",
groupNames = {"group_1"})
@Test
void testGetTaskComments()
throws TaskCommentNotFoundException, NotAuthorizedException, TaskNotFoundException {
TaskService taskService = taskanaEngine.getTaskService();
taskService.getTask("TKI:000000000000000000000000000000000000");
List<TaskCommentImpl> taskComments =
taskService.getTaskComments("TKI:000000000000000000000000000000000000");
assertThat(taskComments).hasSize(2);
}
@WithAccessId(
userName = "user_1_1",
groupNames = {"group_1"})
@Test
void testGetNonExistingTaskCommentsShouldFail() {
TaskService taskService = taskanaEngine.getTaskService();
assertThatThrownBy(
() -> taskService.getTaskComments("TKI:000000000000000000000000000000000036"))
.isInstanceOf(TaskCommentNotFoundException.class);
}
@WithAccessId(
userName = "user_1_1",
groupNames = {"group_1"})
@Test
void testGetTaskCommentsOfNotVisibleTaskShouldFail() {
TaskService taskService = taskanaEngine.getTaskService();
assertThatThrownBy(() -> taskService.getTask("TKI:000000000000000000000000000000000004"))
.isInstanceOf(NotAuthorizedException.class);
}
@WithAccessId(
userName = "user_1_1",
groupNames = {"group_1"})
@Test
void testGetTaskComment() throws TaskCommentNotFoundException {
TaskService taskService = taskanaEngine.getTaskService();
TaskComment taskComment =
taskService.getTaskComment("TCI:000000000000000000000000000000000007");
assertThat(taskComment.getCreator()).isEqualTo("user_1_1");
}
@WithAccessId(
userName = "user_1_1",
groupNames = {"group_1"})
@Test
void testGetNonExistingTaskCommentShouldFail() {
TaskService taskService = taskanaEngine.getTaskService();
assertThatThrownBy(() -> taskService.getTaskComment("Definately Non Existing Task Comment Id"))
.isInstanceOf(TaskCommentNotFoundException.class);
}
}

View File

@ -0,0 +1,121 @@
package acceptance.task;
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.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;
@ExtendWith(JaasExtension.class)
public class UpdateTaskCommentAccTest extends AbstractAccTest {
UpdateTaskCommentAccTest() {
super();
}
@WithAccessId(
userName = "user_1_1",
groupNames = {"group_1"})
@Test
void testUpdateTaskComment()
throws TaskCommentNotFoundException, NotAuthorizedException, ConcurrencyException,
TaskNotFoundException {
TaskService taskService = taskanaEngine.getTaskService();
List<TaskCommentImpl> 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.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 =
taskService.getTaskComments("TKI:000000000000000000000000000000000025");
assertThat(taskCommentsAfterUpdate.get(0).getTextField()).isEqualTo("updated textfield");
}
@WithAccessId(
userName = "user_1_2",
groupNames = {"group_1"})
@Test
void testUpdateTaskCommentWithNoAuthorizationShouldFail()
throws TaskCommentNotFoundException, NotAuthorizedException, TaskNotFoundException {
TaskService taskService = taskanaEngine.getTaskService();
List<TaskCommentImpl> taskComments =
taskService.getTaskComments("TKI:000000000000000000000000000000000000");
assertThat(taskComments).hasSize(2);
assertThat(taskComments.get(1).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(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 =
taskService.getTaskComments("TKI:000000000000000000000000000000000000");
assertThat(taskCommentsAfterUpdateAttempt.get(1).getTextField())
.isEqualTo("some other text in textfield");
}
@WithAccessId(
userName = "user_1_1",
groupNames = {"group_1"})
@Test
void testUpdateTaskCommentWithConcurrentModificationShouldFail()
throws TaskCommentNotFoundException, NotAuthorizedException, TaskNotFoundException {
TaskService taskService = taskanaEngine.getTaskService();
List<TaskCommentImpl> taskComments =
taskService.getTaskComments("TKI:000000000000000000000000000000000000");
assertThat(taskComments).hasSize(2);
assertThat(taskComments.get(1).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");
assertThatThrownBy(() -> taskService.updateTaskComment(taskComment))
.isInstanceOf(ConcurrencyException.class);
// make sure the task comment wasn't updated
List<TaskCommentImpl> taskCommentsAfterUpdateAttempt =
taskService.getTaskComments("TKI:000000000000000000000000000000000000");
assertThat(taskCommentsAfterUpdateAttempt.get(1).getTextField())
.isEqualTo("some other text in textfield");
}
}

View File

@ -2,30 +2,18 @@ package pro.taskana.task.internal;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.mockito.Mockito.when;
import java.time.Duration;
import java.time.Instant;
import java.util.ArrayList;
import org.apache.ibatis.session.SqlSession;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import pro.taskana.TaskanaEngineConfiguration;
import pro.taskana.classification.api.models.Classification;
import pro.taskana.classification.internal.ClassificationQueryImpl;
import pro.taskana.classification.internal.ClassificationServiceImpl;
import pro.taskana.classification.internal.models.ClassificationImpl;
import pro.taskana.common.api.TaskanaEngine;
import pro.taskana.common.internal.InternalTaskanaEngine;
import pro.taskana.common.internal.JunitHelper;
import pro.taskana.task.api.models.ObjectReference;
import pro.taskana.task.api.models.TaskSummary;
import pro.taskana.task.internal.models.TaskImpl;
import pro.taskana.workbasket.api.WorkbasketService;
import pro.taskana.workbasket.api.models.Workbasket;
import pro.taskana.workbasket.internal.models.WorkbasketImpl;
@ -34,39 +22,8 @@ import pro.taskana.workbasket.internal.models.WorkbasketImpl;
*
* @author EH
*/
@ExtendWith(MockitoExtension.class)
class TaskServiceImplTest {
private TaskServiceImpl cut;
@Mock private TaskanaEngineConfiguration taskanaEngineConfigurationMock;
@Mock private InternalTaskanaEngine internalTaskanaEngineMock;
@Mock private TaskanaEngine taskanaEngineMock;
@Mock private TaskMapper taskMapperMock;
@Mock private ObjectReferenceMapper objectReferenceMapperMock;
@Mock private WorkbasketService workbasketServiceMock;
@Mock private ClassificationServiceImpl classificationServiceImplMock;
@Mock private AttachmentMapper attachmentMapperMock;
@Mock private ClassificationQueryImpl classificationQueryImplMock;
@Mock private SqlSession sqlSessionMock;
@BeforeEach
void setup() {
when(internalTaskanaEngineMock.getEngine()).thenReturn(taskanaEngineMock);
when(taskanaEngineMock.getWorkbasketService()).thenReturn(workbasketServiceMock);
when(taskanaEngineMock.getClassificationService()).thenReturn(classificationServiceImplMock);
cut = new TaskServiceImpl(internalTaskanaEngineMock, taskMapperMock, attachmentMapperMock);
}
@Test
void testTaskSummaryEqualsHashCode() throws InterruptedException {
Classification classification = createDummyClassification();

View File

@ -6,6 +6,7 @@ import java.util.stream.Stream;
public final class SampleDataProvider {
static final String TEST_TASK = "/sql/test-data/task.sql";
static final String TEST_TASK_COMMENT = "/sql/test-data/task-comment.sql";
static final String TEST_WORKBASKET = "/sql/test-data/workbasket.sql";
static final String TEST_DISTRIBUTION_TARGETS = "/sql/test-data/distribution-targets.sql";
static final String TEST_WORKBASKET_ACCESS_LIST = "/sql/test-data/workbasket-access-list.sql";
@ -18,6 +19,7 @@ public final class SampleDataProvider {
private static final String CLEAR_HISTORY_EVENTS = "/sql/clear/clear-history-events.sql";
private static final String HISTORY_EVENT = "/sql/sample-data/history-event.sql";
private static final String SAMPLE_TASK = "/sql/sample-data/task.sql";
private static final String SAMPLE_TASK_COMMENT = "/sql/sample-data/task-comment.sql";
private static final String SAMPLE_WORKBASKET = "/sql/sample-data/workbasket.sql";
private static final String SAMPLE_DISTRIBUTION_TARGETS =
"/sql/sample-data/distribution-targets.sql";
@ -35,6 +37,7 @@ public final class SampleDataProvider {
SAMPLE_DISTRIBUTION_TARGETS,
SAMPLE_CLASSIFICATION,
SAMPLE_TASK,
SAMPLE_TASK_COMMENT,
SAMPLE_ATTACHMENT,
SAMPLE_WORKBASKET_ACCESS_LIST,
SAMPLE_OBJECT_REFERENCE);
@ -57,6 +60,7 @@ public final class SampleDataProvider {
TEST_CLASSIFICATION,
TEST_WORKBASKET,
TEST_TASK,
TEST_TASK_COMMENT,
TEST_WORKBASKET_ACCESS_LIST,
TEST_DISTRIBUTION_TARGETS,
TEST_OBJECT_REFERENCE,

View File

@ -1,4 +1,5 @@
-- the order is important!
DELETE FROM TASK_COMMENT;
DELETE FROM ATTACHMENT;
DELETE FROM TASK;
DELETE FROM WORKBASKET_ACCESS_LIST;

View File

@ -1,4 +1,5 @@
DROP TABLE TASKANA_SCHEMA_VERSION;
DROP TABLE TASK_COMMENT;
DROP TABLE ATTACHMENT;
DROP TABLE TASK;
DROP TABLE WORKBASKET_ACCESS_LIST;

View File

@ -0,0 +1,3 @@
-- TASK_COMMENT TABLE ID , TASK_ID ,TEXTFIELD ,CREATOR ,COMPLETED ,MODIFIED
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');

View File

@ -0,0 +1,16 @@
-- TASK_COMMENT TABLE ID , TASK_ID ,TEXTFIELD ,CREATOR ,COMPLETED ,MODIFIED
-- 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');
-- 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');
-- 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');