diff --git a/persistence-service-v1/persistence-service-processor-v1/src/main/java/com/iqser/red/service/persistence/management/v1/processor/service/CommentService.java b/persistence-service-v1/persistence-service-processor-v1/src/main/java/com/iqser/red/service/persistence/management/v1/processor/service/CommentService.java index f5d5916ba..794d2d042 100644 --- a/persistence-service-v1/persistence-service-processor-v1/src/main/java/com/iqser/red/service/persistence/management/v1/processor/service/CommentService.java +++ b/persistence-service-v1/persistence-service-processor-v1/src/main/java/com/iqser/red/service/persistence/management/v1/processor/service/CommentService.java @@ -6,10 +6,12 @@ import java.util.List; import java.util.Map; import java.util.stream.Collectors; +import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import com.iqser.red.service.persistence.management.v1.processor.entity.annotations.CommentEntity; +import com.iqser.red.service.persistence.management.v1.processor.exception.BadRequestException; import com.iqser.red.service.persistence.management.v1.processor.service.persistence.FileStatusPersistenceService; import com.iqser.red.service.persistence.management.v1.processor.service.persistence.annotations.CommentPersistenceService; import com.iqser.red.service.persistence.service.v1.api.shared.model.annotations.Comment; @@ -34,6 +36,7 @@ public class CommentService { FileStatusService fileStatusService; RedactionLogService redactionLogService; FileManagementStorageService fileManagementStorageService; + private final int COMMENT_MAX_LENGTH = 4000; @Transactional @@ -73,6 +76,7 @@ public class CommentService { @Transactional public CommentEntity addComment(String dossierId, String fileId, String annotationId, CommentRequest commentRequest) { + checkComment(commentRequest.getText()); CommentEntity createdComment = addComment(fileId, annotationId, commentRequest.getText(), commentRequest.getUser()); fileStatusPersistenceService.updateHasComments(fileId, true); @@ -94,6 +98,12 @@ public class CommentService { return createdComment; } + private void checkComment(String text) { + + if (!StringUtils.isEmpty(text) && text.length() >= COMMENT_MAX_LENGTH) { + throw new BadRequestException(String.format("The comment is too long (%s), max length %s", text.length(), COMMENT_MAX_LENGTH)); + } + } public Long addCommentAndGetId(String fileId, String annotationId, String comment, String user) {