Merge branch '121-reduce-paper-title' into 'dev'

Resolve "Сокращение названий статей в прикреплении"

Closes #121

See merge request romanov73/ng-tracker!89
This commit is contained in:
Anton Romanov 2019-05-13 06:54:49 +00:00
commit aaa21d591d
6 changed files with 25 additions and 25 deletions

View File

@ -13,7 +13,7 @@ import ru.ulstu.deadline.model.Deadline;
import ru.ulstu.grant.model.Grant; import ru.ulstu.grant.model.Grant;
import ru.ulstu.grant.model.GrantDto; import ru.ulstu.grant.model.GrantDto;
import ru.ulstu.grant.service.GrantService; import ru.ulstu.grant.service.GrantService;
import ru.ulstu.paper.model.Paper; import ru.ulstu.paper.model.PaperDto;
import ru.ulstu.user.model.User; import ru.ulstu.user.model.User;
import springfox.documentation.annotations.ApiIgnore; import springfox.documentation.annotations.ApiIgnore;
@ -104,7 +104,6 @@ public class GrantController {
return GRANT_PAGE; return GRANT_PAGE;
} }
@PostMapping(value = "/grant", params = "createProject") @PostMapping(value = "/grant", params = "createProject")
public String createProject(@Valid GrantDto grantDto, Errors errors) throws IOException { public String createProject(@Valid GrantDto grantDto, Errors errors) throws IOException {
if (errors.hasErrors()) { if (errors.hasErrors()) {
@ -131,7 +130,7 @@ public class GrantController {
} }
@ModelAttribute("allPapers") @ModelAttribute("allPapers")
public List<Paper> getAllPapers() { public List<PaperDto> getAllPapers() {
return grantService.getAllUncompletedPapers(); return grantService.getAllUncompletedPapers();
} }

View File

@ -74,7 +74,6 @@ public class Grant extends BaseEntity implements UserContainer {
@Fetch(FetchMode.SUBSELECT) @Fetch(FetchMode.SUBSELECT)
private List<FileData> files = new ArrayList<>(); private List<FileData> files = new ArrayList<>();
@ManyToOne(cascade = CascadeType.ALL) @ManyToOne(cascade = CascadeType.ALL)
@JoinColumn(name = "project_id") @JoinColumn(name = "project_id")
private Project project; private Project project;

View File

@ -6,7 +6,7 @@ import org.apache.commons.lang3.StringUtils;
import org.hibernate.validator.constraints.NotEmpty; import org.hibernate.validator.constraints.NotEmpty;
import ru.ulstu.deadline.model.Deadline; import ru.ulstu.deadline.model.Deadline;
import ru.ulstu.file.model.FileDataDto; import ru.ulstu.file.model.FileDataDto;
import ru.ulstu.paper.model.Paper; import ru.ulstu.paper.model.PaperDto;
import ru.ulstu.project.model.ProjectDto; import ru.ulstu.project.model.ProjectDto;
import ru.ulstu.user.model.UserDto; import ru.ulstu.user.model.UserDto;
@ -37,7 +37,7 @@ public class GrantDto {
private boolean hasBAKPapers; private boolean hasBAKPapers;
private boolean hasScopusPapers; private boolean hasScopusPapers;
private List<Integer> paperIds = new ArrayList<>(); private List<Integer> paperIds = new ArrayList<>();
private List<Paper> papers = new ArrayList<>(); private List<PaperDto> papers = new ArrayList<>();
private List<Integer> removedDeadlineIds = new ArrayList<>(); private List<Integer> removedDeadlineIds = new ArrayList<>();
public GrantDto() { public GrantDto() {
@ -54,12 +54,12 @@ public class GrantDto {
@JsonProperty("project") ProjectDto project, @JsonProperty("project") ProjectDto project,
@JsonProperty("authorIds") Set<Integer> authorIds, @JsonProperty("authorIds") Set<Integer> authorIds,
@JsonProperty("authors") Set<UserDto> authors, @JsonProperty("authors") Set<UserDto> authors,
@JsonProperty("leader") Integer leaderId, @JsonProperty("leaderId") Integer leaderId,
@JsonProperty("wasLeader") boolean wasLeader, @JsonProperty("wasLeader") boolean wasLeader,
@JsonProperty("hasAge") boolean hasAge, @JsonProperty("hasAge") boolean hasAge,
@JsonProperty("hasDegree") boolean hasDegree, @JsonProperty("hasDegree") boolean hasDegree,
@JsonProperty("paperIds") List<Integer> paperIds, @JsonProperty("paperIds") List<Integer> paperIds,
@JsonProperty("papers") List<Paper> papers) { @JsonProperty("papers") List<PaperDto> papers) {
this.id = id; this.id = id;
this.title = title; this.title = title;
this.status = status; this.status = status;
@ -92,7 +92,7 @@ public class GrantDto {
this.hasAge = false; this.hasAge = false;
this.hasDegree = false; this.hasDegree = false;
this.paperIds = convert(grant.getPapers(), paper -> paper.getId()); this.paperIds = convert(grant.getPapers(), paper -> paper.getId());
this.papers = grant.getPapers(); this.papers = convert(grant.getPapers(), PaperDto::new);
} }
public Integer getId() { public Integer getId() {
@ -214,11 +214,11 @@ public class GrantDto {
this.paperIds = paperIds; this.paperIds = paperIds;
} }
public List<Paper> getPapers() { public List<PaperDto> getPapers() {
return papers; return papers;
} }
public void setPapers(List<Paper> papers) { public void setPapers(List<PaperDto> papers) {
this.papers = papers; this.papers = papers;
} }

View File

@ -11,6 +11,7 @@ import ru.ulstu.grant.model.Grant;
import ru.ulstu.grant.model.GrantDto; import ru.ulstu.grant.model.GrantDto;
import ru.ulstu.grant.repository.GrantRepository; import ru.ulstu.grant.repository.GrantRepository;
import ru.ulstu.paper.model.Paper; import ru.ulstu.paper.model.Paper;
import ru.ulstu.paper.model.PaperDto;
import ru.ulstu.paper.service.PaperService; import ru.ulstu.paper.service.PaperService;
import ru.ulstu.project.model.Project; import ru.ulstu.project.model.Project;
import ru.ulstu.project.model.ProjectDto; import ru.ulstu.project.model.ProjectDto;
@ -34,7 +35,7 @@ import static ru.ulstu.grant.model.Grant.GrantStatus.APPLICATION;
@Service @Service
public class GrantService { public class GrantService {
private final static int MAX_DISPLAY_SIZE = 40; private final static int MAX_DISPLAY_SIZE = 50;
private final GrantRepository grantRepository; private final GrantRepository grantRepository;
private final ProjectService projectService; private final ProjectService projectService;
@ -210,17 +211,16 @@ public class GrantService {
.collect(toList()); .collect(toList());
} }
public List<Paper> getGrantPapers(List<Integer> paperIds) { public List<PaperDto> getGrantPapers(List<Integer> paperIds) {
return paperService.findAllSelect(paperIds); return paperService.findAllSelect(paperIds);
} }
public List<Paper> getAllPapers() { public List<PaperDto> getAllUncompletedPapers() {
return paperService.findAll(); List<PaperDto> papers = paperService.findAllNotCompleted();
} papers.stream()
.forEach(paper ->
public List<Paper> getAllUncompletedPapers() { paper.setTitle(StringUtils.abbreviate(paper.getTitle(), MAX_DISPLAY_SIZE)));
return paperService.findAllNotCompleted(); return papers;
} }
public void attachPaper(GrantDto grantDto) { public void attachPaper(GrantDto grantDto) {

View File

@ -248,12 +248,12 @@ public class PaperService {
} }
} }
public List<Paper> findAllNotCompleted() { public List<PaperDto> findAllNotCompleted() {
return paperRepository.findByStatusNot(COMPLETED); return convert(paperRepository.findByStatusNot(COMPLETED), PaperDto::new);
} }
public List<Paper> findAllSelect(List<Integer> paperIds) { public List<PaperDto> findAllSelect(List<Integer> paperIds) {
return sortPapers(paperRepository.findAllByIdIn(paperIds)); return convert(paperRepository.findAllByIdIn(paperIds), PaperDto::new);
} }
public List<User> getPaperAuthors() { public List<User> getPaperAuthors() {

View File

@ -184,9 +184,9 @@
value="Отобразить прикрепленную статью"/> value="Отобразить прикрепленную статью"/>
</div> </div>
<div class="row"> <div class="row">
<input th:type="hidden" th:field="*{papers}"/>
<div class="form-control list-group div-selected-papers" id="selected-papers"> <div class="form-control list-group div-selected-papers" id="selected-papers">
<div th:each="paper, rowStat : *{papers}"> <div th:each="paper, rowStat : *{papers}">
<input type="hidden" th:field="*{papers[__${rowStat.index}__].id}"/>
<div class="col"> <div class="col">
<a th:href="@{'/papers/paper?id=' + *{papers[__${rowStat.index}__].id} + ''}"> <a th:href="@{'/papers/paper?id=' + *{papers[__${rowStat.index}__].id} + ''}">
<img class="icon-paper" src="/img/conference/paper.png"/> <img class="icon-paper" src="/img/conference/paper.png"/>
@ -201,6 +201,7 @@
Статус статьи Статус статьи
</span> </span>
</div> </div>
<!--
<div class="col" th:unless="${#lists.isEmpty(paper.grants)}"> <div class="col" th:unless="${#lists.isEmpty(paper.grants)}">
<label>Гранты: </label> <label>Гранты: </label>
<div th:each="grant, grantRowStat : *{papers[__${rowStat.index}__].grants}" <div th:each="grant, grantRowStat : *{papers[__${rowStat.index}__].grants}"
@ -225,6 +226,7 @@
</li> </li>
</div> </div>
</div> </div>
-->
</div> </div>
</div> </div>
</div> </div>