diff --git a/src/main/java/ru/ulstu/conference/controller/ConferenceController.java b/src/main/java/ru/ulstu/conference/controller/ConferenceController.java index a416345..4c5ea91 100644 --- a/src/main/java/ru/ulstu/conference/controller/ConferenceController.java +++ b/src/main/java/ru/ulstu/conference/controller/ConferenceController.java @@ -6,7 +6,6 @@ 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.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; @@ -57,6 +56,8 @@ public class ConferenceController { @GetMapping("/dashboard") public void getDashboard(ModelMap modelMap) { modelMap.put("conferences", conferenceService.findAllActiveDto()); + + conferenceService.setChartData(modelMap); // example } @GetMapping("/conference") @@ -68,6 +69,12 @@ public class ConferenceController { } } + @PostMapping(value = "/conferences", params = "deleteConference") + public String delete(@RequestParam("deleteConference") Integer conferenceId) throws IOException { + conferenceService.delete(conferenceId); + return String.format(REDIRECT_TO, CONFERENCES_PAGE); + } + @PostMapping(value = "/conference", params = "save") public String save(@Valid ConferenceDto conferenceDto, Errors errors) throws IOException { filterEmptyDeadlines(conferenceDto); @@ -76,17 +83,10 @@ public class ConferenceController { } conferenceService.save(conferenceDto); return String.format(REDIRECT_TO, CONFERENCES_PAGE); - - } - - @GetMapping("/delete/{conference-id}") - public String delete(@PathVariable("conference-id") Integer conferenceId) throws IOException { - conferenceService.delete(conferenceId); - return String.format(REDIRECT_TO, CONFERENCES_PAGE); } @PostMapping(value = "/conference", params = "addDeadline") - public String addDeadline(@Valid ConferenceDto conferenceDto, Errors errors) { + public String addDeadline(@Valid ConferenceDto conferenceDto, Errors errors) throws IOException { filterEmptyDeadlines(conferenceDto); if (errors.hasErrors()) { return CONFERENCE_PAGE; @@ -105,6 +105,16 @@ public class ConferenceController { return CONFERENCE_PAGE; } + @PostMapping(value = "/conference", params = "addPaper") + public String addPaper(@Valid ConferenceDto conferenceDto, Errors errors) throws IOException { + if (errors.hasErrors()) { + return CONFERENCE_PAGE; + } + conferenceService.addPaper(conferenceDto); + + return CONFERENCE_PAGE; + } + @PostMapping(value = "/conference", params = "removePaper") public String removePaper(@Valid ConferenceDto conferenceDto, Errors errors, @RequestParam(value = "removePaper") Integer paperIndex) throws IOException { @@ -124,6 +134,15 @@ public class ConferenceController { return CONFERENCE_PAGE; } + @PostMapping(value = "/conference", params = "pingConference") + public String ping(@Valid ConferenceDto conferenceDto, Errors errors) throws IOException { + if (errors.hasErrors()) { + return CONFERENCE_PAGE; + } + conferenceService.ping(conferenceDto); + return CONFERENCE_PAGE; + } + @ModelAttribute("allParticipation") public List getAllParticipation() { return conferenceService.getAllParticipations(); diff --git a/src/main/java/ru/ulstu/conference/model/Conference.java b/src/main/java/ru/ulstu/conference/model/Conference.java index e252e4d..3f77699 100644 --- a/src/main/java/ru/ulstu/conference/model/Conference.java +++ b/src/main/java/ru/ulstu/conference/model/Conference.java @@ -35,7 +35,7 @@ public class Conference extends BaseEntity { private String url; - private int ping; + private int ping = 0; @Column(name = "begin_date") @Temporal(TemporalType.TIMESTAMP) @@ -53,7 +53,7 @@ public class Conference extends BaseEntity { @OrderBy("date") private List deadlines = new ArrayList<>(); - @ManyToMany(fetch = FetchType.EAGER) + @ManyToMany(cascade = CascadeType.MERGE, fetch = FetchType.EAGER) @JoinTable(name = "paper_conference", joinColumns = {@JoinColumn(name = "conference_id")}, inverseJoinColumns = {@JoinColumn(name = "paper_id")}) diff --git a/src/main/java/ru/ulstu/conference/model/ConferenceFilterDto.java b/src/main/java/ru/ulstu/conference/model/ConferenceFilterDto.java index 8503b40..0649901 100644 --- a/src/main/java/ru/ulstu/conference/model/ConferenceFilterDto.java +++ b/src/main/java/ru/ulstu/conference/model/ConferenceFilterDto.java @@ -11,14 +11,14 @@ public class ConferenceFilterDto { public ConferenceFilterDto() { } - public ConferenceFilterDto(List conferenceDtos, Integer filterUserId, Integer year) { - this.conferences = conferenceDtos; + public ConferenceFilterDto(List conferences, Integer filterUserId, Integer year) { + this.conferences = conferences; this.filterUserId = filterUserId; this.year = year; } - public ConferenceFilterDto(List conferenceDtos) { - this(conferenceDtos, null, null); + public ConferenceFilterDto(List conferences) { + this(conferences, null, null); } public List getConferences() { diff --git a/src/main/java/ru/ulstu/conference/repository/ConferenceRepository.java b/src/main/java/ru/ulstu/conference/repository/ConferenceRepository.java index cb8a488..3a8bbe1 100644 --- a/src/main/java/ru/ulstu/conference/repository/ConferenceRepository.java +++ b/src/main/java/ru/ulstu/conference/repository/ConferenceRepository.java @@ -1,6 +1,7 @@ package ru.ulstu.conference.repository; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; import ru.ulstu.conference.model.Conference; @@ -16,4 +17,11 @@ public interface ConferenceRepository extends JpaRepository @Query("SELECT c FROM Conference c WHERE c.beginDate > :date") List findAllActive(@Param("date") Date date); + + @Query("SELECT case when count(c) > 0 then true else false end FROM Conference c JOIN c.papers p WHERE p.id = :paperId") + boolean isPaperAttached(@Param("paperId") Integer paperId); + + @Modifying + @Query("UPDATE Conference c SET c.ping = (c.ping + 1) WHERE c.id = :id") + int updatePingConference(@Param("id") Integer id); } diff --git a/src/main/java/ru/ulstu/conference/service/ConferenceService.java b/src/main/java/ru/ulstu/conference/service/ConferenceService.java index e5ce29f..905c208 100644 --- a/src/main/java/ru/ulstu/conference/service/ConferenceService.java +++ b/src/main/java/ru/ulstu/conference/service/ConferenceService.java @@ -4,6 +4,7 @@ import org.apache.commons.lang3.StringUtils; import org.springframework.data.domain.Sort; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import org.springframework.ui.ModelMap; import ru.ulstu.conference.model.Conference; import ru.ulstu.conference.model.ConferenceDto; import ru.ulstu.conference.model.ConferenceFilterDto; @@ -12,6 +13,7 @@ import ru.ulstu.conference.repository.ConferenceRepository; import ru.ulstu.deadline.service.DeadlineService; import ru.ulstu.paper.model.Paper; import ru.ulstu.paper.service.PaperService; +import ru.ulstu.ping.service.PingService; import ru.ulstu.user.model.User; import ru.ulstu.user.service.UserService; @@ -33,17 +35,20 @@ public class ConferenceService { private final DeadlineService deadlineService; private final PaperService paperService; private final UserService userService; + private final PingService pingService; public ConferenceService(ConferenceRepository conferenceRepository, ConferenceUserService conferenceUserService, DeadlineService deadlineService, PaperService paperService, - UserService userService) { + UserService userService, + PingService pingService) { this.conferenceRepository = conferenceRepository; this.conferenceUserService = conferenceUserService; this.deadlineService = deadlineService; this.paperService = paperService; this.userService = userService; + this.pingService = pingService; } public ConferenceDto getExistConferenceById(Integer id) { @@ -111,9 +116,19 @@ public class ConferenceService { conferenceDto.getDeadlines().remove((int) deadlineIndex); } + public void addPaper(ConferenceDto conferenceDto) { + Paper paper = new Paper(); + paper.setTitle(userService.getCurrentUser().getLastName() + "_" + conferenceDto.getTitle() + "_" + (new Date()).getTime()); + paper.setStatus(Paper.PaperStatus.DRAFT); + + conferenceDto.getPapers().add(paper); + } + public void removePaper(ConferenceDto conferenceDto, Integer paperIndex) throws IOException { Paper removedPaper = conferenceDto.getPapers().remove((int) paperIndex); - conferenceDto.getNotSelectedPapers().add(removedPaper); + if (removedPaper.getId() != null) { + conferenceDto.getNotSelectedPapers().add(removedPaper); + } } public void takePart(ConferenceDto conferenceDto) throws IOException { @@ -141,15 +156,15 @@ public class ConferenceService { conference.setTitle(conferenceDto.getTitle()); conference.setDescription(conferenceDto.getDescription()); conference.setUrl(conferenceDto.getUrl()); - conference.setPing(0); conference.setBeginDate(conferenceDto.getBeginDate()); conference.setEndDate(conferenceDto.getEndDate()); - conference.setPapers(conferenceDto.getPapers()); + conference.getPapers().clear(); + conferenceDto.getPapers().forEach(paper -> conference.getPapers().add(paper.getId() != null ? paperService.findPaperById(paper.getId()) : paperService.create(paper))); conference.setDeadlines(deadlineService.saveOrCreate(conferenceDto.getDeadlines())); conference.setUsers(conferenceUserService.saveOrCreate(conferenceDto.getUsers())); if (conferenceDto.getPaperIds() != null && !conferenceDto.getPaperIds().isEmpty()) { conferenceDto.getPaperIds().forEach(paperId -> - conference.getPapers().add(paperService.findEntityById(paperId))); + conference.getPapers().add(paperService.findPaperById(paperId))); } return conference; } @@ -173,4 +188,40 @@ public class ConferenceService { public List findAllActive() { return conferenceRepository.findAllActive(new Date()); } + + public boolean isAttachedToConference(Integer paperId) { + return conferenceRepository.isPaperAttached(paperId); + } + + @Transactional + public void ping(ConferenceDto conferenceDto) throws IOException { + pingService.addPing(findOne(conferenceDto.getId())); + conferenceRepository.updatePingConference(conferenceDto.getId()); + } + + public Conference findOne(Integer conferenceId) { + return conferenceRepository.findOne(conferenceId); + } + + public void setChartData(ModelMap modelMap) { + //first, add the regional sales + Integer northeastSales = 17089; + Integer westSales = 10603; + Integer midwestSales = 5223; + Integer southSales = 10111; + + modelMap.addAttribute("northeastSales", northeastSales); + modelMap.addAttribute("southSales", southSales); + modelMap.addAttribute("midwestSales", midwestSales); + modelMap.addAttribute("westSales", westSales); + + //now add sales by lure type + List inshoreSales = Arrays.asList(4074, 3455, 4112); + List nearshoreSales = Arrays.asList(3222, 3011, 3788); + List offshoreSales = Arrays.asList(7811, 7098, 6455); + + modelMap.addAttribute("inshoreSales", inshoreSales); + modelMap.addAttribute("nearshoreSales", nearshoreSales); + modelMap.addAttribute("offshoreSales", offshoreSales); + } } diff --git a/src/main/java/ru/ulstu/core/controller/AdviceController.java b/src/main/java/ru/ulstu/core/controller/AdviceController.java index 8238797..27ba6c9 100644 --- a/src/main/java/ru/ulstu/core/controller/AdviceController.java +++ b/src/main/java/ru/ulstu/core/controller/AdviceController.java @@ -39,6 +39,11 @@ public class AdviceController { return userService.getCurrentUser().getUserAbbreviate(); } + @ModelAttribute("flashMessage") + public String getFlashMessage() { + return null; + } + private Response handleException(ErrorConstants error) { log.warn(error.toString()); return new Response<>(error); diff --git a/src/main/java/ru/ulstu/grant/controller/GrantController.java b/src/main/java/ru/ulstu/grant/controller/GrantController.java index a0bb916..85a0cd9 100644 --- a/src/main/java/ru/ulstu/grant/controller/GrantController.java +++ b/src/main/java/ru/ulstu/grant/controller/GrantController.java @@ -13,6 +13,7 @@ import ru.ulstu.deadline.model.Deadline; import ru.ulstu.grant.model.Grant; import ru.ulstu.grant.model.GrantDto; import ru.ulstu.grant.service.GrantService; +import ru.ulstu.paper.model.Paper; import ru.ulstu.user.model.User; import springfox.documentation.annotations.ApiIgnore; @@ -50,7 +51,9 @@ public class GrantController { @GetMapping("/grant") public void getGrant(ModelMap modelMap, @RequestParam(value = "id") Integer id) { if (id != null && id > 0) { - modelMap.put("grantDto", grantService.findOneDto(id)); + GrantDto grantDto = grantService.findOneDto(id); + attachPaper(grantDto); + modelMap.put("grantDto", grantDto); } else { modelMap.put("grantDto", new GrantDto()); } @@ -78,6 +81,12 @@ public class GrantController { return GRANT_PAGE; } + @PostMapping(value = "/grant", params = "attachPaper") + public String attachPaper(GrantDto grantDto) { + grantService.attachPaper(grantDto); + return GRANT_PAGE; + } + @PostMapping(value = "/grant", params = "addDeadline") public String addDeadline(@Valid GrantDto grantDto, Errors errors) { filterEmptyDeadlines(grantDto); @@ -88,6 +97,14 @@ public class GrantController { return GRANT_PAGE; } + @PostMapping(value = "/grant", params = "removeDeadline") + public String removeDeadline(GrantDto grantDto, + @RequestParam(value = "removeDeadline") Integer deadlineId) { + grantService.removeDeadline(grantDto, deadlineId); + return GRANT_PAGE; + } + + @PostMapping(value = "/grant", params = "createProject") public String createProject(@Valid GrantDto grantDto, Errors errors) throws IOException { if (errors.hasErrors()) { @@ -113,6 +130,11 @@ public class GrantController { return grantService.getGrantAuthors(grantDto); } + @ModelAttribute("allPapers") + public List getAllPapers() { + return grantService.getAllPapers(); + } + private void filterEmptyDeadlines(GrantDto grantDto) { grantDto.setDeadlines(grantDto.getDeadlines().stream() .filter(dto -> dto.getDate() != null || !isEmpty(dto.getDescription())) diff --git a/src/main/java/ru/ulstu/grant/model/Grant.java b/src/main/java/ru/ulstu/grant/model/Grant.java index 9b1e8fe..abd61ac 100644 --- a/src/main/java/ru/ulstu/grant/model/Grant.java +++ b/src/main/java/ru/ulstu/grant/model/Grant.java @@ -5,6 +5,7 @@ import ru.ulstu.core.model.BaseEntity; import ru.ulstu.core.model.UserContainer; import ru.ulstu.deadline.model.Deadline; import ru.ulstu.file.model.FileData; +import ru.ulstu.paper.model.Paper; import ru.ulstu.project.model.Project; import ru.ulstu.user.model.User; @@ -14,6 +15,7 @@ import javax.persistence.EnumType; import javax.persistence.Enumerated; import javax.persistence.FetchType; import javax.persistence.JoinColumn; +import javax.persistence.JoinTable; import javax.persistence.ManyToMany; import javax.persistence.ManyToOne; import javax.persistence.OneToMany; @@ -62,8 +64,6 @@ public class Grant extends BaseEntity implements UserContainer { @OrderBy("date") private List deadlines = new ArrayList<>(); - //Описание гранта - @NotNull private String comment; //Заявка на грант @@ -83,6 +83,12 @@ public class Grant extends BaseEntity implements UserContainer { @JoinColumn(name = "leader_id") private User leader; + @ManyToMany(fetch = FetchType.EAGER) + @JoinTable(name = "grants_papers", + joinColumns = {@JoinColumn(name = "grant_id")}, + inverseJoinColumns = {@JoinColumn(name = "paper_id")}) + private List papers = new ArrayList<>(); + public GrantStatus getStatus() { return status; } @@ -152,6 +158,14 @@ public class Grant extends BaseEntity implements UserContainer { this.leader = leader; } + public List getPapers() { + return papers; + } + + public void setPapers(List papers) { + this.papers = papers; + } + public Optional getNextDeadline() { return deadlines .stream() diff --git a/src/main/java/ru/ulstu/grant/model/GrantDto.java b/src/main/java/ru/ulstu/grant/model/GrantDto.java index aa8634b..3fb77c5 100644 --- a/src/main/java/ru/ulstu/grant/model/GrantDto.java +++ b/src/main/java/ru/ulstu/grant/model/GrantDto.java @@ -5,6 +5,7 @@ import com.fasterxml.jackson.annotation.JsonProperty; import org.apache.commons.lang3.StringUtils; import org.hibernate.validator.constraints.NotEmpty; import ru.ulstu.deadline.model.Deadline; +import ru.ulstu.paper.model.Paper; import ru.ulstu.project.model.ProjectDto; import ru.ulstu.user.model.UserDto; @@ -32,6 +33,9 @@ public class GrantDto { private boolean wasLeader; private boolean hasAge; private boolean hasDegree; + private List paperIds = new ArrayList<>(); + private List papers = new ArrayList<>(); + private List removedDeadlineIds = new ArrayList<>(); public GrantDto() { deadlines.add(new Deadline()); @@ -49,7 +53,9 @@ public class GrantDto { @JsonProperty("leader") Integer leaderId, @JsonProperty("wasLeader") boolean wasLeader, @JsonProperty("hasAge") boolean hasAge, - @JsonProperty("hasDegree") boolean hasDegree) { + @JsonProperty("hasDegree") boolean hasDegree, + @JsonProperty("paperIds") List paperIds, + @JsonProperty("papers") List papers) { this.id = id; this.title = title; this.status = status; @@ -62,6 +68,8 @@ public class GrantDto { this.wasLeader = wasLeader; this.hasAge = hasAge; this.hasDegree = hasDegree; + this.paperIds = paperIds; + this.papers = papers; } public GrantDto(Grant grant) { @@ -78,6 +86,8 @@ public class GrantDto { this.wasLeader = false; this.hasAge = false; this.hasDegree = false; + this.paperIds = convert(grant.getPapers(), paper -> paper.getId()); + this.papers = grant.getPapers(); } public Integer getId() { @@ -190,4 +200,28 @@ public class GrantDto { public void setHasDegree(boolean hasDegree) { this.hasDegree = hasDegree; } + + public List getPaperIds() { + return paperIds; + } + + public void setPaperIds(List paperIds) { + this.paperIds = paperIds; + } + + public List getPapers() { + return papers; + } + + public void setPapers(List papers) { + this.papers = papers; + } + + public List getRemovedDeadlineIds() { + return removedDeadlineIds; + } + + public void setRemovedDeadlineIds(List removedDeadlineIds) { + this.removedDeadlineIds = removedDeadlineIds; + } } diff --git a/src/main/java/ru/ulstu/grant/service/GrantService.java b/src/main/java/ru/ulstu/grant/service/GrantService.java index 44c0dfa..cabed80 100644 --- a/src/main/java/ru/ulstu/grant/service/GrantService.java +++ b/src/main/java/ru/ulstu/grant/service/GrantService.java @@ -9,6 +9,8 @@ import ru.ulstu.file.service.FileService; import ru.ulstu.grant.model.Grant; import ru.ulstu.grant.model.GrantDto; import ru.ulstu.grant.repository.GrantRepository; +import ru.ulstu.paper.model.Paper; +import ru.ulstu.paper.service.PaperService; import ru.ulstu.project.model.Project; import ru.ulstu.project.model.ProjectDto; import ru.ulstu.project.service.ProjectService; @@ -34,17 +36,20 @@ public class GrantService { private final DeadlineService deadlineService; private final FileService fileService; private final UserService userService; + private final PaperService paperService; public GrantService(GrantRepository grantRepository, FileService fileService, DeadlineService deadlineService, ProjectService projectService, - UserService userService) { + UserService userService, + PaperService paperService) { this.grantRepository = grantRepository; this.fileService = fileService; this.deadlineService = deadlineService; this.projectService = projectService; this.userService = userService; + this.paperService = paperService; } public List findAll() { @@ -86,6 +91,10 @@ public class GrantService { if (grantDto.getLeaderId() != null) { grant.setLeader(userService.findById(grantDto.getLeaderId())); } + grant.getPapers().clear(); + if (grantDto.getPaperIds() != null && !grantDto.getPaperIds().isEmpty()) { + grantDto.getPaperIds().forEach(paperIds -> grant.getPapers().add(paperService.findPaperById(paperIds))); + } return grant; } @@ -100,6 +109,7 @@ public class GrantService { if (grantDto.getApplicationFileName() != null && grant.getApplication() != null) { fileService.deleteFile(grant.getApplication()); } + grantDto.getRemovedDeadlineIds().forEach(deadlineService::remove); grantRepository.save(copyFromDto(grant, grantDto)); return grant.getId(); } @@ -118,7 +128,7 @@ public class GrantService { } @Transactional - public Grant create(String title, Project projectId, Date deadlineDate, User user) { + public Grant create(String title, Project projectId, Date deadlineDate, User user, Paper paper) { Grant grant = new Grant(); grant.setTitle(title); grant.setComment("Комментарий к гранту 1"); @@ -127,6 +137,7 @@ public class GrantService { grant.getDeadlines().add(new Deadline(deadlineDate, "первый дедлайн")); grant.getAuthors().add(user); grant.setLeader(user); + grant.getPapers().add(paper); grant = grantRepository.save(grant); return grant; } @@ -156,4 +167,30 @@ public class GrantService { .map(Grant::getLeader) .collect(Collectors.toList()); } + + public List getGrantPapers(List paperIds) { + return paperService.findAllSelect(paperIds); + + } + + public List getAllPapers() { + return paperService.findAll(); + } + + public void attachPaper(GrantDto grantDto) { + if (!grantDto.getPaperIds().isEmpty()) { + grantDto.getPapers().clear(); + grantDto.setPapers(getGrantPapers(grantDto.getPaperIds())); + } else { + grantDto.getPapers().clear(); + } + } + + public void removeDeadline(GrantDto grantDto, Integer deadlineId) { + if (grantDto.getDeadlines().get(deadlineId).getId() != null) { + grantDto.getRemovedDeadlineIds().add(grantDto.getDeadlines().get(deadlineId).getId()); + } + grantDto.getDeadlines().remove((int) deadlineId); + } + } diff --git a/src/main/java/ru/ulstu/paper/controller/PaperController.java b/src/main/java/ru/ulstu/paper/controller/PaperController.java index e11e4d9..41d5586 100644 --- a/src/main/java/ru/ulstu/paper/controller/PaperController.java +++ b/src/main/java/ru/ulstu/paper/controller/PaperController.java @@ -8,14 +8,14 @@ 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.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; +import ru.ulstu.conference.service.ConferenceService; import ru.ulstu.deadline.model.Deadline; import ru.ulstu.paper.model.Paper; import ru.ulstu.paper.model.PaperDto; -import ru.ulstu.paper.model.PaperFilterDto; +import ru.ulstu.paper.model.PaperListDto; import ru.ulstu.paper.service.LatexService; import ru.ulstu.paper.service.PaperService; import ru.ulstu.user.model.User; @@ -38,23 +38,34 @@ import static org.springframework.util.StringUtils.isEmpty; @ApiIgnore public class PaperController { private final PaperService paperService; + private final ConferenceService conferenceService; private final LatexService latexService; - public PaperController(PaperService paperService, LatexService latexService) { + public PaperController(PaperService paperService, + ConferenceService conferenceService, + LatexService latexService) { this.paperService = paperService; + this.conferenceService = conferenceService; this.latexService = latexService; } @GetMapping("/papers") public void getPapers(ModelMap modelMap) { - modelMap.put("filteredPapers", new PaperFilterDto(paperService.findAllDto(), null, null)); + modelMap.put("filteredPapers", new PaperListDto(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())); + public void listPapers(@Valid PaperListDto paperListDto, ModelMap modelMap) { + if (paperListDto.getPaperDeleteId() != null) { + if (conferenceService.isAttachedToConference(paperListDto.getPaperDeleteId())) { + modelMap.put("flashMessage", "Статью нельзя удалить, она прикреплена к конференции"); + } else { + paperService.delete(paperListDto.getPaperDeleteId()); + } + } + modelMap.put("filteredPapers", new PaperListDto(paperService.filter(paperListDto), + paperListDto.getFilterAuthorId(), + paperListDto.getYear())); } @GetMapping("/dashboard") @@ -94,12 +105,6 @@ public class PaperController { return "/papers/paper"; } - @GetMapping("/delete/{paper-id}") - public String delete(@PathVariable("paper-id") Integer paperId) throws IOException { - paperService.delete(paperId); - return "redirect:/papers/papers"; - } - @ModelAttribute("allStatuses") public List getPaperStatuses() { return paperService.getPaperStatuses(); diff --git a/src/main/java/ru/ulstu/paper/controller/PaperRestController.java b/src/main/java/ru/ulstu/paper/controller/PaperRestController.java index 2bd8384..6da009f 100644 --- a/src/main/java/ru/ulstu/paper/controller/PaperRestController.java +++ b/src/main/java/ru/ulstu/paper/controller/PaperRestController.java @@ -11,7 +11,8 @@ 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.model.PaperListDto; +import ru.ulstu.paper.model.ReferenceDto; import ru.ulstu.paper.service.PaperService; import javax.validation.Valid; @@ -58,12 +59,17 @@ public class PaperRestController { } @PostMapping("/filter") - public Response> filter(@RequestBody @Valid PaperFilterDto paperFilterDto) throws IOException { - return new Response<>(paperService.filter(paperFilterDto)); + public Response> filter(@RequestBody @Valid PaperListDto paperListDto) throws IOException { + return new Response<>(paperService.filter(paperListDto)); } @GetMapping("formatted-list") public Response> getFormattedPaperList() { return new Response<>(paperService.getFormattedPaperList()); } + + @PostMapping("/getFormattedReference") + public Response getFormattedReference(@RequestBody @Valid ReferenceDto referenceDto) { + return new Response<>(paperService.getFormattedReference(referenceDto)); + } } diff --git a/src/main/java/ru/ulstu/paper/error/PaperConferenceRelationExistException.java b/src/main/java/ru/ulstu/paper/error/PaperConferenceRelationExistException.java new file mode 100644 index 0000000..ddb3b5e --- /dev/null +++ b/src/main/java/ru/ulstu/paper/error/PaperConferenceRelationExistException.java @@ -0,0 +1,7 @@ +package ru.ulstu.paper.error; + +public class PaperConferenceRelationExistException extends RuntimeException { + public PaperConferenceRelationExistException(String message) { + super(message); + } +} diff --git a/src/main/java/ru/ulstu/paper/model/PaperFilterDto.java b/src/main/java/ru/ulstu/paper/model/PaperListDto.java similarity index 67% rename from src/main/java/ru/ulstu/paper/model/PaperFilterDto.java rename to src/main/java/ru/ulstu/paper/model/PaperListDto.java index f7aef29..871047a 100644 --- a/src/main/java/ru/ulstu/paper/model/PaperFilterDto.java +++ b/src/main/java/ru/ulstu/paper/model/PaperListDto.java @@ -2,15 +2,16 @@ package ru.ulstu.paper.model; import java.util.List; -public class PaperFilterDto { +public class PaperListDto { private List papers; private Integer filterAuthorId; + private Integer paperDeleteId; private Integer year; - public PaperFilterDto() { + public PaperListDto() { } - public PaperFilterDto(List paperDtos, Integer filterAuthorId, Integer year) { + public PaperListDto(List paperDtos, Integer filterAuthorId, Integer year) { this.papers = paperDtos; this.filterAuthorId = filterAuthorId; this.year = year; @@ -39,4 +40,12 @@ public class PaperFilterDto { public void setYear(Integer year) { this.year = year; } + + public Integer getPaperDeleteId() { + return paperDeleteId; + } + + public void setPaperDeleteId(Integer paperDeleteId) { + this.paperDeleteId = paperDeleteId; + } } diff --git a/src/main/java/ru/ulstu/paper/model/ReferenceDto.java b/src/main/java/ru/ulstu/paper/model/ReferenceDto.java new file mode 100644 index 0000000..8d71ae5 --- /dev/null +++ b/src/main/java/ru/ulstu/paper/model/ReferenceDto.java @@ -0,0 +1,129 @@ +package ru.ulstu.paper.model; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; + +public class ReferenceDto { + public enum ReferenceType { + ARTICLE("Статья"), + BOOK("Книга"); + + private String typeName; + + ReferenceType(String name) { + this.typeName = name; + } + + public String getTypeName() { + return typeName; + } + } + + public enum FormatStandard { + GOST("ГОСТ"), + SPRINGER("Springer"); + + private String standardName; + + FormatStandard(String name) { + this.standardName = name; + } + + public String getStandardName() { + return standardName; + } + } + + private String authors; + private String publicationTitle; + private Integer publicationYear; + private String publisher; + private String pages; + private String journalOrCollectionTitle; + private ReferenceType referenceType; + private FormatStandard formatStandard; + + @JsonCreator + public ReferenceDto( + @JsonProperty("authors") String authors, + @JsonProperty("publicationTitle") String publicationTitle, + @JsonProperty("publicationYear") Integer publicationYear, + @JsonProperty("publisher") String publisher, + @JsonProperty("pages") String pages, + @JsonProperty("journalOrCollectionTitle") String journalOrCollectionTitle, + @JsonProperty("referenceType") ReferenceType referenceType, + @JsonProperty("formatStandard") FormatStandard formatStandard) { + this.authors = authors; + this.publicationTitle = publicationTitle; + this.publicationYear = publicationYear; + this.publisher = publisher; + this.pages = pages; + this.journalOrCollectionTitle = journalOrCollectionTitle; + this.referenceType = referenceType; + this.formatStandard = formatStandard; + } + + public String getAuthors() { + return authors; + } + + public void setAuthors(String authors) { + this.authors = authors; + } + + public String getPublicationTitle() { + return publicationTitle; + } + + public void setPublicationTitle(String publicationTitle) { + this.publicationTitle = publicationTitle; + } + + public Integer getPublicationYear() { + return publicationYear; + } + + public void setPublicationYear(Integer publicationYear) { + this.publicationYear = publicationYear; + } + + public String getPublisher() { + return publisher; + } + + public void setPublisher(String publisher) { + this.publisher = publisher; + } + + public String getPages() { + return pages; + } + + public void setPages(String pages) { + this.pages = pages; + } + + public String getJournalOrCollectionTitle() { + return journalOrCollectionTitle; + } + + public void setJournalOrCollectionTitle(String journalOrCollectionTitle) { + this.journalOrCollectionTitle = journalOrCollectionTitle; + } + + public ReferenceType getReferenceType() { + return referenceType; + } + + public void setReferenceType(ReferenceType referenceType) { + this.referenceType = referenceType; + } + + public FormatStandard getFormatStandard() { + return formatStandard; + } + + public void setFormatStandard(FormatStandard formatStandard) { + this.formatStandard = formatStandard; + } +} diff --git a/src/main/java/ru/ulstu/paper/repository/PaperRepository.java b/src/main/java/ru/ulstu/paper/repository/PaperRepository.java index 343e9e2..cab9b1a 100644 --- a/src/main/java/ru/ulstu/paper/repository/PaperRepository.java +++ b/src/main/java/ru/ulstu/paper/repository/PaperRepository.java @@ -14,4 +14,6 @@ public interface PaperRepository extends JpaRepository { List filter(@Param("author") User author, @Param("year") Integer year); List findByIdNotIn(List paperIds); + + List findAllByIdIn(List paperIds); } diff --git a/src/main/java/ru/ulstu/paper/service/PaperService.java b/src/main/java/ru/ulstu/paper/service/PaperService.java index 1633c07..3db7c84 100644 --- a/src/main/java/ru/ulstu/paper/service/PaperService.java +++ b/src/main/java/ru/ulstu/paper/service/PaperService.java @@ -9,13 +9,15 @@ import ru.ulstu.file.model.FileDataDto; 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.PaperListDto; +import ru.ulstu.paper.model.ReferenceDto; import ru.ulstu.paper.repository.PaperRepository; import ru.ulstu.timeline.service.EventService; import ru.ulstu.user.model.User; import ru.ulstu.user.service.UserService; import java.io.IOException; +import java.text.MessageFormat; import java.util.Arrays; import java.util.Date; import java.util.HashSet; @@ -32,6 +34,9 @@ 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.ON_PREPARATION; 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 public class PaperService { @@ -93,6 +98,14 @@ public class PaperService { return newPaper.getId(); } + @Transactional + public Paper create(Paper paper) { + Paper newPaper = paperRepository.save(paper); + paperNotificationService.sendCreateNotification(newPaper); + eventService.createFromPaper(newPaper); + return newPaper; + } + private Paper copyFromDto(Paper paper, PaperDto paperDto) throws IOException { paper.setComment(paperDto.getComment()); paper.setUrl(paperDto.getUrl()); @@ -173,7 +186,7 @@ public class PaperService { return paper; } - public List filter(PaperFilterDto filterDto) { + public List filter(PaperListDto filterDto) { return convert(sortPapers(paperRepository.filter( filterDto.getFilterAuthorId() == null ? null : userService.findById(filterDto.getFilterAuthorId()), filterDto.getYear())), PaperDto::new); @@ -223,7 +236,7 @@ public class PaperService { return new PaperDto(paperRepository.findOne(paperId)); } - public Paper findEntityById(Integer paperId) { + public Paper findPaperById(Integer paperId) { return paperRepository.findOne(paperId); } @@ -236,6 +249,10 @@ public class PaperService { } + public List findAllSelect(List paperIds) { + return sortPapers(paperRepository.findAllByIdIn(paperIds)); + } + public List getPaperAuthors() { return userService.findAll(); } @@ -260,4 +277,30 @@ public class PaperService { .map(User::getUserAbbreviate) .collect(Collectors.joining(", ")); } + + public String getFormattedReference(ReferenceDto referenceDto) { + return referenceDto.getFormatStandard() == GOST + ? getGostReference(referenceDto) + : getSpringerReference(referenceDto); + } + + public 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().toString(), + referenceDto.getPages(), + StringUtils.isEmpty(referenceDto.getJournalOrCollectionTitle()) ? "." : " // " + referenceDto.getJournalOrCollectionTitle() + "."); + } + + public String getSpringerReference(ReferenceDto referenceDto) { + return MessageFormat.format("{0} ({1}) {2}.{3} {4}pp {5}", + referenceDto.getAuthors(), + referenceDto.getPublicationYear().toString(), + referenceDto.getPublicationTitle(), + referenceDto.getReferenceType() == ARTICLE ? " " + referenceDto.getJournalOrCollectionTitle() + "," : "", + StringUtils.isEmpty(referenceDto.getPublisher()) ? "" : referenceDto.getPublisher() + ", ", + referenceDto.getPages()); + } } diff --git a/src/main/java/ru/ulstu/ping/model/Ping.java b/src/main/java/ru/ulstu/ping/model/Ping.java new file mode 100644 index 0000000..c7e4c5e --- /dev/null +++ b/src/main/java/ru/ulstu/ping/model/Ping.java @@ -0,0 +1,73 @@ +package ru.ulstu.ping.model; + +import com.fasterxml.jackson.annotation.JsonProperty; +import org.springframework.format.annotation.DateTimeFormat; +import ru.ulstu.conference.model.Conference; +import ru.ulstu.core.model.BaseEntity; +import ru.ulstu.user.model.User; + +import javax.persistence.Entity; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import javax.persistence.Table; +import javax.persistence.Temporal; +import javax.persistence.TemporalType; +import java.util.Date; + +@Entity +@Table(name = "ping") +public class Ping extends BaseEntity { + @Temporal(value = TemporalType.TIMESTAMP) + @DateTimeFormat(pattern = "yyyy-MM-dd") + private Date date; + + @ManyToOne(optional = false) + @JoinColumn(name = "users_id") + private User user; + + @ManyToOne(optional = false) + @JoinColumn(name = "conference_id") + private Conference conference; + + public Ping() { + } + + public Ping(Date date, User user) { + this.date = date; + this.user = user; + } + + public Ping(@JsonProperty("id") Integer id, + @JsonProperty("date") Date date, + @JsonProperty("user") User user, + @JsonProperty("conference") Conference conference) { + setId(id); + this.date = date; + this.user = user; + this.conference = conference; + } + + public Date getDate() { + return date; + } + + public void setDate(Date date) { + this.date = date; + } + + public User getUser() { + return user; + } + + public void setUser(User user) { + this.user = user; + } + + public Conference getConference() { + return conference; + } + + public void setConference(Conference conference) { + this.conference = conference; + } +} diff --git a/src/main/java/ru/ulstu/ping/repository/PingRepository.java b/src/main/java/ru/ulstu/ping/repository/PingRepository.java new file mode 100644 index 0000000..ebafc0c --- /dev/null +++ b/src/main/java/ru/ulstu/ping/repository/PingRepository.java @@ -0,0 +1,7 @@ +package ru.ulstu.ping.repository; + +import org.springframework.data.jpa.repository.JpaRepository; +import ru.ulstu.ping.model.Ping; + +public interface PingRepository extends JpaRepository { +} diff --git a/src/main/java/ru/ulstu/ping/service/PingService.java b/src/main/java/ru/ulstu/ping/service/PingService.java new file mode 100644 index 0000000..ff0d249 --- /dev/null +++ b/src/main/java/ru/ulstu/ping/service/PingService.java @@ -0,0 +1,30 @@ +package ru.ulstu.ping.service; + +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import ru.ulstu.conference.model.Conference; +import ru.ulstu.ping.model.Ping; +import ru.ulstu.ping.repository.PingRepository; +import ru.ulstu.user.service.UserService; + +import java.io.IOException; +import java.util.Date; + +@Service +public class PingService { + private final PingRepository pingRepository; + private final UserService userService; + + public PingService(PingRepository pingRepository, + UserService userService) { + this.pingRepository = pingRepository; + this.userService = userService; + } + + @Transactional + public void addPing(Conference conference) throws IOException { + Ping newPing = new Ping(new Date(), userService.getCurrentUser()); + newPing.setConference(conference); + pingRepository.save(newPing); + } +} diff --git a/src/main/java/ru/ulstu/project/controller/ProjectController.java b/src/main/java/ru/ulstu/project/controller/ProjectController.java index affdaec..ae09658 100644 --- a/src/main/java/ru/ulstu/project/controller/ProjectController.java +++ b/src/main/java/ru/ulstu/project/controller/ProjectController.java @@ -5,6 +5,7 @@ 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.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; @@ -78,6 +79,12 @@ public class ProjectController { return "/projects/project"; } + @GetMapping("/delete/{project-id}") + public String delete(@PathVariable("project-id") Integer projectId) throws IOException { + projectService.delete(projectId); + return String.format("redirect:%s", "/projects/projects"); + } + private void filterEmptyDeadlines(ProjectDto projectDto) { projectDto.setDeadlines(projectDto.getDeadlines().stream() .filter(dto -> dto.getDate() != null || !isEmpty(dto.getDescription())) diff --git a/src/main/java/ru/ulstu/project/model/ProjectDto.java b/src/main/java/ru/ulstu/project/model/ProjectDto.java index a2827ad..4e03365 100644 --- a/src/main/java/ru/ulstu/project/model/ProjectDto.java +++ b/src/main/java/ru/ulstu/project/model/ProjectDto.java @@ -15,7 +15,6 @@ public class ProjectDto { @NotEmpty private String title; private Project.ProjectStatus status; - private String statusName; private String description; private List deadlines = new ArrayList<>(); private GrantDto grant; @@ -40,7 +39,6 @@ public class ProjectDto { this.id = id; this.title = title; this.status = status; - this.statusName = status.getStatusName(); this.description = description; this.grant = grant; this.repository = repository; @@ -53,7 +51,6 @@ public class ProjectDto { this.id = project.getId(); this.title = project.getTitle(); this.status = project.getStatus(); - this.statusName = project.getStatus().getStatusName(); this.description = project.getDescription(); this.applicationFileName = project.getApplication() == null ? null : project.getApplication().getName(); this.grant = project.getGrant() == null ? null : new GrantDto(project.getGrant()); @@ -85,14 +82,6 @@ public class ProjectDto { this.status = status; } - public String getStatusName() { - return statusName; - } - - public void setStatusName(String statusName) { - this.statusName = statusName; - } - public String getDescription() { return description; } diff --git a/src/main/java/ru/ulstu/project/service/ProjectService.java b/src/main/java/ru/ulstu/project/service/ProjectService.java index c34bf42..247624d 100644 --- a/src/main/java/ru/ulstu/project/service/ProjectService.java +++ b/src/main/java/ru/ulstu/project/service/ProjectService.java @@ -72,6 +72,15 @@ public class ProjectService { return project; } + @Transactional + public void delete(Integer projectId) throws IOException { + Project project = projectRepository.findOne(projectId); + if (project.getApplication() != null) { + fileService.deleteFile(project.getApplication()); + } + projectRepository.delete(project); + } + private Project copyFromDto(Project project, ProjectDto projectDto) throws IOException { project.setDescription(projectDto.getDescription()); project.setStatus(projectDto.getStatus() == null ? APPLICATION : projectDto.getStatus()); diff --git a/src/main/java/ru/ulstu/students/controller/TaskController.java b/src/main/java/ru/ulstu/students/controller/TaskController.java index 50cb052..5d0f4e8 100644 --- a/src/main/java/ru/ulstu/students/controller/TaskController.java +++ b/src/main/java/ru/ulstu/students/controller/TaskController.java @@ -5,13 +5,16 @@ 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.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import ru.ulstu.deadline.model.Deadline; import ru.ulstu.students.model.Task; import ru.ulstu.students.model.TaskDto; +import ru.ulstu.students.model.TaskFilterDto; import ru.ulstu.students.service.TaskService; +import ru.ulstu.tags.model.Tag; import springfox.documentation.annotations.ApiIgnore; import javax.validation.Valid; @@ -35,16 +38,16 @@ public class TaskController { this.taskService = taskService; } - @GetMapping("/tasks") - public void getTasks(ModelMap modelMap) { - modelMap.put("tasks", taskService.findAllDto()); - } - @GetMapping("/dashboard") public void getDashboard(ModelMap modelMap) { modelMap.put("tasks", taskService.findAllDto()); } + @GetMapping("/tasks") + public void getTask(ModelMap modelMap) { + modelMap.put("filteredTasks", new TaskFilterDto(taskService.findAllDto(), null, null, null)); + } + @GetMapping("/task") public void getTask(ModelMap modelMap, @RequestParam(value = "id") Integer id) { if (id != null && id > 0) { @@ -54,6 +57,14 @@ public class TaskController { } } + @PostMapping("/tasks") + public void filterTasks(@Valid TaskFilterDto taskFilterDto, ModelMap modelMap) { + modelMap.put("filteredTasks", new TaskFilterDto(taskService.filter(taskFilterDto), + taskFilterDto.getStatus(), + taskFilterDto.getTag(), + taskFilterDto.getOrder())); + } + @PostMapping(value = "/task", params = "save") public String save(@Valid TaskDto taskDto, Errors errors) throws IOException { filterEmptyDeadlines(taskDto); @@ -77,11 +88,23 @@ public class TaskController { return TASK_PAGE; } + @GetMapping("/delete/{task-id}") + public String delete(@PathVariable("task-id") Integer taskId) throws IOException { + taskService.delete(taskId); + return String.format(REDIRECT_TO, TASKS_PAGE); + } + + @ModelAttribute("allStatuses") public List getTaskStatuses() { return taskService.getTaskStatuses(); } + @ModelAttribute("allTags") + public List getTags() { + return taskService.getTags(); + } + private void filterEmptyDeadlines(TaskDto taskDto) { taskDto.setDeadlines(taskDto.getDeadlines().stream() .filter(dto -> dto.getDate() != null || !isEmpty(dto.getDescription())) diff --git a/src/main/java/ru/ulstu/students/model/Task.java b/src/main/java/ru/ulstu/students/model/Task.java index c4d7409..8ec9081 100644 --- a/src/main/java/ru/ulstu/students/model/Task.java +++ b/src/main/java/ru/ulstu/students/model/Task.java @@ -50,7 +50,7 @@ public class Task extends BaseEntity { private String description; @Enumerated(value = EnumType.STRING) - private ru.ulstu.students.model.Task.TaskStatus status = TaskStatus.IN_WORK; + private TaskStatus status = TaskStatus.IN_WORK; @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER) @JoinColumn(name = "task_id", unique = true) diff --git a/src/main/java/ru/ulstu/students/model/TaskDto.java b/src/main/java/ru/ulstu/students/model/TaskDto.java index 941a6df..8d52e01 100644 --- a/src/main/java/ru/ulstu/students/model/TaskDto.java +++ b/src/main/java/ru/ulstu/students/model/TaskDto.java @@ -26,7 +26,7 @@ public class TaskDto { private Date createDate; private Date updateDate; private Set tagIds; - private List tags; + private List tags = new ArrayList<>(); public TaskDto() { deadlines.add(new Deadline()); diff --git a/src/main/java/ru/ulstu/students/model/TaskFilterDto.java b/src/main/java/ru/ulstu/students/model/TaskFilterDto.java new file mode 100644 index 0000000..21bd5ac --- /dev/null +++ b/src/main/java/ru/ulstu/students/model/TaskFilterDto.java @@ -0,0 +1,54 @@ +package ru.ulstu.students.model; + +import java.util.List; + +public class TaskFilterDto { + + private List tasks; + private Task.TaskStatus status; + private Integer tagId; + private String order; + + public TaskFilterDto(List tasks, Task.TaskStatus status, Integer tagId, String order) { + this.tasks = tasks; + this.status = status; + this.tagId = tagId; + this.order = order; + } + + public TaskFilterDto() { + + } + + public List getTasks() { + return tasks; + } + + public void setTasks(List tasks) { + this.tasks = tasks; + } + + public Task.TaskStatus getStatus() { + return status; + } + + public void setStatus(Task.TaskStatus status) { + this.status = status; + } + + public Integer getTag() { + return tagId; + } + + public void setTag(Integer tagId) { + this.tagId = tagId; + } + + public String getOrder() { + return order; + } + + public void setOrder(String order) { + this.order = order; + } +} diff --git a/src/main/java/ru/ulstu/students/repository/TaskRepository.java b/src/main/java/ru/ulstu/students/repository/TaskRepository.java index 6f48d1f..ee49ab8 100644 --- a/src/main/java/ru/ulstu/students/repository/TaskRepository.java +++ b/src/main/java/ru/ulstu/students/repository/TaskRepository.java @@ -1,7 +1,18 @@ package ru.ulstu.students.repository; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; import ru.ulstu.students.model.Task; +import ru.ulstu.tags.model.Tag; + +import java.util.List; public interface TaskRepository extends JpaRepository { + + @Query("SELECT t FROM Task t WHERE (t.status = :status OR :status IS NULL) AND (:tag IS NULL OR :tag MEMBER OF t.tags) ORDER BY create_date DESC") + List filterNew(@Param("status") Task.TaskStatus status, @Param("tag") Tag tag); + + @Query("SELECT t FROM Task t WHERE (t.status = :status OR :status IS NULL) AND (:tag IS NULL OR :tag MEMBER OF t.tags) ORDER BY create_date ASC") + List filterOld(@Param("status") Task.TaskStatus status, @Param("tag") Tag tag); } diff --git a/src/main/java/ru/ulstu/students/service/TaskService.java b/src/main/java/ru/ulstu/students/service/TaskService.java index 7b67a44..a8747c7 100644 --- a/src/main/java/ru/ulstu/students/service/TaskService.java +++ b/src/main/java/ru/ulstu/students/service/TaskService.java @@ -1,12 +1,15 @@ package ru.ulstu.students.service; import org.apache.commons.lang3.StringUtils; +import org.springframework.data.domain.Sort; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import ru.ulstu.deadline.service.DeadlineService; import ru.ulstu.students.model.Task; import ru.ulstu.students.model.TaskDto; +import ru.ulstu.students.model.TaskFilterDto; import ru.ulstu.students.repository.TaskRepository; +import ru.ulstu.tags.model.Tag; import ru.ulstu.tags.service.TagService; import java.io.IOException; @@ -27,15 +30,15 @@ public class TaskService { private final DeadlineService deadlineService; private final TagService tagService; - public TaskService(TaskRepository grantRepository, + public TaskService(TaskRepository taskRepository, DeadlineService deadlineService, TagService tagService) { - this.taskRepository = grantRepository; + this.taskRepository = taskRepository; this.deadlineService = deadlineService; this.tagService = tagService; } public List findAll() { - return taskRepository.findAll(); + return taskRepository.findAll(new Sort(Sort.Direction.DESC, "createDate")); } public List findAllDto() { @@ -48,6 +51,18 @@ public class TaskService { return new TaskDto(taskRepository.findOne(id)); } + public List filter(TaskFilterDto filterDto) { + if (filterDto.getOrder().compareTo("new") == 0) { + return convert(taskRepository.filterNew( + filterDto.getStatus(), + filterDto.getTag() == null ? null : tagService.findById(filterDto.getTag())), TaskDto::new); + } else { + return convert(taskRepository.filterOld( + filterDto.getStatus(), + filterDto.getTag() == null ? null : tagService.findById(filterDto.getTag())), TaskDto::new); + } + } + @Transactional public Integer create(TaskDto taskDto) throws IOException { Task newTask = copyFromDto(new Task(), taskDto); @@ -76,8 +91,10 @@ public class TaskService { @Transactional public void delete(Integer taskId) throws IOException { - Task task = taskRepository.findOne(taskId); - taskRepository.delete(task); + if (taskRepository.exists(taskId)) { + taskRepository.delete(taskId); + } + } public void save(TaskDto taskDto) throws IOException { @@ -92,4 +109,8 @@ public class TaskService { return Arrays.asList(Task.TaskStatus.values()); } + public List getTags() { + return tagService.getTags(); + } + } diff --git a/src/main/java/ru/ulstu/tags/service/TagService.java b/src/main/java/ru/ulstu/tags/service/TagService.java index 4e88304..ba942f1 100644 --- a/src/main/java/ru/ulstu/tags/service/TagService.java +++ b/src/main/java/ru/ulstu/tags/service/TagService.java @@ -50,4 +50,12 @@ public class TagService { return newTag; } + public List getTags() { + return tagRepository.findAll(); + } + + public Tag findById(Integer tagId) { + return tagRepository.findOne(tagId); + } + } diff --git a/src/main/resources/db/changelog-20190419_000000-schema.xml b/src/main/resources/db/changelog-20190419_000000-schema.xml new file mode 100644 index 0000000..b56f322 --- /dev/null +++ b/src/main/resources/db/changelog-20190419_000000-schema.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + diff --git a/src/main/resources/db/changelog-20190424_000000-schema.xml b/src/main/resources/db/changelog-20190424_000000-schema.xml new file mode 100644 index 0000000..d61b38a --- /dev/null +++ b/src/main/resources/db/changelog-20190424_000000-schema.xml @@ -0,0 +1,28 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/resources/db/changelog-master.xml b/src/main/resources/db/changelog-master.xml index 1201a65..68b294a 100644 --- a/src/main/resources/db/changelog-master.xml +++ b/src/main/resources/db/changelog-master.xml @@ -30,6 +30,8 @@ + + \ No newline at end of file diff --git a/src/main/resources/public/css/conference.css b/src/main/resources/public/css/conference.css index ad06b3c..6018b9c 100644 --- a/src/main/resources/public/css/conference.css +++ b/src/main/resources/public/css/conference.css @@ -2,8 +2,8 @@ body { min-width: 400px; } -.conference-row .col:hover { - background-color: #f3f3f3; +.conference-row .d-flex:hover { + background-color: #f1f1f1; border-radius: .25rem; } @@ -15,10 +15,20 @@ body { margin-bottom: 10px; } -.conference-row .col .text-decoration { +.conference-row .d-flex .text-decoration { text-decoration: none; } +.conference-row .d-flex .text-decoration:nth-child(1) { + margin-left: 10px; +} + + + +.conference-row .d-flex { + margin: 0 15px; +} + .form-group textarea { min-height: 206px; @@ -61,13 +71,17 @@ body { padding: 0.5rem 1.75em 0.5rem 0.5em; display: inline-block; background: transparent url("https://cdn3.iconfinder.com/data/icons/faticons/32/arrow-down-01-16.png") no-repeat right 7px center; - + cursor: pointer; } .member select:nth-child(4) { border-right: 1px solid #ced4da; } +.member select:hover { + background-color: #f1f1f1; +} + .member-name { padding: .75rem 1.25rem; @@ -77,6 +91,16 @@ body { border-right: 1px solid #ced4da; } +#ping-button[disabled=disabled] { + background-color: #ced4da; + border-color: #c2c5c7; +} + +#ping-button[disabled=disabled]:hover { + background-color: #737475 !important; + border-color: #5d5e5f !important; +} + #take-part[disabled=disabled] { background-color: #ced4da; border-color: #c2c5c7; @@ -104,11 +128,22 @@ body { flex: 1; } +.paper-name:hover { + background-color: #f1f1f1; +} + .paper-name span { - margin: 6px 15px; + margin: 7px 10px; display: inline-block; } +.paper-name span:nth-child(1) { + margin: 3px 0px 3px 10px; + float: left; +} + + + .icon { width: 38px; height: 38px; @@ -117,14 +152,14 @@ body { } .icon-delete { - background-color: #f44; + background-color: #ff7272; background-image: url(/img/conference/delete.png); background-repeat: round; color: transparent !important; } .icon-delete:hover { - background-color: #ff2929; + background-color: #ff0000; transition: background-color .15s ease-in-out; } @@ -153,6 +188,22 @@ body { float: right; } +.note-1 { + background-color: #bfffce; +} + +.note-2 { + background-color: #eaffb4; +} + +.note-3 { + background-color: #fff69f; +} + +.note-4 { + background-color: #ff9973; +} + @media (max-width: 1199px) and (min-width: 768px){ .paper-control { display: block!important; diff --git a/src/main/resources/public/css/grant.css b/src/main/resources/public/css/grant.css index 2c95628..3c0cfc8 100644 --- a/src/main/resources/public/css/grant.css +++ b/src/main/resources/public/css/grant.css @@ -9,4 +9,23 @@ .div-deadline-description{ padding-left: 5px; padding-right: 5px; +} + +.div-view-paper { + margin-top: 6px; +} + +.div-selected-papers { + border: 0px; + padding-left: 12px; +} + +.icon-paper { + height: 22px; + width: 22px; + margin: 3px; +} + +.btn-delete-deadline { + color: black; } \ No newline at end of file diff --git a/src/main/resources/public/css/tasks.css b/src/main/resources/public/css/tasks.css index 6d18c99..7e350ed 100644 --- a/src/main/resources/public/css/tasks.css +++ b/src/main/resources/public/css/tasks.css @@ -13,6 +13,21 @@ cursor: text; } +.filter .bootstrap-select{ + margin-bottom: 10px; +} + +.filter-option-inner-inner{ + font-size: 12px; + text-transform: uppercase; + font-weight: normal; + line-height: 25px; +} + +.sorting .bootstrap-select{ + margin-bottom: 10px; +} + .input-tag-name { border: none; box-shadow: none; diff --git a/src/main/resources/public/js/conference.js b/src/main/resources/public/js/conference.js index d415ca2..18a8c67 100644 --- a/src/main/resources/public/js/conference.js +++ b/src/main/resources/public/js/conference.js @@ -1,7 +1,6 @@ $(document).ready(function () { - - $('a[data-confirm]').click(function(ev) { - var href = $(this).attr('href'); + $('input[data-confirm]').click(function(ev) { + var value = $(this).attr('value'); if (!$('#dataConfirmModal').length) { $('#modalDelete').append('\n' + ' \n' + ' \n' + @@ -22,7 +21,7 @@ $(document).ready(function () { ' '); } $('#dataConfirmModal').find('#myModalLabel').text($(this).attr('data-confirm')); - $('#dataConfirmOK').attr('href', href); + $('#deleteConference').attr('value', value); $('#dataConfirmModal').modal({show:true}); return false; }); diff --git a/src/main/resources/public/js/papers.js b/src/main/resources/public/js/papers.js index 78d3120..7a937ba 100644 --- a/src/main/resources/public/js/papers.js +++ b/src/main/resources/public/js/papers.js @@ -13,7 +13,8 @@ $(document).ready(function () { }); $('a[data-confirm]').click(function(ev) { - var href = $(this).attr('href'); + var id = $(this).parent().parent().find('.id-class').val(); + if (!$('#dataConfirmModal').length) { $('#modalDelete').append(''); } $('#dataConfirmModal').find('#myModalLabel').text($(this).attr('data-confirm')); - $('#dataConfirmOK').attr('href', href); + $('#dataConfirmOK').click(function () { + $("#paperDeleteId").val(id); + $('form').submit(); + }); $('#dataConfirmModal').modal({show:true}); return false; }); diff --git a/src/main/resources/public/js/projects.js b/src/main/resources/public/js/projects.js new file mode 100644 index 0000000..5867c50 --- /dev/null +++ b/src/main/resources/public/js/projects.js @@ -0,0 +1,42 @@ +/*\n' + + ' \n' + + ' '); + } + $('#dataConfirmModal').find('#myModalLabel').text($(this).attr('data-confirm')); + $('#dataConfirmOK').attr('href', href); + $('#dataConfirmModal').modal({show:true}); + return false; + }); +}); +/*]]>*/ \ No newline at end of file diff --git a/src/main/resources/public/js/tasks.js b/src/main/resources/public/js/tasks.js index b333c31..f756199 100644 --- a/src/main/resources/public/js/tasks.js +++ b/src/main/resources/public/js/tasks.js @@ -90,7 +90,7 @@ $(document).ready(function () { ' -
+
+ +
- + diff --git a/src/main/resources/templates/conferences/conferences.html b/src/main/resources/templates/conferences/conferences.html index 7b0ac8d..1c2d64e 100644 --- a/src/main/resources/templates/conferences/conferences.html +++ b/src/main/resources/templates/conferences/conferences.html @@ -8,7 +8,9 @@
-
+ +
@@ -18,9 +20,12 @@

+
+

+
+
\ No newline at end of file diff --git a/src/main/resources/templates/conferences/fragments/confDashboardFragment.html b/src/main/resources/templates/conferences/fragments/confDashboardFragment.html index 17f4aa6..5aabef2 100644 --- a/src/main/resources/templates/conferences/fragments/confDashboardFragment.html +++ b/src/main/resources/templates/conferences/fragments/confDashboardFragment.html @@ -4,12 +4,13 @@ -
+
-
- -
-
+

diff --git a/src/main/resources/templates/conferences/fragments/confLineFragment.html b/src/main/resources/templates/conferences/fragments/confLineFragment.html index 7d948d4..ecd166d 100644 --- a/src/main/resources/templates/conferences/fragments/confLineFragment.html +++ b/src/main/resources/templates/conferences/fragments/confLineFragment.html @@ -5,16 +5,19 @@
-
+
- - - + + + + +
diff --git a/src/main/resources/templates/conferences/fragments/confNavigationFragment.html b/src/main/resources/templates/conferences/fragments/confNavigationFragment.html index 7e67365..7bf9d27 100644 --- a/src/main/resources/templates/conferences/fragments/confNavigationFragment.html +++ b/src/main/resources/templates/conferences/fragments/confNavigationFragment.html @@ -21,7 +21,7 @@
- Новая конференцию + Новая конференция
diff --git a/src/main/resources/templates/default.html b/src/main/resources/templates/default.html index 00e2c0f..65e0be6 100644 --- a/src/main/resources/templates/default.html +++ b/src/main/resources/templates/default.html @@ -55,7 +55,8 @@ Сайт кафедры
+
@@ -59,12 +60,14 @@ th:field="*{deadlines[__${rowStat.index}__].description}"/>
- - +

- + + +
+ + +
+
+ +
+
+ +
+ + + Статус статьи + +
+
+
+
@@ -203,6 +245,8 @@ /*]]>*/ + + + +
diff --git a/src/main/resources/templates/index.html b/src/main/resources/templates/index.html index f821549..6bb134e 100644 --- a/src/main/resources/templates/index.html +++ b/src/main/resources/templates/index.html @@ -40,7 +40,7 @@
- +
diff --git a/src/main/resources/templates/papers/fragments/paperFilesListFragment.html b/src/main/resources/templates/papers/fragments/paperFilesListFragment.html index 5934c59..b4de456 100644 --- a/src/main/resources/templates/papers/fragments/paperFilesListFragment.html +++ b/src/main/resources/templates/papers/fragments/paperFilesListFragment.html @@ -8,7 +8,8 @@
- + diff --git a/src/main/resources/templates/papers/papers.html b/src/main/resources/templates/papers/papers.html index 7a033fe..5efd860 100644 --- a/src/main/resources/templates/papers/papers.html +++ b/src/main/resources/templates/papers/papers.html @@ -7,7 +7,8 @@
- +
@@ -17,7 +18,11 @@
+
+
+

+
@@ -43,7 +48,7 @@
-
+
diff --git a/src/main/resources/templates/projects/fragments/projectDashboardFragment.html b/src/main/resources/templates/projects/fragments/projectDashboardFragment.html index 4e6f1e6..027dce7 100644 --- a/src/main/resources/templates/projects/fragments/projectDashboardFragment.html +++ b/src/main/resources/templates/projects/fragments/projectDashboardFragment.html @@ -11,7 +11,6 @@
title -

status

diff --git a/src/main/resources/templates/projects/fragments/projectLineFragment.html b/src/main/resources/templates/projects/fragments/projectLineFragment.html index 3605273..43bdfb9 100644 --- a/src/main/resources/templates/projects/fragments/projectLineFragment.html +++ b/src/main/resources/templates/projects/fragments/projectLineFragment.html @@ -12,6 +12,10 @@ + + +
diff --git a/src/main/resources/templates/projects/fragments/projectStatusFragment.html b/src/main/resources/templates/projects/fragments/projectStatusFragment.html index e5da374..d8f29cc 100644 --- a/src/main/resources/templates/projects/fragments/projectStatusFragment.html +++ b/src/main/resources/templates/projects/fragments/projectStatusFragment.html @@ -4,7 +4,7 @@ - +
diff --git a/src/main/resources/templates/projects/projects.html b/src/main/resources/templates/projects/projects.html index fd19383..e70b910 100644 --- a/src/main/resources/templates/projects/projects.html +++ b/src/main/resources/templates/projects/projects.html @@ -27,7 +27,9 @@
+
+
diff --git a/src/main/resources/templates/students/dashboard.html b/src/main/resources/templates/students/dashboard.html index c0c2f0e..1f930cd 100644 --- a/src/main/resources/templates/students/dashboard.html +++ b/src/main/resources/templates/students/dashboard.html @@ -14,10 +14,10 @@

-
- - - + +
+ +
diff --git a/src/main/resources/templates/students/fragments/taskStatusFragment.html b/src/main/resources/templates/students/fragments/taskStatusFragment.html index 77fd529..d8ef4f4 100644 --- a/src/main/resources/templates/students/fragments/taskStatusFragment.html +++ b/src/main/resources/templates/students/fragments/taskStatusFragment.html @@ -6,9 +6,6 @@ - - -
diff --git a/src/main/resources/templates/students/tasks.html b/src/main/resources/templates/students/tasks.html index b1177d8..72c4194 100644 --- a/src/main/resources/templates/students/tasks.html +++ b/src/main/resources/templates/students/tasks.html @@ -7,7 +7,7 @@
-
+
@@ -20,27 +20,43 @@
- +
+
+
Сортировать:
+ +
Фильтр:
- + -