diff --git a/build.gradle b/build.gradle index d09505e..4e0e9cb 100644 --- a/build.gradle +++ b/build.gradle @@ -116,6 +116,7 @@ dependencies { compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.7' compile group: 'org.webjars', name: 'bootstrap', version: '4.1.0' + compile group: 'org.webjars', name: 'bootstrap-select', version: '1.13.3' compile group: 'org.webjars', name: 'jquery', version: '3.3.1-1' compile group: 'org.webjars.npm', name: 'jquery.easing', version: '1.4.1' compile group: 'org.webjars', name: 'font-awesome', version: '4.7.0' diff --git a/src/main/java/ru/ulstu/core/controller/AdviceController.java b/src/main/java/ru/ulstu/core/controller/AdviceController.java index 2fe853e..18c25dc 100644 --- a/src/main/java/ru/ulstu/core/controller/AdviceController.java +++ b/src/main/java/ru/ulstu/core/controller/AdviceController.java @@ -97,10 +97,4 @@ public class AdviceController { public ResponseExtended handleUserIsUndeadException(Throwable e) { return handleException(ErrorConstants.USER_UNDEAD_ERROR, e.getMessage()); } - - @ExceptionHandler(Exception.class) - public ResponseExtended handleUnknownException(Throwable e) { - e.printStackTrace(); - return handleException(ErrorConstants.UNKNOWN, e.getMessage()); - } } diff --git a/src/main/java/ru/ulstu/deadline/model/DeadlineDto.java b/src/main/java/ru/ulstu/deadline/model/DeadlineDto.java index fbfb598..7f724aa 100644 --- a/src/main/java/ru/ulstu/deadline/model/DeadlineDto.java +++ b/src/main/java/ru/ulstu/deadline/model/DeadlineDto.java @@ -2,15 +2,20 @@ package ru.ulstu.deadline.model; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; +import org.springframework.format.annotation.DateTimeFormat; import java.util.Date; public class DeadlineDto { - private final Integer id; + private Integer id; - private final String description; + private String description; - private final Date date; + @DateTimeFormat(pattern = "yyyy-MM-dd") + private Date date; + + public DeadlineDto() { + } @JsonCreator public DeadlineDto(@JsonProperty("id") Integer id, @@ -38,4 +43,16 @@ public class DeadlineDto { public Date getDate() { return date; } + + public void setId(Integer id) { + this.id = id; + } + + public void setDescription(String description) { + this.description = description; + } + + public void setDate(Date date) { + this.date = date; + } } diff --git a/src/main/java/ru/ulstu/file/FileController.java b/src/main/java/ru/ulstu/file/FileController.java index c372910..e60626b 100644 --- a/src/main/java/ru/ulstu/file/FileController.java +++ b/src/main/java/ru/ulstu/file/FileController.java @@ -20,7 +20,7 @@ import java.io.UnsupportedEncodingException; import java.net.URLEncoder; import static java.nio.charset.StandardCharsets.UTF_8; -import static ru.ulstu.paper.controller.PaperController.URL; +import static ru.ulstu.file.FileController.URL; @RestController @RequestMapping(URL) diff --git a/src/main/java/ru/ulstu/paper/controller/PaperController.java b/src/main/java/ru/ulstu/paper/controller/PaperController.java index b004b18..8969a06 100644 --- a/src/main/java/ru/ulstu/paper/controller/PaperController.java +++ b/src/main/java/ru/ulstu/paper/controller/PaperController.java @@ -1,70 +1,117 @@ package ru.ulstu.paper.controller; -import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.stereotype.Controller; +import org.springframework.ui.ModelMap; +import org.springframework.validation.Errors; 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.PutMapping; -import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; -import ru.ulstu.configuration.Constants; -import ru.ulstu.core.model.response.Response; +import org.springframework.web.bind.annotation.RequestParam; +import ru.ulstu.deadline.model.DeadlineDto; +import ru.ulstu.paper.model.Paper; import ru.ulstu.paper.model.PaperDto; import ru.ulstu.paper.model.PaperFilterDto; -import ru.ulstu.paper.model.PaperStatusDto; import ru.ulstu.paper.service.PaperService; +import ru.ulstu.user.model.User; import javax.validation.Valid; import java.io.IOException; +import java.util.ArrayList; +import java.util.Calendar; import java.util.List; +import java.util.stream.Collectors; -import static ru.ulstu.paper.controller.PaperController.URL; +import static org.springframework.util.StringUtils.isEmpty; -@RestController -@RequestMapping(URL) -public class PaperController { - public static final String URL = Constants.API_1_0 + "papers"; +@Controller() +@RequestMapping(value = "/papers") +public class PaperController { private final PaperService paperService; public PaperController(PaperService paperService) { this.paperService = paperService; } - @GetMapping - public Response> getPapers() { - return new Response<>(paperService.findAllDto()); + @GetMapping("/papers") + public void getPapers(ModelMap modelMap) { + modelMap.put("filteredPapers", new PaperFilterDto(paperService.findAllDto(), null, null)); + } + + @PostMapping("/papers") + public void filterPapers(@Valid PaperFilterDto paperFilterDto, ModelMap modelMap) { + modelMap.put("filteredPapers", new PaperFilterDto(paperService.filter(paperFilterDto), + paperFilterDto.getFilterAuthorId(), + paperFilterDto.getYear())); + } + + @GetMapping("/dashboard") + public void getDashboard(ModelMap modelMap) { + modelMap.put("papers", paperService.findAllDto()); } - @GetMapping("/{paper-id}") - public Response getPaper(@PathVariable("paper-id") Integer paperId){ - return new Response(paperService.findPaper(paperId)); + @GetMapping("/paper") + public void getPapers(ModelMap modelMap, @RequestParam(value = "id") Integer id) { + if (id != null && id > 0) { + modelMap.put("paperDto", paperService.findOneDto(id)); + } else { + modelMap.put("paperDto", new PaperDto()); + } } - @PostMapping - public Response createPaper(@RequestBody @Valid PaperDto paperDto) throws IOException { - return new Response<>(paperService.create(paperDto)); + @PostMapping(value = "/paper", params = "save") + public String save(@Valid PaperDto paperDto, Errors errors) throws IOException { + filterEmptyDeadlines(paperDto); + if (paperDto.getDeadlines().isEmpty()) { + errors.rejectValue("deadlines", "errorCode","Не может быть пустым"); + } + if (errors.hasErrors()) { + return "/papers/paper"; + } + paperService.save(paperDto); + return "redirect:/papers/papers"; } - @PutMapping - public Response updatePaper(@RequestBody @Valid PaperDto paperDto) throws IOException { - return new Response<>(paperService.update(paperDto)); + @PostMapping(value = "/paper", params = "addDeadline") + public String addDeadline(@Valid PaperDto paperDto, Errors errors) { + filterEmptyDeadlines(paperDto); + if (errors.hasErrors()) { + return "/papers/paper"; + } + paperDto.getDeadlines().add(new DeadlineDto()); + return "/papers/paper"; } - @DeleteMapping("/{paper-id}") - public Response delete(@PathVariable("paper-id") Integer paperId) throws IOException { + @GetMapping("/delete/{paper-id}") + public String delete(@PathVariable("paper-id") Integer paperId) throws IOException { paperService.delete(paperId); - return new Response<>(true); + return "redirect:/papers/papers"; + } + + @ModelAttribute("allStatuses") + public List getPaperStatuses() { + return paperService.getPaperStatuses(); + } + + @ModelAttribute("allAuthors") + public List getAllAuthors() { + return paperService.getPaperAuthors(); } - @GetMapping("/statuses") - public Response> getPaperStatuses() { - return new Response<>(paperService.getPaperStatuses()); + @ModelAttribute("allYears") + public List getAllYears() { + List years = new ArrayList<>(); + for (int i = Calendar.getInstance().get(Calendar.YEAR); i > 2010; i-- ) { + years.add(i); + } + return years; } - @PostMapping("/filter") - public Response> filter(@RequestBody @Valid PaperFilterDto paperFilterDto) throws IOException { - return new Response<>(paperService.filter(paperFilterDto)); + private void filterEmptyDeadlines(PaperDto paperDto) { + paperDto.setDeadlines(paperDto.getDeadlines().stream() + .filter(dto -> dto.getDate() != null || !isEmpty(dto.getDescription())) + .collect(Collectors.toList())); } } diff --git a/src/main/java/ru/ulstu/paper/controller/PaperRestController.java b/src/main/java/ru/ulstu/paper/controller/PaperRestController.java new file mode 100644 index 0000000..66efcc7 --- /dev/null +++ b/src/main/java/ru/ulstu/paper/controller/PaperRestController.java @@ -0,0 +1,64 @@ +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.RestController; +import ru.ulstu.configuration.Constants; +import ru.ulstu.core.model.response.Response; +import ru.ulstu.paper.model.PaperDto; +import ru.ulstu.paper.model.PaperFilterDto; +import ru.ulstu.paper.service.PaperService; + +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> getPapers() { + return new Response<>(paperService.findAllDto()); + } + + @GetMapping("/{paper-id}") + public Response getPaper(@PathVariable("paper-id") Integer paperId){ + return new Response(paperService.findById(paperId)); + } + + @PostMapping + public Response createPaper(@RequestBody @Valid PaperDto paperDto) throws IOException { + return new Response<>(paperService.create(paperDto)); + } + + @PutMapping + public Response updatePaper(@RequestBody @Valid PaperDto paperDto) throws IOException { + return new Response<>(paperService.update(paperDto)); + } + + @DeleteMapping("/{paper-id}") + public Response delete(@PathVariable("paper-id") Integer paperId) throws IOException { + paperService.delete(paperId); + return new Response<>(true); + } + + @PostMapping("/filter") + public Response> filter(@RequestBody @Valid PaperFilterDto paperFilterDto) throws IOException { + return new Response<>(paperService.filter(paperFilterDto)); + } +} diff --git a/src/main/java/ru/ulstu/paper/model/Paper.java b/src/main/java/ru/ulstu/paper/model/Paper.java index 96befe7..a1074c0 100644 --- a/src/main/java/ru/ulstu/paper/model/Paper.java +++ b/src/main/java/ru/ulstu/paper/model/Paper.java @@ -16,6 +16,8 @@ import javax.persistence.FetchType; import javax.persistence.JoinColumn; import javax.persistence.ManyToMany; import javax.persistence.ManyToOne; +import javax.persistence.Temporal; +import javax.persistence.TemporalType; import javax.persistence.OneToMany; import javax.validation.constraints.NotNull; import java.util.ArrayList; @@ -36,14 +38,14 @@ public class Paper extends BaseEntity implements UserContainer { COMPLETED("Завершена"), FAILED("Провалены сроки"); - private String name; + private String statusName; PaperStatus(String name) { - this.name = name; + this.statusName = name; } - public String getName() { - return name; + public String getStatusName() { + return statusName; } } @@ -54,12 +56,14 @@ public class Paper extends BaseEntity implements UserContainer { private PaperStatus status = PaperStatus.DRAFT; @Column(name = "create_date") + @Temporal(TemporalType.TIMESTAMP) private Date createDate = new Date(); @Column(name = "update_date") + @Temporal(TemporalType.TIMESTAMP) private Date updateDate = new Date(); - @OneToMany(cascade = CascadeType.ALL) + @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER) @JoinColumn(name = "paper_id") private List deadlines = new ArrayList<>(); @@ -154,6 +158,7 @@ public class Paper extends BaseEntity implements UserContainer { public Optional getNextDeadline() { return deadlines .stream() + .filter(deadline -> deadline.getDate() != null) .sorted(Comparator.comparing(Deadline::getDate)) .filter(d -> d.getDate().after(new Date())) .findFirst(); diff --git a/src/main/java/ru/ulstu/paper/model/PaperDto.java b/src/main/java/ru/ulstu/paper/model/PaperDto.java index 208fe4d..139cc3a 100644 --- a/src/main/java/ru/ulstu/paper/model/PaperDto.java +++ b/src/main/java/ru/ulstu/paper/model/PaperDto.java @@ -6,7 +6,8 @@ import org.hibernate.validator.constraints.NotEmpty; import ru.ulstu.deadline.model.DeadlineDto; import ru.ulstu.user.model.UserDto; -import javax.validation.constraints.NotNull; +import javax.validation.constraints.Size; +import java.util.ArrayList; import java.util.Date; import java.util.List; import java.util.Set; @@ -15,20 +16,28 @@ import java.util.stream.Collectors; import static ru.ulstu.core.util.StreamApiUtils.convert; public class PaperDto { - private final Integer id; + private Integer id; @NotEmpty - private final String title; - private final Paper.PaperStatus status; - private final Date createDate; - private final Date updateDate; - private final List deadlines; - private final String comment; - private final Boolean locked; - private final String tmpFileName; - private final Integer fileId; - private final String fileName; - private final Date fileCreateDate; - private final Set authors; + @Size(min = 3, max = 100) + private String title; + private Paper.PaperStatus status; + private Date createDate; + private Date updateDate; + @NotEmpty + private List deadlines = new ArrayList<>(); + private String comment; + private Boolean locked; + private String tmpFileName; + private Integer fileId; + private String fileName; + private Date fileCreateDate; + private Set authorIds; + private Set authors; + private Integer filterAuthorId; + + public PaperDto() { + deadlines.add(new DeadlineDto()); + } @JsonCreator public PaperDto(@JsonProperty("id") Integer id, @@ -40,6 +49,7 @@ public class PaperDto { @JsonProperty("comment") String comment, @JsonProperty("locked") Boolean locked, @JsonProperty("tmpFileName") String tmpFileName, + @JsonProperty("authorIds") Set authorIds, @JsonProperty("authors") Set authors) { this.id = id; this.title = title; @@ -69,6 +79,7 @@ public class PaperDto { this.fileId = paper.getFileData() == null ? null : paper.getFileData().getId(); this.fileName = paper.getFileData() == null ? null : paper.getFileData().getName(); this.fileCreateDate = paper.getFileData() == null ? null : paper.getFileData().getCreateDate(); + this.authorIds = convert(paper.getAuthors(), user -> user.getId()); this.authors = convert(paper.getAuthors(), UserDto::new); } @@ -76,58 +87,126 @@ public class PaperDto { return id; } + public void setId(Integer id) { + this.id = id; + } + public String getTitle() { return title; } + public void setTitle(String title) { + this.title = title; + } + public Paper.PaperStatus getStatus() { return status; } + public void setStatus(Paper.PaperStatus status) { + this.status = status; + } + public Date getCreateDate() { return createDate; } + public void setCreateDate(Date createDate) { + this.createDate = createDate; + } + public Date getUpdateDate() { return updateDate; } + public void setUpdateDate(Date updateDate) { + this.updateDate = updateDate; + } + public List getDeadlines() { return deadlines; } + public void setDeadlines(List deadlines) { + this.deadlines = deadlines; + } + public String getComment() { return comment; } + public void setComment(String comment) { + this.comment = comment; + } + public Boolean getLocked() { return locked; } + public void setLocked(Boolean locked) { + this.locked = locked; + } + public String getTmpFileName() { return tmpFileName; } + public void setTmpFileName(String tmpFileName) { + this.tmpFileName = tmpFileName; + } + public Integer getFileId() { return fileId; } + public void setFileId(Integer fileId) { + this.fileId = fileId; + } + public String getFileName() { return fileName; } + public void setFileName(String fileName) { + this.fileName = fileName; + } + public Date getFileCreateDate() { return fileCreateDate; } + public void setFileCreateDate(Date fileCreateDate) { + this.fileCreateDate = fileCreateDate; + } + public Set getAuthors() { return authors; } + public void setAuthors(Set authors) { + this.authors = authors; + } + + public Set getAuthorIds() { + return authorIds; + } + + public void setAuthorIds(Set authorIds) { + this.authorIds = authorIds; + } + public String getAuthorsString() { return authors .stream() - .map(author -> author.getLastName() + author.getFirstName()) + .map(author -> author.getLastName()) .collect(Collectors.joining(", ")); } + + public Integer getFilterAuthorId() { + return filterAuthorId; + } + + public void setFilterAuthorId(Integer filterAuthorId) { + this.filterAuthorId = filterAuthorId; + } } diff --git a/src/main/java/ru/ulstu/paper/model/PaperFilterDto.java b/src/main/java/ru/ulstu/paper/model/PaperFilterDto.java index c832bed..f7aef29 100644 --- a/src/main/java/ru/ulstu/paper/model/PaperFilterDto.java +++ b/src/main/java/ru/ulstu/paper/model/PaperFilterDto.java @@ -1,24 +1,42 @@ package ru.ulstu.paper.model; -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonProperty; +import java.util.List; public class PaperFilterDto { - private final Integer authorId; - private final Integer year; + private List papers; + private Integer filterAuthorId; + private Integer year; - @JsonCreator - public PaperFilterDto(@JsonProperty("authorId") Integer authorId, - @JsonProperty("year") Integer year) { - this.authorId = authorId; + public PaperFilterDto() { + } + + public PaperFilterDto(List paperDtos, Integer filterAuthorId, Integer year) { + this.papers = paperDtos; + this.filterAuthorId = filterAuthorId; this.year = year; } - public Integer getAuthorId() { - return authorId; + public List getPapers() { + return papers; + } + + public void setPapers(List papers) { + this.papers = papers; + } + + public Integer getFilterAuthorId() { + return filterAuthorId; + } + + public void setFilterAuthorId(Integer filterAuthorId) { + this.filterAuthorId = filterAuthorId; } public Integer getYear() { return year; } + + public void setYear(Integer year) { + this.year = year; + } } diff --git a/src/main/java/ru/ulstu/paper/model/PaperStatusDto.java b/src/main/java/ru/ulstu/paper/model/PaperStatusDto.java deleted file mode 100644 index d95b19e..0000000 --- a/src/main/java/ru/ulstu/paper/model/PaperStatusDto.java +++ /dev/null @@ -1,19 +0,0 @@ -package ru.ulstu.paper.model; - -public class PaperStatusDto { - private final String id; - private final String name; - - public PaperStatusDto(Paper.PaperStatus status) { - this.id = status.name(); - this.name = status.getName(); - } - - public String getId() { - return id; - } - - public String getName() { - return name; - } -} diff --git a/src/main/java/ru/ulstu/paper/repository/PaperRepository.java b/src/main/java/ru/ulstu/paper/repository/PaperRepository.java index 5d0cd9a..3951f53 100644 --- a/src/main/java/ru/ulstu/paper/repository/PaperRepository.java +++ b/src/main/java/ru/ulstu/paper/repository/PaperRepository.java @@ -10,6 +10,6 @@ import java.util.List; public interface PaperRepository extends JpaRepository { - @Query("SELECT p FROM Paper p WHERE (:author IS NULL OR :author MEMBER OF p.authors) AND YEAR(p.createDate) = :year OR :year IS NULL") + @Query("SELECT p FROM Paper p WHERE (:author IS NULL OR :author MEMBER OF p.authors) AND (YEAR(p.createDate) = :year OR :year IS NULL)") List filter(@Param("author") User author, @Param("year") Integer year); } diff --git a/src/main/java/ru/ulstu/paper/service/PaperScheduler.java b/src/main/java/ru/ulstu/paper/service/PaperScheduler.java index ed035d9..c7fcf0f 100644 --- a/src/main/java/ru/ulstu/paper/service/PaperScheduler.java +++ b/src/main/java/ru/ulstu/paper/service/PaperScheduler.java @@ -7,7 +7,7 @@ import org.springframework.stereotype.Service; @Service public class PaperScheduler { - private final static boolean IS_DEADLINE_NOTIFICATION_BEFORE_WEEK = true; + private final static boolean IS_DEADLINE_NOTIFICATION_AFTER_WEEK = true; private final Logger log = LoggerFactory.getLogger(PaperScheduler.class); @@ -24,14 +24,14 @@ public class PaperScheduler { @Scheduled(cron = "0 0 8 * 1 ?") public void checkDeadlineBeforeWeek() { log.debug("PaperScheduler.checkDeadlineBeforeWeek started"); - paperNotificationService.sendDeadlineNotifications(paperService.findAll(), !IS_DEADLINE_NOTIFICATION_BEFORE_WEEK); + paperNotificationService.sendDeadlineNotifications(paperService.findAll(), !IS_DEADLINE_NOTIFICATION_AFTER_WEEK); log.debug("PaperScheduler.checkDeadlineBeforeWeek finished"); } @Scheduled(cron = "0 0 8 * * ?") public void checkDeadlineAfterWeek() { log.debug("PaperScheduler.checkDeadlineAfterWeek started"); - paperNotificationService.sendDeadlineNotifications(paperService.findAll(), IS_DEADLINE_NOTIFICATION_BEFORE_WEEK); + paperNotificationService.sendDeadlineNotifications(paperService.findAll(), IS_DEADLINE_NOTIFICATION_AFTER_WEEK); log.debug("PaperScheduler.checkDeadlineAfterWeek finished"); } diff --git a/src/main/java/ru/ulstu/paper/service/PaperService.java b/src/main/java/ru/ulstu/paper/service/PaperService.java index 30388b3..88ea8c9 100644 --- a/src/main/java/ru/ulstu/paper/service/PaperService.java +++ b/src/main/java/ru/ulstu/paper/service/PaperService.java @@ -8,7 +8,6 @@ import ru.ulstu.file.service.FileService; import ru.ulstu.paper.model.Paper; import ru.ulstu.paper.model.PaperDto; import ru.ulstu.paper.model.PaperFilterDto; -import ru.ulstu.paper.model.PaperStatusDto; import ru.ulstu.paper.repository.PaperRepository; import ru.ulstu.user.model.User; import ru.ulstu.user.service.UserService; @@ -16,9 +15,12 @@ import ru.ulstu.user.service.UserService; import java.io.IOException; import java.util.Arrays; import java.util.Date; +import java.util.HashSet; import java.util.List; +import java.util.Set; import java.util.stream.Collectors; +import static org.springframework.util.ObjectUtils.isEmpty; import static ru.ulstu.core.util.StreamApiUtils.convert; import static ru.ulstu.paper.model.Paper.PaperStatus.ATTENTION; import static ru.ulstu.paper.model.Paper.PaperStatus.DRAFT; @@ -60,6 +62,10 @@ public class PaperService { return convert(findAll(), PaperDto::new); } + public PaperDto findOneDto(Integer id) { + return new PaperDto(paperRepository.findOne(id)); + } + @Transactional public Integer create(PaperDto paperDto) throws IOException { Paper newPaper = copyFromDto(new Paper(), paperDto); @@ -79,8 +85,9 @@ public class PaperService { if (paperDto.getTmpFileName() != null) { paper.setFileData(fileService.createFileFromTmp(paperDto.getTmpFileName())); } - if (paperDto.getAuthors() != null && !paperDto.getAuthors().isEmpty()) { - paperDto.getAuthors().forEach(authorIds -> paper.getAuthors().add(userService.findById(authorIds.getId()))); + paper.getAuthors().clear(); + if (paperDto.getAuthorIds() != null && !paperDto.getAuthorIds().isEmpty()) { + paperDto.getAuthorIds().forEach(authorIds -> paper.getAuthors().add(userService.findById(authorIds))); } return paper; } @@ -89,11 +96,18 @@ public class PaperService { public Integer update(PaperDto paperDto) throws IOException { Paper paper = paperRepository.findOne(paperDto.getId()); Paper.PaperStatus oldStatus = paper.getStatus(); + Set oldAuthors = new HashSet<>(paper.getAuthors()); if (paperDto.getTmpFileName() != null && paper.getFileData() != null) { fileService.deleteFile(paper.getFileData()); } paperRepository.save(copyFromDto(paper, paperDto)); + paper.getAuthors().forEach(author -> { + if (!oldAuthors.contains(author)) { + paperNotificationService.sendCreateNotification(paper); + } + }); + if (paper.getStatus() != oldStatus) { paperNotificationService.statusChangeNotification(paper, oldStatus); } @@ -110,8 +124,8 @@ public class PaperService { paperRepository.delete(paper); } - public List getPaperStatuses() { - return convert(Arrays.asList(Paper.PaperStatus.values()), PaperStatusDto::new); + public List getPaperStatuses() { + return Arrays.asList(Paper.PaperStatus.values()); } @Transactional @@ -131,10 +145,12 @@ public class PaperService { } public List filter(PaperFilterDto filterDto) { - return convert(paperRepository.filter(userService.findById(filterDto.getAuthorId()), filterDto.getYear()), PaperDto::new); + return convert(paperRepository.filter( + filterDto.getFilterAuthorId() == null ? null : userService.findById(filterDto.getFilterAuthorId()), + filterDto.getYear()), PaperDto::new); } - public PaperDto findPaper(int id){ + public PaperDto findPaper(int id) { return new PaperDto(paperRepository.getOne(id)); } @@ -154,4 +170,20 @@ public class PaperService { paperNotificationService.sendFailedNotification(paper, oldStatus); }); } + + public void save(PaperDto paperDto) throws IOException { + if (isEmpty(paperDto.getId())) { + create(paperDto); + } else { + update(paperDto); + } + } + + public PaperDto findById(Integer paperId) { + return new PaperDto(paperRepository.findOne(paperId)); + } + + public List getPaperAuthors() { + return userService.findAll(); + } } diff --git a/src/main/resources/db/changelog-20181111_000000-schema.xml b/src/main/resources/db/changelog-20181111_000000-schema.xml index 1aa0c64..d292cf7 100644 --- a/src/main/resources/db/changelog-20181111_000000-schema.xml +++ b/src/main/resources/db/changelog-20181111_000000-schema.xml @@ -23,4 +23,10 @@ constraintName="fk_event_child_event" referencedTableName="event" referencedColumnNames="id"/> + + + \ No newline at end of file diff --git a/src/main/resources/mail_templates/paperStatusChangeNotification.html b/src/main/resources/mail_templates/paperStatusChangeNotification.html index 15db20a..853458d 100644 --- a/src/main/resources/mail_templates/paperStatusChangeNotification.html +++ b/src/main/resources/mail_templates/paperStatusChangeNotification.html @@ -11,7 +11,7 @@

Статус статьи "Title" сменился с - "oldStatus" на "newStatus". + "oldStatus" на "newStatus".

Regards, diff --git a/src/main/resources/public/css/agency.css b/src/main/resources/public/css/agency.css index 80102ba..91f7593 100644 --- a/src/main/resources/public/css/agency.css +++ b/src/main/resources/public/css/agency.css @@ -50,7 +50,7 @@ section { } section h2.section-heading { - font-size: 40px; + font-size: 3.5vw; margin-top: 0; margin-bottom: 15px; } diff --git a/src/main/resources/public/js/papers.js b/src/main/resources/public/js/papers.js index 9866874..78d3120 100644 --- a/src/main/resources/public/js/papers.js +++ b/src/main/resources/public/js/papers.js @@ -1,144 +1,42 @@ -var urlPapers = "/api/1.0/papers"; -var urlPaperStatuses = "/api/1.0/papers/statuses"; -var urlDeletePaper = "/api/1.0/papers/"; -var urlFilterPaper = "/api/1.0/papers/filter" +/*" + - "

" + - " \n" + - " " + - " " + - " " + - " " + (index + 1) + ". " + paper.title + "" + - "" + - "" + - "
"); - }); - - $(paperRowClass).mouseenter(function (event) { - var paperRow = $(event.target).closest(paperRowClass); - $(paperRow).css("background-color", "#f8f9fa"); - $(paperRow).find(".remove-paper").removeClass("d-none"); - - }); - $(paperRowClass).mouseleave(function (event) { - var paperRow = $(event.target).closest(paperRowClass); - $(paperRow).css("background-color", "white"); - $(paperRow).closest(paperRowClass).find(".remove-paper").addClass("d-none"); - }); - }); -} - -function filterPapers(papersElement, paperRowClass, authorId, year) { - var paperData = JSON.stringify({ - "authorId": authorId, - "year": year - }); - postToRest(urlFilterPaper, paperData, function (data) { - $(paperRowClass).remove(); - if(data.length > 0){ - data.forEach(function (paper, index) { - $(papersElement).parent().append("
" + - "
" + - " \n" + - " " + - " " + - " " + - " " + paper.title + "
" + - "
" + - "" + - "" + - "
"); - }); - - - $(paperRowClass).mouseenter(function (event) { - var paperRow = $(event.target).closest(paperRowClass); - $(paperRow).css("background-color", "#f8f9fa"); - $(paperRow).find(".remove-paper").removeClass("d-none"); - - }); - $(paperRowClass).mouseleave(function (event) { - var paperRow = $(event.target).closest(paperRowClass); - $(paperRow).css("background-color", "white"); - $(paperRow).closest(paperRowClass).find(".remove-paper").addClass("d-none"); - }); - } }); - - -} - -function deletePaper(id, papersElement, paperRowClass) { - $("#remove-paper-modal").modal('show'); - - $("#modal-btn-yes").on("click", function () { - deleteFromRest(urlDeletePaper + id, function () { - showFeedbackMessage("Статья удалена"); - $(paperRowClass).remove(); - showPapers(papersElement, paperRowClass); - }); - $("#remove-paper-modal").modal('hide'); + $(".paper-row").mouseleave(function (event) { + var paperRow = $(event.target).closest(".paper-row"); + $(paperRow).css("background-color", "white"); + $(paperRow).closest(".paper-row").find(".remove-paper").addClass("d-none"); }); - $("#modal-btn-no").on("click", function () { - $("#remove-paper-modal").modal('hide'); - }); -} - -function addPaper(title, status, datePublish, dateUpdate, deadline, comment, locked, tmpFileName, authors) { - var paperData = JSON.stringify({ - "title": title, - "status": status, - "deadlineDate":deadline, - "comment": comment - }); - postToRest(urlPapers, paperData, function (data) { - alert(data); - }); -} - -function getPaperStatusClass(status) { - switch (status) { - case 'DRAFT': - return "text-draft" - case 'ON_PREPARATION': - return "text-primary"; - case 'ON_REVIEW': - return "text-primary"; - case 'COMPLETED': - return "text-success"; - case 'ATTENTION': - return "text-warning"; - case 'FAILED': - return "text-failed"; - default: - return ""; - } -} - -function showPaperDashboard(dashboardElement) { - getFromRest(urlPapers, function (paperList) { - paperList.forEach(function (paper, index) { - $(dashboardElement).append("
" + - "
" + - "
" + - "" + - "" + - "" + - "" + - "
" + - "
" + - "" + paper.title + "" + - "

" + paper.authorsString + "

" + - "
" + - "
" + - "
"); - }); + $('a[data-confirm]').click(function(ev) { + var href = $(this).attr('href'); + if (!$('#dataConfirmModal').length) { + $('#modalDelete').append(''); + } + $('#dataConfirmModal').find('#myModalLabel').text($(this).attr('data-confirm')); + $('#dataConfirmOK').attr('href', href); + $('#dataConfirmModal').modal({show:true}); + return false; }); -} \ No newline at end of file +}); +/*]]>*/ \ No newline at end of file diff --git a/src/main/resources/templates/default.html b/src/main/resources/templates/default.html index b261b2f..5bb5c14 100644 --- a/src/main/resources/templates/default.html +++ b/src/main/resources/templates/default.html @@ -12,6 +12,7 @@ + @@ -25,6 +26,7 @@ + @@ -88,8 +90,6 @@ - - - - - \ No newline at end of file diff --git a/src/main/resources/templates/papers/fragments/paperDashboardFragment.html b/src/main/resources/templates/papers/fragments/paperDashboardFragment.html new file mode 100644 index 0000000..edbcd30 --- /dev/null +++ b/src/main/resources/templates/papers/fragments/paperDashboardFragment.html @@ -0,0 +1,43 @@ + + + + + + +
+
+
+ + +
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+
+ title +

authors

+
+
+
+ + + + \ No newline at end of file diff --git a/src/main/resources/templates/papers/fragments/paperLineFragment.html b/src/main/resources/templates/papers/fragments/paperLineFragment.html new file mode 100644 index 0000000..bb66aab --- /dev/null +++ b/src/main/resources/templates/papers/fragments/paperLineFragment.html @@ -0,0 +1,46 @@ + + + + + + +
+
+ + +
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+ + + + + + + + +
+
+ + + + \ No newline at end of file diff --git a/src/main/resources/templates/papers/fragments/paperNavigationFragment.html b/src/main/resources/templates/papers/fragments/paperNavigationFragment.html new file mode 100644 index 0000000..23c8260 --- /dev/null +++ b/src/main/resources/templates/papers/fragments/paperNavigationFragment.html @@ -0,0 +1,27 @@ + + + + + + + + + \ No newline at end of file diff --git a/src/main/resources/templates/papers/paper.html b/src/main/resources/templates/papers/paper.html index fe81537..811e522 100644 --- a/src/main/resources/templates/papers/paper.html +++ b/src/main/resources/templates/papers/paper.html @@ -1,7 +1,7 @@ + layout:decorator="default" xmlns:th="http://www.w3.org/1999/xhtml" xmlns="http://www.w3.org/1999/html"> @@ -14,127 +14,100 @@

Редактирование статьи

-
-
-
-
-
-
- +
-
+
+
- - + + +

Incorrect title

- +
- +
- - + +
+ +
+ +
+
+ +
+
+ + +
+
+

Incorrect title

+
+
+
- +
- - +
- - + + text
- + text
-

Редактировать авторов - статьи

-
@@ -148,14 +121,15 @@
- - +
+
@@ -164,7 +138,6 @@
-
diff --git a/src/main/resources/templates/papers/papers.html b/src/main/resources/templates/papers/papers.html index cb492db..e88b413 100644 --- a/src/main/resources/templates/papers/papers.html +++ b/src/main/resources/templates/papers/papers.html @@ -1,82 +1,58 @@ + layout:decorator="default" xmlns:th="">
-
-
-
-
-

Статьи

- -
- - - - - +
+ +
+
+
+
+

Статьи

+
-
-
Фильтровать по:
- - - +
+
+
+ +
+ +
+
+
+
Фильтр:
+ + +
-
-
+
- +
+ - +