|
|
|
@ -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<Paper.PaperStatus> getPaperStatuses() {
|
|
|
|
|
return paperService.getPaperStatuses();
|
|
|
|
@ -140,29 +123,6 @@ public class PaperController {
|
|
|
|
|
return years;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ModelAttribute("allFormatStandards")
|
|
|
|
|
public List<ReferenceDto.FormatStandard> getFormatStandards() {
|
|
|
|
|
return paperService.getFormatStandards();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ModelAttribute("allReferenceTypes")
|
|
|
|
|
public List<ReferenceDto.ReferenceType> getReferenceTypes() {
|
|
|
|
|
return paperService.getReferenceTypes();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@PostMapping("/generatePdf")
|
|
|
|
|
public ResponseEntity<byte[]> 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<String> 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()));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|