Merge branch 'RED-7185' into 'master'

RED-7185 - Fix comment too long

Closes RED-7185

See merge request redactmanager/persistence-service!138
This commit is contained in:
Corina Olariu 2023-09-25 10:27:15 +02:00
commit 6cdd2178f1

View File

@ -6,10 +6,12 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; 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.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.FileStatusPersistenceService;
import com.iqser.red.service.persistence.management.v1.processor.service.persistence.annotations.CommentPersistenceService; 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; import com.iqser.red.service.persistence.service.v1.api.shared.model.annotations.Comment;
@ -34,6 +36,7 @@ public class CommentService {
FileStatusService fileStatusService; FileStatusService fileStatusService;
RedactionLogService redactionLogService; RedactionLogService redactionLogService;
FileManagementStorageService fileManagementStorageService; FileManagementStorageService fileManagementStorageService;
private final int COMMENT_MAX_LENGTH = 4000;
@Transactional @Transactional
@ -73,6 +76,7 @@ public class CommentService {
@Transactional @Transactional
public CommentEntity addComment(String dossierId, String fileId, String annotationId, CommentRequest commentRequest) { public CommentEntity addComment(String dossierId, String fileId, String annotationId, CommentRequest commentRequest) {
checkComment(commentRequest.getText());
CommentEntity createdComment = addComment(fileId, annotationId, commentRequest.getText(), commentRequest.getUser()); CommentEntity createdComment = addComment(fileId, annotationId, commentRequest.getText(), commentRequest.getUser());
fileStatusPersistenceService.updateHasComments(fileId, true); fileStatusPersistenceService.updateHasComments(fileId, true);
@ -94,6 +98,12 @@ public class CommentService {
return createdComment; 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) { public Long addCommentAndGetId(String fileId, String annotationId, String comment, String user) {