From 469a3ad07d0e1964a3c12802130ebfd5bd9bd0ff Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Fri, 21 Dec 2018 00:07:26 +0400 Subject: [PATCH] fix display paper title --- src/main/java/ru/ulstu/paper/model/PaperDto.java | 9 ++++++--- src/main/java/ru/ulstu/paper/service/PaperService.java | 7 ++++++- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/main/java/ru/ulstu/paper/model/PaperDto.java b/src/main/java/ru/ulstu/paper/model/PaperDto.java index 139cc3a..545b432 100644 --- a/src/main/java/ru/ulstu/paper/model/PaperDto.java +++ b/src/main/java/ru/ulstu/paper/model/PaperDto.java @@ -2,6 +2,7 @@ package ru.ulstu.paper.model; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; +import org.apache.commons.lang3.StringUtils; import org.hibernate.validator.constraints.NotEmpty; import ru.ulstu.deadline.model.DeadlineDto; import ru.ulstu.user.model.UserDto; @@ -16,9 +17,11 @@ import java.util.stream.Collectors; import static ru.ulstu.core.util.StreamApiUtils.convert; public class PaperDto { + private final static int MAX_AUTHORS_LENGTH = 60; + private Integer id; @NotEmpty - @Size(min = 3, max = 100) + @Size(min = 3, max = 254) private String title; private Paper.PaperStatus status; private Date createDate; @@ -196,10 +199,10 @@ public class PaperDto { } public String getAuthorsString() { - return authors + return StringUtils.abbreviate(authors .stream() .map(author -> author.getLastName()) - .collect(Collectors.joining(", ")); + .collect(Collectors.joining(", ")), MAX_AUTHORS_LENGTH); } public Integer getFilterAuthorId() { diff --git a/src/main/java/ru/ulstu/paper/service/PaperService.java b/src/main/java/ru/ulstu/paper/service/PaperService.java index bfb70c3..affbf0e 100644 --- a/src/main/java/ru/ulstu/paper/service/PaperService.java +++ b/src/main/java/ru/ulstu/paper/service/PaperService.java @@ -1,5 +1,6 @@ package ru.ulstu.paper.service; +import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import ru.ulstu.deadline.model.Deadline; @@ -28,6 +29,8 @@ import static ru.ulstu.paper.model.Paper.PaperStatus.ON_PREPARATION; @Service public class PaperService { + private final static int MAX_DISPLAY_SIZE = 40; + private final PaperNotificationService paperNotificationService; private final PaperRepository paperRepository; private final UserService userService; @@ -51,7 +54,9 @@ public class PaperService { } public List findAllDto() { - return convert(findAll(), PaperDto::new); + List papers = convert(findAll(), PaperDto::new); + papers.forEach(paperDto -> paperDto.setTitle(StringUtils.abbreviate(paperDto.getTitle(), MAX_DISPLAY_SIZE))); + return papers; } public PaperDto findOneDto(Integer id) {