From e6b4ed9f2ccaf6f621efb480f55d919be866479a Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Thu, 2 May 2024 19:16:18 +0400 Subject: [PATCH] #247 -- Fix paper dates --- .../paper/controller/PaperController.java | 44 +------------------ src/main/java/ru/ulstu/paper/model/Paper.java | 3 ++ .../java/ru/ulstu/paper/model/PaperDto.java | 3 ++ .../ru/ulstu/paper/service/PaperService.java | 2 +- .../resources/templates/papers/paper.html | 2 + 5 files changed, 11 insertions(+), 43 deletions(-) diff --git a/src/main/java/ru/ulstu/paper/controller/PaperController.java b/src/main/java/ru/ulstu/paper/controller/PaperController.java index e2b85f2..2d92a93 100644 --- a/src/main/java/ru/ulstu/paper/controller/PaperController.java +++ b/src/main/java/ru/ulstu/paper/controller/PaperController.java @@ -2,9 +2,6 @@ package ru.ulstu.paper.controller; import io.swagger.v3.oas.annotations.Hidden; import jakarta.validation.Valid; -import org.springframework.http.HttpHeaders; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Controller; import org.springframework.ui.ModelMap; import org.springframework.validation.Errors; @@ -19,21 +16,16 @@ import ru.ulstu.paper.model.AutoCompleteData; import ru.ulstu.paper.model.Paper; import ru.ulstu.paper.model.PaperDto; import ru.ulstu.paper.model.PaperListDto; -import ru.ulstu.paper.model.ReferenceDto; import ru.ulstu.paper.service.LatexService; import ru.ulstu.paper.service.PaperService; import ru.ulstu.user.model.User; import java.io.IOException; -import java.net.URLEncoder; import java.util.ArrayList; import java.util.Calendar; import java.util.List; import java.util.stream.Collectors; -import static java.nio.charset.StandardCharsets.UTF_8; -import static org.springframework.util.StringUtils.isEmpty; - @Controller() @RequestMapping(value = "/papers") @@ -76,7 +68,7 @@ public class PaperController { } @GetMapping("/paper") - public void getPapers(ModelMap modelMap, @RequestParam(value = "id") Integer id) { + public void getPaper(ModelMap modelMap, @RequestParam(value = "id") Integer id) { if (id != null && id > 0) { modelMap.put("paperDto", paperService.findOneDto(id)); } else { @@ -107,15 +99,6 @@ public class PaperController { return "/papers/paper"; } - @PostMapping(value = "/paper", params = "addReference") - public String addReference(@Valid PaperDto paperDto, Errors errors) { - if (errors.hasErrors()) { - return "/papers/paper"; - } - paperDto.getReferences().add(new ReferenceDto()); - return "/papers/paper"; - } - @ModelAttribute("allStatuses") public List getPaperStatuses() { return paperService.getPaperStatuses(); @@ -140,29 +123,6 @@ public class PaperController { return years; } - @ModelAttribute("allFormatStandards") - public List getFormatStandards() { - return paperService.getFormatStandards(); - } - - @ModelAttribute("allReferenceTypes") - public List getReferenceTypes() { - return paperService.getReferenceTypes(); - } - - @PostMapping("/generatePdf") - public ResponseEntity getPdfFile(PaperDto paper) throws IOException, InterruptedException { - HttpHeaders headers = new HttpHeaders(); - headers.add("Content-Disposition", "attachment; filename='" + - URLEncoder.encode(paper.getTitle() + ".pdf", UTF_8.toString()) + "'"); - return new ResponseEntity<>(latexService.generatePdfFromLatexFile(paper), headers, HttpStatus.OK); - } - - @PostMapping("/getFormattedReferences") - public ResponseEntity getFormattedReferences(PaperDto paperDto) { - return new ResponseEntity<>(paperService.getFormattedReferences(paperDto), new HttpHeaders(), HttpStatus.OK); - } - @ModelAttribute("autocompleteData") public AutoCompleteData getAutocompleteData() { return paperService.getAutoCompleteData(); @@ -170,7 +130,7 @@ public class PaperController { private void filterEmptyDeadlines(PaperDto paperDto) { paperDto.setDeadlines(paperDto.getDeadlines().stream() - .filter(dto -> dto.getDate() != null || !isEmpty(dto.getDescription())) + .filter(dto -> dto.getDate() != null || !dto.getDescription().isEmpty()) .collect(Collectors.toList())); } } diff --git a/src/main/java/ru/ulstu/paper/model/Paper.java b/src/main/java/ru/ulstu/paper/model/Paper.java index 74141f9..d525fa7 100644 --- a/src/main/java/ru/ulstu/paper/model/Paper.java +++ b/src/main/java/ru/ulstu/paper/model/Paper.java @@ -17,6 +17,7 @@ import jakarta.persistence.TemporalType; import jakarta.validation.constraints.NotBlank; import org.hibernate.annotations.Fetch; import org.hibernate.annotations.FetchMode; +import org.springframework.format.annotation.DateTimeFormat; import ru.ulstu.conference.model.Conference; import ru.ulstu.core.model.BaseEntity; import ru.ulstu.core.model.EventSource; @@ -94,10 +95,12 @@ public class Paper extends BaseEntity implements UserActivity, EventSource { @Column(name = "create_date") @Temporal(TemporalType.TIMESTAMP) + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss.SSSXXX") private Date createDate = new Date(); @Column(name = "update_date") @Temporal(TemporalType.TIMESTAMP) + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss.SSSXXX") private Date updateDate = new Date(); @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY) diff --git a/src/main/java/ru/ulstu/paper/model/PaperDto.java b/src/main/java/ru/ulstu/paper/model/PaperDto.java index 96d2e75..f2dbcb3 100644 --- a/src/main/java/ru/ulstu/paper/model/PaperDto.java +++ b/src/main/java/ru/ulstu/paper/model/PaperDto.java @@ -5,6 +5,7 @@ import com.fasterxml.jackson.annotation.JsonProperty; import jakarta.validation.constraints.NotEmpty; import jakarta.validation.constraints.Size; import org.apache.commons.lang3.StringUtils; +import org.springframework.format.annotation.DateTimeFormat; import ru.ulstu.core.model.BaseEntity; import ru.ulstu.deadline.model.Deadline; import ru.ulstu.file.model.FileDataDto; @@ -27,7 +28,9 @@ public class PaperDto { private String title; private Paper.PaperStatus status; private Paper.PaperType type; + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss.SSSXXX") private Date createDate; + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss.SSSXXX") private Date updateDate; @NotEmpty private List deadlines = new ArrayList<>(); diff --git a/src/main/java/ru/ulstu/paper/service/PaperService.java b/src/main/java/ru/ulstu/paper/service/PaperService.java index 9e02113..e53f41d 100644 --- a/src/main/java/ru/ulstu/paper/service/PaperService.java +++ b/src/main/java/ru/ulstu/paper/service/PaperService.java @@ -103,7 +103,7 @@ public class PaperService { } public PaperDto findOneDto(Integer id) { - return new PaperDto(paperRepository.getOne(id)); + return new PaperDto(paperRepository.findById(id).orElseThrow()); } @Transactional diff --git a/src/main/resources/templates/papers/paper.html b/src/main/resources/templates/papers/paper.html index 6820984..1343b13 100644 --- a/src/main/resources/templates/papers/paper.html +++ b/src/main/resources/templates/papers/paper.html @@ -32,6 +32,8 @@
+ +