fix: limit author name to 255 characters as in table (#801)
This commit is contained in:
+3
-1
@@ -56,13 +56,15 @@ public class BookCreatorService {
|
|||||||
bookEntity.getMetadata().setAuthors(new HashSet<>());
|
bookEntity.getMetadata().setAuthors(new HashSet<>());
|
||||||
}
|
}
|
||||||
authors.stream()
|
authors.stream()
|
||||||
|
.map(authorName -> truncate(authorName, 255))
|
||||||
.map(authorName -> authorRepository.findByName(authorName)
|
.map(authorName -> authorRepository.findByName(authorName)
|
||||||
.orElseGet(() -> authorRepository.save(AuthorEntity.builder().name(authorName).build())))
|
.orElseGet(() -> authorRepository.save(AuthorEntity.builder().name(authorName).build())))
|
||||||
.forEach(authorEntity -> bookEntity.getMetadata().getAuthors().add(authorEntity));
|
.forEach(authorEntity -> bookEntity.getMetadata().getAuthors().add(authorEntity));
|
||||||
}
|
}
|
||||||
|
|
||||||
private String truncate(String input, int maxLength) {
|
private String truncate(String input, int maxLength) {
|
||||||
if (input == null) return null;
|
if (input == null)
|
||||||
|
return null;
|
||||||
return input.length() <= maxLength ? input : input.substring(0, maxLength);
|
return input.length() <= maxLength ? input : input.substring(0, maxLength);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user