-- reduce code to more clarity (some features where disabled)
-- some refactor -- add pagination for entities
This commit is contained in:
parent
a9fb97bd2e
commit
56d8098a01
15
src/main/java/ru/ulstu/boundary/model/AbstractActivity.java
Normal file
15
src/main/java/ru/ulstu/boundary/model/AbstractActivity.java
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
package ru.ulstu.boundary.model;
|
||||||
|
|
||||||
|
import ru.ulstu.core.model.BaseEntity;
|
||||||
|
|
||||||
|
public abstract class AbstractActivity extends BaseEntity {
|
||||||
|
private String title;
|
||||||
|
|
||||||
|
public String getTitle() {
|
||||||
|
return title;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTitle(String title) {
|
||||||
|
this.title = title;
|
||||||
|
}
|
||||||
|
}
|
4
src/main/java/ru/ulstu/boundary/model/ActivityDto.java
Normal file
4
src/main/java/ru/ulstu/boundary/model/ActivityDto.java
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
package ru.ulstu.boundary.model;
|
||||||
|
|
||||||
|
public interface ActivityDto {
|
||||||
|
}
|
@ -0,0 +1,4 @@
|
|||||||
|
package ru.ulstu.boundary.model;
|
||||||
|
|
||||||
|
public interface ActivityListDto {
|
||||||
|
}
|
@ -0,0 +1,29 @@
|
|||||||
|
package ru.ulstu.boundary.service;
|
||||||
|
|
||||||
|
import ru.ulstu.boundary.model.AbstractActivity;
|
||||||
|
import ru.ulstu.boundary.model.ActivityDto;
|
||||||
|
import ru.ulstu.boundary.model.ActivityListDto;
|
||||||
|
import ru.ulstu.core.model.response.PageableItems;
|
||||||
|
|
||||||
|
import static ru.ulstu.core.util.StreamApiUtils.convertPageable;
|
||||||
|
|
||||||
|
public abstract class AbstractActivityService<T extends AbstractActivity, D extends ActivityDto, L extends ActivityListDto> {
|
||||||
|
|
||||||
|
public abstract T create(T entity);
|
||||||
|
|
||||||
|
public abstract D create(D entity);
|
||||||
|
|
||||||
|
public abstract T update(T entity);
|
||||||
|
|
||||||
|
public abstract D update(D entity);
|
||||||
|
|
||||||
|
public abstract boolean delete(Integer id);
|
||||||
|
|
||||||
|
public abstract PageableItems<T> findAll(int offset, int count);
|
||||||
|
|
||||||
|
public PageableItems<L> findAllDto(int offset, int count) {
|
||||||
|
return convertPageable(findAll(offset, count), entity -> getActivityListDto(entity));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract L getActivityListDto(T entity);
|
||||||
|
}
|
@ -11,7 +11,7 @@ public class OffsetablePageRequest implements Pageable, Serializable {
|
|||||||
private final Sort sort;
|
private final Sort sort;
|
||||||
|
|
||||||
public OffsetablePageRequest(long offset, int count) {
|
public OffsetablePageRequest(long offset, int count) {
|
||||||
this(offset, count, null);
|
this(offset, count, Sort.unsorted());
|
||||||
}
|
}
|
||||||
|
|
||||||
public OffsetablePageRequest(long offset, int count, Sort.Direction direction, String... properties) {
|
public OffsetablePageRequest(long offset, int count, Sort.Direction direction, String... properties) {
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package ru.ulstu.core.util;
|
package ru.ulstu.core.util;
|
||||||
|
|
||||||
|
import ru.ulstu.core.model.response.PageableItems;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
@ -19,4 +21,10 @@ public class StreamApiUtils {
|
|||||||
? Collections.emptySet()
|
? Collections.emptySet()
|
||||||
: entities.stream().map(converter).collect(Collectors.toSet());
|
: entities.stream().map(converter).collect(Collectors.toSet());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static <T, R> PageableItems<T> convertPageable(PageableItems<R> pageableEntities, Function<R, T> converter) {
|
||||||
|
return pageableEntities == null
|
||||||
|
? new PageableItems<>(0, Collections.emptyList())
|
||||||
|
: new PageableItems<>(pageableEntities.getCount(), convert((List) pageableEntities.getItems(), converter));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,6 +11,7 @@ import javax.persistence.FetchType;
|
|||||||
import javax.persistence.OneToMany;
|
import javax.persistence.OneToMany;
|
||||||
import javax.persistence.Temporal;
|
import javax.persistence.Temporal;
|
||||||
import javax.persistence.TemporalType;
|
import javax.persistence.TemporalType;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
@ -24,8 +25,8 @@ public class Deadline extends BaseEntity {
|
|||||||
@DateTimeFormat(pattern = "yyyy-MM-dd")
|
@DateTimeFormat(pattern = "yyyy-MM-dd")
|
||||||
private Date date;
|
private Date date;
|
||||||
|
|
||||||
@OneToMany(targetEntity = User.class, fetch = FetchType.EAGER)
|
@OneToMany(targetEntity = User.class, fetch = FetchType.LAZY)
|
||||||
private List<User> executors;
|
private List<User> executors = new ArrayList<>();
|
||||||
|
|
||||||
private Boolean done;
|
private Boolean done;
|
||||||
|
|
||||||
|
@ -38,13 +38,7 @@ public class DeadlineService {
|
|||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public Deadline create(Deadline deadline) {
|
public Deadline create(Deadline deadline) {
|
||||||
Deadline newDeadline = new Deadline();
|
return deadlineRepository.save(deadline);
|
||||||
newDeadline.setDate(deadline.getDate());
|
|
||||||
newDeadline.setDescription(deadline.getDescription());
|
|
||||||
newDeadline.setExecutors(deadline.getExecutors());
|
|
||||||
newDeadline.setDone(deadline.getDone());
|
|
||||||
newDeadline = deadlineRepository.save(newDeadline);
|
|
||||||
return newDeadline;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
|
@ -9,13 +9,9 @@ import ru.ulstu.grant.service.GrantService;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.text.ParseException;
|
import java.text.ParseException;
|
||||||
|
|
||||||
import static ru.ulstu.paper.controller.PaperRestController.URL;
|
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping(URL)
|
@RequestMapping(Constants.API_1_0 + "grants")
|
||||||
public class GrantRestController {
|
public class GrantRestController {
|
||||||
public static final String URL = Constants.API_1_0 + "grants";
|
|
||||||
|
|
||||||
private final GrantService grantService;
|
private final GrantService grantService;
|
||||||
|
|
||||||
public GrantRestController(GrantService grantService) {
|
public GrantRestController(GrantService grantService) {
|
||||||
|
@ -1,155 +1,87 @@
|
|||||||
package ru.ulstu.paper.controller;
|
package ru.ulstu.paper.controller;
|
||||||
|
|
||||||
import org.springframework.http.HttpHeaders;
|
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||||
import org.springframework.http.HttpStatus;
|
|
||||||
import org.springframework.http.ResponseEntity;
|
|
||||||
import org.springframework.ui.ModelMap;
|
|
||||||
import org.springframework.validation.Errors;
|
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.ModelAttribute;
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PutMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
import ru.ulstu.conference.service.ConferenceService;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
import ru.ulstu.deadline.model.Deadline;
|
import ru.ulstu.configuration.Constants;
|
||||||
import ru.ulstu.paper.model.AutoCompleteData;
|
import ru.ulstu.core.model.response.PageableItems;
|
||||||
|
import ru.ulstu.core.model.response.Response;
|
||||||
|
import ru.ulstu.paper.model.PaperDashboardDto;
|
||||||
import ru.ulstu.paper.model.PaperDto;
|
import ru.ulstu.paper.model.PaperDto;
|
||||||
import ru.ulstu.paper.model.PaperFilterListDto;
|
import ru.ulstu.paper.model.PaperListDto;
|
||||||
import ru.ulstu.paper.model.ReferenceDto;
|
import ru.ulstu.paper.model.PaperStatusDto;
|
||||||
import ru.ulstu.paper.service.LatexService;
|
import ru.ulstu.paper.model.PaperTypeDto;
|
||||||
import ru.ulstu.paper.service.PaperService;
|
import ru.ulstu.paper.service.PaperService;
|
||||||
import springfox.documentation.annotations.ApiIgnore;
|
import ru.ulstu.user.model.User;
|
||||||
|
|
||||||
import javax.validation.Valid;
|
import javax.validation.Valid;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URLEncoder;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Calendar;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
@RestController
|
||||||
import static org.springframework.util.StringUtils.isEmpty;
|
@RequestMapping(Constants.API_1_0 + "papers")
|
||||||
|
|
||||||
|
|
||||||
@ApiIgnore
|
|
||||||
public class PaperController {
|
public class PaperController {
|
||||||
private final PaperService paperService;
|
private final PaperService paperService;
|
||||||
private final ConferenceService conferenceService;
|
|
||||||
private final LatexService latexService;
|
|
||||||
|
|
||||||
public PaperController(PaperService paperService,
|
public PaperController(PaperService paperService) {
|
||||||
ConferenceService conferenceService,
|
|
||||||
LatexService latexService) {
|
|
||||||
this.paperService = paperService;
|
this.paperService = paperService;
|
||||||
this.conferenceService = conferenceService;
|
|
||||||
this.latexService = latexService;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/papers")
|
@GetMapping("list")
|
||||||
public void getPapers(ModelMap modelMap) {
|
public Response<PageableItems<PaperListDto>> getPapers(@RequestParam(value = "offset", defaultValue = "0") int offset,
|
||||||
modelMap.put("filteredPapers", new PaperFilterListDto(paperService.findAllDto(), null, null));
|
@RequestParam(value = "count", defaultValue = "10") int count) {
|
||||||
|
return new Response<>(paperService.findAllDto(offset, count));
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/papers")
|
@GetMapping("dashboard")
|
||||||
public void listPapers(@Valid PaperFilterListDto paperFilterListDto, ModelMap modelMap) {
|
public Response<PageableItems<PaperDashboardDto>> getDashboard(@RequestParam(value = "offset", defaultValue = "0") int offset,
|
||||||
if (paperFilterListDto.getPaperDeleteId() != null) {
|
@RequestParam(value = "count", defaultValue = "10") int count) {
|
||||||
if (conferenceService.isAttachedToConference(paperFilterListDto.getPaperDeleteId())) {
|
return new Response<>(paperService.findAllActiveDto(offset, count));
|
||||||
modelMap.put("flashMessage", "Статью нельзя удалить, она прикреплена к конференции");
|
|
||||||
} else {
|
|
||||||
paperService.delete(paperFilterListDto.getPaperDeleteId());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
modelMap.put("filteredPapers", new PaperFilterListDto(paperService.filter(paperFilterListDto),
|
|
||||||
paperFilterListDto.getFilterAuthorId(),
|
|
||||||
paperFilterListDto.getYear()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/dashboard")
|
@GetMapping("{paper-id}")
|
||||||
public void getDashboard(ModelMap modelMap) {
|
public Response<PaperDto> getPaper(@PathVariable("paper-id") Integer paperId) {
|
||||||
modelMap.put("papers", paperService.findAllActiveDto());
|
return new Response<>(paperService.findById(paperId));
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/paper")
|
@PostMapping
|
||||||
public void getPapers(ModelMap modelMap, @RequestParam(value = "id") Integer id) {
|
public Response<PaperDto> createPaper(@RequestBody @Valid PaperDto paperDto) {
|
||||||
if (id != null && id > 0) {
|
return new Response<>(paperService.create(paperDto));
|
||||||
modelMap.put("paperDto", paperService.findOneDto(id));
|
|
||||||
} else {
|
|
||||||
modelMap.put("paperDto", new PaperDto());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping(value = "/paper", params = "save")
|
@PutMapping
|
||||||
public String save(@Valid PaperDto paperDto, Errors errors) throws IOException {
|
public Response<PaperDto> updatePaper(@RequestBody @Valid PaperDto paperDto) {
|
||||||
filterEmptyDeadlines(paperDto);
|
return new Response<>(paperService.update(paperDto));
|
||||||
if (paperDto.getDeadlines().isEmpty()) {
|
|
||||||
errors.rejectValue("deadlines", "errorCode", "Не может быть пустым");
|
|
||||||
}
|
|
||||||
if (errors.hasErrors()) {
|
|
||||||
return "/papers/paper";
|
|
||||||
}
|
|
||||||
paperService.save(paperDto);
|
|
||||||
return "redirect:/papers/papers";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping(value = "/paper", params = "addDeadline")
|
@DeleteMapping("/{paper-id}")
|
||||||
public String addDeadline(@Valid PaperDto paperDto, Errors errors) {
|
public Response<Boolean> delete(@PathVariable("paper-id") Integer paperId) {
|
||||||
filterEmptyDeadlines(paperDto);
|
return new Response<>(paperService.delete(paperId));
|
||||||
if (errors.hasErrors()) {
|
|
||||||
return "/papers/paper";
|
|
||||||
}
|
|
||||||
paperDto.getDeadlines().add(new Deadline());
|
|
||||||
return "/papers/paper";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping(value = "/paper", params = "addReference")
|
@PostMapping("ping/{paper-id}")
|
||||||
public String addReference(@Valid PaperDto paperDto, Errors errors) {
|
public void ping(@PathVariable("paper-id") int paperId) throws IOException {
|
||||||
if (errors.hasErrors()) {
|
paperService.ping(paperId);
|
||||||
return "/papers/paper";
|
|
||||||
}
|
|
||||||
paperDto.getReferences().add(new ReferenceDto());
|
|
||||||
return "/papers/paper";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ModelAttribute("allYears")
|
@GetMapping("allAuthors")
|
||||||
public List<Integer> getAllYears() {
|
public Response<List<User>> getAllAuthors() {
|
||||||
List<Integer> years = new ArrayList<>();
|
return new Response<>(paperService.getPaperAuthors());
|
||||||
for (int i = Calendar.getInstance().get(Calendar.YEAR); i > 2010; i--) {
|
|
||||||
years.add(i);
|
|
||||||
}
|
|
||||||
return years;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ModelAttribute("allFormatStandards")
|
@GetMapping("allTypes")
|
||||||
public List<ReferenceDto.FormatStandard> getFormatStandards() {
|
public Response<List<PaperTypeDto>> getPaperTypes() {
|
||||||
return paperService.getFormatStandards();
|
return new Response<>(paperService.getPaperTypes());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ModelAttribute("allReferenceTypes")
|
@GetMapping("allStatuses")
|
||||||
public List<ReferenceDto.ReferenceType> getReferenceTypes() {
|
public Response<List<PaperStatusDto>> getPaperStatuses() {
|
||||||
return paperService.getReferenceTypes();
|
return new Response<>(paperService.getPaperStatuses());
|
||||||
}
|
|
||||||
|
|
||||||
@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();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void filterEmptyDeadlines(PaperDto paperDto) {
|
|
||||||
paperDto.setDeadlines(paperDto.getDeadlines().stream()
|
|
||||||
.filter(dto -> dto.getDate() != null || !isEmpty(dto.getDescription()))
|
|
||||||
.collect(Collectors.toList()));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,100 +0,0 @@
|
|||||||
package ru.ulstu.paper.controller;
|
|
||||||
|
|
||||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
|
||||||
import org.springframework.web.bind.annotation.PathVariable;
|
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
|
||||||
import org.springframework.web.bind.annotation.PutMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RequestBody;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
import ru.ulstu.configuration.Constants;
|
|
||||||
import ru.ulstu.core.model.response.Response;
|
|
||||||
import ru.ulstu.paper.model.PaperDashboardDto;
|
|
||||||
import ru.ulstu.paper.model.PaperDto;
|
|
||||||
import ru.ulstu.paper.model.PaperListDto;
|
|
||||||
import ru.ulstu.paper.model.PaperStatusDto;
|
|
||||||
import ru.ulstu.paper.model.PaperTypeDto;
|
|
||||||
import ru.ulstu.paper.model.ReferenceDto;
|
|
||||||
import ru.ulstu.paper.service.PaperService;
|
|
||||||
import ru.ulstu.user.model.User;
|
|
||||||
|
|
||||||
import javax.validation.Valid;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import static ru.ulstu.paper.controller.PaperRestController.URL;
|
|
||||||
|
|
||||||
@RestController
|
|
||||||
@RequestMapping(URL)
|
|
||||||
public class PaperRestController {
|
|
||||||
public static final String URL = Constants.API_1_0 + "papers";
|
|
||||||
|
|
||||||
private final PaperService paperService;
|
|
||||||
|
|
||||||
public PaperRestController(PaperService paperService) {
|
|
||||||
this.paperService = paperService;
|
|
||||||
}
|
|
||||||
|
|
||||||
@GetMapping
|
|
||||||
public Response<List<PaperListDto>> getPapers() {
|
|
||||||
return new Response<>(paperService.findAllDto());
|
|
||||||
}
|
|
||||||
|
|
||||||
@GetMapping("/dashboard")
|
|
||||||
public Response<List<PaperDashboardDto>> getDashboard() {
|
|
||||||
return new Response<>(paperService.findAllActiveDto());
|
|
||||||
}
|
|
||||||
|
|
||||||
@GetMapping("/{paper-id}")
|
|
||||||
public Response<PaperDto> getPaper(@PathVariable("paper-id") Integer paperId) {
|
|
||||||
return new Response<>(paperService.findById(paperId));
|
|
||||||
}
|
|
||||||
|
|
||||||
@PostMapping
|
|
||||||
public Response<Integer> createPaper(@RequestBody @Valid PaperDto paperDto) throws IOException {
|
|
||||||
return new Response<>(paperService.create(paperDto));
|
|
||||||
}
|
|
||||||
|
|
||||||
@PutMapping
|
|
||||||
public Response<Integer> updatePaper(@RequestBody @Valid PaperDto paperDto) throws IOException {
|
|
||||||
return new Response<>(paperService.update(paperDto));
|
|
||||||
}
|
|
||||||
|
|
||||||
@DeleteMapping("/{paper-id}")
|
|
||||||
public Response<Boolean> delete(@PathVariable("paper-id") Integer paperId) throws IOException {
|
|
||||||
paperService.delete(paperId);
|
|
||||||
return new Response<>(Boolean.TRUE);
|
|
||||||
}
|
|
||||||
|
|
||||||
@GetMapping("formatted-list")
|
|
||||||
public Response<List<String>> getFormattedPaperList() {
|
|
||||||
return new Response<>(paperService.getFormattedPaperList());
|
|
||||||
}
|
|
||||||
|
|
||||||
@PostMapping("/getFormattedReference")
|
|
||||||
public Response<String> getFormattedReference(@RequestBody @Valid ReferenceDto referenceDto) {
|
|
||||||
return new Response<>(paperService.getFormattedReference(referenceDto));
|
|
||||||
}
|
|
||||||
|
|
||||||
@PostMapping(value = "/ping")
|
|
||||||
public void ping(@RequestParam("paperId") int paperId) throws IOException {
|
|
||||||
paperService.ping(paperId);
|
|
||||||
}
|
|
||||||
|
|
||||||
@GetMapping("/allAuthors")
|
|
||||||
public Response<List<User>> getAllAuthors() {
|
|
||||||
return new Response<>(paperService.getPaperAuthors());
|
|
||||||
}
|
|
||||||
|
|
||||||
@GetMapping("/allTypes")
|
|
||||||
public Response<List<PaperTypeDto>> getPaperTypes() {
|
|
||||||
return new Response<>(paperService.getPaperTypes());
|
|
||||||
}
|
|
||||||
|
|
||||||
@GetMapping("/allStatuses")
|
|
||||||
public Response<List<PaperStatusDto>> getPaperStatuses() {
|
|
||||||
return new Response<>(paperService.getPaperStatuses());
|
|
||||||
}
|
|
||||||
}
|
|
@ -2,8 +2,8 @@ package ru.ulstu.paper.model;
|
|||||||
|
|
||||||
import org.hibernate.annotations.Fetch;
|
import org.hibernate.annotations.Fetch;
|
||||||
import org.hibernate.annotations.FetchMode;
|
import org.hibernate.annotations.FetchMode;
|
||||||
|
import ru.ulstu.boundary.model.AbstractActivity;
|
||||||
import ru.ulstu.conference.model.Conference;
|
import ru.ulstu.conference.model.Conference;
|
||||||
import ru.ulstu.core.model.BaseEntity;
|
|
||||||
import ru.ulstu.core.model.EventSource;
|
import ru.ulstu.core.model.EventSource;
|
||||||
import ru.ulstu.core.model.UserActivity;
|
import ru.ulstu.core.model.UserActivity;
|
||||||
import ru.ulstu.deadline.model.Deadline;
|
import ru.ulstu.deadline.model.Deadline;
|
||||||
@ -37,7 +37,7 @@ import java.util.Set;
|
|||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@DiscriminatorValue("PAPER")
|
@DiscriminatorValue("PAPER")
|
||||||
public class Paper extends BaseEntity implements UserActivity, EventSource {
|
public class Paper extends AbstractActivity implements UserActivity, EventSource {
|
||||||
public enum PaperStatus {
|
public enum PaperStatus {
|
||||||
ATTENTION("Обратить внимание"),
|
ATTENTION("Обратить внимание"),
|
||||||
ON_PREPARATION("На подготовке"),
|
ON_PREPARATION("На подготовке"),
|
||||||
|
@ -2,7 +2,7 @@ package ru.ulstu.paper.model;
|
|||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import ru.ulstu.boundary.model.ActivityDto;
|
||||||
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.user.model.UserDto;
|
import ru.ulstu.user.model.UserDto;
|
||||||
@ -13,13 +13,10 @@ import java.util.ArrayList;
|
|||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
import static ru.ulstu.core.util.StreamApiUtils.convert;
|
import static ru.ulstu.core.util.StreamApiUtils.convert;
|
||||||
|
|
||||||
public class PaperDto {
|
public class PaperDto implements ActivityDto {
|
||||||
private final static int MAX_AUTHORS_LENGTH = 60;
|
|
||||||
|
|
||||||
private Integer id;
|
private Integer id;
|
||||||
@NotEmpty
|
@NotEmpty
|
||||||
@Size(min = 3, max = 254)
|
@Size(min = 3, max = 254)
|
||||||
@ -34,17 +31,14 @@ public class PaperDto {
|
|||||||
private String url;
|
private String url;
|
||||||
private Boolean locked;
|
private Boolean locked;
|
||||||
private List<FileDataDto> files = new ArrayList<>();
|
private List<FileDataDto> files = new ArrayList<>();
|
||||||
private Set<Integer> authorIds;
|
|
||||||
private Set<UserDto> authors;
|
private Set<UserDto> authors;
|
||||||
private Integer filterAuthorId;
|
|
||||||
private String latexText;
|
|
||||||
private List<ReferenceDto> references = new ArrayList<>();
|
|
||||||
private ReferenceDto.FormatStandard formatStandard = ReferenceDto.FormatStandard.GOST;
|
|
||||||
|
|
||||||
public PaperDto() {
|
public String getLatexText() {
|
||||||
deadlines.add(new Deadline());
|
return latexText;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String latexText;
|
||||||
|
|
||||||
@JsonCreator
|
@JsonCreator
|
||||||
public PaperDto(@JsonProperty("id") Integer id,
|
public PaperDto(@JsonProperty("id") Integer id,
|
||||||
@JsonProperty("title") String title,
|
@JsonProperty("title") String title,
|
||||||
@ -54,14 +48,10 @@ public class PaperDto {
|
|||||||
@JsonProperty("updateDate") Date updateDate,
|
@JsonProperty("updateDate") Date updateDate,
|
||||||
@JsonProperty("deadlines") List<Deadline> deadlines,
|
@JsonProperty("deadlines") List<Deadline> deadlines,
|
||||||
@JsonProperty("comment") String comment,
|
@JsonProperty("comment") String comment,
|
||||||
@JsonProperty("latex_text") String latexText,
|
|
||||||
@JsonProperty("url") String url,
|
@JsonProperty("url") String url,
|
||||||
@JsonProperty("locked") Boolean locked,
|
@JsonProperty("locked") Boolean locked,
|
||||||
@JsonProperty("files") List<FileDataDto> files,
|
@JsonProperty("files") List<FileDataDto> files,
|
||||||
@JsonProperty("authorIds") Set<Integer> authorIds,
|
@JsonProperty("authors") Set<UserDto> authors) {
|
||||||
@JsonProperty("authors") Set<UserDto> authors,
|
|
||||||
@JsonProperty("references") List<ReferenceDto> references,
|
|
||||||
@JsonProperty("formatStandard") ReferenceDto.FormatStandard formatStandard) {
|
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.title = title;
|
this.title = title;
|
||||||
this.status = status;
|
this.status = status;
|
||||||
@ -71,12 +61,9 @@ public class PaperDto {
|
|||||||
this.deadlines = deadlines;
|
this.deadlines = deadlines;
|
||||||
this.comment = comment;
|
this.comment = comment;
|
||||||
this.url = url;
|
this.url = url;
|
||||||
this.latexText = latexText;
|
|
||||||
this.locked = locked;
|
this.locked = locked;
|
||||||
this.files = files;
|
this.files = files;
|
||||||
this.authors = authors;
|
this.authors = authors;
|
||||||
this.references = references;
|
|
||||||
this.formatStandard = formatStandard;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public PaperDto(Paper paper) {
|
public PaperDto(Paper paper) {
|
||||||
@ -89,12 +76,9 @@ public class PaperDto {
|
|||||||
this.deadlines = paper.getDeadlines();
|
this.deadlines = paper.getDeadlines();
|
||||||
this.comment = paper.getComment();
|
this.comment = paper.getComment();
|
||||||
this.url = paper.getUrl();
|
this.url = paper.getUrl();
|
||||||
this.latexText = paper.getLatexText();
|
|
||||||
this.locked = paper.getLocked();
|
this.locked = paper.getLocked();
|
||||||
this.files = convert(paper.getFiles(), FileDataDto::new);
|
this.files = convert(paper.getFiles(), FileDataDto::new);
|
||||||
this.authorIds = convert(paper.getAuthors(), user -> user.getId());
|
|
||||||
this.authors = convert(paper.getAuthors(), UserDto::new);
|
this.authors = convert(paper.getAuthors(), UserDto::new);
|
||||||
this.references = convert(paper.getReferences(), ReferenceDto::new);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Integer getId() {
|
public Integer getId() {
|
||||||
@ -185,14 +169,6 @@ public class PaperDto {
|
|||||||
this.authors = authors;
|
this.authors = authors;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Set<Integer> getAuthorIds() {
|
|
||||||
return authorIds;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setAuthorIds(Set<Integer> authorIds) {
|
|
||||||
this.authorIds = authorIds;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getUrl() {
|
public String getUrl() {
|
||||||
return url;
|
return url;
|
||||||
}
|
}
|
||||||
@ -200,43 +176,4 @@ public class PaperDto {
|
|||||||
public void setUrl(String url) {
|
public void setUrl(String url) {
|
||||||
this.url = url;
|
this.url = url;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getLatexText() {
|
|
||||||
return latexText;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setLatexText(String latexText) {
|
|
||||||
this.latexText = latexText;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getAuthorsString() {
|
|
||||||
return StringUtils.abbreviate(authors
|
|
||||||
.stream()
|
|
||||||
.map(author -> author.getLastName())
|
|
||||||
.collect(Collectors.joining(", ")), MAX_AUTHORS_LENGTH);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Integer getFilterAuthorId() {
|
|
||||||
return filterAuthorId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setFilterAuthorId(Integer filterAuthorId) {
|
|
||||||
this.filterAuthorId = filterAuthorId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<ReferenceDto> getReferences() {
|
|
||||||
return references;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setReferences(List<ReferenceDto> references) {
|
|
||||||
this.references = references;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ReferenceDto.FormatStandard getFormatStandard() {
|
|
||||||
return formatStandard;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setFormatStandard(ReferenceDto.FormatStandard formatStandard) {
|
|
||||||
this.formatStandard = formatStandard;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,13 @@
|
|||||||
package ru.ulstu.paper.model;
|
package ru.ulstu.paper.model;
|
||||||
|
|
||||||
|
import ru.ulstu.boundary.model.ActivityListDto;
|
||||||
import ru.ulstu.user.model.UserDto;
|
import ru.ulstu.user.model.UserDto;
|
||||||
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import static ru.ulstu.core.util.StreamApiUtils.convert;
|
import static ru.ulstu.core.util.StreamApiUtils.convert;
|
||||||
|
|
||||||
public class PaperListDto {
|
public class PaperListDto implements ActivityListDto {
|
||||||
|
|
||||||
private Integer id;
|
private Integer id;
|
||||||
private String title;
|
private String title;
|
||||||
@ -20,6 +21,10 @@ public class PaperListDto {
|
|||||||
this.authors = convert(paper.getAuthors(), UserDto::new);
|
this.authors = convert(paper.getAuthors(), UserDto::new);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static PaperListDto createFromEntity(Paper entity) {
|
||||||
|
return new PaperListDto(entity);
|
||||||
|
}
|
||||||
|
|
||||||
public Integer getId() {
|
public Integer getId() {
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package ru.ulstu.paper.repository;
|
package ru.ulstu.paper.repository;
|
||||||
|
|
||||||
|
import org.springframework.data.domain.Page;
|
||||||
|
import org.springframework.data.domain.Pageable;
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
import org.springframework.data.jpa.repository.Query;
|
import org.springframework.data.jpa.repository.Query;
|
||||||
import org.springframework.data.repository.query.Param;
|
import org.springframework.data.repository.query.Param;
|
||||||
@ -24,4 +26,10 @@ public interface PaperRepository extends JpaRepository<Paper, Integer> {
|
|||||||
List<Paper> findByConferencesIsNullAndStatusNot(Paper.PaperStatus status);
|
List<Paper> findByConferencesIsNullAndStatusNot(Paper.PaperStatus status);
|
||||||
|
|
||||||
List<Paper> findByIdNotInAndConferencesIsNullAndStatusNot(List<Integer> paperIds, Paper.PaperStatus status);
|
List<Paper> findByIdNotInAndConferencesIsNullAndStatusNot(List<Integer> paperIds, Paper.PaperStatus status);
|
||||||
|
|
||||||
|
@Query("SELECT p FROM Paper p WHERE p.status NOT IN (:statuses)")
|
||||||
|
Page<Paper> findAllWithoutStatuses(Pageable pageable, Paper.PaperStatus... statuses);
|
||||||
|
|
||||||
|
@Query("SELECT p FROM Paper p ")
|
||||||
|
Page<Paper> findAll(Pageable pageable);
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,7 @@ public class PaperCreateStrategy extends EntityCreateStrategy<Paper> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected List<Paper> getActiveEntities() {
|
protected List<Paper> getActiveEntities() {
|
||||||
return paperService.findAll();
|
return (List<Paper>) paperService.findAll(0, 100).getItems();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -2,13 +2,15 @@ package ru.ulstu.paper.service;
|
|||||||
|
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import ru.ulstu.core.model.response.PageableItems;
|
||||||
import ru.ulstu.core.util.DateUtils;
|
import ru.ulstu.core.util.DateUtils;
|
||||||
import ru.ulstu.paper.model.Paper;
|
import ru.ulstu.paper.model.Paper;
|
||||||
|
import ru.ulstu.user.model.User;
|
||||||
import ru.ulstu.user.service.MailService;
|
import ru.ulstu.user.service.MailService;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class PaperNotificationService {
|
public class PaperNotificationService {
|
||||||
@ -30,9 +32,9 @@ public class PaperNotificationService {
|
|||||||
this.mailService = mailService;
|
this.mailService = mailService;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendDeadlineNotifications(List<Paper> papers, boolean isDeadlineBeforeWeek) {
|
public void sendDeadlineNotifications(PageableItems<Paper> papers, boolean isDeadlineBeforeWeek) {
|
||||||
Date now = DateUtils.addDays(new Date(), DAYS_TO_DEADLINE_NOTIFICATION);
|
Date now = DateUtils.addDays(new Date(), DAYS_TO_DEADLINE_NOTIFICATION);
|
||||||
papers
|
papers.getItems()
|
||||||
.stream()
|
.stream()
|
||||||
.filter(paper -> needToSendDeadlineNotification(paper, now, isDeadlineBeforeWeek))
|
.filter(paper -> needToSendDeadlineNotification(paper, now, isDeadlineBeforeWeek))
|
||||||
.forEach(paper -> sendMessageDeadline(paper));
|
.forEach(paper -> sendMessageDeadline(paper));
|
||||||
@ -47,25 +49,43 @@ public class PaperNotificationService {
|
|||||||
|
|
||||||
private void sendMessageDeadline(Paper paper) {
|
private void sendMessageDeadline(Paper paper) {
|
||||||
Map<String, Object> variables = ImmutableMap.of("paper", paper);
|
Map<String, Object> variables = ImmutableMap.of("paper", paper);
|
||||||
sendForAllAuhtors(variables, paper, TEMPLATE_DEADLINE, TITLE_DEADLINE);
|
sendForAllAuthors(variables, paper, TEMPLATE_DEADLINE, TITLE_DEADLINE);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendCreateNotification(Paper paper) {
|
public void sendCreateNotification(Paper paper) {
|
||||||
Map<String, Object> variables = ImmutableMap.of("paper", paper);
|
Map<String, Object> variables = ImmutableMap.of("paper", paper);
|
||||||
sendForAllAuhtors(variables, paper, TEMPLATE_CREATE, TITLE_CREATE);
|
sendForAllAuthors(variables, paper, TEMPLATE_CREATE, TITLE_CREATE);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendCreateNotification(Paper paper, User author) {
|
||||||
|
Map<String, Object> variables = ImmutableMap.of("paper", paper);
|
||||||
|
sendForAuthor(variables, author, TEMPLATE_CREATE, TITLE_CREATE);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendCreateNotification(Paper paper, Set<User> oldAuthors) {
|
||||||
|
paper.getAuthors()
|
||||||
|
.stream()
|
||||||
|
.filter(author -> !oldAuthors.contains(author))
|
||||||
|
.forEach(author -> sendCreateNotification(paper, author));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void statusChangeNotification(Paper paper, Paper.PaperStatus oldStatus) {
|
public void statusChangeNotification(Paper paper, Paper.PaperStatus oldStatus) {
|
||||||
Map<String, Object> variables = ImmutableMap.of("paper", paper, "oldStatus", oldStatus);
|
if (paper.getStatus() != oldStatus) {
|
||||||
sendForAllAuhtors(variables, paper, TEMPLATE_STATUS_CHANGED, TITLE_STATUS_CHANGED);
|
Map<String, Object> variables = ImmutableMap.of("paper", paper, "oldStatus", oldStatus);
|
||||||
|
sendForAllAuthors(variables, paper, TEMPLATE_STATUS_CHANGED, TITLE_STATUS_CHANGED);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendFailedNotification(Paper paper, Paper.PaperStatus oldStatus) {
|
public void sendFailedNotification(Paper paper, Paper.PaperStatus oldStatus) {
|
||||||
Map<String, Object> variables = ImmutableMap.of("paper", paper, "oldStatus", oldStatus);
|
Map<String, Object> variables = ImmutableMap.of("paper", paper, "oldStatus", oldStatus);
|
||||||
sendForAllAuhtors(variables, paper, TEMPLATE_FAILED, TITLE_FAILED);
|
sendForAllAuthors(variables, paper, TEMPLATE_FAILED, TITLE_FAILED);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sendForAllAuhtors(Map<String, Object> variables, Paper paper, String template, String title) {
|
private void sendForAuthor(Map<String, Object> variables, User author, String template, String title) {
|
||||||
paper.getAuthors().forEach(author -> mailService.sendEmailFromTemplate(variables, author, template, title));
|
mailService.sendEmailFromTemplate(variables, author, template, title);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void sendForAllAuthors(Map<String, Object> variables, Paper paper, String template, String title) {
|
||||||
|
paper.getAuthors().forEach(author -> sendForAuthor(variables, author, template, title));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -24,14 +24,14 @@ public class PaperScheduler {
|
|||||||
@Scheduled(cron = "0 0 8 * * MON", zone = "Europe/Samara")
|
@Scheduled(cron = "0 0 8 * * MON", zone = "Europe/Samara")
|
||||||
public void checkDeadlineBeforeWeek() {
|
public void checkDeadlineBeforeWeek() {
|
||||||
log.debug("PaperScheduler.checkDeadlineBeforeWeek started");
|
log.debug("PaperScheduler.checkDeadlineBeforeWeek started");
|
||||||
paperNotificationService.sendDeadlineNotifications(paperService.findAll(), IS_DEADLINE_NOTIFICATION_BEFORE_WEEK);
|
paperNotificationService.sendDeadlineNotifications(paperService.findAll(0, 100), IS_DEADLINE_NOTIFICATION_BEFORE_WEEK);
|
||||||
log.debug("PaperScheduler.checkDeadlineBeforeWeek finished");
|
log.debug("PaperScheduler.checkDeadlineBeforeWeek finished");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Scheduled(cron = "0 0 8 * * ?", zone = "Europe/Samara")
|
@Scheduled(cron = "0 0 8 * * ?", zone = "Europe/Samara")
|
||||||
public void checkDeadlineAfterWeek() {
|
public void checkDeadlineAfterWeek() {
|
||||||
log.debug("PaperScheduler.checkDeadlineAfterWeek started");
|
log.debug("PaperScheduler.checkDeadlineAfterWeek started");
|
||||||
paperNotificationService.sendDeadlineNotifications(paperService.findAll(), !IS_DEADLINE_NOTIFICATION_BEFORE_WEEK);
|
paperNotificationService.sendDeadlineNotifications(paperService.findAll(0, 100), !IS_DEADLINE_NOTIFICATION_BEFORE_WEEK);
|
||||||
log.debug("PaperScheduler.checkDeadlineAfterWeek finished");
|
log.debug("PaperScheduler.checkDeadlineAfterWeek finished");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,13 +1,15 @@
|
|||||||
package ru.ulstu.paper.service;
|
package ru.ulstu.paper.service;
|
||||||
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.springframework.data.domain.Page;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
import ru.ulstu.boundary.service.AbstractActivityService;
|
||||||
|
import ru.ulstu.core.jpa.OffsetablePageRequest;
|
||||||
|
import ru.ulstu.core.model.response.PageableItems;
|
||||||
import ru.ulstu.deadline.model.Deadline;
|
import ru.ulstu.deadline.model.Deadline;
|
||||||
import ru.ulstu.deadline.service.DeadlineService;
|
import ru.ulstu.deadline.service.DeadlineService;
|
||||||
import ru.ulstu.file.model.FileDataDto;
|
import ru.ulstu.file.model.FileDataDto;
|
||||||
import ru.ulstu.file.service.FileService;
|
import ru.ulstu.file.service.FileService;
|
||||||
import ru.ulstu.paper.model.AutoCompleteData;
|
|
||||||
import ru.ulstu.paper.model.Paper;
|
import ru.ulstu.paper.model.Paper;
|
||||||
import ru.ulstu.paper.model.PaperDashboardDto;
|
import ru.ulstu.paper.model.PaperDashboardDto;
|
||||||
import ru.ulstu.paper.model.PaperDto;
|
import ru.ulstu.paper.model.PaperDto;
|
||||||
@ -15,55 +17,44 @@ import ru.ulstu.paper.model.PaperFilterListDto;
|
|||||||
import ru.ulstu.paper.model.PaperListDto;
|
import ru.ulstu.paper.model.PaperListDto;
|
||||||
import ru.ulstu.paper.model.PaperStatusDto;
|
import ru.ulstu.paper.model.PaperStatusDto;
|
||||||
import ru.ulstu.paper.model.PaperTypeDto;
|
import ru.ulstu.paper.model.PaperTypeDto;
|
||||||
import ru.ulstu.paper.model.Reference;
|
|
||||||
import ru.ulstu.paper.model.ReferenceDto;
|
|
||||||
import ru.ulstu.paper.repository.PaperRepository;
|
import ru.ulstu.paper.repository.PaperRepository;
|
||||||
import ru.ulstu.paper.repository.ReferenceRepository;
|
|
||||||
import ru.ulstu.ping.service.PingService;
|
import ru.ulstu.ping.service.PingService;
|
||||||
import ru.ulstu.timeline.service.EventService;
|
import ru.ulstu.timeline.service.EventService;
|
||||||
import ru.ulstu.user.model.User;
|
import ru.ulstu.user.model.User;
|
||||||
import ru.ulstu.user.service.UserService;
|
import ru.ulstu.user.service.UserService;
|
||||||
|
|
||||||
|
import javax.persistence.EntityNotFoundException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.text.MessageFormat;
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
import static java.util.stream.Collectors.toList;
|
import static java.util.stream.Collectors.toList;
|
||||||
|
import static org.hibernate.internal.util.collections.CollectionHelper.isNotEmpty;
|
||||||
import static org.springframework.util.ObjectUtils.isEmpty;
|
import static org.springframework.util.ObjectUtils.isEmpty;
|
||||||
import static ru.ulstu.core.util.StreamApiUtils.convert;
|
import static ru.ulstu.core.util.StreamApiUtils.convert;
|
||||||
|
import static ru.ulstu.core.util.StreamApiUtils.convertPageable;
|
||||||
import static ru.ulstu.paper.model.Paper.PaperStatus.ATTENTION;
|
import static ru.ulstu.paper.model.Paper.PaperStatus.ATTENTION;
|
||||||
import static ru.ulstu.paper.model.Paper.PaperStatus.COMPLETED;
|
import static ru.ulstu.paper.model.Paper.PaperStatus.COMPLETED;
|
||||||
import static ru.ulstu.paper.model.Paper.PaperStatus.DRAFT;
|
import static ru.ulstu.paper.model.Paper.PaperStatus.DRAFT;
|
||||||
import static ru.ulstu.paper.model.Paper.PaperStatus.FAILED;
|
import static ru.ulstu.paper.model.Paper.PaperStatus.FAILED;
|
||||||
import static ru.ulstu.paper.model.Paper.PaperStatus.ON_PREPARATION;
|
import static ru.ulstu.paper.model.Paper.PaperStatus.ON_PREPARATION;
|
||||||
import static ru.ulstu.paper.model.Paper.PaperType.OTHER;
|
import static ru.ulstu.paper.model.Paper.PaperType.OTHER;
|
||||||
import static ru.ulstu.paper.model.ReferenceDto.FormatStandard.GOST;
|
|
||||||
import static ru.ulstu.paper.model.ReferenceDto.ReferenceType.ARTICLE;
|
|
||||||
import static ru.ulstu.paper.model.ReferenceDto.ReferenceType.BOOK;
|
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
@Transactional
|
@Transactional
|
||||||
public class PaperService {
|
public class PaperService extends AbstractActivityService<Paper, PaperDto, PaperListDto> {
|
||||||
private final static int MAX_DISPLAY_SIZE = 75;
|
|
||||||
private final static String PAPER_FORMATTED_TEMPLATE = "%s %s";
|
|
||||||
|
|
||||||
private final PaperNotificationService paperNotificationService;
|
private final PaperNotificationService paperNotificationService;
|
||||||
private final PaperRepository paperRepository;
|
private final PaperRepository paperRepository;
|
||||||
private final UserService userService;
|
private final UserService userService;
|
||||||
private final DeadlineService deadlineService;
|
private final DeadlineService deadlineService;
|
||||||
private final FileService fileService;
|
private final FileService fileService;
|
||||||
private final EventService eventService;
|
private final EventService eventService;
|
||||||
private final ReferenceRepository referenceRepository;
|
|
||||||
private final PingService pingService;
|
private final PingService pingService;
|
||||||
|
|
||||||
public PaperService(PaperRepository paperRepository,
|
public PaperService(PaperRepository paperRepository,
|
||||||
ReferenceRepository referenceRepository,
|
|
||||||
FileService fileService,
|
FileService fileService,
|
||||||
PaperNotificationService paperNotificationService,
|
PaperNotificationService paperNotificationService,
|
||||||
UserService userService,
|
UserService userService,
|
||||||
@ -71,7 +62,6 @@ public class PaperService {
|
|||||||
EventService eventService,
|
EventService eventService,
|
||||||
PingService pingService) {
|
PingService pingService) {
|
||||||
this.paperRepository = paperRepository;
|
this.paperRepository = paperRepository;
|
||||||
this.referenceRepository = referenceRepository;
|
|
||||||
this.fileService = fileService;
|
this.fileService = fileService;
|
||||||
this.paperNotificationService = paperNotificationService;
|
this.paperNotificationService = paperNotificationService;
|
||||||
this.userService = userService;
|
this.userService = userService;
|
||||||
@ -80,36 +70,23 @@ public class PaperService {
|
|||||||
this.pingService = pingService;
|
this.pingService = pingService;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Paper> findAll() {
|
public PageableItems<PaperDashboardDto> findAllActiveDto(int offset, int count) {
|
||||||
return sortPapers(paperRepository.findAll());
|
return convertPageable(findAllActive(offset, count), PaperDashboardDto::new);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<PaperListDto> findAllDto() {
|
public PageableItems<Paper> findAll(int offset, int count) {
|
||||||
return convert(findAll(), PaperListDto::new);
|
final Page<Paper> page = paperRepository.findAll(new OffsetablePageRequest(offset, count));
|
||||||
|
return new PageableItems<>(page.getTotalElements(), sortPapers(page.getContent()));
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<Paper> findAllActive() {
|
@Override
|
||||||
return findAll()
|
protected PaperListDto getActivityListDto(Paper entity) {
|
||||||
.stream()
|
return new PaperListDto(entity);
|
||||||
.filter(paper -> paper.getStatus() != COMPLETED && paper.getStatus() != FAILED)
|
|
||||||
.collect(toList());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<PaperDashboardDto> findAllActiveDto() {
|
private PageableItems<Paper> findAllActive(int offset, int count) {
|
||||||
return convert(findAllActive(), PaperDashboardDto::new);
|
Page<Paper> activePapersPage = paperRepository.findAllWithoutStatuses(new OffsetablePageRequest(offset, count), COMPLETED, FAILED);
|
||||||
}
|
return new PageableItems<>(activePapersPage.getTotalElements(), sortPapers(activePapersPage.getContent()));
|
||||||
|
|
||||||
public PaperDto findOneDto(Integer id) {
|
|
||||||
return new PaperDto(paperRepository.getOne(id));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional
|
|
||||||
public Integer create(PaperDto paperDto) throws IOException {
|
|
||||||
Paper newPaper = copyFromDto(new Paper(), paperDto);
|
|
||||||
newPaper = paperRepository.save(newPaper);
|
|
||||||
paperNotificationService.sendCreateNotification(newPaper);
|
|
||||||
eventService.createFromPaper(newPaper);
|
|
||||||
return newPaper.getId();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
@ -120,73 +97,27 @@ public class PaperService {
|
|||||||
return newPaper;
|
return newPaper;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Paper copyFromDto(Paper paper, PaperDto paperDto) throws IOException {
|
@Transactional
|
||||||
paper.setComment(paperDto.getComment());
|
public Paper update(Paper paper) {
|
||||||
paper.setUrl(paperDto.getUrl());
|
Paper.PaperStatus oldStatus = paper.getStatus();
|
||||||
paper.setLatexText(paperDto.getLatexText());
|
Set<User> oldAuthors = new HashSet<>(paper.getAuthors());
|
||||||
paper.setCreateDate(paper.getCreateDate() == null ? new Date() : paper.getCreateDate());
|
paperRepository.save(paper);
|
||||||
paper.setLocked(paperDto.getLocked());
|
paperNotificationService.sendCreateNotification(paper, oldAuthors);
|
||||||
paper.setStatus(paperDto.getStatus() == null ? DRAFT : paperDto.getStatus());
|
paperNotificationService.statusChangeNotification(paper, oldStatus);
|
||||||
paper.setType(paperDto.getType() == null ? OTHER : paperDto.getType());
|
|
||||||
paper.setTitle(paperDto.getTitle());
|
|
||||||
paper.setUpdateDate(new Date());
|
|
||||||
paper.setDeadlines(deadlineService.saveOrCreate(paperDto.getDeadlines()));
|
|
||||||
paper.setReferences(saveOrCreateReferences(paperDto.getReferences()));
|
|
||||||
if (paperDto.getFiles() != null) {
|
|
||||||
paper.setFiles(fileService.saveOrCreate(paperDto.getFiles().stream()
|
|
||||||
.filter(f -> !f.isDeleted())
|
|
||||||
.collect(toList())));
|
|
||||||
}
|
|
||||||
paper.getAuthors().clear();
|
|
||||||
if (paperDto.getAuthorIds() != null && !paperDto.getAuthorIds().isEmpty()) {
|
|
||||||
paperDto.getAuthorIds().forEach(authorIds -> paper.getAuthors().add(userService.findById(authorIds)));
|
|
||||||
}
|
|
||||||
return paper;
|
return paper;
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<Reference> saveOrCreateReferences(List<ReferenceDto> references) {
|
@Transactional
|
||||||
return references == null
|
public PaperDto create(PaperDto paperDto) {
|
||||||
? Collections.emptyList()
|
return new PaperDto(create(copyFromDto(new Paper(), paperDto)));
|
||||||
: references
|
|
||||||
.stream()
|
|
||||||
.filter(reference -> !reference.getDeleted())
|
|
||||||
.map(reference -> reference.getId() != null ? updateReference(reference) : createReference(reference))
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
private Reference updateReference(ReferenceDto referenceDto) {
|
public PaperDto update(PaperDto paperDto) {
|
||||||
Reference updateReference = referenceRepository.getOne(referenceDto.getId());
|
Paper paper = paperRepository.findById(paperDto.getId())
|
||||||
copyFromDto(updateReference, referenceDto);
|
.orElseThrow(() -> new EntityNotFoundException("Paper with id=" + paperDto.getId() + " not found"));
|
||||||
referenceRepository.save(updateReference);
|
|
||||||
return updateReference;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional
|
|
||||||
private Reference createReference(ReferenceDto referenceDto) {
|
|
||||||
Reference newReference = new Reference();
|
|
||||||
copyFromDto(newReference, referenceDto);
|
|
||||||
newReference = referenceRepository.save(newReference);
|
|
||||||
return newReference;
|
|
||||||
}
|
|
||||||
|
|
||||||
private Reference copyFromDto(Reference reference, ReferenceDto referenceDto) {
|
|
||||||
reference.setAuthors(referenceDto.getAuthors());
|
|
||||||
reference.setJournalOrCollectionTitle(referenceDto.getJournalOrCollectionTitle());
|
|
||||||
reference.setPages(referenceDto.getPages());
|
|
||||||
reference.setPublicationTitle(referenceDto.getPublicationTitle());
|
|
||||||
reference.setPublicationYear(referenceDto.getPublicationYear());
|
|
||||||
reference.setPublisher(referenceDto.getPublisher());
|
|
||||||
reference.setReferenceType(referenceDto.getReferenceType());
|
|
||||||
return reference;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional
|
|
||||||
public Integer update(PaperDto paperDto) throws IOException {
|
|
||||||
Paper paper = paperRepository.getOne(paperDto.getId());
|
|
||||||
Paper.PaperStatus oldStatus = paper.getStatus();
|
|
||||||
Set<User> oldAuthors = new HashSet<>(paper.getAuthors());
|
|
||||||
|
|
||||||
|
//TODO: move to service
|
||||||
if (paperDto.getFiles() != null) {
|
if (paperDto.getFiles() != null) {
|
||||||
for (FileDataDto file : paperDto.getFiles().stream()
|
for (FileDataDto file : paperDto.getFiles().stream()
|
||||||
.filter(f -> f.isDeleted() && f.getId() != null)
|
.filter(f -> f.isDeleted() && f.getId() != null)
|
||||||
@ -194,33 +125,40 @@ public class PaperService {
|
|||||||
fileService.delete(file.getId());
|
fileService.delete(file.getId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
paperRepository.save(copyFromDto(paper, paperDto));
|
return new PaperDto(update(copyFromDto(paper, paperDto)));
|
||||||
if (paperDto.getReferences() != null) {
|
}
|
||||||
for (ReferenceDto referenceDto : paperDto.getReferences().stream()
|
|
||||||
.filter(f -> f.getDeleted() && f.getId() != null)
|
private Paper copyFromDto(Paper paper, PaperDto paperDto) {
|
||||||
.collect(toList())) {
|
paper.setComment(paperDto.getComment());
|
||||||
referenceRepository.deleteById(referenceDto.getId());
|
paper.setUrl(paperDto.getUrl());
|
||||||
|
paper.setCreateDate(paper.getCreateDate() == null ? new Date() : paper.getCreateDate());
|
||||||
|
paper.setLocked(paperDto.getLocked());
|
||||||
|
paper.setStatus(paperDto.getStatus() == null ? DRAFT : paperDto.getStatus());
|
||||||
|
paper.setType(paperDto.getType() == null ? OTHER : paperDto.getType());
|
||||||
|
paper.setTitle(paperDto.getTitle());
|
||||||
|
paper.setUpdateDate(new Date());
|
||||||
|
paper.setDeadlines(deadlineService.saveOrCreate(paperDto.getDeadlines()));
|
||||||
|
//TODO: move to service
|
||||||
|
try {
|
||||||
|
if (paperDto.getFiles() != null) {
|
||||||
|
paper.setFiles(fileService.saveOrCreate(paperDto.getFiles().stream()
|
||||||
|
.filter(f -> !f.isDeleted())
|
||||||
|
.collect(toList())));
|
||||||
}
|
}
|
||||||
|
} catch (IOException ex) {
|
||||||
|
throw new RuntimeException(ex);
|
||||||
}
|
}
|
||||||
eventService.updatePaperDeadlines(paper);
|
if (isNotEmpty(paperDto.getAuthors())) {
|
||||||
|
paperDto.getAuthors().forEach(authors -> paper.getAuthors().add(userService.findById(authors.getId())));
|
||||||
paper.getAuthors().forEach(author -> {
|
|
||||||
if (!oldAuthors.contains(author)) {
|
|
||||||
paperNotificationService.sendCreateNotification(paper);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
if (paper.getStatus() != oldStatus) {
|
|
||||||
paperNotificationService.statusChangeNotification(paper, oldStatus);
|
|
||||||
}
|
}
|
||||||
|
return paper;
|
||||||
return paper.getId();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public void delete(Integer paperId) {
|
public boolean delete(Integer paperId) {
|
||||||
Paper paper = paperRepository.getOne(paperId);
|
Paper paper = paperRepository.getOne(paperId);
|
||||||
paperRepository.delete(paper);
|
paperRepository.delete(paper);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<PaperStatusDto> getPaperStatuses() {
|
public List<PaperStatusDto> getPaperStatuses() {
|
||||||
@ -231,14 +169,6 @@ public class PaperService {
|
|||||||
return convert(Arrays.asList(Paper.PaperType.values()), PaperTypeDto::new);
|
return convert(Arrays.asList(Paper.PaperType.values()), PaperTypeDto::new);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<ReferenceDto.FormatStandard> getFormatStandards() {
|
|
||||||
return Arrays.asList(ReferenceDto.FormatStandard.values());
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<ReferenceDto.ReferenceType> getReferenceTypes() {
|
|
||||||
return Arrays.asList(ReferenceDto.ReferenceType.values());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public Paper create(String title, User user, Date deadlineDate) {
|
public Paper create(String title, User user, Date deadlineDate) {
|
||||||
Paper paper = new Paper();
|
Paper paper = new Paper();
|
||||||
@ -275,10 +205,6 @@ public class PaperService {
|
|||||||
}).collect(toList());
|
}).collect(toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
public PaperDto findPaper(int id) {
|
|
||||||
return new PaperDto(paperRepository.getOne(id));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void closeFailedPapers() {
|
public void closeFailedPapers() {
|
||||||
List<Paper> papers = paperRepository.findAll()
|
List<Paper> papers = paperRepository.findAll()
|
||||||
.stream()
|
.stream()
|
||||||
@ -331,77 +257,10 @@ public class PaperService {
|
|||||||
return userService.findAll();
|
return userService.findAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<String> getFormattedPaperList() {
|
|
||||||
return findAllCompleted()
|
|
||||||
.stream()
|
|
||||||
.map(paper -> String.format(PAPER_FORMATTED_TEMPLATE, paper.getTitle(), getAuthors(paper)))
|
|
||||||
.collect(toList());
|
|
||||||
}
|
|
||||||
|
|
||||||
private List<Paper> findAllCompleted() {
|
|
||||||
return findAll()
|
|
||||||
.stream()
|
|
||||||
.filter(paper -> paper.getStatus() == COMPLETED)
|
|
||||||
.collect(toList());
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getAuthors(Paper paper) {
|
|
||||||
return paper.getAuthors()
|
|
||||||
.stream()
|
|
||||||
.map(User::getUserAbbreviate)
|
|
||||||
.collect(Collectors.joining(", "));
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getFormattedReference(ReferenceDto referenceDto) {
|
|
||||||
return referenceDto.getFormatStandard() == GOST
|
|
||||||
? getGostReference(referenceDto)
|
|
||||||
: getSpringerReference(referenceDto);
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getFormattedReferences(PaperDto paperDto) {
|
|
||||||
return String.join("\r\n", paperDto.getReferences()
|
|
||||||
.stream()
|
|
||||||
.filter(r -> !r.getDeleted())
|
|
||||||
.map(r -> {
|
|
||||||
r.setFormatStandard(paperDto.getFormatStandard());
|
|
||||||
return getFormattedReference(r);
|
|
||||||
})
|
|
||||||
.collect(Collectors.toList()));
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getGostReference(ReferenceDto referenceDto) {
|
|
||||||
return MessageFormat.format(referenceDto.getReferenceType() == BOOK ? "{0} {1} - {2}{3}. - {4}с." : "{0} {1}{5} {2}{3}. С. {4}.",
|
|
||||||
referenceDto.getAuthors(),
|
|
||||||
referenceDto.getPublicationTitle(),
|
|
||||||
StringUtils.isEmpty(referenceDto.getPublisher()) ? "" : referenceDto.getPublisher() + ", ",
|
|
||||||
referenceDto.getPublicationYear() != null ? referenceDto.getPublicationYear().toString() : "",
|
|
||||||
referenceDto.getPages(),
|
|
||||||
StringUtils.isEmpty(referenceDto.getJournalOrCollectionTitle()) ? "." : " // " + referenceDto.getJournalOrCollectionTitle() + ".");
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getSpringerReference(ReferenceDto referenceDto) {
|
|
||||||
return MessageFormat.format("{0} ({1}) {2}.{3} {4}pp {5}",
|
|
||||||
referenceDto.getAuthors(),
|
|
||||||
referenceDto.getPublicationYear() != null ? referenceDto.getPublicationYear().toString() : "",
|
|
||||||
referenceDto.getPublicationTitle(),
|
|
||||||
referenceDto.getReferenceType() == ARTICLE ? " " + referenceDto.getJournalOrCollectionTitle() + "," : "",
|
|
||||||
StringUtils.isEmpty(referenceDto.getPublisher()) ? "" : referenceDto.getPublisher() + ", ",
|
|
||||||
referenceDto.getPages());
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<Paper> findAllCompletedByType(Paper.PaperType type) {
|
public List<Paper> findAllCompletedByType(Paper.PaperType type) {
|
||||||
return paperRepository.findByTypeAndStatus(type, Paper.PaperStatus.COMPLETED);
|
return paperRepository.findByTypeAndStatus(type, Paper.PaperStatus.COMPLETED);
|
||||||
}
|
}
|
||||||
|
|
||||||
public AutoCompleteData getAutoCompleteData() {
|
|
||||||
AutoCompleteData autoCompleteData = new AutoCompleteData();
|
|
||||||
autoCompleteData.setAuthors(referenceRepository.findDistinctAuthors());
|
|
||||||
autoCompleteData.setJournalOrCollectionTitles(referenceRepository.findDistinctJournalOrCollectionTitles());
|
|
||||||
autoCompleteData.setPublicationTitles(referenceRepository.findDistinctPublicationTitles());
|
|
||||||
autoCompleteData.setPublishers(referenceRepository.findDistinctPublishers());
|
|
||||||
return autoCompleteData;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public void ping(int paperId) throws IOException {
|
public void ping(int paperId) throws IOException {
|
||||||
pingService.addPing(findPaperById(paperId));
|
pingService.addPing(findPaperById(paperId));
|
||||||
|
@ -18,7 +18,7 @@
|
|||||||
var getOwl = basePath + "/get-owl";
|
var getOwl = basePath + "/get-owl";
|
||||||
var getTables = basePath + "/get-tables";
|
var getTables = basePath + "/get-tables";
|
||||||
var makeIntegration = basePath + "/make-integration";
|
var makeIntegration = basePath + "/make-integration";
|
||||||
var paperList = basePath + "/papers";
|
var paperList = basePath + "/papers/list";
|
||||||
var paperDashboard = basePath + "/papers/dashboard";
|
var paperDashboard = basePath + "/papers/dashboard";
|
||||||
var paper = basePath + "/papers";
|
var paper = basePath + "/papers";
|
||||||
var allPaperAuthors = basePath + "/papers/allAuthors";
|
var allPaperAuthors = basePath + "/papers/allAuthors";
|
||||||
|
@ -28,9 +28,9 @@
|
|||||||
mounted: function () {
|
mounted: function () {
|
||||||
var self = this;
|
var self = this;
|
||||||
axiosEx.get(
|
axiosEx.get(
|
||||||
appConfig.paperList,
|
appConfig.paperList + "?offset=0&count=50",
|
||||||
function (data) {
|
function (data) {
|
||||||
self.papers = data;
|
self.papers = data.items;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -27,8 +27,7 @@
|
|||||||
aria-labelledby="nav-main-tab">
|
aria-labelledby="nav-main-tab">
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="title">Название:</label>
|
<label for="title">Название:</label>
|
||||||
<input class="form-control" id="title" type="text"
|
<input class="form-control" id="title" type="text" v-model="paper.title"
|
||||||
:value="paper.title"
|
|
||||||
placeholder="Название статьи"/>
|
placeholder="Название статьи"/>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
@ -59,6 +58,10 @@
|
|||||||
:value="paper.url"/>
|
:value="paper.url"/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div v-for="deadline of paper.deadlines">
|
||||||
|
{{ deadline.description }}
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label>Авторы:</label>
|
<label>Авторы:</label>
|
||||||
<multiselect v-model="paper.authors"
|
<multiselect v-model="paper.authors"
|
||||||
@ -120,9 +123,7 @@
|
|||||||
Отмена
|
Отмена
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
@ -151,10 +152,19 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
savePaper: function (event) {
|
savePaper: function (event) {
|
||||||
|
this.paper.deadlines = [{
|
||||||
|
date: "2019-05-25T16:34:57.457+0000",
|
||||||
|
description: "123"
|
||||||
|
}];
|
||||||
|
var self = this;
|
||||||
if (this.$route.query.id && Number.isInteger(parseInt(this.$route.query.id)) && parseInt(this.$route.query.id) != 0) {
|
if (this.$route.query.id && Number.isInteger(parseInt(this.$route.query.id)) && parseInt(this.$route.query.id) != 0) {
|
||||||
axiosEx.put(appConfig.paper, this.paper);
|
axiosEx.put(appConfig.paper, this.paper, function () {
|
||||||
|
self.$router.push('/papers/papers')
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
axiosEx.post(appConfig.paper, this.paper);
|
axiosEx.post(appConfig.paper, this.paper, function () {
|
||||||
|
self.$router.push('/papers/papers')
|
||||||
|
});
|
||||||
}
|
}
|
||||||
this.$store.dispatch("addSuccessMessage", "Статья успешно сохранена!");
|
this.$store.dispatch("addSuccessMessage", "Статья успешно сохранена!");
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
Loading…
Reference in New Issue
Block a user