From b1e101c94036eb56b7d6c9d67667179433ae0c53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=92=D0=B0=D1=81=D0=B8=D0=BD=20=D0=90=D0=BD=D1=82=D0=BE?= =?UTF-8?q?=D0=BD?= Date: Tue, 7 May 2019 13:34:00 +0300 Subject: [PATCH 01/30] #101 db event edited --- .../db/changelog-20190507_000000-schema.xml | 14 ++++++++++++++ src/main/resources/db/changelog-master.xml | 1 + 2 files changed, 15 insertions(+) create mode 100644 src/main/resources/db/changelog-20190507_000000-schema.xml diff --git a/src/main/resources/db/changelog-20190507_000000-schema.xml b/src/main/resources/db/changelog-20190507_000000-schema.xml new file mode 100644 index 0000000..6962e7d --- /dev/null +++ b/src/main/resources/db/changelog-20190507_000000-schema.xml @@ -0,0 +1,14 @@ + + + + + + + + + + diff --git a/src/main/resources/db/changelog-master.xml b/src/main/resources/db/changelog-master.xml index 83ff280..65a07c2 100644 --- a/src/main/resources/db/changelog-master.xml +++ b/src/main/resources/db/changelog-master.xml @@ -38,4 +38,5 @@ + \ No newline at end of file From 279cc0e18a876ee6bf70fc06087680162cbd45ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=92=D0=B0=D1=81=D0=B8=D0=BD=20=D0=90=D0=BD=D1=82=D0=BE?= =?UTF-8?q?=D0=BD?= Date: Tue, 7 May 2019 14:00:24 +0300 Subject: [PATCH 02/30] #101 project model edited --- src/main/java/ru/ulstu/project/model/Project.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/main/java/ru/ulstu/project/model/Project.java b/src/main/java/ru/ulstu/project/model/Project.java index c971c4b..a596b76 100644 --- a/src/main/java/ru/ulstu/project/model/Project.java +++ b/src/main/java/ru/ulstu/project/model/Project.java @@ -5,11 +5,13 @@ import ru.ulstu.core.model.BaseEntity; import ru.ulstu.deadline.model.Deadline; import ru.ulstu.file.model.FileData; import ru.ulstu.grant.model.Grant; +import ru.ulstu.timeline.model.Event; import javax.persistence.CascadeType; import javax.persistence.Entity; import javax.persistence.EnumType; import javax.persistence.Enumerated; +import javax.persistence.FetchType; import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; import javax.persistence.OneToMany; @@ -62,6 +64,10 @@ public class Project extends BaseEntity { @JoinColumn(name = "file_id") private FileData application; + @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY) + @JoinColumn(name = "project_id") + private List events = new ArrayList<>(); + public String getTitle() { return title; } @@ -117,4 +123,12 @@ public class Project extends BaseEntity { public void setApplication(FileData application) { this.application = application; } + + public List getEvents() { + return events; + } + + public void setEvents(List events) { + this.events = events; + } } From ecda92326be467704b9e4e51128ee4440bc4ba45 Mon Sep 17 00:00:00 2001 From: T-Midnight Date: Wed, 22 May 2019 16:04:51 +0400 Subject: [PATCH 03/30] #103 create blank classes --- src/test/java/grant/GrantPage.java | 10 ++++++++++ src/test/java/grant/GrantsDashboardPage.java | 10 ++++++++++ src/test/java/grant/GrantsPage.java | 10 ++++++++++ 3 files changed, 30 insertions(+) create mode 100644 src/test/java/grant/GrantPage.java create mode 100644 src/test/java/grant/GrantsDashboardPage.java create mode 100644 src/test/java/grant/GrantsPage.java diff --git a/src/test/java/grant/GrantPage.java b/src/test/java/grant/GrantPage.java new file mode 100644 index 0000000..a0eee3c --- /dev/null +++ b/src/test/java/grant/GrantPage.java @@ -0,0 +1,10 @@ +package grant; + +import core.PageObject; + +public class GrantPage extends PageObject { + @Override + public String getSubTitle() { + return null; + } +} diff --git a/src/test/java/grant/GrantsDashboardPage.java b/src/test/java/grant/GrantsDashboardPage.java new file mode 100644 index 0000000..02939e1 --- /dev/null +++ b/src/test/java/grant/GrantsDashboardPage.java @@ -0,0 +1,10 @@ +package grant; + +import core.PageObject; + +public class GrantsDashboardPage extends PageObject { + @Override + public String getSubTitle() { + return null; + } +} diff --git a/src/test/java/grant/GrantsPage.java b/src/test/java/grant/GrantsPage.java new file mode 100644 index 0000000..9d8d6cf --- /dev/null +++ b/src/test/java/grant/GrantsPage.java @@ -0,0 +1,10 @@ +package grant; + +import core.PageObject; + +public class GrantsPage extends PageObject { + @Override + public String getSubTitle() { + return null; + } +} From b1c090b0eaf5411ab8d75cb209e2f3143bedecb2 Mon Sep 17 00:00:00 2001 From: T-Midnight Date: Wed, 22 May 2019 23:11:06 +0400 Subject: [PATCH 04/30] #103 add selenium-support library --- build.gradle | 1 + 1 file changed, 1 insertion(+) diff --git a/build.gradle b/build.gradle index 38de2c7..bd3f6e8 100644 --- a/build.gradle +++ b/build.gradle @@ -127,5 +127,6 @@ dependencies { testCompile group: 'org.springframework.boot', name: 'spring-boot-starter-test' testCompile group: 'org.seleniumhq.selenium', name: 'selenium-java', version: '3.3.1' + compile group: 'org.seleniumhq.selenium', name: 'selenium-support', version: '3.3.1' } \ No newline at end of file From 16885cc94f41a50fb9dae5ce7e1de64dfd68e575 Mon Sep 17 00:00:00 2001 From: T-Midnight Date: Wed, 22 May 2019 23:12:30 +0400 Subject: [PATCH 05/30] #103 update overriding method --- src/test/java/grant/GrantsDashboardPage.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/test/java/grant/GrantsDashboardPage.java b/src/test/java/grant/GrantsDashboardPage.java index 02939e1..036e785 100644 --- a/src/test/java/grant/GrantsDashboardPage.java +++ b/src/test/java/grant/GrantsDashboardPage.java @@ -1,10 +1,11 @@ package grant; import core.PageObject; +import org.openqa.selenium.By; public class GrantsDashboardPage extends PageObject { @Override public String getSubTitle() { - return null; + return driver.findElement(By.tagName("h2")).getText(); } } From 3e9bbb35840e11c06176be961109df1e55d2bcbe Mon Sep 17 00:00:00 2001 From: T-Midnight Date: Wed, 22 May 2019 23:15:04 +0400 Subject: [PATCH 06/30] #103 create tests for create, update and delete functions --- src/test/java/IndexGrantTest.java | 92 +++++++++++++++++++++++++++++ src/test/java/grant/GrantPage.java | 40 ++++++++++++- src/test/java/grant/GrantsPage.java | 30 +++++++++- 3 files changed, 160 insertions(+), 2 deletions(-) create mode 100644 src/test/java/IndexGrantTest.java diff --git a/src/test/java/IndexGrantTest.java b/src/test/java/IndexGrantTest.java new file mode 100644 index 0000000..064b2c7 --- /dev/null +++ b/src/test/java/IndexGrantTest.java @@ -0,0 +1,92 @@ +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.Iterables; +import core.PageObject; +import core.TestTemplate; +import grant.GrantPage; +import grant.GrantsDashboardPage; +import grant.GrantsPage; +import org.junit.Assert; +import org.junit.FixMethodOrder; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.MethodSorters; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; +import ru.ulstu.NgTrackerApplication; +import ru.ulstu.configuration.ApplicationProperties; + +import java.util.Arrays; +import java.util.Date; +import java.util.List; +import java.util.Map; + +@RunWith(SpringRunner.class) +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +@SpringBootTest(classes = NgTrackerApplication.class, webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT) +public class IndexGrantTest extends TestTemplate { + private final Map> navigationHolder = ImmutableMap.of( + new GrantsPage(), Arrays.asList("ГРАНТЫ", "/grants/grants"), + new GrantPage(), Arrays.asList("РЕДАКТИРОВАНИЕ ГРАНТА", "/grants/grant?id=0"), + new GrantsDashboardPage(), Arrays.asList("Гранты", "/grants/dashboard") + ); + + @Autowired + private ApplicationProperties applicationProperties; + + @Test + public void createNewGrant() { + Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 1); + getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); + GrantPage grantPage = (GrantPage) getContext().initPage(page.getKey()); + GrantsPage grantsPage = (GrantsPage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 0).getKey()); + + String newGrantName = "test grant" + (new Date()); + grantPage.setTitle(newGrantName); + String deadlineDate = new Date().toString(); + String deadlineDescription = "test deadline description"; + grantPage.setDeadline(deadlineDate, 0, deadlineDescription); + grantPage.setLeader(); + grantPage.saveGrant(); + + Assert.assertTrue(grantsPage.findGrantByTitle(newGrantName)); + } + + @Test + public void createBlankGrant() { + Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 1); + getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); + GrantPage grantPage = (GrantPage) getContext().initPage(page.getKey()); + + grantPage.saveGrant(); + + Assert.assertTrue(grantPage.checkBlankFields()); + } + + @Test + public void updateGrantTitle() { + Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); + getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); + GrantsPage grantsPage = (GrantsPage) getContext().initPage(page.getKey()); + GrantPage grantPage = (GrantPage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 1).getKey()); + + grantsPage.getFirstGrant(); + String newGrantTitle = "test " + (new Date()); + grantPage.setTitle(newGrantTitle); + grantPage.saveGrant(); + + Assert.assertTrue(grantsPage.findGrantByTitle(newGrantTitle)); + } + + @Test + public void deleteGrant() throws InterruptedException { + Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); + + getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); + GrantsPage grantsPage = (GrantsPage) getContext().initPage(page.getKey()); + + Integer size = grantsPage.getGrantsList().size(); + grantsPage.deleteFirst(); + Assert.assertEquals(size - 1, grantsPage.getGrantsList().size()); + } +} diff --git a/src/test/java/grant/GrantPage.java b/src/test/java/grant/GrantPage.java index a0eee3c..1754db5 100644 --- a/src/test/java/grant/GrantPage.java +++ b/src/test/java/grant/GrantPage.java @@ -1,10 +1,48 @@ package grant; import core.PageObject; +import org.openqa.selenium.By; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.support.ui.Select; public class GrantPage extends PageObject { @Override public String getSubTitle() { - return null; + return driver.findElement(By.tagName("h2")).getText(); + } + + public String getId() { + return driver.findElement(By.id("id")).getAttribute("value"); + } + + public void setTitle(String name) { + driver.findElement(By.id("title")).clear(); + driver.findElement(By.id("title")).sendKeys(name); + } + + public String getTitle() { + return driver.findElement(By.id("title")).getAttribute("value"); + } + + public void setDeadline(String date, Integer i, String description) { + driver.findElement(By.id(String.format("deadlines%d.date", i))).sendKeys(date); + driver.findElement(By.id(String.format("deadlines%d.description", i))).sendKeys(description); + } + + public void setLeader() { + WebElement webElement = driver.findElement(By.id("leaderId")); + Select selectLeader = new Select(webElement); + selectLeader.selectByVisibleText("Романов"); + } + + public void saveGrant() { + driver.findElement(By.id("sendMessageButton")).click(); + } + + public boolean checkBlankFields() { + if (driver.findElements(By.className("alert-danger")).size() > 0) { + return true; + } + return false; } } diff --git a/src/test/java/grant/GrantsPage.java b/src/test/java/grant/GrantsPage.java index 9d8d6cf..68f50db 100644 --- a/src/test/java/grant/GrantsPage.java +++ b/src/test/java/grant/GrantsPage.java @@ -1,10 +1,38 @@ package grant; import core.PageObject; +import org.openqa.selenium.By; +import org.openqa.selenium.WebElement; + +import java.util.List; public class GrantsPage extends PageObject { @Override public String getSubTitle() { - return null; + return driver.findElement(By.tagName("h2")).getText(); + } + + public List getGrantsList() { + return driver.findElements(By.cssSelector("span.h6")); + } + + public boolean findGrantByTitle(String grantTitle) { + return getGrantsList() + .stream() + .anyMatch(webElement -> webElement.getText().equals(grantTitle)); + } + + public void deleteFirst() throws InterruptedException { + WebElement findDeleteButton = driver.findElement(By.xpath("//*[@id=\"grants\"]/div/div[2]/div[1]/div[1]/div")); + findDeleteButton.click(); + Thread.sleep(3000); + WebElement grant = driver.findElement(By.xpath("//*[@id=\"grants\"]/div/div[2]/div[1]/div[1]/div/a[2]")); + grant.click(); + WebElement ok = driver.findElement(By.id("dataConfirmOK")); + ok.click(); + } + + public void getFirstGrant() { + driver.findElement(By.xpath("//*[@id=\"grants\"]/div/div[2]/div[1]/div[1]/div/a[1]")).click(); } } From 47131f1fb777c3ecbf087dbf67bbc9dcb8948046 Mon Sep 17 00:00:00 2001 From: T-Midnight Date: Thu, 23 May 2019 13:43:18 +0400 Subject: [PATCH 07/30] #103 add tests for papers --- src/test/java/IndexGrantTest.java | 30 ++++++++++++++++++++++- src/test/java/grant/GrantPage.java | 38 ++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+), 1 deletion(-) diff --git a/src/test/java/IndexGrantTest.java b/src/test/java/IndexGrantTest.java index 064b2c7..c633cfa 100644 --- a/src/test/java/IndexGrantTest.java +++ b/src/test/java/IndexGrantTest.java @@ -81,7 +81,6 @@ public class IndexGrantTest extends TestTemplate { @Test public void deleteGrant() throws InterruptedException { Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); - getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); GrantsPage grantsPage = (GrantsPage) getContext().initPage(page.getKey()); @@ -89,4 +88,33 @@ public class IndexGrantTest extends TestTemplate { grantsPage.deleteFirst(); Assert.assertEquals(size - 1, grantsPage.getGrantsList().size()); } + + @Test + public void attachPaper() { + Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); + getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); + GrantsPage grantsPage = (GrantsPage) getContext().initPage(page.getKey()); + GrantPage grantPage = (GrantPage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 1).getKey()); + + grantsPage.getFirstGrant(); + Integer countPapers = grantPage.getAttachedPapers().size(); + + Assert.assertEquals(countPapers + 1, grantPage.attachPaper().size()); + } + + @Test + public void deletePaper() { + Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); + getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); + GrantsPage grantsPage = (GrantsPage) getContext().initPage(page.getKey()); + GrantPage grantPage = (GrantPage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 1).getKey()); + + grantsPage.getFirstGrant(); + Integer oldCountPapers = grantPage.getAttachedPapers().size(); + if (oldCountPapers == 0) { + oldCountPapers = grantPage.attachPaper().size(); + } + + Assert.assertEquals(oldCountPapers - 1, grantPage.deletePaper().size()); + } } diff --git a/src/test/java/grant/GrantPage.java b/src/test/java/grant/GrantPage.java index 1754db5..809e22f 100644 --- a/src/test/java/grant/GrantPage.java +++ b/src/test/java/grant/GrantPage.java @@ -5,6 +5,8 @@ import org.openqa.selenium.By; import org.openqa.selenium.WebElement; import org.openqa.selenium.support.ui.Select; +import java.util.List; + public class GrantPage extends PageObject { @Override public String getSubTitle() { @@ -45,4 +47,40 @@ public class GrantPage extends PageObject { } return false; } + + public List getAttachedPapers() { + try { + return driver.findElement(By.className("div-selected-papers")).findElements(By.tagName("div")); + } catch (Exception ex) { + return null; + } + } + + public List attachPaper() { + WebElement selectPapers = driver.findElement(By.id("allPapers")); + Select select = new Select(selectPapers); + List selectedOptions = select.getAllSelectedOptions(); + List allOptions = select.getOptions(); + if (selectedOptions.size() >= allOptions.size()) { + for (int i = 0; i < allOptions.size(); i++) { + if (!allOptions.get(i).equals(selectedOptions.get(i))) { + select.selectByVisibleText(allOptions.get(i).getText()); + selectedOptions.add(allOptions.get(i)); + return selectedOptions; + } + } + } else { + select.selectByVisibleText(allOptions.get(0).getText()); + selectedOptions.add(allOptions.get(0)); + return selectedOptions; + } + return null; + } + + public List deletePaper() { + WebElement selectPapers = driver.findElement(By.id("allPapers")); + Select select = new Select(selectPapers); + select.deselectByVisibleText(select.getFirstSelectedOption().getText()); + return select.getAllSelectedOptions(); + } } From eb30d07d10f9d8072832e1077fcac22e481e3cbd Mon Sep 17 00:00:00 2001 From: "a.vasin" Date: Wed, 29 May 2019 18:27:34 +0400 Subject: [PATCH 08/30] #101 project deadlines on timeline --- .../ulstu/project/service/ProjectService.java | 6 ++++ .../java/ru/ulstu/timeline/model/Event.java | 13 +++++++ .../ru/ulstu/timeline/model/EventDto.java | 15 ++++++++ .../timeline/repository/EventRepository.java | 3 ++ .../ulstu/timeline/service/EventService.java | 34 +++++++++++++++++++ 5 files changed, 71 insertions(+) diff --git a/src/main/java/ru/ulstu/project/service/ProjectService.java b/src/main/java/ru/ulstu/project/service/ProjectService.java index fe8813c..30b5f01 100644 --- a/src/main/java/ru/ulstu/project/service/ProjectService.java +++ b/src/main/java/ru/ulstu/project/service/ProjectService.java @@ -9,6 +9,7 @@ import ru.ulstu.grant.repository.GrantRepository; import ru.ulstu.project.model.Project; import ru.ulstu.project.model.ProjectDto; import ru.ulstu.project.repository.ProjectRepository; +import ru.ulstu.timeline.service.EventService; import ru.ulstu.user.model.User; import ru.ulstu.user.service.UserService; @@ -28,17 +29,20 @@ public class ProjectService { private final DeadlineService deadlineService; private final GrantRepository grantRepository; private final FileService fileService; + private final EventService eventService; private final UserService userService; public ProjectService(ProjectRepository projectRepository, DeadlineService deadlineService, GrantRepository grantRepository, FileService fileService, + EventService eventService, UserService userService) { this.projectRepository = projectRepository; this.deadlineService = deadlineService; this.grantRepository = grantRepository; this.fileService = fileService; + this.eventService = eventService; this.userService = userService; } @@ -64,6 +68,7 @@ public class ProjectService { public Project create(ProjectDto projectDto) throws IOException { Project newProject = copyFromDto(new Project(), projectDto); newProject = projectRepository.save(newProject); + eventService.createFromProject(newProject); return newProject; } @@ -74,6 +79,7 @@ public class ProjectService { fileService.deleteFile(project.getApplication()); } projectRepository.save(copyFromDto(project, projectDto)); + eventService.updateProjectDeadlines(project); return project; } diff --git a/src/main/java/ru/ulstu/timeline/model/Event.java b/src/main/java/ru/ulstu/timeline/model/Event.java index 8038f0b..a8b4571 100644 --- a/src/main/java/ru/ulstu/timeline/model/Event.java +++ b/src/main/java/ru/ulstu/timeline/model/Event.java @@ -5,6 +5,7 @@ import ru.ulstu.conference.model.Conference; import ru.ulstu.core.model.BaseEntity; import ru.ulstu.grant.model.Grant; import ru.ulstu.paper.model.Paper; +import ru.ulstu.project.model.Project; import ru.ulstu.students.model.Task; import ru.ulstu.user.model.User; @@ -88,6 +89,10 @@ public class Event extends BaseEntity { @JoinColumn(name = "grant_id") private Grant grant; + @ManyToOne + @JoinColumn(name = "project_id") + private Project project; + @ManyToOne @JoinColumn(name = "task_id") private Task task; @@ -196,6 +201,14 @@ public class Event extends BaseEntity { this.grant = grant; } + public Project getProject() { + return project; + } + + public void setProject(Project project) { + this.project = project; + } + public Task getTask() { return task; } diff --git a/src/main/java/ru/ulstu/timeline/model/EventDto.java b/src/main/java/ru/ulstu/timeline/model/EventDto.java index ccf0f0a..1f0076b 100644 --- a/src/main/java/ru/ulstu/timeline/model/EventDto.java +++ b/src/main/java/ru/ulstu/timeline/model/EventDto.java @@ -6,6 +6,7 @@ import org.hibernate.validator.constraints.NotBlank; import ru.ulstu.conference.model.ConferenceDto; import ru.ulstu.grant.model.GrantDto; import ru.ulstu.paper.model.PaperDto; +import ru.ulstu.project.model.ProjectDto; import ru.ulstu.students.model.TaskDto; import ru.ulstu.user.model.UserDto; @@ -30,6 +31,7 @@ public class EventDto { private PaperDto paperDto; private ConferenceDto conferenceDto; private GrantDto grantDto; + private ProjectDto projectDto; private TaskDto taskDto; @JsonCreator @@ -45,6 +47,7 @@ public class EventDto { @JsonProperty("recipients") List recipients, @JsonProperty("conferenceDto") ConferenceDto conferenceDto, @JsonProperty("grantDto") GrantDto grantDto, + @JsonProperty("projectDto") ProjectDto projectDto, @JsonProperty("taskDto") TaskDto taskDto) { this.id = id; this.title = title; @@ -58,6 +61,7 @@ public class EventDto { this.paperDto = paperDto; this.conferenceDto = conferenceDto; this.grantDto = grantDto; + this.projectDto = projectDto; this.taskDto = taskDto; } @@ -80,6 +84,9 @@ public class EventDto { if (grantDto != null) { this.grantDto = new GrantDto(event.getGrant()); } + if (projectDto != null) { + this.projectDto = new ProjectDto(event.getProject()); + } if (taskDto != null) { this.taskDto = new TaskDto(event.getTask()); } @@ -145,6 +152,14 @@ public class EventDto { this.grantDto = grantDto; } + public ProjectDto getProjectDto() { + return projectDto; + } + + public void setProjectDto(ProjectDto projectDto) { + this.projectDto = projectDto; + } + public TaskDto getTaskDto() { return taskDto; } diff --git a/src/main/java/ru/ulstu/timeline/repository/EventRepository.java b/src/main/java/ru/ulstu/timeline/repository/EventRepository.java index 7ebd3c9..15e1355 100644 --- a/src/main/java/ru/ulstu/timeline/repository/EventRepository.java +++ b/src/main/java/ru/ulstu/timeline/repository/EventRepository.java @@ -5,6 +5,7 @@ import org.springframework.data.jpa.repository.Query; import ru.ulstu.conference.model.Conference; import ru.ulstu.grant.model.Grant; import ru.ulstu.paper.model.Paper; +import ru.ulstu.project.model.Project; import ru.ulstu.students.model.Task; import ru.ulstu.timeline.model.Event; @@ -23,5 +24,7 @@ public interface EventRepository extends JpaRepository { List findAllByGrant(Grant grant); + List findAllByProject(Project project); + List findAllByTask(Task task); } diff --git a/src/main/java/ru/ulstu/timeline/service/EventService.java b/src/main/java/ru/ulstu/timeline/service/EventService.java index 8c68291..eef38eb 100644 --- a/src/main/java/ru/ulstu/timeline/service/EventService.java +++ b/src/main/java/ru/ulstu/timeline/service/EventService.java @@ -8,11 +8,13 @@ import ru.ulstu.conference.model.Conference; import ru.ulstu.deadline.model.Deadline; import ru.ulstu.grant.model.Grant; import ru.ulstu.paper.model.Paper; +import ru.ulstu.project.model.Project; import ru.ulstu.students.model.Task; import ru.ulstu.timeline.model.Event; import ru.ulstu.timeline.model.EventDto; import ru.ulstu.timeline.model.Timeline; import ru.ulstu.timeline.repository.EventRepository; +import ru.ulstu.user.model.User; import ru.ulstu.user.model.UserDto; import ru.ulstu.user.service.UserService; @@ -205,6 +207,38 @@ public class EventService { createFromGrant(grant); } + public void createFromProject(Project newProject) { + List timelines = timelineService.findAll(); + Timeline timeline = timelines.isEmpty() ? new Timeline() : timelines.get(0); + + for (Deadline deadline : newProject.getDeadlines() + .stream() + .filter(d -> d.getDate().after(new Date()) || DateUtils.isSameDay(d.getDate(), new Date())) + .collect(Collectors.toList())) { + Event newEvent = new Event(); + newEvent.setTitle("Дедлайн проекта"); + newEvent.setStatus(Event.EventStatus.NEW); + newEvent.setExecuteDate(deadline.getDate()); + newEvent.setCreateDate(new Date()); + newEvent.setUpdateDate(new Date()); + newEvent.setDescription("Дедлайн '" + deadline.getDescription() + "' проекта '" + newProject.getTitle() + "'"); + if (newProject.getExecutors() != null) { + newEvent.setRecipients(new ArrayList(newProject.getExecutors())); + } + newEvent.getRecipients().add((User) newProject.getExecutors()); + newEvent.setProject(newProject); + eventRepository.save(newEvent); + + timeline.getEvents().add(newEvent); + timelineService.save(timeline); + } + } + + public void updateProjectDeadlines(Project project) { + eventRepository.delete(eventRepository.findAllByProject(project)); + createFromProject(project); + } + public void removeConferencesEvent(Conference conference) { List eventList = eventRepository.findAllByConference(conference); eventList.forEach(event -> eventRepository.delete(event.getId())); From 192adbfa0b73a539c1b2b241cf3f21f57643d2bc Mon Sep 17 00:00:00 2001 From: "a.vasin" Date: Wed, 29 May 2019 18:40:14 +0400 Subject: [PATCH 09/30] #101 no projects message --- src/main/resources/templates/projects/dashboard.html | 1 + src/main/resources/templates/projects/projects.html | 1 + 2 files changed, 2 insertions(+) diff --git a/src/main/resources/templates/projects/dashboard.html b/src/main/resources/templates/projects/dashboard.html index c48b035..0eafb4a 100644 --- a/src/main/resources/templates/projects/dashboard.html +++ b/src/main/resources/templates/projects/dashboard.html @@ -17,6 +17,7 @@
+
diff --git a/src/main/resources/templates/projects/projects.html b/src/main/resources/templates/projects/projects.html index e70b910..de334f8 100644 --- a/src/main/resources/templates/projects/projects.html +++ b/src/main/resources/templates/projects/projects.html @@ -24,6 +24,7 @@
+
From 9013d79228d5688bc308a821440d39a62de8d21c Mon Sep 17 00:00:00 2001 From: "a.vasin" Date: Wed, 29 May 2019 23:40:30 +0400 Subject: [PATCH 10/30] #101 grant attach --- .../grant/repository/GrantRepository.java | 2 ++ .../ru/ulstu/grant/service/GrantService.java | 4 +++ .../project/controller/ProjectController.java | 15 ++++++++++ .../java/ru/ulstu/project/model/Project.java | 29 +++++++++++++++---- .../ru/ulstu/project/model/ProjectDto.java | 27 ++++++++++++++++- .../ulstu/project/service/ProjectService.java | 24 +++++++++++++++ .../ulstu/timeline/service/EventService.java | 2 +- .../db/changelog-20190529_000000-schema.xml | 17 +++++++++++ src/main/resources/db/changelog-master.xml | 1 + .../resources/templates/projects/project.html | 16 ++++++---- 10 files changed, 125 insertions(+), 12 deletions(-) create mode 100644 src/main/resources/db/changelog-20190529_000000-schema.xml diff --git a/src/main/java/ru/ulstu/grant/repository/GrantRepository.java b/src/main/java/ru/ulstu/grant/repository/GrantRepository.java index 876a8c1..50fad13 100644 --- a/src/main/java/ru/ulstu/grant/repository/GrantRepository.java +++ b/src/main/java/ru/ulstu/grant/repository/GrantRepository.java @@ -14,6 +14,8 @@ public interface GrantRepository extends JpaRepository, BaseRepo Grant findByTitle(String title); + Grant findGrantById(Integer grantId); + @Override @Query("SELECT title FROM Grant g WHERE (g.title = :name) AND (:id IS NULL OR g.id != :id) ") String findByNameAndNotId(@Param("name") String name, @Param("id") Integer id); diff --git a/src/main/java/ru/ulstu/grant/service/GrantService.java b/src/main/java/ru/ulstu/grant/service/GrantService.java index 86f8f1b..09da77f 100644 --- a/src/main/java/ru/ulstu/grant/service/GrantService.java +++ b/src/main/java/ru/ulstu/grant/service/GrantService.java @@ -336,4 +336,8 @@ public class GrantService extends BaseService { private List findAllActive() { return grantRepository.findAllActive(); } + + public Grant findGrantById(Integer grantId) { + return grantRepository.findOne(grantId); + } } diff --git a/src/main/java/ru/ulstu/project/controller/ProjectController.java b/src/main/java/ru/ulstu/project/controller/ProjectController.java index 88f0c7a..87ae8df 100644 --- a/src/main/java/ru/ulstu/project/controller/ProjectController.java +++ b/src/main/java/ru/ulstu/project/controller/ProjectController.java @@ -10,6 +10,8 @@ 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.grant.model.Grant; +import ru.ulstu.grant.model.GrantDto; import ru.ulstu.project.model.Project; import ru.ulstu.project.model.ProjectDto; import ru.ulstu.project.service.ProjectService; @@ -46,6 +48,8 @@ public class ProjectController { @GetMapping("/project") public void getProject(ModelMap modelMap, @RequestParam(value = "id") Integer id) { if (id != null && id > 0) { + ProjectDto projectDto = projectService.findOneDto(id); + attachGrant(projectDto); modelMap.put("projectDto", projectService.findOneDto(id)); } else { modelMap.put("projectDto", new ProjectDto()); @@ -70,6 +74,12 @@ public class ProjectController { return String.format("redirect:%s", "/projects/projects"); } + @PostMapping(value = "/project", params = "attachGrant") + public String attachGrant(ProjectDto projectDto) { + projectService.attachGrant(projectDto); + return "/projects/project"; + } + @PostMapping(value = "/project", params = "addDeadline") public String addDeadline(@Valid ProjectDto projectDto, Errors errors) { filterEmptyDeadlines(projectDto); @@ -98,6 +108,11 @@ public class ProjectController { return projectService.getProjectExecutors(projectDto); } + @ModelAttribute("allGrants") + public List getAllGrants() { + return projectService.getAllGrants(); + } + 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/Project.java b/src/main/java/ru/ulstu/project/model/Project.java index cb53645..27a4ae6 100644 --- a/src/main/java/ru/ulstu/project/model/Project.java +++ b/src/main/java/ru/ulstu/project/model/Project.java @@ -1,5 +1,7 @@ package ru.ulstu.project.model; +import org.hibernate.annotations.Fetch; +import org.hibernate.annotations.FetchMode; import org.hibernate.validator.constraints.NotBlank; import ru.ulstu.core.model.BaseEntity; import ru.ulstu.core.model.UserContainer; @@ -8,15 +10,17 @@ import ru.ulstu.file.model.FileData; import ru.ulstu.grant.model.Grant; import ru.ulstu.timeline.model.Event; import ru.ulstu.user.model.User; -import javax.persistence.CascadeType; + import javax.persistence.Entity; import javax.persistence.EnumType; import javax.persistence.Enumerated; -import javax.persistence.FetchType; -import javax.persistence.JoinColumn; -import javax.persistence.ManyToMany; -import javax.persistence.ManyToOne; import javax.persistence.OneToMany; +import javax.persistence.CascadeType; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import javax.persistence.FetchType; +import javax.persistence.ManyToMany; +import javax.persistence.JoinTable; import javax.validation.constraints.NotNull; import java.util.ArrayList; import java.util.HashSet; @@ -76,6 +80,13 @@ public class Project extends BaseEntity implements UserContainer { @ManyToMany(fetch = FetchType.LAZY) private List executors = new ArrayList<>(); + @ManyToMany(fetch = FetchType.LAZY) + @JoinTable(name = "project_grants", + joinColumns = {@JoinColumn(name = "project_id")}, + inverseJoinColumns = {@JoinColumn(name = "grants_id")}) + @Fetch(FetchMode.SUBSELECT) + private List grants = new ArrayList<>(); + public String getTitle() { return title; } @@ -153,4 +164,12 @@ public class Project extends BaseEntity implements UserContainer { Set users = new HashSet(getExecutors()); return users; } + + public List getGrants() { + return grants; + } + + public void setGrants(List grants) { + this.grants = grants; + } } diff --git a/src/main/java/ru/ulstu/project/model/ProjectDto.java b/src/main/java/ru/ulstu/project/model/ProjectDto.java index affee4e..7da4ac4 100644 --- a/src/main/java/ru/ulstu/project/model/ProjectDto.java +++ b/src/main/java/ru/ulstu/project/model/ProjectDto.java @@ -5,6 +5,7 @@ import com.fasterxml.jackson.annotation.JsonProperty; import org.hibernate.validator.constraints.NotEmpty; import org.thymeleaf.util.StringUtils; import ru.ulstu.deadline.model.Deadline; +import ru.ulstu.grant.model.Grant; import ru.ulstu.grant.model.GrantDto; import ru.ulstu.user.model.User; import ru.ulstu.user.model.UserDto; @@ -31,6 +32,8 @@ public class ProjectDto { private List removedDeadlineIds = new ArrayList<>(); private Set executorIds; private List executors; + private List grantIds; + private List grants; private final static int MAX_EXECUTORS_LENGTH = 40; @@ -50,7 +53,9 @@ public class ProjectDto { @JsonProperty("repository") String repository, @JsonProperty("deadlines") List deadlines, @JsonProperty("executorIds") Set executorIds, - @JsonProperty("executors") List executors) { + @JsonProperty("executors") List executors, + @JsonProperty("grantIds") List grantIds, + @JsonProperty("grants") List grants) { this.id = id; this.title = title; this.status = status; @@ -61,6 +66,8 @@ public class ProjectDto { this.applicationFileName = null; this.executorIds = executorIds; this.executors = executors; + this.grantIds = grantIds; + this.grants = grants; } @@ -76,6 +83,8 @@ public class ProjectDto { this.deadlines = project.getDeadlines(); this.executorIds = convert(users, user -> user.getId()); this.executors = convert(project.getExecutors(), UserDto::new); + this.grantIds = convert(project.getGrants(), grant -> grant.getId()); + this.grants = convert(project.getGrants(), GrantDto::new); } public Integer getId() { @@ -172,4 +181,20 @@ public class ProjectDto { .map(executor -> executor.getLastName()) .collect(Collectors.joining(", ")), MAX_EXECUTORS_LENGTH); } + + public List getGrantIds() { + return grantIds; + } + + public void setGrantIds(List grantIds) { + this.grantIds = grantIds; + } + + public List getGrants() { + return grants; + } + + public void setGrants(List grants) { + this.grants = grants; + } } diff --git a/src/main/java/ru/ulstu/project/service/ProjectService.java b/src/main/java/ru/ulstu/project/service/ProjectService.java index 30b5f01..fe0671c 100644 --- a/src/main/java/ru/ulstu/project/service/ProjectService.java +++ b/src/main/java/ru/ulstu/project/service/ProjectService.java @@ -5,6 +5,7 @@ import org.springframework.transaction.annotation.Transactional; import org.thymeleaf.util.StringUtils; import ru.ulstu.deadline.service.DeadlineService; import ru.ulstu.file.service.FileService; +import ru.ulstu.grant.model.GrantDto; import ru.ulstu.grant.repository.GrantRepository; import ru.ulstu.project.model.Project; import ru.ulstu.project.model.ProjectDto; @@ -16,6 +17,7 @@ import ru.ulstu.user.service.UserService; import java.io.IOException; import java.util.Arrays; import java.util.List; +import java.util.Set; import static org.springframework.util.ObjectUtils.isEmpty; import static ru.ulstu.core.util.StreamApiUtils.convert; @@ -104,6 +106,10 @@ public class ProjectService { if (projectDto.getApplicationFileName() != null) { project.setApplication(fileService.createFileFromTmp(projectDto.getApplicationFileName())); } + project.getGrants().clear(); + if (projectDto.getGrantIds() != null && !projectDto.getGrantIds().isEmpty()) { + projectDto.getGrantIds().forEach(grantIds -> project.getGrants().add(grantRepository.findGrantById(grantIds))); + } return project; } @@ -131,4 +137,22 @@ public class ProjectService { return users; } + public List getAllGrants() { + List grants = convert(grantRepository.findAll(), GrantDto::new); + return grants; + } + + public List getProjectGrants(List grantIds) { + return convert(grantRepository.findAll(grantIds), GrantDto::new); + } + + public void attachGrant(ProjectDto projectDto) { + if (!projectDto.getGrantIds().isEmpty()) { + projectDto.getGrants().clear(); + projectDto.setGrants(getProjectGrants(projectDto.getGrantIds())); + } else { + projectDto.getGrants().clear(); + } + } + } diff --git a/src/main/java/ru/ulstu/timeline/service/EventService.java b/src/main/java/ru/ulstu/timeline/service/EventService.java index eef38eb..8f5376e 100644 --- a/src/main/java/ru/ulstu/timeline/service/EventService.java +++ b/src/main/java/ru/ulstu/timeline/service/EventService.java @@ -225,7 +225,7 @@ public class EventService { if (newProject.getExecutors() != null) { newEvent.setRecipients(new ArrayList(newProject.getExecutors())); } - newEvent.getRecipients().add((User) newProject.getExecutors()); +// newEvent.getRecipients().add((User) newProject.getExecutors()); newEvent.setProject(newProject); eventRepository.save(newEvent); diff --git a/src/main/resources/db/changelog-20190529_000000-schema.xml b/src/main/resources/db/changelog-20190529_000000-schema.xml new file mode 100644 index 0000000..40079ff --- /dev/null +++ b/src/main/resources/db/changelog-20190529_000000-schema.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + diff --git a/src/main/resources/db/changelog-master.xml b/src/main/resources/db/changelog-master.xml index 1cede5f..6dadded 100644 --- a/src/main/resources/db/changelog-master.xml +++ b/src/main/resources/db/changelog-master.xml @@ -50,4 +50,5 @@ + \ No newline at end of file diff --git a/src/main/resources/templates/projects/project.html b/src/main/resources/templates/projects/project.html index 2c4a67b..67dac69 100644 --- a/src/main/resources/templates/projects/project.html +++ b/src/main/resources/templates/projects/project.html @@ -51,12 +51,18 @@
- -
- + +
+
+ +
-
From 632c6299b776664dd0ca15def3496739c5ecf5a8 Mon Sep 17 00:00:00 2001 From: "a.vasin" Date: Thu, 30 May 2019 00:08:13 +0400 Subject: [PATCH 11/30] #101 files attach modified --- .../java/ru/ulstu/project/model/Project.java | 15 +-- .../ru/ulstu/project/model/ProjectDto.java | 17 ++-- .../ulstu/project/service/ProjectService.java | 19 ++-- .../db/changelog-20190529_000001-schema.xml | 13 +++ src/main/resources/db/changelog-master.xml | 1 + .../fragments/projectFilesListFragment.html | 40 ++++++++ .../resources/templates/projects/project.html | 97 ++++++++++++++++++- 7 files changed, 176 insertions(+), 26 deletions(-) create mode 100644 src/main/resources/db/changelog-20190529_000001-schema.xml create mode 100644 src/main/resources/templates/projects/fragments/projectFilesListFragment.html diff --git a/src/main/java/ru/ulstu/project/model/Project.java b/src/main/java/ru/ulstu/project/model/Project.java index 27a4ae6..0c0af94 100644 --- a/src/main/java/ru/ulstu/project/model/Project.java +++ b/src/main/java/ru/ulstu/project/model/Project.java @@ -69,9 +69,10 @@ public class Project extends BaseEntity implements UserContainer { @NotNull private String repository; - @ManyToOne - @JoinColumn(name = "file_id") - private FileData application; + @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER) + @JoinColumn(name = "project_id", unique = true) + @Fetch(FetchMode.SUBSELECT) + private List files = new ArrayList<>(); @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY) @JoinColumn(name = "project_id") @@ -135,12 +136,12 @@ public class Project extends BaseEntity implements UserContainer { this.deadlines = deadlines; } - public FileData getApplication() { - return application; + public List getFiles() { + return files; } - public void setApplication(FileData application) { - this.application = application; + public void setFiles(List files) { + this.files = files; } public List getEvents() { diff --git a/src/main/java/ru/ulstu/project/model/ProjectDto.java b/src/main/java/ru/ulstu/project/model/ProjectDto.java index 7da4ac4..fb60703 100644 --- a/src/main/java/ru/ulstu/project/model/ProjectDto.java +++ b/src/main/java/ru/ulstu/project/model/ProjectDto.java @@ -5,7 +5,7 @@ import com.fasterxml.jackson.annotation.JsonProperty; import org.hibernate.validator.constraints.NotEmpty; import org.thymeleaf.util.StringUtils; import ru.ulstu.deadline.model.Deadline; -import ru.ulstu.grant.model.Grant; +import ru.ulstu.file.model.FileDataDto; import ru.ulstu.grant.model.GrantDto; import ru.ulstu.user.model.User; import ru.ulstu.user.model.UserDto; @@ -28,7 +28,7 @@ public class ProjectDto { private List deadlines = new ArrayList<>(); private GrantDto grant; private String repository; - private String applicationFileName; + private List files = new ArrayList<>(); private List removedDeadlineIds = new ArrayList<>(); private Set executorIds; private List executors; @@ -51,6 +51,7 @@ public class ProjectDto { @JsonProperty("description") String description, @JsonProperty("grant") GrantDto grant, @JsonProperty("repository") String repository, + @JsonProperty("files") List files, @JsonProperty("deadlines") List deadlines, @JsonProperty("executorIds") Set executorIds, @JsonProperty("executors") List executors, @@ -63,7 +64,7 @@ public class ProjectDto { this.grant = grant; this.repository = repository; this.deadlines = deadlines; - this.applicationFileName = null; + this.files = files; this.executorIds = executorIds; this.executors = executors; this.grantIds = grantIds; @@ -77,7 +78,7 @@ public class ProjectDto { this.title = project.getTitle(); this.status = project.getStatus(); this.description = project.getDescription(); - this.applicationFileName = project.getApplication() == null ? null : project.getApplication().getName(); + this.files = convert(project.getFiles(), FileDataDto::new); this.grant = project.getGrant() == null ? null : new GrantDto(project.getGrant()); this.repository = project.getRepository(); this.deadlines = project.getDeadlines(); @@ -143,12 +144,12 @@ public class ProjectDto { this.deadlines = deadlines; } - public String getApplicationFileName() { - return applicationFileName; + public List getFiles() { + return files; } - public void setApplicationFileName(String applicationFileName) { - this.applicationFileName = applicationFileName; + public void setFiles(List files) { + this.files = files; } public List getRemovedDeadlineIds() { diff --git a/src/main/java/ru/ulstu/project/service/ProjectService.java b/src/main/java/ru/ulstu/project/service/ProjectService.java index fe0671c..e77cc88 100644 --- a/src/main/java/ru/ulstu/project/service/ProjectService.java +++ b/src/main/java/ru/ulstu/project/service/ProjectService.java @@ -4,6 +4,7 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.thymeleaf.util.StringUtils; import ru.ulstu.deadline.service.DeadlineService; +import ru.ulstu.file.model.FileDataDto; import ru.ulstu.file.service.FileService; import ru.ulstu.grant.model.GrantDto; import ru.ulstu.grant.repository.GrantRepository; @@ -19,6 +20,7 @@ import java.util.Arrays; import java.util.List; import java.util.Set; +import static java.util.stream.Collectors.toList; import static org.springframework.util.ObjectUtils.isEmpty; import static ru.ulstu.core.util.StreamApiUtils.convert; import static ru.ulstu.project.model.Project.ProjectStatus.TECHNICAL_TASK; @@ -77,20 +79,19 @@ public class ProjectService { @Transactional public Project update(ProjectDto projectDto) throws IOException { Project project = projectRepository.findOne(projectDto.getId()); - if (projectDto.getApplicationFileName() != null && project.getApplication() != null) { - fileService.deleteFile(project.getApplication()); - } projectRepository.save(copyFromDto(project, projectDto)); eventService.updateProjectDeadlines(project); + for (FileDataDto file : projectDto.getFiles().stream() + .filter(f -> f.isDeleted() && f.getId() != null) + .collect(toList())) { + fileService.delete(file.getId()); + } 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); } @@ -103,9 +104,9 @@ public class ProjectService { } project.setRepository(projectDto.getRepository()); project.setDeadlines(deadlineService.saveOrCreate(projectDto.getDeadlines())); - if (projectDto.getApplicationFileName() != null) { - project.setApplication(fileService.createFileFromTmp(projectDto.getApplicationFileName())); - } + project.setFiles(fileService.saveOrCreate(projectDto.getFiles().stream() + .filter(f -> !f.isDeleted()) + .collect(toList()))); project.getGrants().clear(); if (projectDto.getGrantIds() != null && !projectDto.getGrantIds().isEmpty()) { projectDto.getGrantIds().forEach(grantIds -> project.getGrants().add(grantRepository.findGrantById(grantIds))); diff --git a/src/main/resources/db/changelog-20190529_000001-schema.xml b/src/main/resources/db/changelog-20190529_000001-schema.xml new file mode 100644 index 0000000..0b6548b --- /dev/null +++ b/src/main/resources/db/changelog-20190529_000001-schema.xml @@ -0,0 +1,13 @@ + + + + + + + + + diff --git a/src/main/resources/db/changelog-master.xml b/src/main/resources/db/changelog-master.xml index 6dadded..529b597 100644 --- a/src/main/resources/db/changelog-master.xml +++ b/src/main/resources/db/changelog-master.xml @@ -51,4 +51,5 @@ + \ No newline at end of file diff --git a/src/main/resources/templates/projects/fragments/projectFilesListFragment.html b/src/main/resources/templates/projects/fragments/projectFilesListFragment.html new file mode 100644 index 0000000..0e803d9 --- /dev/null +++ b/src/main/resources/templates/projects/fragments/projectFilesListFragment.html @@ -0,0 +1,40 @@ + + + + + + + +
+ + +
+ + + + +
+ + + +
+
+ + +
+
+
+
+ + + + + \ No newline at end of file diff --git a/src/main/resources/templates/projects/project.html b/src/main/resources/templates/projects/project.html index 67dac69..0d132e9 100644 --- a/src/main/resources/templates/projects/project.html +++ b/src/main/resources/templates/projects/project.html @@ -119,6 +119,13 @@ value="Добавить дедлайн"/>
+
+ + +
+ +
+
@@ -154,17 +161,103 @@ new FileLoader({ div: "loader", url: urlFileUpload, - maxSize: 2, - extensions: ["doc", "docx", "xls", "jpg", "png", "pdf", "txt"], + maxSize: -1, + extensions: [], callback: function (response) { showFeedbackMessage("Файл успешно загружен"); console.debug(response); + + addNewFile(response, $("#files-list")); } }); $('.selectpicker').selectpicker(); }); /*]]>*/ + function addNewFile(fileDto, listElement) { + var fileNumber = $('.files-list div.row').length; + var newFileRow = $("
") + .attr("id", 'files' + fileNumber) + .addClass("row"); + + var idInput = $("") + .attr("type", "hidden") + .attr("id", "files" + fileNumber + ".id") + .attr("value", '') + .attr("name", "files[" + fileNumber + "].id"); + newFileRow.append(idInput); + + var flagInput = $("") + .attr("type", "hidden") + .attr("id", "files" + fileNumber + ".deleted") + .attr("value", "false") + .attr("name", "files[" + fileNumber + "].deleted"); + newFileRow.append(flagInput); + + var nameInput = $("") + .attr("type", "hidden") + .attr("id", "files" + fileNumber + ".name") + .attr("value", fileDto.fileName) + .attr("name", "files[" + fileNumber + "].name"); + newFileRow.append(nameInput); + + var tmpFileNameInput = $("") + .attr("type", "hidden") + .attr("id", "files" + fileNumber + ".tmpFileName") + .attr("value", fileDto.tmpFileName) + .attr("name", "files[" + fileNumber + "].tmpFileName"); + newFileRow.append(tmpFileNameInput); + + var nextDiv = $("
") + .addClass("col-2"); + + var nextA = $("") + .addClass("btn btn-danger float-right") + .attr("onclick", "$('#files" + fileNumber + "\\\\.deleted').val('true'); $('#files" + fileNumber + "').hide();") + .append(($("").attr("aria-hidden", "true")).append($("").addClass("fa fa-times"))) + ; + nextDiv.append(nextA) + newFileRow.append(nextDiv); + + var nameDiv = $("
") + .addClass("col-10") + .append($("").text(fileDto.fileName) + .attr("href", 'javascript:void(0)') + .attr("onclick", "downloadFile('" + fileDto.tmpFileName + "',null,'" + fileDto.fileName + "')")); + newFileRow.append(nameDiv); + + listElement.append(newFileRow); + + } + + function downloadFile(tmpName, fileId, downloadName) { + let xhr = new XMLHttpRequest(); + if (fileId != null) xhr.open('GET', urlFileDownload + fileId); + if (tmpName != null) xhr.open('GET', urlFileDownloadTmp + tmpName); + xhr.responseType = 'blob'; + + var formData = new FormData(); + if (fileId != null) formData.append("file-id", fileId); + if (tmpName != null) formData.append("tmp-file-name", tmpName); + + xhr.send(formData); + + xhr.onload = function () { + if (this.status == 200) { + console.debug(this.response); + var blob = new Blob([this.response], {type: '*'}); + let a = document.createElement("a"); + a.style = "display: none"; + document.body.appendChild(a); + let url = window.URL.createObjectURL(blob); + a.href = url; + a.download = downloadName; + a.click(); + window.URL.revokeObjectURL(url); + } else { + } + } + }
From 4498b712595a72b8ff82799f5f4dc0c737b72abd Mon Sep 17 00:00:00 2001 From: "a.vasin" Date: Thu, 30 May 2019 09:53:27 +0400 Subject: [PATCH 12/30] #101 project tests --- src/test/java/ProjectTest.java | 37 +++++++ src/test/java/project/ProjectDashboard.java | 11 ++ src/test/java/project/ProjectPage.java | 107 ++++++++++++++++++++ src/test/java/project/ProjectsPage.java | 41 ++++++++ 4 files changed, 196 insertions(+) create mode 100644 src/test/java/ProjectTest.java create mode 100644 src/test/java/project/ProjectDashboard.java create mode 100644 src/test/java/project/ProjectPage.java create mode 100644 src/test/java/project/ProjectsPage.java diff --git a/src/test/java/ProjectTest.java b/src/test/java/ProjectTest.java new file mode 100644 index 0000000..5791b07 --- /dev/null +++ b/src/test/java/ProjectTest.java @@ -0,0 +1,37 @@ +import com.google.common.collect.ImmutableMap; +import core.PageObject; +import core.TestTemplate; +import org.junit.FixMethodOrder; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.MethodSorters; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; +import project.ProjectDashboard; +import project.ProjectPage; +import project.ProjectsPage; +import ru.ulstu.NgTrackerApplication; +import ru.ulstu.configuration.ApplicationProperties; + +import java.util.Arrays; +import java.util.List; +import java.util.Map; + +@RunWith(SpringRunner.class) +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +@SpringBootTest(classes = NgTrackerApplication.class, webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT) +public class ProjectTest extends TestTemplate { + private final Map> navigationHolder = ImmutableMap.of( + new ProjectPage(), Arrays.asList("ПРОЕКТЫ", "/projects/projects"), + new ProjectsPage(), Arrays.asList("РЕДАКТИРОВАНИЕ ПРОЕКТА", "/projects/project?id=0"), + new ProjectDashboard(), Arrays.asList("ПРОЕКТЫ", "/projects/dashboard") + ); + + @Autowired + private ApplicationProperties applicationProperties; + + @Test + public void testACreateNewProject() { + } +} diff --git a/src/test/java/project/ProjectDashboard.java b/src/test/java/project/ProjectDashboard.java new file mode 100644 index 0000000..0b36204 --- /dev/null +++ b/src/test/java/project/ProjectDashboard.java @@ -0,0 +1,11 @@ +package project; + +import core.PageObject; +import org.openqa.selenium.By; + +public class ProjectDashboard extends PageObject { + + public String getSubTitle() { + return driver.findElement(By.tagName("h2")).getText(); + } +} diff --git a/src/test/java/project/ProjectPage.java b/src/test/java/project/ProjectPage.java new file mode 100644 index 0000000..b392099 --- /dev/null +++ b/src/test/java/project/ProjectPage.java @@ -0,0 +1,107 @@ +package project; + +import core.PageObject; +import org.openqa.selenium.By; +import org.openqa.selenium.WebElement; + +import java.util.List; + +public class ProjectPage extends PageObject { + + public String getSubTitle() { + return driver.findElement(By.tagName("h3")).getText(); + } + + public String getId() { + return driver.findElement(By.id("id")).getAttribute("value"); + } + + public void setName(String name) { + driver.findElement(By.id("title")).sendKeys(name); + } + + public String getName() { + return driver.findElement(By.id("title")).getAttribute("value"); + } + + public void clearName() { + driver.findElement(By.id("title")).clear(); + } + + public void clickSaveBut() { + driver.findElement(By.id("send-message-button")).click(); + } + + public void clickAddDeadlineBut() { + driver.findElement(By.id("addDeadline")).click(); + } + + public List getDeadlineList() { + return driver.findElements(By.className("deadline")); + } + + public Integer getDeadlineCount() { + return driver.findElements(By.className("deadline")).size(); + } + + public void setDeadlineDescription(String description, Integer i) { + driver.findElement(By.id(String.format("deadlines%d.description", i))).sendKeys(description); + } + + public void setDeadlineDate(String date, Integer i) { + driver.findElement(By.id(String.format("deadlines%d.date", i))).sendKeys(date); + } + + public void clickTakePartBut() { + driver.findElement(By.id("take-part")).click(); + } + + public Boolean isTakePartButDisabledValueTrue() { + return driver.findElement(By.id("take-part")).getAttribute("disabled").equals("true"); + } + + public Integer getMemberCount() { + return driver.findElements(By.className("member")).size(); + } + + public void clickDeleteDeadlineBut() { + driver.findElement(By.xpath("//*[@id=\"deadlines\"]/div/input[4]")).click(); + } + + public void showAllowToAttachArticles() { + driver.findElement(By.cssSelector("button[data-id=\"paperIds\"]")).click(); + } + + public void clickAddPaperBut() { + driver.findElement(By.id("add-paper")).click(); + } + + + public List getArticles() { + return driver.findElements(By.className("paper")); + } + + public Integer getArticlesCount() { + return driver.findElements(By.className("paper")).size(); + } + + public WebElement selectArticle() { + WebElement webElement = driver.findElement(By.xpath("//*[@id=\"project-form\"]/div/div[2]/div[5]/div/div/div[2]/ul/li[1]/a")); + webElement.click(); + return webElement; + } + + public void clickUndockArticleBut() { + driver.findElement(By.name("removePaper")).click(); + } + + public boolean checkDeadline(String description, String dateValue) { + return getDeadlineList() + .stream() + .anyMatch(webElement -> { + return webElement.findElement(By.className("deadline-text")).getAttribute("value").equals(description) + && webElement.findElement(By.cssSelector("input[type=\"date\"]")).getAttribute("value").equals(dateValue); + }); + } + +} \ No newline at end of file diff --git a/src/test/java/project/ProjectsPage.java b/src/test/java/project/ProjectsPage.java new file mode 100644 index 0000000..f0cc4a1 --- /dev/null +++ b/src/test/java/project/ProjectsPage.java @@ -0,0 +1,41 @@ +package project; + +import core.PageObject; +import org.openqa.selenium.By; +import org.openqa.selenium.WebElement; + +import java.util.List; + +public class ProjectsPage extends PageObject { + + public String getSubTitle() { + return driver.findElement(By.tagName("h2")).getText(); + } + + public List getProjectsList() { + return driver.findElements(By.cssSelector("span.h6")); + } + + public void getFirstProject() { + driver.findElement(By.xpath("//*[@id=\"projects\"]/div/div[2]/div[1]/div[1]/div/a")).click(); + } + + public void selectMember() { + driver.findElements(By.className("bootstrap-select")).get(0).findElement(By.className("btn")).click(); + driver.findElements(By.className("bootstrap-select")).get(0).findElements(By.className("dropdown-item")).get(1).click(); + } + + public void deleteFirst() { + js.executeScript("$('input[data-confirm]').click();"); + } + + public void clickConfirm() { + driver.findElement(By.id("deleteProject")).click(); + } + + public boolean checkNameInList(String newProjectName) { + return getProjectsList() + .stream() + .anyMatch(webElement -> webElement.getText().equals(newProjectName)); + } +} \ No newline at end of file From 9388302a47c9548eb6fa4055c11f7ce6fc9cade4 Mon Sep 17 00:00:00 2001 From: "a.vasin" Date: Fri, 31 May 2019 01:08:40 +0400 Subject: [PATCH 13/30] #101 project tests --- src/main/resources/templates/index.html | 2 +- src/test/java/ProjectTest.java | 137 ++++++++++++++++++ src/test/java/project/ProjectPage.java | 52 +++++-- src/test/java/project/ProjectsPage.java | 4 +- .../project/service/ProjectServiceTest.java | 1 + 5 files changed, 184 insertions(+), 12 deletions(-) create mode 100644 src/test/java/ru/ulstu/project/service/ProjectServiceTest.java diff --git a/src/main/resources/templates/index.html b/src/main/resources/templates/index.html index 6bb134e..f821549 100644 --- a/src/main/resources/templates/index.html +++ b/src/main/resources/templates/index.html @@ -40,7 +40,7 @@
- +
diff --git a/src/test/java/ProjectTest.java b/src/test/java/ProjectTest.java index 5791b07..f2c6367 100644 --- a/src/test/java/ProjectTest.java +++ b/src/test/java/ProjectTest.java @@ -1,6 +1,8 @@ import com.google.common.collect.ImmutableMap; +import com.google.common.collect.Iterables; import core.PageObject; import core.TestTemplate; +import org.junit.Assert; import org.junit.FixMethodOrder; import org.junit.Test; import org.junit.runner.RunWith; @@ -15,6 +17,7 @@ import ru.ulstu.NgTrackerApplication; import ru.ulstu.configuration.ApplicationProperties; import java.util.Arrays; +import java.util.Date; import java.util.List; import java.util.Map; @@ -33,5 +36,139 @@ public class ProjectTest extends TestTemplate { @Test public void testACreateNewProject() { + Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 1); + getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); + ProjectsPage projectsPage = (ProjectsPage) getContext().initPage(page.getKey()); + ProjectPage projectPage = (ProjectPage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 0).getKey()); + String name = "Project " + (new Date()).getTime(); + String date = "01.01.2019"; + Integer deadNum = projectPage.getDeadlineCount(); + projectPage.setName(name); + projectPage.clickAddDeadline(); + projectPage.addDeadlineDate(date, deadNum); + projectPage.clickSave(); + Assert.assertTrue(projectsPage.checkNameInList(name)); + } + + @Test + public void testBChangeNameAndSave() { + Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); + getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); + ProjectPage projectPage = (ProjectPage) getContext().initPage(page.getKey()); + ProjectsPage projectsPage = (ProjectsPage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 1).getKey()); + projectsPage.getFirstProject(); + String name = "Project " + (new Date()).getTime(); + projectPage.clearName(); + projectPage.setName(name); + projectPage.clickSave(); + Assert.assertTrue(projectsPage.checkNameInList(name)); + } + + @Test + public void testCChangeDeadlineAndSave() { + Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); + getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); + ProjectPage projectPage = (ProjectPage) getContext().initPage(page.getKey()); + ProjectsPage projectsPage = (ProjectsPage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 1).getKey()); + projectsPage.getFirstProject(); + String name = projectPage.getName(); + String date = "01.01.2019"; + Integer deadNum = projectPage.getDeadlineCount(); + projectPage.addDeadlineDate(date, deadNum); + projectPage.clickSave(); + Assert.assertTrue(projectsPage.checkNameInList(name)); + } + + @Test + public void testDSetStatusAndSave() { + Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); + getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); + ProjectPage projectPage = (ProjectPage) getContext().initPage(page.getKey()); + ProjectsPage projectsPage = (ProjectsPage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 1).getKey()); + projectsPage.getFirstProject(); + String name = projectPage.getName(); + projectPage.setStatus(); + projectPage.clickSave(); + Assert.assertTrue(projectsPage.checkNameInList(name)); + } + + @Test + public void testEAddDescriptionAndSave() { + Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); + getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); + ProjectPage projectPage = (ProjectPage) getContext().initPage(page.getKey()); + ProjectsPage projectsPage = (ProjectsPage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 1).getKey()); + projectsPage.getFirstProject(); + String name = projectPage.getName(); + String description = "Description " + (new Date()).getTime(); + projectPage.addDescription(description); + projectPage.clickSave(); + Assert.assertTrue(projectsPage.checkNameInList(name)); + } + + @Test + public void testFAddLinkAndSave() { + Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); + getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); + ProjectPage projectPage = (ProjectPage) getContext().initPage(page.getKey()); + ProjectsPage projectsPage = (ProjectsPage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 1).getKey()); + projectsPage.getFirstProject(); + String name = projectPage.getName(); + String link = "Link " + (new Date()).getTime(); + projectPage.addLink(link); + projectPage.clickSave(); + Assert.assertTrue(projectsPage.checkNameInList(name)); + } + + @Test + public void testGAddDeadlineDescriptionAndSave() { + Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); + getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); + ProjectPage projectPage = (ProjectPage) getContext().initPage(page.getKey()); + ProjectsPage projectsPage = (ProjectsPage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 1).getKey()); + projectsPage.getFirstProject(); + String name = projectPage.getName(); + String deadDesc = "Description " + (new Date()).getTime(); + projectPage.addDeadlineDescription(deadDesc); + projectPage.clickSave(); + Assert.assertTrue(projectsPage.checkNameInList(name)); + } + + @Test + public void testHSetDeadlineCompletionAndSave() { + Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); + getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); + ProjectPage projectPage = (ProjectPage) getContext().initPage(page.getKey()); + ProjectsPage projectsPage = (ProjectsPage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 1).getKey()); + projectsPage.getFirstProject(); + String name = projectPage.getName(); + projectPage.setDeadlineCompletion(); + projectPage.clickSave(); + Assert.assertTrue(projectsPage.checkNameInList(name)); + } + + @Test + public void testIDeleteDeadline() { + Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); + getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); + ProjectPage projectPage = (ProjectPage) getContext().initPage(page.getKey()); + ProjectsPage projectsPage = (ProjectsPage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 1).getKey()); + projectsPage.getFirstProject(); + projectPage.clickDeleteDeadline(); + Assert.assertTrue(projectPage.getDeadlineCount() == 0); + } + + @Test + public void testJDeleteProject() { + Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); + getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); + ProjectPage projectPage = (ProjectPage) getContext().initPage(page.getKey()); + ProjectsPage projectsPage = (ProjectsPage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 1).getKey()); + projectsPage.getFirstProject(); + String name = projectPage.getName(); + projectPage.clickSave(); + projectsPage.deleteFirst(); + projectsPage.clickConfirm(); + Assert.assertFalse(projectsPage.checkNameInList(name)); } } diff --git a/src/test/java/project/ProjectPage.java b/src/test/java/project/ProjectPage.java index b392099..1bbad67 100644 --- a/src/test/java/project/ProjectPage.java +++ b/src/test/java/project/ProjectPage.java @@ -28,14 +28,43 @@ public class ProjectPage extends PageObject { driver.findElement(By.id("title")).clear(); } - public void clickSaveBut() { - driver.findElement(By.id("send-message-button")).click(); + public void clickSave() { + driver.findElement(By.id("sendMessageButton")).click(); } - public void clickAddDeadlineBut() { + public void clickAddDeadline() { driver.findElement(By.id("addDeadline")).click(); } + public void addDeadlineDate(String deadDate, Integer deadNum) { + driver.findElement(By.id(String.format("deadlines%d.date", deadNum))).sendKeys(deadDate); + } + + public void addDeadlineDescription(String description) { + driver.findElement(By.id("deadlines0.description")).sendKeys(description); + } + + public void setDeadlineCompletion() { + driver.findElement(By.id("deadlines0.done1")).click(); + } + + public void setStatus() { + driver.findElement(By.id("status")).click(); + getFirstStatus(); + } + + public void getFirstStatus() { + driver.findElement(By.xpath("//*[@id=\"status\"]/option[1]")).click(); + } + + public void addDescription(String description) { + driver.findElement(By.id("description")).sendKeys(description); + } + + public void addLink(String link) { + driver.findElement(By.id("repository")).sendKeys(link); + } + public List getDeadlineList() { return driver.findElements(By.className("deadline")); } @@ -44,6 +73,15 @@ public class ProjectPage extends PageObject { return driver.findElements(By.className("deadline")).size(); } + public void setExecutors() { + driver.findElement(By.id("status")).click(); + getFirstExecutor(); + } + + public void getFirstExecutor() { + driver.findElement(By.xpath("//*[@id=\"status\"]/option[1]")).click(); + } + public void setDeadlineDescription(String description, Integer i) { driver.findElement(By.id(String.format("deadlines%d.description", i))).sendKeys(description); } @@ -52,10 +90,6 @@ public class ProjectPage extends PageObject { driver.findElement(By.id(String.format("deadlines%d.date", i))).sendKeys(date); } - public void clickTakePartBut() { - driver.findElement(By.id("take-part")).click(); - } - public Boolean isTakePartButDisabledValueTrue() { return driver.findElement(By.id("take-part")).getAttribute("disabled").equals("true"); } @@ -64,8 +98,8 @@ public class ProjectPage extends PageObject { return driver.findElements(By.className("member")).size(); } - public void clickDeleteDeadlineBut() { - driver.findElement(By.xpath("//*[@id=\"deadlines\"]/div/input[4]")).click(); + public void clickDeleteDeadline() { + driver.findElement(By.className("btn-danger")).click(); } public void showAllowToAttachArticles() { diff --git a/src/test/java/project/ProjectsPage.java b/src/test/java/project/ProjectsPage.java index f0cc4a1..64c50b7 100644 --- a/src/test/java/project/ProjectsPage.java +++ b/src/test/java/project/ProjectsPage.java @@ -26,11 +26,11 @@ public class ProjectsPage extends PageObject { } public void deleteFirst() { - js.executeScript("$('input[data-confirm]').click();"); + js.executeScript("$('a[data-confirm]').click();"); } public void clickConfirm() { - driver.findElement(By.id("deleteProject")).click(); + driver.findElement(By.id("dataConfirmOK")).click(); } public boolean checkNameInList(String newProjectName) { diff --git a/src/test/java/ru/ulstu/project/service/ProjectServiceTest.java b/src/test/java/ru/ulstu/project/service/ProjectServiceTest.java new file mode 100644 index 0000000..1f2debe --- /dev/null +++ b/src/test/java/ru/ulstu/project/service/ProjectServiceTest.java @@ -0,0 +1 @@ +package ru.ulstu.project.service; \ No newline at end of file From a7b48e1534eb191a26f6543436209a0fd8bd8835 Mon Sep 17 00:00:00 2001 From: "a.vasin" Date: Fri, 31 May 2019 02:23:15 +0400 Subject: [PATCH 14/30] #101 project tests --- .../ulstu/project/service/ProjectService.java | 13 +- .../project/service/ProjectServiceTest.java | 149 +++++++++++++++++- 2 files changed, 157 insertions(+), 5 deletions(-) diff --git a/src/main/java/ru/ulstu/project/service/ProjectService.java b/src/main/java/ru/ulstu/project/service/ProjectService.java index e77cc88..80bd52f 100644 --- a/src/main/java/ru/ulstu/project/service/ProjectService.java +++ b/src/main/java/ru/ulstu/project/service/ProjectService.java @@ -90,9 +90,13 @@ public class ProjectService { } @Transactional - public void delete(Integer projectId) throws IOException { - Project project = projectRepository.findOne(projectId); - projectRepository.delete(project); + public boolean delete(Integer projectId) throws IOException { + if (projectRepository.exists(projectId)) { + Project project = projectRepository.findOne(projectId); + projectRepository.delete(project); + return true; + } + return false; } private Project copyFromDto(Project project, ProjectDto projectDto) throws IOException { @@ -122,11 +126,12 @@ public class ProjectService { } } - public void removeDeadline(ProjectDto projectDto, Integer deadlineId) { + public ProjectDto removeDeadline(ProjectDto projectDto, Integer deadlineId) { if (deadlineId != null) { projectDto.getRemovedDeadlineIds().add(deadlineId); } projectDto.getDeadlines().remove((int) deadlineId); + return projectDto; } public Project findById(Integer id) { diff --git a/src/test/java/ru/ulstu/project/service/ProjectServiceTest.java b/src/test/java/ru/ulstu/project/service/ProjectServiceTest.java index 1f2debe..7c4f5fa 100644 --- a/src/test/java/ru/ulstu/project/service/ProjectServiceTest.java +++ b/src/test/java/ru/ulstu/project/service/ProjectServiceTest.java @@ -1 +1,148 @@ -package ru.ulstu.project.service; \ No newline at end of file +package ru.ulstu.project.service; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.runners.MockitoJUnitRunner; +import ru.ulstu.deadline.model.Deadline; +import ru.ulstu.deadline.service.DeadlineService; +import ru.ulstu.file.model.FileData; +import ru.ulstu.file.service.FileService; +import ru.ulstu.grant.model.GrantDto; +import ru.ulstu.grant.service.GrantService; +import ru.ulstu.project.model.Project; +import ru.ulstu.project.model.ProjectDto; +import ru.ulstu.project.repository.ProjectRepository; +import ru.ulstu.timeline.service.EventService; +import ru.ulstu.user.model.User; +import ru.ulstu.user.service.UserService; + +import java.io.IOException; +import java.util.*; + +import static junit.framework.TestCase.assertTrue; +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.when; + +@RunWith(MockitoJUnitRunner.class) +public class ProjectServiceTest { + + @Mock + ProjectRepository projectRepository; + + @Mock + DeadlineService deadlineService; + + @Mock + EventService eventService; + + @Mock + FileService fileService; + + @Mock + UserService userService; + + @Mock + GrantService grantService; + + @InjectMocks + ProjectService projectService; + + private final static String TITLE = "title"; + private final static String DESCR = "descr"; + private final static Integer ID = 1; + private final static Integer INDEX = 0; + private final static String NAME = "name"; + + private List projects; + private Project project; + private ProjectDto projectDto; + private Deadline deadline; + private List deadlines; + private FileData file; + private List files; + private User user; + private GrantDto grant; + private List grants; + + @Before + public void setUp() throws Exception { + projects = new ArrayList<>(); + project = new Project(); + + projects.add(project); + projectDto = new ProjectDto(project); + + deadlines = new ArrayList<>(); + deadline = new Deadline(new Date(), DESCR); + deadline.setId(ID); + deadlines.add(deadline); + + user = new User(); + user.setFirstName(NAME); + + grants = new ArrayList<>(); + grant = new GrantDto(); + grant.setId(ID); + grants.add(grant); + } + + @Test + public void findAll() { + when(projectRepository.findAll()).thenReturn(projects); + assertEquals(projects, projectService.findAll()); + } + + @Test + public void create() throws IOException { + when(deadlineService.saveOrCreate(new ArrayList<>())).thenReturn(deadlines); + when(projectRepository.save(new Project())).thenReturn(project); + eventService.createFromProject(new Project()); + + projectDto.setTitle(TITLE); + projectDto.setDeadlines(deadlines); + + project.setId(ID); + project.setTitle(TITLE); + project.setDescription(DESCR); + project.setDeadlines(deadlines); + project.setFiles(files); + + assertEquals(project.getId(), (projectService.create(projectDto)).getId()); + } + + @Test + public void delete() throws IOException { + when(projectRepository.exists(ID)).thenReturn(true); + when(projectRepository.findOne(ID)).thenReturn(project); + + assertTrue(projectService.delete(ID)); + } + + @Test + public void getProjectExecutors() { + List executors = Collections.singletonList(user); + when(userService.findAll()).thenReturn(executors); + + assertEquals(executors, projectService.getProjectExecutors(projectDto)); + } + + @Test + public void findById() { + when(projectRepository.findOne(ID)).thenReturn(project); + assertEquals(project, projectService.findById(ID)); + } + + @Test + public void removeDeadline() throws IOException { + ProjectDto newProjectDto = new ProjectDto(); + newProjectDto.getRemovedDeadlineIds().add(INDEX); + projectDto.getDeadlines().add(deadline); + ProjectDto result = projectService.removeDeadline(projectDto, INDEX); + + assertEquals(newProjectDto.getDeadlines(), result.getDeadlines()); + assertEquals(newProjectDto.getRemovedDeadlineIds(), result.getRemovedDeadlineIds()); + } +} \ No newline at end of file From 291f4e1e33fcf45ab45390dc3be87c7cd219fe44 Mon Sep 17 00:00:00 2001 From: "a.vasin" Date: Sat, 1 Jun 2019 09:44:25 +0400 Subject: [PATCH 15/30] #101 db edited --- ...0000-schema.xml => changelog-20190601_000001-schema.xml} | 6 +++--- src/main/resources/db/changelog-master.xml | 3 +-- 2 files changed, 4 insertions(+), 5 deletions(-) rename src/main/resources/db/{changelog-20190428_000000-schema.xml => changelog-20190601_000001-schema.xml} (75%) diff --git a/src/main/resources/db/changelog-20190428_000000-schema.xml b/src/main/resources/db/changelog-20190601_000001-schema.xml similarity index 75% rename from src/main/resources/db/changelog-20190428_000000-schema.xml rename to src/main/resources/db/changelog-20190601_000001-schema.xml index b44691d..409bde4 100644 --- a/src/main/resources/db/changelog-20190428_000000-schema.xml +++ b/src/main/resources/db/changelog-20190601_000001-schema.xml @@ -2,9 +2,9 @@ - + - + - \ No newline at end of file + diff --git a/src/main/resources/db/changelog-master.xml b/src/main/resources/db/changelog-master.xml index 529b597..aed9997 100644 --- a/src/main/resources/db/changelog-master.xml +++ b/src/main/resources/db/changelog-master.xml @@ -35,7 +35,6 @@ - @@ -51,5 +50,5 @@ - + \ No newline at end of file From 267bd5b0f37f0f257d08c6e4cc7766ced1264d8e Mon Sep 17 00:00:00 2001 From: "a.vasin" Date: Sat, 1 Jun 2019 11:44:41 +0400 Subject: [PATCH 16/30] #101 event service edited --- .../conference/service/ConferenceService.java | 3 +- .../ru/ulstu/grant/service/GrantService.java | 4 +- .../ulstu/project/service/ProjectService.java | 4 +- .../ulstu/students/service/TaskService.java | 9 +- .../ulstu/timeline/service/EventService.java | 257 +++++++++--------- src/main/resources/db/changelog-master.xml | 2 +- 6 files changed, 144 insertions(+), 135 deletions(-) diff --git a/src/main/java/ru/ulstu/conference/service/ConferenceService.java b/src/main/java/ru/ulstu/conference/service/ConferenceService.java index 1b8e67b..3b3bace 100644 --- a/src/main/java/ru/ulstu/conference/service/ConferenceService.java +++ b/src/main/java/ru/ulstu/conference/service/ConferenceService.java @@ -27,6 +27,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Date; import java.util.List; +import java.util.Collections; import java.util.stream.Collectors; import static org.springframework.util.ObjectUtils.isEmpty; @@ -116,7 +117,7 @@ public class ConferenceService extends BaseService { Conference newConference = copyFromDto(new Conference(), conferenceDto); newConference = conferenceRepository.save(newConference); conferenceNotificationService.sendCreateNotification(newConference); - eventService.createFromConference(newConference); + eventService.createFromObject(newConference, Collections.emptyList()); return newConference; } diff --git a/src/main/java/ru/ulstu/grant/service/GrantService.java b/src/main/java/ru/ulstu/grant/service/GrantService.java index e5754eb..d8e4aad 100644 --- a/src/main/java/ru/ulstu/grant/service/GrantService.java +++ b/src/main/java/ru/ulstu/grant/service/GrantService.java @@ -90,7 +90,7 @@ public class GrantService extends BaseService { public Integer create(GrantDto grantDto) throws IOException { Grant newGrant = copyFromDto(new Grant(), grantDto); newGrant = grantRepository.save(newGrant); - eventService.createFromGrant(newGrant); + eventService.createFromObject(newGrant, Collections.emptyList()); grantNotificationService.sendCreateNotification(newGrant); return newGrant.getId(); } @@ -178,7 +178,7 @@ public class GrantService extends BaseService { grant.getPapers().add(paper); grant = grantRepository.save(grant); - eventService.createFromGrant(grant); + eventService.createFromObject(grant, Collections.emptyList()); grantNotificationService.sendCreateNotification(grant); return grant; diff --git a/src/main/java/ru/ulstu/project/service/ProjectService.java b/src/main/java/ru/ulstu/project/service/ProjectService.java index 80bd52f..de64c4c 100644 --- a/src/main/java/ru/ulstu/project/service/ProjectService.java +++ b/src/main/java/ru/ulstu/project/service/ProjectService.java @@ -17,8 +17,8 @@ import ru.ulstu.user.service.UserService; import java.io.IOException; import java.util.Arrays; +import java.util.Collections; import java.util.List; -import java.util.Set; import static java.util.stream.Collectors.toList; import static org.springframework.util.ObjectUtils.isEmpty; @@ -72,7 +72,7 @@ public class ProjectService { public Project create(ProjectDto projectDto) throws IOException { Project newProject = copyFromDto(new Project(), projectDto); newProject = projectRepository.save(newProject); - eventService.createFromProject(newProject); + eventService.createFromObject(newProject, Collections.emptyList()); return newProject; } diff --git a/src/main/java/ru/ulstu/students/service/TaskService.java b/src/main/java/ru/ulstu/students/service/TaskService.java index e89aedf..0a4590a 100644 --- a/src/main/java/ru/ulstu/students/service/TaskService.java +++ b/src/main/java/ru/ulstu/students/service/TaskService.java @@ -18,14 +18,15 @@ import ru.ulstu.tags.service.TagService; import ru.ulstu.timeline.service.EventService; import java.io.IOException; -import java.util.ArrayList; -import java.util.Arrays; import java.util.Calendar; +import java.util.Collections; import java.util.Date; import java.util.List; -import java.util.Map; import java.util.Set; +import java.util.Map; import java.util.TreeMap; +import java.util.ArrayList; +import java.util.Arrays; import java.util.stream.Collectors; import static org.springframework.util.ObjectUtils.isEmpty; @@ -83,7 +84,7 @@ public class TaskService { public Integer create(TaskDto taskDto) throws IOException { Task newTask = copyFromDto(new Task(), taskDto); newTask = taskRepository.save(newTask); - eventService.createFromTask(newTask); + eventService.createFromObject(newTask, Collections.emptyList()); return newTask.getId(); } diff --git a/src/main/java/ru/ulstu/timeline/service/EventService.java b/src/main/java/ru/ulstu/timeline/service/EventService.java index 906a5e6..01113c7 100644 --- a/src/main/java/ru/ulstu/timeline/service/EventService.java +++ b/src/main/java/ru/ulstu/timeline/service/EventService.java @@ -1,10 +1,12 @@ package ru.ulstu.timeline.service; +import com.sun.jna.platform.win32.COM.util.Convert; import org.apache.commons.lang3.time.DateUtils; import org.springframework.context.annotation.Lazy; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import ru.ulstu.conference.model.Conference; +import ru.ulstu.core.model.BaseEntity; import ru.ulstu.deadline.model.Deadline; import ru.ulstu.grant.model.Grant; import ru.ulstu.paper.model.Paper; @@ -34,6 +36,13 @@ public class EventService { private final TimelineService timelineService; private final UserService userService; + private String objectClassName = ""; + private Paper newPaper = new Paper(); + private Conference newConference = new Conference(); + private Grant newGrant = new Grant(); + private Project newProject = new Project(); + private Task newTask = new Task(); + public EventService(EventRepository eventRepository, @Lazy TimelineService timelineService, UserService userService) { @@ -107,35 +116,135 @@ public class EventService { } public void createFromPaper(Paper newPaper) { - createFromPaper(newPaper, Collections.emptyList()); + createFromObject(newPaper, Collections.emptyList()); } - public void createFromPaper(Paper newPaper, List events) { + public void createFromObject(Object newObject, List events) { List timelines = timelineService.findAll(); Timeline timeline = timelines.isEmpty() ? new Timeline() : timelines.get(0); - timeline.getEvents().removeAll(events); - for (Deadline deadline : newPaper.getDeadlines() - .stream() - .filter(d -> d.getDate().after(new Date()) || DateUtils.isSameDay(d.getDate(), new Date())) - .collect(Collectors.toList())) { - Event newEvent = new Event(); - newEvent.setTitle("Дедлайн статьи"); - newEvent.setStatus(Event.EventStatus.NEW); - newEvent.setExecuteDate(deadline.getDate()); - newEvent.setCreateDate(new Date()); - newEvent.setUpdateDate(new Date()); - newEvent.setDescription("Дедлайн '" + deadline.getDescription() + "' cтатьи '" + newPaper.getTitle() + "'"); - newEvent.setRecipients(new ArrayList(newPaper.getAuthors())); - newEvent.setPaper(newPaper); - timeline.getEvents().add(eventRepository.save(newEvent)); + objectClassName = newObject.getClass().getName(); + + switch(objectClassName) { + case "ru.ulstu.paper.model.Paper": + newPaper = (Paper)newObject; + timeline.getEvents().removeAll(events); + for (Deadline deadline : newPaper.getDeadlines() + .stream() + .filter(d -> d.getDate().after(new Date()) || DateUtils.isSameDay(d.getDate(), new Date())) + .collect(Collectors.toList())) { + Event newEvent = new Event(); + newEvent.setTitle("Дедлайн статьи"); + newEvent.setStatus(Event.EventStatus.NEW); + newEvent.setExecuteDate(deadline.getDate()); + newEvent.setCreateDate(new Date()); + newEvent.setUpdateDate(new Date()); + newEvent.setDescription("Дедлайн '" + deadline.getDescription() + "' cтатьи '" + newPaper.getTitle() + "'"); + newEvent.setRecipients(new ArrayList(newPaper.getAuthors())); + newEvent.setPaper(newPaper); + timeline.getEvents().add(eventRepository.save(newEvent)); + } + timelineService.save(timeline); + break; + case "ru.ulstu.conference.model.Conference": + newConference = (Conference)newObject; + for (Deadline deadline : newConference.getDeadlines() + .stream() + .filter(d -> d.getDate().after(new Date()) || DateUtils.isSameDay(d.getDate(), new Date())) + .collect(Collectors.toList())) { + Event newEvent = new Event(); + newEvent.setTitle("Дедлайн конференции"); + newEvent.setStatus(Event.EventStatus.NEW); + newEvent.setExecuteDate(deadline.getDate()); + newEvent.setCreateDate(new Date()); + newEvent.setUpdateDate(new Date()); + newEvent.setDescription("Дедлайн '" + deadline.getDescription() + "' конференции '" + newConference.getTitle() + "'"); + newConference.getUsers().forEach(conferenceUser -> newEvent.getRecipients().add(conferenceUser.getUser())); + newEvent.setConference(newConference); + save(newEvent); + + timeline.getEvents().add(newEvent); + timelineService.save(timeline); + } + break; + case "ru.ulstu.grant.model.Grant": + newGrant = (Grant)newObject; + for (Deadline deadline : newGrant.getDeadlines() + .stream() + .filter(d -> d.getDate().after(new Date()) || DateUtils.isSameDay(d.getDate(), new Date())) + .collect(Collectors.toList())) { + Event newEvent = new Event(); + newEvent.setTitle("Дедлайн гранта"); + newEvent.setStatus(Event.EventStatus.NEW); + newEvent.setExecuteDate(deadline.getDate()); + newEvent.setCreateDate(new Date()); + newEvent.setUpdateDate(new Date()); + newEvent.setDescription("Дедлайн '" + deadline.getDescription() + "' гранта '" + newGrant.getTitle() + "'"); + if (newGrant.getAuthors() != null) { + newEvent.setRecipients(new ArrayList(newGrant.getAuthors())); + } + newEvent.getRecipients().add(newGrant.getLeader()); + newEvent.setGrant(newGrant); + eventRepository.save(newEvent); + + timeline.getEvents().add(newEvent); + timelineService.save(timeline); + } + break; + case "ru.ulstu.project.model.Project": + newProject = (Project)newObject; + for (Deadline deadline : newProject.getDeadlines() + .stream() + .filter(d -> d.getDate().after(new Date()) || DateUtils.isSameDay(d.getDate(), new Date())) + .collect(Collectors.toList())) { + Event newEvent = new Event(); + newEvent.setTitle("Дедлайн проекта"); + newEvent.setStatus(Event.EventStatus.NEW); + newEvent.setExecuteDate(deadline.getDate()); + newEvent.setCreateDate(new Date()); + newEvent.setUpdateDate(new Date()); + newEvent.setDescription("Дедлайн '" + deadline.getDescription() + "' проекта '" + newProject.getTitle() + "'"); + if (newProject.getExecutors() != null) { + newEvent.setRecipients(new ArrayList(newProject.getExecutors())); + } + newEvent.setProject(newProject); + eventRepository.save(newEvent); + + timeline.getEvents().add(newEvent); + timelineService.save(timeline); + } + break; + case "ru.ulstu.students.model.Task": + newTask = (Task)newObject; + for (Deadline deadline : newTask.getDeadlines() + .stream() + .filter(d -> d.getDate().after(new Date()) || DateUtils.isSameDay(d.getDate(), new Date())) + .collect(Collectors.toList())) { + Event newEvent = new Event(); + newEvent.setTitle("Дедлайн задачи"); + newEvent.setStatus(Event.EventStatus.NEW); + newEvent.setExecuteDate(deadline.getDate()); + newEvent.setCreateDate(new Date()); + newEvent.setUpdateDate(new Date()); + newEvent.setDescription("Дедлайн '" + deadline.getDescription() + "' задачи '" + newTask.getTitle() + "'"); + newEvent.getRecipients().add(userService.getCurrentUser()); + newEvent.setTask(newTask); + eventRepository.save(newEvent); + + timeline.getEvents().add(newEvent); + timelineService.save(timeline); + } + System.out.println("5"); + break; + default: + System.out.println("No such object"); + break; } - timelineService.save(timeline); } public void updatePaperDeadlines(Paper paper) { List foundEvents = eventRepository.findAllByPaper(paper); eventRepository.delete(foundEvents); - createFromPaper(paper, foundEvents); + createFromObject(paper, foundEvents); } public List findByCurrentDate() { @@ -150,97 +259,19 @@ public class EventService { return convert(findAllFuture(), EventDto::new); } - public void createFromConference(Conference newConference) { - List timelines = timelineService.findAll(); - Timeline timeline = timelines.isEmpty() ? new Timeline() : timelines.get(0); - - for (Deadline deadline : newConference.getDeadlines() - .stream() - .filter(d -> d.getDate().after(new Date()) || DateUtils.isSameDay(d.getDate(), new Date())) - .collect(Collectors.toList())) { - Event newEvent = new Event(); - newEvent.setTitle("Дедлайн конференции"); - newEvent.setStatus(Event.EventStatus.NEW); - newEvent.setExecuteDate(deadline.getDate()); - newEvent.setCreateDate(new Date()); - newEvent.setUpdateDate(new Date()); - newEvent.setDescription("Дедлайн '" + deadline.getDescription() + "' конференции '" + newConference.getTitle() + "'"); - newConference.getUsers().forEach(conferenceUser -> newEvent.getRecipients().add(conferenceUser.getUser())); - newEvent.setConference(newConference); - save(newEvent); - - timeline.getEvents().add(newEvent); - timelineService.save(timeline); - } - } - public void updateConferenceDeadlines(Conference conference) { eventRepository.delete(eventRepository.findAllByConference(conference)); - createFromConference(conference); - } - - public void createFromGrant(Grant newGrant) { - List timelines = timelineService.findAll(); - Timeline timeline = timelines.isEmpty() ? new Timeline() : timelines.get(0); - - for (Deadline deadline : newGrant.getDeadlines() - .stream() - .filter(d -> d.getDate().after(new Date()) || DateUtils.isSameDay(d.getDate(), new Date())) - .collect(Collectors.toList())) { - Event newEvent = new Event(); - newEvent.setTitle("Дедлайн гранта"); - newEvent.setStatus(Event.EventStatus.NEW); - newEvent.setExecuteDate(deadline.getDate()); - newEvent.setCreateDate(new Date()); - newEvent.setUpdateDate(new Date()); - newEvent.setDescription("Дедлайн '" + deadline.getDescription() + "' гранта '" + newGrant.getTitle() + "'"); - if (newGrant.getAuthors() != null) { - newEvent.setRecipients(new ArrayList(newGrant.getAuthors())); - } - newEvent.getRecipients().add(newGrant.getLeader()); - newEvent.setGrant(newGrant); - eventRepository.save(newEvent); - - timeline.getEvents().add(newEvent); - timelineService.save(timeline); - } + createFromObject(conference, Collections.emptyList()); } public void updateGrantDeadlines(Grant grant) { eventRepository.delete(eventRepository.findAllByGrant(grant)); - createFromGrant(grant); - } - - public void createFromProject(Project newProject) { - List timelines = timelineService.findAll(); - Timeline timeline = timelines.isEmpty() ? new Timeline() : timelines.get(0); - - for (Deadline deadline : newProject.getDeadlines() - .stream() - .filter(d -> d.getDate().after(new Date()) || DateUtils.isSameDay(d.getDate(), new Date())) - .collect(Collectors.toList())) { - Event newEvent = new Event(); - newEvent.setTitle("Дедлайн проекта"); - newEvent.setStatus(Event.EventStatus.NEW); - newEvent.setExecuteDate(deadline.getDate()); - newEvent.setCreateDate(new Date()); - newEvent.setUpdateDate(new Date()); - newEvent.setDescription("Дедлайн '" + deadline.getDescription() + "' проекта '" + newProject.getTitle() + "'"); - if (newProject.getExecutors() != null) { - newEvent.setRecipients(new ArrayList(newProject.getExecutors())); - } -// newEvent.getRecipients().add((User) newProject.getExecutors()); - newEvent.setProject(newProject); - eventRepository.save(newEvent); - - timeline.getEvents().add(newEvent); - timelineService.save(timeline); - } + createFromObject(grant, Collections.emptyList()); } public void updateProjectDeadlines(Project project) { eventRepository.delete(eventRepository.findAllByProject(project)); - createFromProject(project); + createFromObject(project, Collections.emptyList()); } public void removeConferencesEvent(Conference conference) { @@ -248,32 +279,8 @@ public class EventService { eventList.forEach(event -> eventRepository.delete(event.getId())); } - public void createFromTask(Task newTask) { - List timelines = timelineService.findAll(); - Timeline timeline = timelines.isEmpty() ? new Timeline() : timelines.get(0); - - for (Deadline deadline : newTask.getDeadlines() - .stream() - .filter(d -> d.getDate().after(new Date()) || DateUtils.isSameDay(d.getDate(), new Date())) - .collect(Collectors.toList())) { - Event newEvent = new Event(); - newEvent.setTitle("Дедлайн задачи"); - newEvent.setStatus(Event.EventStatus.NEW); - newEvent.setExecuteDate(deadline.getDate()); - newEvent.setCreateDate(new Date()); - newEvent.setUpdateDate(new Date()); - newEvent.setDescription("Дедлайн '" + deadline.getDescription() + "' задачи '" + newTask.getTitle() + "'"); - newEvent.getRecipients().add(userService.getCurrentUser()); - newEvent.setTask(newTask); - eventRepository.save(newEvent); - - timeline.getEvents().add(newEvent); - timelineService.save(timeline); - } - } - public void updateTaskDeadlines(Task task) { eventRepository.delete(eventRepository.findAllByTask(task)); - createFromTask(task); + createFromObject(task, Collections.emptyList()); } } diff --git a/src/main/resources/db/changelog-master.xml b/src/main/resources/db/changelog-master.xml index aed9997..4504857 100644 --- a/src/main/resources/db/changelog-master.xml +++ b/src/main/resources/db/changelog-master.xml @@ -49,6 +49,6 @@ - + \ No newline at end of file From 961a6a318e29917922bfa539d792ecdda3e9cc9b Mon Sep 17 00:00:00 2001 From: "a.vasin" Date: Sat, 1 Jun 2019 11:51:01 +0400 Subject: [PATCH 17/30] #101 event service edited --- src/main/java/ru/ulstu/timeline/service/EventService.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/java/ru/ulstu/timeline/service/EventService.java b/src/main/java/ru/ulstu/timeline/service/EventService.java index 01113c7..d307a8d 100644 --- a/src/main/java/ru/ulstu/timeline/service/EventService.java +++ b/src/main/java/ru/ulstu/timeline/service/EventService.java @@ -123,7 +123,6 @@ public class EventService { List timelines = timelineService.findAll(); Timeline timeline = timelines.isEmpty() ? new Timeline() : timelines.get(0); objectClassName = newObject.getClass().getName(); - switch(objectClassName) { case "ru.ulstu.paper.model.Paper": newPaper = (Paper)newObject; @@ -240,7 +239,6 @@ public class EventService { break; } } - public void updatePaperDeadlines(Paper paper) { List foundEvents = eventRepository.findAllByPaper(paper); eventRepository.delete(foundEvents); From 7edb9d2aa38d27778a16d6c3c2389333de3a3e09 Mon Sep 17 00:00:00 2001 From: "a.vasin" Date: Sat, 1 Jun 2019 11:56:38 +0400 Subject: [PATCH 18/30] #101 event service edited --- src/main/java/ru/ulstu/paper/service/LatexService.java | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/main/java/ru/ulstu/paper/service/LatexService.java b/src/main/java/ru/ulstu/paper/service/LatexService.java index 82dd1ba..27dfa1e 100644 --- a/src/main/java/ru/ulstu/paper/service/LatexService.java +++ b/src/main/java/ru/ulstu/paper/service/LatexService.java @@ -41,12 +41,6 @@ public class LatexService { Process process = processBuilder.start(); InputStreamReader inputStreamReader = new InputStreamReader(process.getInputStream()); - try (BufferedReader bufferedReader = new BufferedReader(inputStreamReader)) { - while ((bufferedReader.readLine()) != null) { - // - } - } - int exitCode = process.waitFor(); if (exitCode != 0) { errorMessage = message + " Exit value of the process: " + exitCode; From 38478835fbca880a8dabf764d6a9d28c0435fc78 Mon Sep 17 00:00:00 2001 From: "a.vasin" Date: Sat, 1 Jun 2019 12:03:42 +0400 Subject: [PATCH 19/30] #101 event service edited --- src/test/java/ru/ulstu/project/service/ProjectServiceTest.java | 2 +- src/test/java/ru/ulstu/students/service/TaskServiceTest.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/java/ru/ulstu/project/service/ProjectServiceTest.java b/src/test/java/ru/ulstu/project/service/ProjectServiceTest.java index 7c4f5fa..d06ad0e 100644 --- a/src/test/java/ru/ulstu/project/service/ProjectServiceTest.java +++ b/src/test/java/ru/ulstu/project/service/ProjectServiceTest.java @@ -99,7 +99,7 @@ public class ProjectServiceTest { public void create() throws IOException { when(deadlineService.saveOrCreate(new ArrayList<>())).thenReturn(deadlines); when(projectRepository.save(new Project())).thenReturn(project); - eventService.createFromProject(new Project()); + eventService.createFromObject(new Project(), Collections.emptyList()); projectDto.setTitle(TITLE); projectDto.setDeadlines(deadlines); diff --git a/src/test/java/ru/ulstu/students/service/TaskServiceTest.java b/src/test/java/ru/ulstu/students/service/TaskServiceTest.java index 8edfc77..0d33630 100644 --- a/src/test/java/ru/ulstu/students/service/TaskServiceTest.java +++ b/src/test/java/ru/ulstu/students/service/TaskServiceTest.java @@ -136,7 +136,7 @@ public class TaskServiceTest { when(tagService.saveOrCreate(new ArrayList<>())).thenReturn(tags); when(deadlineService.saveOrCreate(new ArrayList<>())).thenReturn(deadlines); when(taskRepository.save(new Task())).thenReturn(task); - eventService.createFromTask(new Task()); + eventService.createFromObject(new Task(), Collections.emptyList()); taskDto.setTags(tags); taskDto.setDeadlines(deadlines); From ae8dc58a9dab04bafa5a2722d383cda2d428bbe9 Mon Sep 17 00:00:00 2001 From: "a.vasin" Date: Sat, 1 Jun 2019 12:16:59 +0400 Subject: [PATCH 20/30] #101 event service edited --- src/main/resources/application.properties | 4 ++-- src/main/resources/db/changelog-20190528_000002-schema.xml | 2 +- src/main/resources/db/changelog-master.xml | 1 + 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index f4be778..276e6c4 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -22,9 +22,9 @@ spring.mail.properties.mail.smtp.auth=true spring.mail.properties.mail.smtp.ssl.enable=true spring.mail.properties.mail.smtp.socketFactory.class=javax.net.ssl.SSLSocketFactory # JPA Settings -spring.datasource.url=jdbc:postgresql://localhost:5432/ng-tracker +spring.datasource.url=jdbc:postgresql://localhost:5433/ng-tracker spring.datasource.username=postgres -spring.datasource.password=postgres +spring.datasource.password=1234 spring.datasource.driverclassName=org.postgresql.Driver spring.jpa.hibernate.ddl-auto=validate # Liquibase Settings diff --git a/src/main/resources/db/changelog-20190528_000002-schema.xml b/src/main/resources/db/changelog-20190528_000002-schema.xml index 7df707c..a4e2032 100644 --- a/src/main/resources/db/changelog-20190528_000002-schema.xml +++ b/src/main/resources/db/changelog-20190528_000002-schema.xml @@ -2,7 +2,7 @@ - + diff --git a/src/main/resources/db/changelog-master.xml b/src/main/resources/db/changelog-master.xml index 4504857..26ad8b9 100644 --- a/src/main/resources/db/changelog-master.xml +++ b/src/main/resources/db/changelog-master.xml @@ -49,6 +49,7 @@ + \ No newline at end of file From e6dc2abdd9ca7292a3bf4115a6c20eb27fbdbe68 Mon Sep 17 00:00:00 2001 From: "a.vasin" Date: Sat, 1 Jun 2019 12:23:52 +0400 Subject: [PATCH 21/30] #101 event service edited --- src/main/resources/application.properties | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 276e6c4..f4be778 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -22,9 +22,9 @@ spring.mail.properties.mail.smtp.auth=true spring.mail.properties.mail.smtp.ssl.enable=true spring.mail.properties.mail.smtp.socketFactory.class=javax.net.ssl.SSLSocketFactory # JPA Settings -spring.datasource.url=jdbc:postgresql://localhost:5433/ng-tracker +spring.datasource.url=jdbc:postgresql://localhost:5432/ng-tracker spring.datasource.username=postgres -spring.datasource.password=1234 +spring.datasource.password=postgres spring.datasource.driverclassName=org.postgresql.Driver spring.jpa.hibernate.ddl-auto=validate # Liquibase Settings From db3252d8228da4662275e92fe262c1da9703039f Mon Sep 17 00:00:00 2001 From: "a.vasin" Date: Sat, 1 Jun 2019 12:55:13 +0400 Subject: [PATCH 22/30] #101 event service edited --- src/main/java/ru/ulstu/paper/service/LatexService.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main/java/ru/ulstu/paper/service/LatexService.java b/src/main/java/ru/ulstu/paper/service/LatexService.java index 27dfa1e..82dd1ba 100644 --- a/src/main/java/ru/ulstu/paper/service/LatexService.java +++ b/src/main/java/ru/ulstu/paper/service/LatexService.java @@ -41,6 +41,12 @@ public class LatexService { Process process = processBuilder.start(); InputStreamReader inputStreamReader = new InputStreamReader(process.getInputStream()); + try (BufferedReader bufferedReader = new BufferedReader(inputStreamReader)) { + while ((bufferedReader.readLine()) != null) { + // + } + } + int exitCode = process.waitFor(); if (exitCode != 0) { errorMessage = message + " Exit value of the process: " + exitCode; From bde4ac5f1c3a98235f2062e713e78fa21b91eacd Mon Sep 17 00:00:00 2001 From: "a.vasin" Date: Sat, 1 Jun 2019 13:25:12 +0400 Subject: [PATCH 23/30] #101 event service edited --- src/main/java/ru/ulstu/paper/service/LatexService.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/ru/ulstu/paper/service/LatexService.java b/src/main/java/ru/ulstu/paper/service/LatexService.java index 82dd1ba..9892e35 100644 --- a/src/main/java/ru/ulstu/paper/service/LatexService.java +++ b/src/main/java/ru/ulstu/paper/service/LatexService.java @@ -42,8 +42,9 @@ public class LatexService { InputStreamReader inputStreamReader = new InputStreamReader(process.getInputStream()); try (BufferedReader bufferedReader = new BufferedReader(inputStreamReader)) { - while ((bufferedReader.readLine()) != null) { - // + String line = bufferedReader.readLine(); + while (line != null) { + line = bufferedReader.readLine(); } } From 23d4e5602f90a11f1eaaf123098d8b8da2e6748f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D0=B5=D0=BC=D0=B5=D0=BD=D0=BE=D0=B2=D0=B0=20=D0=9C?= =?UTF-8?q?=D0=B0=D1=80=D0=B8=D1=8F?= Date: Sat, 1 Jun 2019 23:16:39 +0400 Subject: [PATCH 24/30] #103 integration auto tests --- build.gradle | 2 + .../fragments/paperDashboardFragment.html | 3 +- .../resources/templates/papers/paper.html | 14 +- src/test/java/PaperTest.java | 247 ++++++++++++++++++ src/test/java/core/PageObject.java | 8 + src/test/java/paper/PaperPage.java | 206 +++++++++++++++ src/test/java/paper/PapersDashboardPage.java | 13 + src/test/java/paper/PapersPage.java | 50 ++++ 8 files changed, 537 insertions(+), 6 deletions(-) create mode 100644 src/test/java/PaperTest.java diff --git a/build.gradle b/build.gradle index 71c9977..e57e620 100644 --- a/build.gradle +++ b/build.gradle @@ -127,5 +127,7 @@ dependencies { testCompile group: 'org.springframework.boot', name: 'spring-boot-starter-test' compile group: 'org.seleniumhq.selenium', name: 'selenium-java', version: '3.3.1' + testCompile group: 'org.seleniumhq.selenium', name: 'selenium-support', version: '3.3.1' + testCompile group: 'com.google.guava', name: 'guava', version: '21.0' } \ 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 index d0ec0c5..62d2466 100644 --- a/src/main/resources/templates/papers/fragments/paperDashboardFragment.html +++ b/src/main/resources/templates/papers/fragments/paperDashboardFragment.html @@ -10,7 +10,8 @@
-

diff --git a/src/main/resources/templates/papers/paper.html b/src/main/resources/templates/papers/paper.html index 2755aba..2fbfa3a 100644 --- a/src/main/resources/templates/papers/paper.html +++ b/src/main/resources/templates/papers/paper.html @@ -87,14 +87,16 @@
-
+
-
-
@@ -234,7 +236,8 @@
-
@@ -247,7 +250,8 @@
-
diff --git a/src/test/java/PaperTest.java b/src/test/java/PaperTest.java new file mode 100644 index 0000000..a08a1d8 --- /dev/null +++ b/src/test/java/PaperTest.java @@ -0,0 +1,247 @@ +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.Iterables; +import core.PageObject; +import core.TestTemplate; +import org.junit.Assert; +import org.junit.FixMethodOrder; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.MethodSorters; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; +import paper.PaperPage; +import paper.PapersDashboardPage; +import paper.PapersPage; +import ru.ulstu.NgTrackerApplication; +import ru.ulstu.configuration.ApplicationProperties; + +import java.util.Arrays; +import java.util.List; +import java.util.Map; + +@RunWith(SpringRunner.class) +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +@SpringBootTest(classes = NgTrackerApplication.class, webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT) +public class PaperTest extends TestTemplate { + private final Map> navigationHolder = ImmutableMap.of( + new PapersPage(), Arrays.asList("СТАТЬИ", "/papers/papers"), + new PaperPage(), Arrays.asList("РЕДАКТИРОВАНИЕ СТАТЬИ", "/papers/paper?id=0"), + new PapersDashboardPage(), Arrays.asList("СТАТЬИ", "/papers/dashboard") + ); + + @Autowired + private ApplicationProperties applicationProperties; + + private String getPaperPageUrl() { + return Iterables.get(navigationHolder.entrySet(), 1).getValue().get(1); + } + + private PaperPage getPaperPage() { + PaperPage paperPage = (PaperPage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 1).getKey()); + paperPage.initElements(); + return paperPage; + } + + private String getPapersPageUrl() { + return Iterables.get(navigationHolder.entrySet(), 0).getValue().get(1); + } + + private PapersPage getPapersPage() { + PapersPage papersPage = (PapersPage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 0).getKey()); + papersPage.initElements(); + return papersPage; + } + + private String getPapersDashboardPageUrl() { + return Iterables.get(navigationHolder.entrySet(), 2).getValue().get(1); + } + + private PapersDashboardPage getPapersDashboardPage() { + PapersDashboardPage papersDashboardPage = (PapersDashboardPage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 2).getKey()); + papersDashboardPage.initElements(); + return papersDashboardPage; + } + + @Test + public void createNewPaperTest() { + getContext().goTo(applicationProperties.getBaseUrl() + getPaperPageUrl()); + PaperPage paperPage = getPaperPage(); + + String testTitle = "test " + (String.valueOf(System.currentTimeMillis())); + fillRequiredFields(paperPage, testTitle); + paperPage.clickSaveBtn(); + + PapersPage papersPage = getPapersPage(); + + Assert.assertTrue(papersPage.havePaperWithTitle(testTitle)); + } + + @Test + public void editPaperTest() { + createNewPaper(); + getContext().goTo(applicationProperties.getBaseUrl() + getPapersPageUrl()); + PapersPage papersPage = getPapersPage(); + papersPage.clickFirstPaper(); + + PaperPage paperPage = getPaperPage(); + String testTitle = "test " + (String.valueOf(System.currentTimeMillis())); + paperPage.setTitle(testTitle); + paperPage.clickSaveBtn(); + + Assert.assertTrue(papersPage.havePaperWithTitle(testTitle)); + } + + private void createNewPaper() { + getContext().goTo(applicationProperties.getBaseUrl() + getPaperPageUrl()); + PaperPage paperPage = getPaperPage(); + String testTitle = "test " + (String.valueOf(System.currentTimeMillis())); + fillRequiredFields(paperPage, testTitle); + paperPage.clickSaveBtn(); + } + + @Test + public void addDeadlineTest() { + createNewPaper(); + getContext().goTo(applicationProperties.getBaseUrl() + getPapersPageUrl()); + PapersPage papersPage = getPapersPage(); + papersPage.clickFirstPaper(); + + PaperPage paperPage = getPaperPage(); + papersPage.clickAddDeadline(); + String testDate = "01.01.2019"; + String testDateResult = "2019-01-01"; + String testDesc = "desc"; + Integer deadlineNumber = 2; + paperPage.setDeadlineDate(deadlineNumber, testDate); + paperPage.setDeadlineDescription(deadlineNumber, testDesc); + String paperId = paperPage.getId(); + paperPage.clickSaveBtn(); + + getContext().goTo(applicationProperties.getBaseUrl() + String.format("/papers/paper?id=%s", paperId)); + + Assert.assertTrue(paperPage.deadlineExist(testDesc, testDateResult)); + } + + @Test + public void noDeadlinesValidationTest() { + getContext().goTo(applicationProperties.getBaseUrl() + getPaperPageUrl()); + PaperPage paperPage = getPaperPage(); + + String testTitle = "test " + (String.valueOf(System.currentTimeMillis())); + paperPage.setTitle(testTitle); + paperPage.clickSaveBtn(); + + Assert.assertTrue(paperPage.hasAlert("Не может быть пустым")); + } + + private void fillRequiredFields(PaperPage paperPage, String title) { + paperPage.setTitle(title); + String testDate = "01.01.2019"; + String testDesc = "desc"; + Integer deadlineNumber = 1; + paperPage.setDeadlineDate(deadlineNumber, testDate); + paperPage.setDeadlineDescription(deadlineNumber, testDesc); + } + + @Test + public void addReferenceTest() { + createNewPaper(); + getContext().goTo(applicationProperties.getBaseUrl() + getPapersPageUrl()); + PapersPage papersPage = getPapersPage(); + papersPage.clickFirstPaper(); + + PaperPage paperPage = getPaperPage(); + fillRequiredFields(paperPage, "test " + (String.valueOf(System.currentTimeMillis()))); + paperPage.clickReferenceTab(); + paperPage.clickAddReferenceButton(); + + paperPage.clickReferenceTab(); + paperPage.showFirstReference(); + String authors = "testAuthors"; + paperPage.setFirstReferenceAuthors(authors); + + String paperId = paperPage.getId(); + paperPage.clickSaveBtn(); + + getContext().goTo(applicationProperties.getBaseUrl() + String.format("/papers/paper?id=%s", paperId)); + + Assert.assertTrue(paperPage.authorsExists(authors)); + } + + @Test + public void referencesFormatTest() { + getContext().goTo(applicationProperties.getBaseUrl() + getPaperPageUrl()); + + PaperPage paperPage = getPaperPage(); + paperPage.setTitle("test"); + paperPage.clickReferenceTab(); + paperPage.clickAddReferenceButton(); + + paperPage.clickReferenceTab(); + paperPage.showFirstReference(); + paperPage.setFirstReferenceAuthors("authors"); + paperPage.setFirstReferencePublicationTitle("title"); + paperPage.setFirstReferencePublicationYear("2010"); + paperPage.setFirstReferencePublisher("publisher"); + paperPage.setFirstReferencePages("200"); + paperPage.setFirstReferenceJournalOrCollectionTitle("journal"); + paperPage.setFormatStandardSpringer(); + paperPage.clickFormatButton(); + + Assert.assertEquals("authors (2010) title. journal, publisher, pp 200", paperPage.getFormatString()); + } + + @Test + public void dashboardLinkTest() { + getContext().goTo(applicationProperties.getBaseUrl() + getPaperPageUrl()); + PaperPage paperPage = getPaperPage(); + + fillRequiredFields(paperPage, "test " + (String.valueOf(System.currentTimeMillis()))); + String testLink = "http://test.com/"; + paperPage.setUrl(testLink); + paperPage.clickSaveBtn(); + + getContext().goTo(applicationProperties.getBaseUrl() + getPapersDashboardPageUrl()); + PapersDashboardPage papersDashboardPage = getPapersDashboardPage(); + + Assert.assertTrue(papersDashboardPage.externalLinkExists(testLink)); + } + + @Test + public void deletePaperTest() { + createNewPaper(); + getContext().goTo(applicationProperties.getBaseUrl() + getPapersPageUrl()); + PapersPage papersPage = getPapersPage(); + + int size = papersPage.getPapersCount(); + papersPage.clickRemoveFirstPaperButton(); + papersPage.clickConfirmDeleteButton(); + + Assert.assertEquals(size - 1, papersPage.getPapersCount()); + } + + @Test + public void latexValidationTest() { + getContext().goTo(applicationProperties.getBaseUrl() + getPaperPageUrl()); + + PaperPage paperPage = getPaperPage(); + paperPage.setTitle("test"); + paperPage.clickLatexTab(); + paperPage.setLatexText("test"); + paperPage.clickPdfButton(); + + Assert.assertTrue(paperPage.dangerMessageExist("Ошибка при создании PDF")); + } + + @Test + public void titleValidationTest() { + getContext().goTo(applicationProperties.getBaseUrl() + getPaperPageUrl()); + PaperPage paperPage = getPaperPage(); + + paperPage.clickSaveBtn(); + + Assert.assertTrue(paperPage.hasAlert("не может быть пусто")); + } + +} diff --git a/src/test/java/core/PageObject.java b/src/test/java/core/PageObject.java index f3e5cb8..e8eae6e 100644 --- a/src/test/java/core/PageObject.java +++ b/src/test/java/core/PageObject.java @@ -2,16 +2,24 @@ package core; import org.openqa.selenium.JavascriptExecutor; import org.openqa.selenium.WebDriver; +import org.openqa.selenium.support.PageFactory; +import org.openqa.selenium.support.ui.WebDriverWait; public abstract class PageObject { protected WebDriver driver; protected JavascriptExecutor js; + protected WebDriverWait waiter; public abstract String getSubTitle(); public PageObject setDriver(WebDriver driver) { this.driver = driver; js = (JavascriptExecutor) driver; + waiter = new WebDriverWait(driver, 10); return this; } + + public void initElements() { + PageFactory.initElements(driver, this); + } } diff --git a/src/test/java/paper/PaperPage.java b/src/test/java/paper/PaperPage.java index 9c3c357..908f8a1 100644 --- a/src/test/java/paper/PaperPage.java +++ b/src/test/java/paper/PaperPage.java @@ -2,10 +2,216 @@ package paper; import core.PageObject; import org.openqa.selenium.By; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.support.FindBy; +import org.openqa.selenium.support.ui.ExpectedConditions; +import org.openqa.selenium.support.ui.Select; + +import java.util.List; public class PaperPage extends PageObject { + @FindBy(id = "title") + private WebElement titleInput; + + @FindBy(id = "sendMessageButton") + private WebElement sendMessageButton; + + @FindBy(id = "id") + private WebElement idInput; + + @FindBy(css = "#messages .alert-danger span") + private WebElement dangerMessage; + + @FindBy(className = "deadline") + private List deadlines; + + @FindBy(className = "deadline-date") + private List deadlineDates; + + @FindBy(className = "deadline-desc") + private List deadlineDescs; + + @FindBy(css = ".alert.alert-danger") + private List dangerAlerts; + + @FindBy(className = "collapse-heading") + private WebElement firstCollapsedLink; + + @FindBy(id = "nav-references-tab") + private WebElement referenceTab; + + @FindBy(id = "nav-latex-tab") + private WebElement latexTab; + + @FindBy(id = "latex-text") + private WebElement latexTextarea; + + @FindBy(id = "addReference") + private WebElement addReferenceButton; + + @FindBy(css = "input.author ") + private WebElement firstAuthorInput; + + @FindBy(css = "input.publicationTitle") + private WebElement firstPublicationTitleInput; + + @FindBy(css = "input.publicationYear") + private WebElement firstPublicationYearInput; + + @FindBy(css = "input.publisher") + private WebElement firstPublisherInput; + + @FindBy(css = "input.pages") + private WebElement firstPagesInput; + + @FindBy(css = "input.journalOrCollectionTitle") + private WebElement firstJournalOrCollectionTitleInput; + + @FindBy(id = "formatBtn") + private WebElement formatButton; + + @FindBy(id = "formattedReferencesArea") + private WebElement formatArea; + + @FindBy(id = "url") + private WebElement urlInput; + + @FindBy(id = "pdfBtn") + private WebElement pdfButton; + + @FindBy(css = "input.author ") + private List authorInputs; + public String getSubTitle() { return driver.findElement(By.tagName("h2")).getText(); } + + public void clickReferenceTab() { + js.executeScript("document.getElementById('nav-references-tab').scrollIntoView(false);"); + referenceTab.click(); + } + + public void clickLatexTab() { + latexTab.click(); + } + + public void showFirstReference() { + waiter.until(ExpectedConditions.elementToBeClickable(firstCollapsedLink)); + firstCollapsedLink.click(); + } + + public void clickAddReferenceButton() { + js.executeScript("arguments[0].click()", addReferenceButton); + } + + public void clickFormatButton() { + formatButton.click(); + } + + public void clickPdfButton() { + pdfButton.click(); + } + + public void setTitle(String title) { + titleInput.clear(); + titleInput.sendKeys(title); + } + + public void setLatexText(String text) { + waiter.until(ExpectedConditions.visibilityOf(latexTextarea)); + latexTextarea.clear(); + latexTextarea.sendKeys(text); + } + + public void setFirstReferenceAuthors(String authors) { + waiter.until(ExpectedConditions.visibilityOf(firstAuthorInput)); + + firstAuthorInput.clear(); + firstAuthorInput.sendKeys(authors); + } + + public void setFirstReferencePublicationTitle(String title) { + firstPublicationTitleInput.clear(); + firstPublicationTitleInput.sendKeys(title); + } + + public void setFirstReferencePublicationYear(String year) { + firstPublicationYearInput.clear(); + firstPublicationYearInput.sendKeys(year); + } + + public void setFirstReferencePublisher(String publisher) { + firstPublisherInput.clear(); + firstPublisherInput.sendKeys(publisher); + } + + public void setFirstReferencePages(String pages) { + firstPagesInput.clear(); + firstPagesInput.sendKeys(pages); + } + + public void setFirstReferenceJournalOrCollectionTitle(String journal) { + firstJournalOrCollectionTitleInput.clear(); + firstJournalOrCollectionTitleInput.sendKeys(journal); + } + + public void setUrl(String url) { + urlInput.clear(); + urlInput.sendKeys(url); + } + + public void setFormatStandardSpringer() { + Select standards = new Select(driver.findElement(By.id("formatStandard"))); + standards.selectByValue("SPRINGER"); + } + + public void setDeadlineDate(Integer deadlineNumber, String date) { + deadlineDates.get(deadlineNumber - 1).sendKeys(date); + } + + public void setDeadlineDescription(Integer deadlineNumber, String desc) { + deadlineDescs.get(deadlineNumber - 1).clear(); + deadlineDescs.get(deadlineNumber - 1).sendKeys(desc); + } + + public boolean hasAlert(String alertMessage) { + return dangerAlerts + .stream() + .anyMatch( + webElement -> webElement.getText().contains(alertMessage)); + } + + public void clickSaveBtn() { + sendMessageButton.click(); + } + + public String getId() { + return idInput.getAttribute("value"); + } + + public String getFormatString() { + waiter.until(ExpectedConditions.attributeToBeNotEmpty(formatArea, "value")); + return formatArea.getAttribute("value"); + } + + public boolean deadlineExist(String desc, String date) { + return deadlines + .stream() + .anyMatch( + webElement -> webElement.findElement(By.className("deadline-desc")).getAttribute("value").equals(desc) + && webElement.findElement(By.className("deadline-date")).getAttribute("value").equals(date)); + } + + public boolean authorsExists(String authors) { + return authorInputs + .stream() + .anyMatch( + webElement -> webElement.getAttribute("value").equals(authors)); + } + + public boolean dangerMessageExist(String message) { + waiter.until(ExpectedConditions.visibilityOf(dangerMessage)); + return dangerMessage.getText().equals(message); + } } diff --git a/src/test/java/paper/PapersDashboardPage.java b/src/test/java/paper/PapersDashboardPage.java index 51d7cb8..4567490 100644 --- a/src/test/java/paper/PapersDashboardPage.java +++ b/src/test/java/paper/PapersDashboardPage.java @@ -2,10 +2,23 @@ package paper; import core.PageObject; import org.openqa.selenium.By; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.support.FindBy; + +import java.util.List; public class PapersDashboardPage extends PageObject { + @FindBy(className = "externalLink") + private List externalLinks; public String getSubTitle() { return driver.findElement(By.tagName("h2")).getText(); } + + public boolean externalLinkExists(String link) { + return externalLinks + .stream() + .anyMatch( + webElement -> webElement.getAttribute("href").equals(link)); + } } diff --git a/src/test/java/paper/PapersPage.java b/src/test/java/paper/PapersPage.java index f191d9b..620d0c0 100644 --- a/src/test/java/paper/PapersPage.java +++ b/src/test/java/paper/PapersPage.java @@ -2,10 +2,60 @@ package paper; import core.PageObject; import org.openqa.selenium.By; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.support.FindBy; +import org.openqa.selenium.support.ui.ExpectedConditions; + +import java.util.List; public class PapersPage extends PageObject { + @FindBy(css = ".paper-row .h6") + private List paperTitles; + + @FindBy(className = "paper-row") + private List paperItems; + + @FindBy(className = "remove-paper") + private WebElement removeFirstPaperButton; + + @FindBy(id = "dataConfirmOK") + private WebElement confirmDeleteButton; + + @FindBy(id = "addDeadline") + private WebElement addDeadlineButton; + + @FindBy(css = ".paper-row a:nth-child(2)") + private WebElement firstPaper; public String getSubTitle() { return driver.findElement(By.tagName("h2")).getText(); } + + public void clickFirstPaper() { + firstPaper.click(); + } + + public void clickAddDeadline() { + addDeadlineButton.click(); + } + + public void clickRemoveFirstPaperButton() { + js.executeScript("arguments[0].click()", removeFirstPaperButton); + } + + public void clickConfirmDeleteButton() { + waiter.until(ExpectedConditions.visibilityOf(confirmDeleteButton)); + confirmDeleteButton.click(); + } + + public boolean havePaperWithTitle(String title) { + return paperTitles + .stream() + .anyMatch(webElement -> webElement.getText().equals(title)); + } + + public int getPapersCount() { + return paperItems.size(); + } + } From 482964fe5315475574bbf839229476f6aae6d663 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=92=D0=B0=D1=81=D0=B8=D0=BD=20=D0=90=D0=BD=D1=82=D0=BE?= =?UTF-8?q?=D0=BD?= Date: Mon, 3 Jun 2019 20:21:46 +0300 Subject: [PATCH 25/30] #101 EventService edited --- .../ru/ulstu/conference/model/Conference.java | 18 +- .../conference/service/ConferenceService.java | 2 +- .../java/ru/ulstu/core/model/EventSource.java | 17 ++ src/main/java/ru/ulstu/grant/model/Grant.java | 14 +- .../ru/ulstu/grant/service/GrantService.java | 4 +- src/main/java/ru/ulstu/paper/model/Paper.java | 13 +- .../java/ru/ulstu/project/model/Project.java | 14 +- .../ulstu/project/service/ProjectService.java | 2 +- .../java/ru/ulstu/students/model/Task.java | 34 +++- .../ulstu/students/service/TaskService.java | 2 +- .../ulstu/timeline/service/EventService.java | 162 ++++-------------- 11 files changed, 139 insertions(+), 143 deletions(-) create mode 100644 src/main/java/ru/ulstu/core/model/EventSource.java diff --git a/src/main/java/ru/ulstu/conference/model/Conference.java b/src/main/java/ru/ulstu/conference/model/Conference.java index 4df1a1f..572921e 100644 --- a/src/main/java/ru/ulstu/conference/model/Conference.java +++ b/src/main/java/ru/ulstu/conference/model/Conference.java @@ -5,8 +5,11 @@ import org.hibernate.annotations.FetchMode; import org.hibernate.validator.constraints.NotBlank; import org.springframework.format.annotation.DateTimeFormat; import ru.ulstu.core.model.BaseEntity; +import ru.ulstu.core.model.EventSource; import ru.ulstu.deadline.model.Deadline; import ru.ulstu.paper.model.Paper; +import ru.ulstu.timeline.model.Event; +import ru.ulstu.user.model.User; import javax.persistence.CascadeType; import javax.persistence.Column; @@ -28,7 +31,7 @@ import java.util.Optional; @Entity @Table(name = "conference") -public class Conference extends BaseEntity { +public class Conference extends BaseEntity implements EventSource { @NotBlank private String title; @@ -71,6 +74,19 @@ public class Conference extends BaseEntity { return title; } + @Override + public List getRecipients() { + List list = new ArrayList<>(); + + getUsers().forEach(conferenceUser -> list.add(conferenceUser.getUser())); + return list; + } + + @Override + public void addObjectToEvent(Event event) { + event.setConference(this); + } + public void setTitle(String title) { this.title = title; } diff --git a/src/main/java/ru/ulstu/conference/service/ConferenceService.java b/src/main/java/ru/ulstu/conference/service/ConferenceService.java index 3b3bace..f742139 100644 --- a/src/main/java/ru/ulstu/conference/service/ConferenceService.java +++ b/src/main/java/ru/ulstu/conference/service/ConferenceService.java @@ -117,7 +117,7 @@ public class ConferenceService extends BaseService { Conference newConference = copyFromDto(new Conference(), conferenceDto); newConference = conferenceRepository.save(newConference); conferenceNotificationService.sendCreateNotification(newConference); - eventService.createFromObject(newConference, Collections.emptyList()); + eventService.createFromObject(newConference, Collections.emptyList(), false, "конференции"); return newConference; } diff --git a/src/main/java/ru/ulstu/core/model/EventSource.java b/src/main/java/ru/ulstu/core/model/EventSource.java new file mode 100644 index 0000000..32ffcf2 --- /dev/null +++ b/src/main/java/ru/ulstu/core/model/EventSource.java @@ -0,0 +1,17 @@ +package ru.ulstu.core.model; + +import ru.ulstu.deadline.model.Deadline; +import ru.ulstu.timeline.model.Event; +import ru.ulstu.user.model.User; + +import java.util.List; + +public interface EventSource { + List getDeadlines(); + + String getTitle(); + + List getRecipients(); + + void addObjectToEvent(Event event); +} diff --git a/src/main/java/ru/ulstu/grant/model/Grant.java b/src/main/java/ru/ulstu/grant/model/Grant.java index 369568f..78583c3 100644 --- a/src/main/java/ru/ulstu/grant/model/Grant.java +++ b/src/main/java/ru/ulstu/grant/model/Grant.java @@ -4,6 +4,7 @@ import org.hibernate.annotations.Fetch; import org.hibernate.annotations.FetchMode; import org.hibernate.validator.constraints.NotBlank; import ru.ulstu.core.model.BaseEntity; +import ru.ulstu.core.model.EventSource; import ru.ulstu.core.model.UserContainer; import ru.ulstu.deadline.model.Deadline; import ru.ulstu.file.model.FileData; @@ -26,6 +27,7 @@ import javax.persistence.OrderBy; import javax.persistence.Table; import javax.validation.constraints.NotNull; import java.util.ArrayList; +import java.util.Collections; import java.util.Comparator; import java.util.Date; import java.util.HashSet; @@ -35,7 +37,7 @@ import java.util.Set; @Entity @Table(name = "grants") -public class Grant extends BaseEntity implements UserContainer { +public class Grant extends BaseEntity implements UserContainer, EventSource { public enum GrantStatus { APPLICATION("Заявка"), ON_COMPETITION("Отправлен на конкурс"), @@ -134,6 +136,16 @@ public class Grant extends BaseEntity implements UserContainer { return title; } + @Override + public List getRecipients() { + return authors != null ? new ArrayList<>(authors) : Collections.emptyList(); + } + + @Override + public void addObjectToEvent(Event event) { + event.setGrant(this); + } + public void setTitle(String title) { this.title = title; } diff --git a/src/main/java/ru/ulstu/grant/service/GrantService.java b/src/main/java/ru/ulstu/grant/service/GrantService.java index d8e4aad..27841e3 100644 --- a/src/main/java/ru/ulstu/grant/service/GrantService.java +++ b/src/main/java/ru/ulstu/grant/service/GrantService.java @@ -90,7 +90,7 @@ public class GrantService extends BaseService { public Integer create(GrantDto grantDto) throws IOException { Grant newGrant = copyFromDto(new Grant(), grantDto); newGrant = grantRepository.save(newGrant); - eventService.createFromObject(newGrant, Collections.emptyList()); + eventService.createFromObject(newGrant, Collections.emptyList(), false, "гранта"); grantNotificationService.sendCreateNotification(newGrant); return newGrant.getId(); } @@ -178,7 +178,7 @@ public class GrantService extends BaseService { grant.getPapers().add(paper); grant = grantRepository.save(grant); - eventService.createFromObject(grant, Collections.emptyList()); + eventService.createFromObject(grant, Collections.emptyList(), false, "гранта"); grantNotificationService.sendCreateNotification(grant); return grant; diff --git a/src/main/java/ru/ulstu/paper/model/Paper.java b/src/main/java/ru/ulstu/paper/model/Paper.java index 413c5db..dbc9b52 100644 --- a/src/main/java/ru/ulstu/paper/model/Paper.java +++ b/src/main/java/ru/ulstu/paper/model/Paper.java @@ -5,6 +5,7 @@ import org.hibernate.annotations.FetchMode; import org.hibernate.validator.constraints.NotBlank; import ru.ulstu.conference.model.Conference; import ru.ulstu.core.model.BaseEntity; +import ru.ulstu.core.model.EventSource; import ru.ulstu.core.model.UserContainer; import ru.ulstu.deadline.model.Deadline; import ru.ulstu.file.model.FileData; @@ -34,7 +35,7 @@ import java.util.Optional; import java.util.Set; @Entity -public class Paper extends BaseEntity implements UserContainer { +public class Paper extends BaseEntity implements UserContainer, EventSource { public enum PaperStatus { ATTENTION("Обратить внимание"), ON_PREPARATION("На подготовке"), @@ -196,6 +197,16 @@ public class Paper extends BaseEntity implements UserContainer { return title; } + @Override + public List getRecipients() { + return new ArrayList(authors); + } + + @Override + public void addObjectToEvent(Event event) { + event.setPaper(this); + } + public void setTitle(String title) { this.title = title; } diff --git a/src/main/java/ru/ulstu/project/model/Project.java b/src/main/java/ru/ulstu/project/model/Project.java index 0c0af94..07f0141 100644 --- a/src/main/java/ru/ulstu/project/model/Project.java +++ b/src/main/java/ru/ulstu/project/model/Project.java @@ -4,6 +4,7 @@ import org.hibernate.annotations.Fetch; import org.hibernate.annotations.FetchMode; import org.hibernate.validator.constraints.NotBlank; import ru.ulstu.core.model.BaseEntity; +import ru.ulstu.core.model.EventSource; import ru.ulstu.core.model.UserContainer; import ru.ulstu.deadline.model.Deadline; import ru.ulstu.file.model.FileData; @@ -23,12 +24,13 @@ import javax.persistence.ManyToMany; import javax.persistence.JoinTable; import javax.validation.constraints.NotNull; import java.util.ArrayList; +import java.util.Collections; import java.util.HashSet; import java.util.List; import java.util.Set; @Entity -public class Project extends BaseEntity implements UserContainer { +public class Project extends BaseEntity implements UserContainer, EventSource { public enum ProjectStatus { TECHNICAL_TASK("Техническое задание"), @@ -92,6 +94,16 @@ public class Project extends BaseEntity implements UserContainer { return title; } + @Override + public List getRecipients() { + return executors != null ? new ArrayList<>(executors) : Collections.emptyList(); + } + + @Override + public void addObjectToEvent(Event event) { + event.setProject(this); + } + public void setTitle(String title) { this.title = title; } diff --git a/src/main/java/ru/ulstu/project/service/ProjectService.java b/src/main/java/ru/ulstu/project/service/ProjectService.java index de64c4c..6491b04 100644 --- a/src/main/java/ru/ulstu/project/service/ProjectService.java +++ b/src/main/java/ru/ulstu/project/service/ProjectService.java @@ -72,7 +72,7 @@ public class ProjectService { public Project create(ProjectDto projectDto) throws IOException { Project newProject = copyFromDto(new Project(), projectDto); newProject = projectRepository.save(newProject); - eventService.createFromObject(newProject, Collections.emptyList()); + eventService.createFromObject(newProject, Collections.emptyList(), false, "проекта"); return newProject; } diff --git a/src/main/java/ru/ulstu/students/model/Task.java b/src/main/java/ru/ulstu/students/model/Task.java index 2a03e37..2e63a3c 100644 --- a/src/main/java/ru/ulstu/students/model/Task.java +++ b/src/main/java/ru/ulstu/students/model/Task.java @@ -4,8 +4,17 @@ import org.hibernate.annotations.Fetch; import org.hibernate.annotations.FetchMode; import org.hibernate.validator.constraints.NotBlank; import ru.ulstu.core.model.BaseEntity; +import ru.ulstu.core.model.EventSource; import ru.ulstu.deadline.model.Deadline; +import ru.ulstu.deadline.service.DeadlineService; +import ru.ulstu.students.repository.SchedulerRepository; +import ru.ulstu.students.repository.TaskRepository; import ru.ulstu.tags.model.Tag; +import ru.ulstu.tags.service.TagService; +import ru.ulstu.timeline.model.Event; +import ru.ulstu.timeline.service.EventService; +import ru.ulstu.user.model.User; +import ru.ulstu.user.service.UserService; import javax.persistence.CascadeType; import javax.persistence.Column; @@ -20,12 +29,14 @@ import javax.persistence.OneToMany; import javax.persistence.OrderBy; import javax.persistence.Temporal; import javax.persistence.TemporalType; +import javax.persistence.Transient; import java.util.ArrayList; +import java.util.Collections; import java.util.Date; import java.util.List; @Entity -public class Task extends BaseEntity { +public class Task extends BaseEntity implements EventSource { public enum TaskStatus { IN_WORK("В работе"), @@ -49,6 +60,17 @@ public class Task extends BaseEntity { private String description; + @Transient + private UserService userService; + + public Task() { + + } + + public Task(UserService userService) { + this.userService = userService; + } + @Enumerated(value = EnumType.STRING) private TaskStatus status = TaskStatus.IN_WORK; @@ -77,6 +99,16 @@ public class Task extends BaseEntity { return title; } + @Override + public List getRecipients() { + return Collections.emptyList(); + } + + @Override + public void addObjectToEvent(Event event) { + event.setTask(this); + } + public void setTitle(String title) { this.title = title; } diff --git a/src/main/java/ru/ulstu/students/service/TaskService.java b/src/main/java/ru/ulstu/students/service/TaskService.java index 0a4590a..f78f8f7 100644 --- a/src/main/java/ru/ulstu/students/service/TaskService.java +++ b/src/main/java/ru/ulstu/students/service/TaskService.java @@ -84,7 +84,7 @@ public class TaskService { public Integer create(TaskDto taskDto) throws IOException { Task newTask = copyFromDto(new Task(), taskDto); newTask = taskRepository.save(newTask); - eventService.createFromObject(newTask, Collections.emptyList()); + eventService.createFromObject(newTask, Collections.emptyList(), true, "задачи"); return newTask.getId(); } diff --git a/src/main/java/ru/ulstu/timeline/service/EventService.java b/src/main/java/ru/ulstu/timeline/service/EventService.java index d307a8d..c22b9a3 100644 --- a/src/main/java/ru/ulstu/timeline/service/EventService.java +++ b/src/main/java/ru/ulstu/timeline/service/EventService.java @@ -1,12 +1,11 @@ package ru.ulstu.timeline.service; -import com.sun.jna.platform.win32.COM.util.Convert; import org.apache.commons.lang3.time.DateUtils; import org.springframework.context.annotation.Lazy; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import ru.ulstu.conference.model.Conference; -import ru.ulstu.core.model.BaseEntity; +import ru.ulstu.core.model.EventSource; import ru.ulstu.deadline.model.Deadline; import ru.ulstu.grant.model.Grant; import ru.ulstu.paper.model.Paper; @@ -16,12 +15,10 @@ import ru.ulstu.timeline.model.Event; import ru.ulstu.timeline.model.EventDto; import ru.ulstu.timeline.model.Timeline; import ru.ulstu.timeline.repository.EventRepository; -import ru.ulstu.user.model.User; import ru.ulstu.user.model.UserDto; import ru.ulstu.user.service.UserService; import java.util.ArrayList; -import java.util.Collection; import java.util.Collections; import java.util.Date; import java.util.List; @@ -36,13 +33,6 @@ public class EventService { private final TimelineService timelineService; private final UserService userService; - private String objectClassName = ""; - private Paper newPaper = new Paper(); - private Conference newConference = new Conference(); - private Grant newGrant = new Grant(); - private Project newProject = new Project(); - private Task newTask = new Task(); - public EventService(EventRepository eventRepository, @Lazy TimelineService timelineService, UserService userService) { @@ -116,133 +106,39 @@ public class EventService { } public void createFromPaper(Paper newPaper) { - createFromObject(newPaper, Collections.emptyList()); + createFromObject(newPaper, Collections.emptyList(), false, "статьи"); } - public void createFromObject(Object newObject, List events) { + public void createFromObject(EventSource eventSource, List events, Boolean addCurrentUser, String suffix) { List timelines = timelineService.findAll(); Timeline timeline = timelines.isEmpty() ? new Timeline() : timelines.get(0); - objectClassName = newObject.getClass().getName(); - switch(objectClassName) { - case "ru.ulstu.paper.model.Paper": - newPaper = (Paper)newObject; - timeline.getEvents().removeAll(events); - for (Deadline deadline : newPaper.getDeadlines() - .stream() - .filter(d -> d.getDate().after(new Date()) || DateUtils.isSameDay(d.getDate(), new Date())) - .collect(Collectors.toList())) { - Event newEvent = new Event(); - newEvent.setTitle("Дедлайн статьи"); - newEvent.setStatus(Event.EventStatus.NEW); - newEvent.setExecuteDate(deadline.getDate()); - newEvent.setCreateDate(new Date()); - newEvent.setUpdateDate(new Date()); - newEvent.setDescription("Дедлайн '" + deadline.getDescription() + "' cтатьи '" + newPaper.getTitle() + "'"); - newEvent.setRecipients(new ArrayList(newPaper.getAuthors())); - newEvent.setPaper(newPaper); - timeline.getEvents().add(eventRepository.save(newEvent)); - } - timelineService.save(timeline); - break; - case "ru.ulstu.conference.model.Conference": - newConference = (Conference)newObject; - for (Deadline deadline : newConference.getDeadlines() - .stream() - .filter(d -> d.getDate().after(new Date()) || DateUtils.isSameDay(d.getDate(), new Date())) - .collect(Collectors.toList())) { - Event newEvent = new Event(); - newEvent.setTitle("Дедлайн конференции"); - newEvent.setStatus(Event.EventStatus.NEW); - newEvent.setExecuteDate(deadline.getDate()); - newEvent.setCreateDate(new Date()); - newEvent.setUpdateDate(new Date()); - newEvent.setDescription("Дедлайн '" + deadline.getDescription() + "' конференции '" + newConference.getTitle() + "'"); - newConference.getUsers().forEach(conferenceUser -> newEvent.getRecipients().add(conferenceUser.getUser())); - newEvent.setConference(newConference); - save(newEvent); - timeline.getEvents().add(newEvent); - timelineService.save(timeline); - } - break; - case "ru.ulstu.grant.model.Grant": - newGrant = (Grant)newObject; - for (Deadline deadline : newGrant.getDeadlines() - .stream() - .filter(d -> d.getDate().after(new Date()) || DateUtils.isSameDay(d.getDate(), new Date())) - .collect(Collectors.toList())) { - Event newEvent = new Event(); - newEvent.setTitle("Дедлайн гранта"); - newEvent.setStatus(Event.EventStatus.NEW); - newEvent.setExecuteDate(deadline.getDate()); - newEvent.setCreateDate(new Date()); - newEvent.setUpdateDate(new Date()); - newEvent.setDescription("Дедлайн '" + deadline.getDescription() + "' гранта '" + newGrant.getTitle() + "'"); - if (newGrant.getAuthors() != null) { - newEvent.setRecipients(new ArrayList(newGrant.getAuthors())); - } - newEvent.getRecipients().add(newGrant.getLeader()); - newEvent.setGrant(newGrant); - eventRepository.save(newEvent); - - timeline.getEvents().add(newEvent); - timelineService.save(timeline); - } - break; - case "ru.ulstu.project.model.Project": - newProject = (Project)newObject; - for (Deadline deadline : newProject.getDeadlines() - .stream() - .filter(d -> d.getDate().after(new Date()) || DateUtils.isSameDay(d.getDate(), new Date())) - .collect(Collectors.toList())) { - Event newEvent = new Event(); - newEvent.setTitle("Дедлайн проекта"); - newEvent.setStatus(Event.EventStatus.NEW); - newEvent.setExecuteDate(deadline.getDate()); - newEvent.setCreateDate(new Date()); - newEvent.setUpdateDate(new Date()); - newEvent.setDescription("Дедлайн '" + deadline.getDescription() + "' проекта '" + newProject.getTitle() + "'"); - if (newProject.getExecutors() != null) { - newEvent.setRecipients(new ArrayList(newProject.getExecutors())); - } - newEvent.setProject(newProject); - eventRepository.save(newEvent); - - timeline.getEvents().add(newEvent); - timelineService.save(timeline); - } - break; - case "ru.ulstu.students.model.Task": - newTask = (Task)newObject; - for (Deadline deadline : newTask.getDeadlines() - .stream() - .filter(d -> d.getDate().after(new Date()) || DateUtils.isSameDay(d.getDate(), new Date())) - .collect(Collectors.toList())) { - Event newEvent = new Event(); - newEvent.setTitle("Дедлайн задачи"); - newEvent.setStatus(Event.EventStatus.NEW); - newEvent.setExecuteDate(deadline.getDate()); - newEvent.setCreateDate(new Date()); - newEvent.setUpdateDate(new Date()); - newEvent.setDescription("Дедлайн '" + deadline.getDescription() + "' задачи '" + newTask.getTitle() + "'"); - newEvent.getRecipients().add(userService.getCurrentUser()); - newEvent.setTask(newTask); - eventRepository.save(newEvent); - - timeline.getEvents().add(newEvent); - timelineService.save(timeline); - } - System.out.println("5"); - break; - default: - System.out.println("No such object"); - break; + timeline.getEvents().removeAll(events); + for (Deadline deadline : eventSource.getDeadlines() + .stream() + .filter(d -> d.getDate().after(new Date()) || DateUtils.isSameDay(d.getDate(), new Date())) + .collect(Collectors.toList())) { + Event newEvent = new Event(); + newEvent.setTitle("Дедлайн " + suffix); + newEvent.setStatus(Event.EventStatus.NEW); + newEvent.setExecuteDate(deadline.getDate()); + newEvent.setCreateDate(new Date()); + newEvent.setUpdateDate(new Date()); + newEvent.setDescription("Дедлайн '" + deadline.getDescription() + "' " + suffix + " '" + + eventSource.getTitle() + "'"); + if (addCurrentUser) { + newEvent.getRecipients().add(userService.getCurrentUser()); + } + newEvent.setRecipients(eventSource.getRecipients()); + eventSource.addObjectToEvent(newEvent); + timeline.getEvents().add(eventRepository.save(newEvent)); } + timelineService.save(timeline); } public void updatePaperDeadlines(Paper paper) { List foundEvents = eventRepository.findAllByPaper(paper); eventRepository.delete(foundEvents); - createFromObject(paper, foundEvents); + createFromObject(paper, foundEvents, false, "статьи"); } public List findByCurrentDate() { @@ -259,17 +155,17 @@ public class EventService { public void updateConferenceDeadlines(Conference conference) { eventRepository.delete(eventRepository.findAllByConference(conference)); - createFromObject(conference, Collections.emptyList()); + createFromObject(conference, Collections.emptyList(), false, "конференции"); } public void updateGrantDeadlines(Grant grant) { eventRepository.delete(eventRepository.findAllByGrant(grant)); - createFromObject(grant, Collections.emptyList()); + createFromObject(grant, Collections.emptyList(), false, "гранта"); } public void updateProjectDeadlines(Project project) { eventRepository.delete(eventRepository.findAllByProject(project)); - createFromObject(project, Collections.emptyList()); + createFromObject(project, Collections.emptyList(), false, "проекта"); } public void removeConferencesEvent(Conference conference) { @@ -279,6 +175,6 @@ public class EventService { public void updateTaskDeadlines(Task task) { eventRepository.delete(eventRepository.findAllByTask(task)); - createFromObject(task, Collections.emptyList()); + createFromObject(task, Collections.emptyList(), true, "задачи"); } -} +} \ No newline at end of file From bdff81d25eba7c66559a79b669ae2509bd3317c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=92=D0=B0=D1=81=D0=B8=D0=BD=20=D0=90=D0=BD=D1=82=D0=BE?= =?UTF-8?q?=D0=BD?= Date: Mon, 3 Jun 2019 20:42:49 +0300 Subject: [PATCH 26/30] #101 tests edited --- src/test/java/ru/ulstu/project/service/ProjectServiceTest.java | 2 +- src/test/java/ru/ulstu/students/service/TaskServiceTest.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/java/ru/ulstu/project/service/ProjectServiceTest.java b/src/test/java/ru/ulstu/project/service/ProjectServiceTest.java index d06ad0e..4015f3b 100644 --- a/src/test/java/ru/ulstu/project/service/ProjectServiceTest.java +++ b/src/test/java/ru/ulstu/project/service/ProjectServiceTest.java @@ -99,7 +99,7 @@ public class ProjectServiceTest { public void create() throws IOException { when(deadlineService.saveOrCreate(new ArrayList<>())).thenReturn(deadlines); when(projectRepository.save(new Project())).thenReturn(project); - eventService.createFromObject(new Project(), Collections.emptyList()); + eventService.createFromObject(new Project(), Collections.emptyList(), false, "проекта"); projectDto.setTitle(TITLE); projectDto.setDeadlines(deadlines); diff --git a/src/test/java/ru/ulstu/students/service/TaskServiceTest.java b/src/test/java/ru/ulstu/students/service/TaskServiceTest.java index 0d33630..d3db954 100644 --- a/src/test/java/ru/ulstu/students/service/TaskServiceTest.java +++ b/src/test/java/ru/ulstu/students/service/TaskServiceTest.java @@ -136,7 +136,7 @@ public class TaskServiceTest { when(tagService.saveOrCreate(new ArrayList<>())).thenReturn(tags); when(deadlineService.saveOrCreate(new ArrayList<>())).thenReturn(deadlines); when(taskRepository.save(new Task())).thenReturn(task); - eventService.createFromObject(new Task(), Collections.emptyList()); + eventService.createFromObject(new Task(), Collections.emptyList(), true, "задачи"); taskDto.setTags(tags); taskDto.setDeadlines(deadlines); From 0cd8003dd79c95dc8fd826b4f523171d201911d5 Mon Sep 17 00:00:00 2001 From: T-Midnight Date: Tue, 4 Jun 2019 16:26:42 +0400 Subject: [PATCH 27/30] #103 add tests for deadline --- .../resources/templates/grants/grant.html | 2 +- src/test/java/IndexGrantTest.java | 52 +++++++++++++++++++ src/test/java/grant/GrantPage.java | 26 ++++++++++ 3 files changed, 79 insertions(+), 1 deletion(-) diff --git a/src/main/resources/templates/grants/grant.html b/src/main/resources/templates/grants/grant.html index 38047bf..2699fa6 100644 --- a/src/main/resources/templates/grants/grant.html +++ b/src/main/resources/templates/grants/grant.html @@ -49,7 +49,7 @@
-
+
> page = Iterables.get(navigationHolder.entrySet(), 0); + getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); + GrantsPage grantsPage = (GrantsPage) getContext().initPage(page.getKey()); + GrantPage grantPage = (GrantPage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 1).getKey()); + + grantsPage.getFirstGrant(); + String grantId = grantPage.getId(); + Integer deadlineCount = grantPage.getDeadlineCount(); + + String description = "deadline test"; + String date = "09.09.2019"; + String dateValue = "2019-09-09"; + grantPage.addDeadline(); + grantPage.setDeadline(date, deadlineCount, description); + grantPage.saveGrant(); + + getContext().goTo(applicationProperties.getBaseUrl() + String.format("/grants/grant?id=%s", grantId)); + + Assert.assertTrue(grantPage.checkDeadline(description, dateValue)); + } + + @Test + public void deleteDeadline() { + Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); + getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); + GrantsPage grantsPage = (GrantsPage) getContext().initPage(page.getKey()); + GrantPage grantPage = (GrantPage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 1).getKey()); + + grantsPage.getFirstGrant(); + String grantId = grantPage.getId(); + Integer deadlineCount = grantPage.getDeadlineCount(); + + String description = "deadline test"; + String date = "09.09.2019"; + String dateValue = "2019-09-09"; + grantPage.addDeadline(); + grantPage.setDeadline(date, deadlineCount, description); + grantPage.saveGrant(); + + getContext().goTo(applicationProperties.getBaseUrl() + String.format("/grants/grant?id=%s", grantId)); + deadlineCount = grantPage.getDeadlineCount(); + + grantPage.deleteDeadline(); + grantPage.saveGrant(); + + getContext().goTo(applicationProperties.getBaseUrl() + String.format("/grants/grant?id=%s", grantId)); + Integer newDeadlineCount = grantPage.getDeadlineCount(); + Assert.assertEquals(deadlineCount - 1, (int) newDeadlineCount); + } } diff --git a/src/test/java/grant/GrantPage.java b/src/test/java/grant/GrantPage.java index 809e22f..9fd1986 100644 --- a/src/test/java/grant/GrantPage.java +++ b/src/test/java/grant/GrantPage.java @@ -83,4 +83,30 @@ public class GrantPage extends PageObject { select.deselectByVisibleText(select.getFirstSelectedOption().getText()); return select.getAllSelectedOptions(); } + + public List getDeadlineList() { + return driver.findElements(By.id("deadlines")); + } + + public Integer getDeadlineCount() { + return getDeadlineList().size(); + } + + public void addDeadline() { + driver.findElement(By.id("addDeadline")).click(); + } + + public boolean checkDeadline(String description, String dateValue) { + return getDeadlineList() + .stream() + .anyMatch(webElement -> { + return webElement.findElement(By.className("div-deadline-description")).findElement( + By.tagName("input")).getAttribute("value").equals(description) + && webElement.findElement(By.className("form-deadline-date")).getAttribute("value").equals(dateValue); + }); + } + + public void deleteDeadline() { + driver.findElements(By.className("btn-delete-deadline")).get(0).click(); + } } From 1ff38fc80e83f781688247ffffa487de09a7678d Mon Sep 17 00:00:00 2001 From: T-Midnight Date: Wed, 5 Jun 2019 09:36:29 +0400 Subject: [PATCH 28/30] #103 merge with dev --- .../ru/ulstu/conference/service/ConferenceService.java | 2 +- src/main/java/ru/ulstu/grant/service/GrantService.java | 1 - .../ru/ulstu/project/controller/ProjectController.java | 1 - src/main/java/ru/ulstu/project/model/Project.java | 10 +++++----- src/main/java/ru/ulstu/students/model/Task.java | 5 ----- .../java/ru/ulstu/students/service/TaskService.java | 6 +++--- .../java/ru/ulstu/timeline/service/EventService.java | 1 - .../java/ru/ulstu/user/controller/UserController.java | 2 -- .../ru/ulstu/user/controller/UserMvcController.java | 2 +- src/main/java/ru/ulstu/user/service/UserService.java | 2 +- .../ru/ulstu/utils/timetable/TimetableService.java | 8 ++++---- src/main/java/ru/ulstu/utils/timetable/model/Day.java | 2 +- .../java/ru/ulstu/utils/timetable/model/Lesson.java | 2 +- .../ulstu/utils/timetable/model/TimetableResponse.java | 2 +- .../templates/grants/fragments/grantLineFragment.html | 6 ++++-- .../templates/papers/fragments/paperLineFragment.html | 6 ++++-- src/main/resources/templates/papers/paper.html | 1 + src/main/resources/templates/projects/project.html | 6 ++++-- src/main/resources/templates/resetRequest.html | 5 +++-- src/main/resources/templates/users/dashboard.html | 1 + .../users/fragments/userDashboardFragment.html | 10 +++++++--- .../ru/ulstu/project/service/ProjectServiceTest.java | 5 ++++- 22 files changed, 46 insertions(+), 40 deletions(-) diff --git a/src/main/java/ru/ulstu/conference/service/ConferenceService.java b/src/main/java/ru/ulstu/conference/service/ConferenceService.java index f742139..d877232 100644 --- a/src/main/java/ru/ulstu/conference/service/ConferenceService.java +++ b/src/main/java/ru/ulstu/conference/service/ConferenceService.java @@ -25,9 +25,9 @@ import ru.ulstu.user.service.UserService; import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import java.util.Date; import java.util.List; -import java.util.Collections; import java.util.stream.Collectors; import static org.springframework.util.ObjectUtils.isEmpty; diff --git a/src/main/java/ru/ulstu/grant/service/GrantService.java b/src/main/java/ru/ulstu/grant/service/GrantService.java index 27841e3..542965a 100644 --- a/src/main/java/ru/ulstu/grant/service/GrantService.java +++ b/src/main/java/ru/ulstu/grant/service/GrantService.java @@ -1,6 +1,5 @@ package ru.ulstu.grant.service; -import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Service; diff --git a/src/main/java/ru/ulstu/project/controller/ProjectController.java b/src/main/java/ru/ulstu/project/controller/ProjectController.java index 87ae8df..a991e35 100644 --- a/src/main/java/ru/ulstu/project/controller/ProjectController.java +++ b/src/main/java/ru/ulstu/project/controller/ProjectController.java @@ -10,7 +10,6 @@ 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.grant.model.Grant; import ru.ulstu.grant.model.GrantDto; import ru.ulstu.project.model.Project; import ru.ulstu.project.model.ProjectDto; diff --git a/src/main/java/ru/ulstu/project/model/Project.java b/src/main/java/ru/ulstu/project/model/Project.java index 07f0141..6b5f925 100644 --- a/src/main/java/ru/ulstu/project/model/Project.java +++ b/src/main/java/ru/ulstu/project/model/Project.java @@ -12,16 +12,16 @@ import ru.ulstu.grant.model.Grant; import ru.ulstu.timeline.model.Event; import ru.ulstu.user.model.User; +import javax.persistence.CascadeType; import javax.persistence.Entity; import javax.persistence.EnumType; import javax.persistence.Enumerated; -import javax.persistence.OneToMany; -import javax.persistence.CascadeType; -import javax.persistence.JoinColumn; -import javax.persistence.ManyToOne; import javax.persistence.FetchType; -import javax.persistence.ManyToMany; +import javax.persistence.JoinColumn; import javax.persistence.JoinTable; +import javax.persistence.ManyToMany; +import javax.persistence.ManyToOne; +import javax.persistence.OneToMany; import javax.validation.constraints.NotNull; import java.util.ArrayList; import java.util.Collections; diff --git a/src/main/java/ru/ulstu/students/model/Task.java b/src/main/java/ru/ulstu/students/model/Task.java index 2e63a3c..c3f195b 100644 --- a/src/main/java/ru/ulstu/students/model/Task.java +++ b/src/main/java/ru/ulstu/students/model/Task.java @@ -6,13 +6,8 @@ import org.hibernate.validator.constraints.NotBlank; import ru.ulstu.core.model.BaseEntity; import ru.ulstu.core.model.EventSource; import ru.ulstu.deadline.model.Deadline; -import ru.ulstu.deadline.service.DeadlineService; -import ru.ulstu.students.repository.SchedulerRepository; -import ru.ulstu.students.repository.TaskRepository; import ru.ulstu.tags.model.Tag; -import ru.ulstu.tags.service.TagService; import ru.ulstu.timeline.model.Event; -import ru.ulstu.timeline.service.EventService; import ru.ulstu.user.model.User; import ru.ulstu.user.service.UserService; diff --git a/src/main/java/ru/ulstu/students/service/TaskService.java b/src/main/java/ru/ulstu/students/service/TaskService.java index f78f8f7..548e899 100644 --- a/src/main/java/ru/ulstu/students/service/TaskService.java +++ b/src/main/java/ru/ulstu/students/service/TaskService.java @@ -18,15 +18,15 @@ import ru.ulstu.tags.service.TagService; import ru.ulstu.timeline.service.EventService; import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; import java.util.Calendar; import java.util.Collections; import java.util.Date; import java.util.List; -import java.util.Set; import java.util.Map; +import java.util.Set; import java.util.TreeMap; -import java.util.ArrayList; -import java.util.Arrays; import java.util.stream.Collectors; import static org.springframework.util.ObjectUtils.isEmpty; diff --git a/src/main/java/ru/ulstu/timeline/service/EventService.java b/src/main/java/ru/ulstu/timeline/service/EventService.java index c22b9a3..868d576 100644 --- a/src/main/java/ru/ulstu/timeline/service/EventService.java +++ b/src/main/java/ru/ulstu/timeline/service/EventService.java @@ -18,7 +18,6 @@ import ru.ulstu.timeline.repository.EventRepository; import ru.ulstu.user.model.UserDto; import ru.ulstu.user.service.UserService; -import java.util.ArrayList; import java.util.Collections; import java.util.Date; import java.util.List; diff --git a/src/main/java/ru/ulstu/user/controller/UserController.java b/src/main/java/ru/ulstu/user/controller/UserController.java index c40ed8f..407986f 100644 --- a/src/main/java/ru/ulstu/user/controller/UserController.java +++ b/src/main/java/ru/ulstu/user/controller/UserController.java @@ -3,7 +3,6 @@ package ru.ulstu.user.controller; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.security.access.annotation.Secured; -import org.springframework.ui.ModelMap; import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; @@ -33,7 +32,6 @@ import ru.ulstu.user.service.UserSessionService; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpSession; import javax.validation.Valid; - import java.util.Map; import static ru.ulstu.user.controller.UserController.URL; diff --git a/src/main/java/ru/ulstu/user/controller/UserMvcController.java b/src/main/java/ru/ulstu/user/controller/UserMvcController.java index 044bde8..7f1c1b8 100644 --- a/src/main/java/ru/ulstu/user/controller/UserMvcController.java +++ b/src/main/java/ru/ulstu/user/controller/UserMvcController.java @@ -9,8 +9,8 @@ import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import ru.ulstu.configuration.Constants; import ru.ulstu.odin.controller.OdinController; -import ru.ulstu.user.model.UserDto; import ru.ulstu.user.model.User; +import ru.ulstu.user.model.UserDto; import ru.ulstu.user.model.UserListDto; import ru.ulstu.user.service.UserService; import ru.ulstu.user.service.UserSessionService; diff --git a/src/main/java/ru/ulstu/user/service/UserService.java b/src/main/java/ru/ulstu/user/service/UserService.java index 217215b..b731c1e 100644 --- a/src/main/java/ru/ulstu/user/service/UserService.java +++ b/src/main/java/ru/ulstu/user/service/UserService.java @@ -252,7 +252,7 @@ public class UserService implements UserDetailsService { mailService.sendChangePasswordMail(user); } - public boolean requestUserPasswordReset(String email) { + public boolean requestUserPasswordReset(String email) { User user = userRepository.findOneByEmailIgnoreCase(email); if (user == null) { throw new UserNotFoundException(email); diff --git a/src/main/java/ru/ulstu/utils/timetable/TimetableService.java b/src/main/java/ru/ulstu/utils/timetable/TimetableService.java index d65e276..78a1c66 100644 --- a/src/main/java/ru/ulstu/utils/timetable/TimetableService.java +++ b/src/main/java/ru/ulstu/utils/timetable/TimetableService.java @@ -18,7 +18,7 @@ public class TimetableService { private static final String TIMETABLE_URL = "http://timetable.athene.tech/api/1.0/timetable?filter=%s"; private SimpleDateFormat lessonTimeFormat = new SimpleDateFormat("hh:mm"); - private long[] lessonsStarts = new long[] { + private long[] lessonsStarts = new long[]{ lessonTimeFormat.parse("8:00:00").getTime(), lessonTimeFormat.parse("9:40:00").getTime(), lessonTimeFormat.parse("11:30:00").getTime(), @@ -58,8 +58,8 @@ public class TimetableService { firstJan.set(Calendar.MONTH, 0); firstJan.set(Calendar.DAY_OF_MONTH, 1); - return (int) Math.round(Math.ceil((((currentDate.getTime() - firstJan.getTime().getTime()) / 86400000) - + DateUtils.addDays(firstJan.getTime(), 1).getTime() / 7) % 2)); + return (int) Math.round(Math.ceil((((currentDate.getTime() - firstJan.getTime().getTime()) / 86400000) + + DateUtils.addDays(firstJan.getTime(), 1).getTime() / 7) % 2)); } private TimetableResponse getTimetableForUser(String userFIO) throws RestClientException { @@ -67,7 +67,7 @@ public class TimetableService { return restTemplate.getForObject(String.format(TIMETABLE_URL, userFIO), TimetableResponse.class); } - public Lesson getCurrentLesson(String userFio) { + public Lesson getCurrentLesson(String userFio) { TimetableResponse response; try { response = getTimetableForUser(userFio); diff --git a/src/main/java/ru/ulstu/utils/timetable/model/Day.java b/src/main/java/ru/ulstu/utils/timetable/model/Day.java index e4e37f9..211165d 100644 --- a/src/main/java/ru/ulstu/utils/timetable/model/Day.java +++ b/src/main/java/ru/ulstu/utils/timetable/model/Day.java @@ -4,7 +4,7 @@ import java.util.ArrayList; import java.util.List; -public class Day { +public class Day { private Integer day; private List> lessons = new ArrayList<>(); diff --git a/src/main/java/ru/ulstu/utils/timetable/model/Lesson.java b/src/main/java/ru/ulstu/utils/timetable/model/Lesson.java index b1b1707..9c855bd 100644 --- a/src/main/java/ru/ulstu/utils/timetable/model/Lesson.java +++ b/src/main/java/ru/ulstu/utils/timetable/model/Lesson.java @@ -1,6 +1,6 @@ package ru.ulstu.utils.timetable.model; -public class Lesson { +public class Lesson { private String group; private String nameOfLesson; private String teacher; diff --git a/src/main/java/ru/ulstu/utils/timetable/model/TimetableResponse.java b/src/main/java/ru/ulstu/utils/timetable/model/TimetableResponse.java index 925d9a8..118c979 100644 --- a/src/main/java/ru/ulstu/utils/timetable/model/TimetableResponse.java +++ b/src/main/java/ru/ulstu/utils/timetable/model/TimetableResponse.java @@ -1,6 +1,6 @@ package ru.ulstu.utils.timetable.model; -public class TimetableResponse { +public class TimetableResponse { private Response response; private String error; diff --git a/src/main/resources/templates/grants/fragments/grantLineFragment.html b/src/main/resources/templates/grants/fragments/grantLineFragment.html index 877f1d7..3a2a683 100644 --- a/src/main/resources/templates/grants/fragments/grantLineFragment.html +++ b/src/main/resources/templates/grants/fragments/grantLineFragment.html @@ -8,8 +8,10 @@
- - + + diff --git a/src/main/resources/templates/papers/fragments/paperLineFragment.html b/src/main/resources/templates/papers/fragments/paperLineFragment.html index 40d9c34..1975dc0 100644 --- a/src/main/resources/templates/papers/fragments/paperLineFragment.html +++ b/src/main/resources/templates/papers/fragments/paperLineFragment.html @@ -8,8 +8,10 @@
- - + + diff --git a/src/main/resources/templates/papers/paper.html b/src/main/resources/templates/papers/paper.html index 2fbfa3a..e77ccbb 100644 --- a/src/main/resources/templates/papers/paper.html +++ b/src/main/resources/templates/papers/paper.html @@ -530,6 +530,7 @@ } } + @@ -35,7 +35,8 @@
- +
diff --git a/src/main/resources/templates/users/fragments/userDashboardFragment.html b/src/main/resources/templates/users/fragments/userDashboardFragment.html index 267bbf8..3095cca 100644 --- a/src/main/resources/templates/users/fragments/userDashboardFragment.html +++ b/src/main/resources/templates/users/fragments/userDashboardFragment.html @@ -7,9 +7,13 @@
-

-

-

+

+
+

+
+

+

Онлайн

diff --git a/src/test/java/ru/ulstu/project/service/ProjectServiceTest.java b/src/test/java/ru/ulstu/project/service/ProjectServiceTest.java index 4015f3b..25a201b 100644 --- a/src/test/java/ru/ulstu/project/service/ProjectServiceTest.java +++ b/src/test/java/ru/ulstu/project/service/ProjectServiceTest.java @@ -20,7 +20,10 @@ import ru.ulstu.user.model.User; import ru.ulstu.user.service.UserService; import java.io.IOException; -import java.util.*; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Date; +import java.util.List; import static junit.framework.TestCase.assertTrue; import static org.junit.Assert.assertEquals; From acd58005deaec61bc99d664abffe4c48463d3c57 Mon Sep 17 00:00:00 2001 From: T-Midnight Date: Wed, 5 Jun 2019 15:52:29 +0400 Subject: [PATCH 29/30] #103 merge with 44 --- .../templates/conferences/conference.html | 6 ++++-- .../grants/fragments/grantLineFragment.html | 4 ++++ .../grants/fragments/grantStatusFragment.html | 2 +- .../resources/templates/grants/grant.html | 2 ++ .../fragments/paperDashboardFragment.html | 3 ++- .../papers/fragments/paperLineFragment.html | 4 ++-- .../papers/fragments/paperStatusFragment.html | 21 ++++++++++--------- 7 files changed, 26 insertions(+), 16 deletions(-) diff --git a/src/main/resources/templates/conferences/conference.html b/src/main/resources/templates/conferences/conference.html index 201aa01..106f014 100644 --- a/src/main/resources/templates/conferences/conference.html +++ b/src/main/resources/templates/conferences/conference.html @@ -156,14 +156,16 @@ - + Имя статьи - + Имя статьи diff --git a/src/main/resources/templates/grants/fragments/grantLineFragment.html b/src/main/resources/templates/grants/fragments/grantLineFragment.html index 3a2a683..821cf89 100644 --- a/src/main/resources/templates/grants/fragments/grantLineFragment.html +++ b/src/main/resources/templates/grants/fragments/grantLineFragment.html @@ -14,6 +14,10 @@ th:title="${grant.title}"/> + + + diff --git a/src/main/resources/templates/grants/fragments/grantStatusFragment.html b/src/main/resources/templates/grants/fragments/grantStatusFragment.html index 569f5ee..bf866d2 100644 --- a/src/main/resources/templates/grants/fragments/grantStatusFragment.html +++ b/src/main/resources/templates/grants/fragments/grantStatusFragment.html @@ -25,7 +25,7 @@
- + \ No newline at end of file diff --git a/src/main/resources/templates/grants/grant.html b/src/main/resources/templates/grants/grant.html index 10d21e0..04a86a7 100644 --- a/src/main/resources/templates/grants/grant.html +++ b/src/main/resources/templates/grants/grant.html @@ -191,6 +191,7 @@
+
diff --git a/src/main/resources/templates/papers/fragments/paperDashboardFragment.html b/src/main/resources/templates/papers/fragments/paperDashboardFragment.html index 62d2466..48b6bae 100644 --- a/src/main/resources/templates/papers/fragments/paperDashboardFragment.html +++ b/src/main/resources/templates/papers/fragments/paperDashboardFragment.html @@ -7,7 +7,8 @@
- +

- - + + - +
- +
- +
- +
- +
- +
- +
- +
- +
- +
\ No newline at end of file From fddc15af5a7e1331c69580c6907a4ce1aac7e14a Mon Sep 17 00:00:00 2001 From: T-Midnight Date: Wed, 5 Jun 2019 23:14:52 +0400 Subject: [PATCH 30/30] #103 add tests for authors and description --- .../{IndexGrantTest.java => GrantTest.java} | 115 +++++++++++++----- src/test/java/grant/GrantPage.java | 45 ++++++- src/test/java/grant/GrantsPage.java | 30 ++++- 3 files changed, 154 insertions(+), 36 deletions(-) rename src/test/java/{IndexGrantTest.java => GrantTest.java} (68%) diff --git a/src/test/java/IndexGrantTest.java b/src/test/java/GrantTest.java similarity index 68% rename from src/test/java/IndexGrantTest.java rename to src/test/java/GrantTest.java index e1560a9..b824852 100644 --- a/src/test/java/IndexGrantTest.java +++ b/src/test/java/GrantTest.java @@ -10,6 +10,7 @@ import org.junit.FixMethodOrder; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.MethodSorters; +import org.openqa.selenium.WebElement; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit4.SpringRunner; @@ -24,7 +25,7 @@ import java.util.Map; @RunWith(SpringRunner.class) @FixMethodOrder(MethodSorters.NAME_ASCENDING) @SpringBootTest(classes = NgTrackerApplication.class, webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT) -public class IndexGrantTest extends TestTemplate { +public class GrantTest extends TestTemplate { private final Map> navigationHolder = ImmutableMap.of( new GrantsPage(), Arrays.asList("ГРАНТЫ", "/grants/grants"), new GrantPage(), Arrays.asList("РЕДАКТИРОВАНИЕ ГРАНТА", "/grants/grant?id=0"), @@ -35,7 +36,7 @@ public class IndexGrantTest extends TestTemplate { private ApplicationProperties applicationProperties; @Test - public void createNewGrant() { + public void aCreateNewGrant() { Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 1); getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); GrantPage grantPage = (GrantPage) getContext().initPage(page.getKey()); @@ -53,7 +54,7 @@ public class IndexGrantTest extends TestTemplate { } @Test - public void createBlankGrant() { + public void bCreateBlankGrant() { Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 1); getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); GrantPage grantPage = (GrantPage) getContext().initPage(page.getKey()); @@ -64,7 +65,7 @@ public class IndexGrantTest extends TestTemplate { } @Test - public void updateGrantTitle() { + public void cUpdateGrantTitle() { Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); GrantsPage grantsPage = (GrantsPage) getContext().initPage(page.getKey()); @@ -79,18 +80,7 @@ public class IndexGrantTest extends TestTemplate { } @Test - public void deleteGrant() throws InterruptedException { - Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); - getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); - GrantsPage grantsPage = (GrantsPage) getContext().initPage(page.getKey()); - - Integer size = grantsPage.getGrantsList().size(); - grantsPage.deleteFirst(); - Assert.assertEquals(size - 1, grantsPage.getGrantsList().size()); - } - - @Test - public void attachPaper() { + public void dAttachPaper() { Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); GrantsPage grantsPage = (GrantsPage) getContext().initPage(page.getKey()); @@ -103,7 +93,7 @@ public class IndexGrantTest extends TestTemplate { } @Test - public void deletePaper() { + public void eDeletePaper() { Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); GrantsPage grantsPage = (GrantsPage) getContext().initPage(page.getKey()); @@ -119,7 +109,7 @@ public class IndexGrantTest extends TestTemplate { } @Test - public void addDeadline() { + public void fAddDeadline() { Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); GrantsPage grantsPage = (GrantsPage) getContext().initPage(page.getKey()); @@ -130,8 +120,8 @@ public class IndexGrantTest extends TestTemplate { Integer deadlineCount = grantPage.getDeadlineCount(); String description = "deadline test"; - String date = "09.09.2019"; - String dateValue = "2019-09-09"; + String date = "08.08.2019"; + String dateValue = "2019-08-08"; grantPage.addDeadline(); grantPage.setDeadline(date, deadlineCount, description); grantPage.saveGrant(); @@ -142,7 +132,7 @@ public class IndexGrantTest extends TestTemplate { } @Test - public void deleteDeadline() { + public void gDeleteDeadline() { Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); GrantsPage grantsPage = (GrantsPage) getContext().initPage(page.getKey()); @@ -152,16 +142,6 @@ public class IndexGrantTest extends TestTemplate { String grantId = grantPage.getId(); Integer deadlineCount = grantPage.getDeadlineCount(); - String description = "deadline test"; - String date = "09.09.2019"; - String dateValue = "2019-09-09"; - grantPage.addDeadline(); - grantPage.setDeadline(date, deadlineCount, description); - grantPage.saveGrant(); - - getContext().goTo(applicationProperties.getBaseUrl() + String.format("/grants/grant?id=%s", grantId)); - deadlineCount = grantPage.getDeadlineCount(); - grantPage.deleteDeadline(); grantPage.saveGrant(); @@ -169,4 +149,77 @@ public class IndexGrantTest extends TestTemplate { Integer newDeadlineCount = grantPage.getDeadlineCount(); Assert.assertEquals(deadlineCount - 1, (int) newDeadlineCount); } + + @Test + public void hAddAuthor() { + Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); + getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); + GrantsPage grantsPage = (GrantsPage) getContext().initPage(page.getKey()); + GrantPage grantPage = (GrantPage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 1).getKey()); + + WebElement grant = grantsPage.getFirstGrantWithoutClick(); + String grantTitle = grantsPage.getGrantTitle(grant); + Integer authorsCount = grantsPage.getAuthorsCount(grant); + + grantsPage.getFirstGrant(); + grantPage.addAuthor(); + grantPage.saveGrant(); + + grant = grantsPage.getGrantByTitle(grantTitle); + Integer newAuthorsCount = grantsPage.getAuthorsCount(grant); + + Assert.assertEquals(authorsCount + 1, (int) newAuthorsCount); + } + + @Test + public void iDeleteAuthor() { + Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); + getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); + GrantsPage grantsPage = (GrantsPage) getContext().initPage(page.getKey()); + GrantPage grantPage = (GrantPage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 1).getKey()); + + WebElement grant = grantsPage.getFirstGrantWithoutClick(); + String grantTitle = grantsPage.getGrantTitle(grant); + Integer authorsCount = grantsPage.getAuthorsCount(grant); + + grantsPage.getFirstGrant(); + grantPage.deleteAuthor(); + grantPage.saveGrant(); + + grant = grantsPage.getGrantByTitle(grantTitle); + Integer newAuthorsCount = grantsPage.getAuthorsCount(grant); + + authorsCount = (authorsCount == 0) ? 0 : authorsCount - 1; + + Assert.assertEquals((int) authorsCount, (int) newAuthorsCount); + } + + @Test + public void jUpdateGrantDescription() { + Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); + getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); + GrantsPage grantsPage = (GrantsPage) getContext().initPage(page.getKey()); + GrantPage grantPage = (GrantPage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 1).getKey()); + + String description = "newDescriptionForGrant"; + grantsPage.getFirstGrant(); + String grantId = grantPage.getId(); + grantPage.setDescription(description); + grantPage.saveGrant(); + + getContext().goTo(applicationProperties.getBaseUrl() + String.format("/grants/grant?id=%s", grantId)); + + Assert.assertTrue(description.equals(grantPage.getDescription())); + } + + @Test + public void kDeleteGrant() throws InterruptedException { + Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); + getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); + GrantsPage grantsPage = (GrantsPage) getContext().initPage(page.getKey()); + + Integer size = grantsPage.getGrantsList().size(); + grantsPage.deleteFirst(); + Assert.assertEquals(size - 1, grantsPage.getGrantsList().size()); + } } diff --git a/src/test/java/grant/GrantPage.java b/src/test/java/grant/GrantPage.java index 9fd1986..fe13956 100644 --- a/src/test/java/grant/GrantPage.java +++ b/src/test/java/grant/GrantPage.java @@ -42,10 +42,7 @@ public class GrantPage extends PageObject { } public boolean checkBlankFields() { - if (driver.findElements(By.className("alert-danger")).size() > 0) { - return true; - } - return false; + return driver.findElements(By.className("alert-danger")).size() > 0; } public List getAttachedPapers() { @@ -109,4 +106,44 @@ public class GrantPage extends PageObject { public void deleteDeadline() { driver.findElements(By.className("btn-delete-deadline")).get(0).click(); } + + public List addAuthor() { + WebElement selectAuthors = driver.findElement(By.id("authors")); + Select select = new Select(selectAuthors); + List selectedOptions = select.getAllSelectedOptions(); + List allOptions = select.getOptions(); + int i = 0; + while (i < selectedOptions.size()) { + if (!allOptions.get(i).equals(selectedOptions.get(i))) { + select.selectByVisibleText(allOptions.get(i).getText()); + selectedOptions.add(allOptions.get(i)); + return selectedOptions; + } else { + i++; + } + } + if (selectedOptions.size() != allOptions.size()) { + select.selectByVisibleText(allOptions.get(i).getText()); + selectedOptions.add(allOptions.get(i)); + } + return selectedOptions; + } + + public void deleteAuthor() { + WebElement selectAuthors = driver.findElement(By.id("authors")); + Select select = new Select(selectAuthors); + List selectedOptions = select.getAllSelectedOptions(); + if (selectedOptions.size() != 0) { + select.deselectByVisibleText(selectedOptions.get(0).getText()); + } + } + + public void setDescription(String description) { + driver.findElement(By.id("comment")).clear(); + driver.findElement(By.id("comment")).sendKeys(description); + } + + public String getDescription() { + return driver.findElement(By.id("comment")).getText(); + } } diff --git a/src/test/java/grant/GrantsPage.java b/src/test/java/grant/GrantsPage.java index 68f50db..33c388d 100644 --- a/src/test/java/grant/GrantsPage.java +++ b/src/test/java/grant/GrantsPage.java @@ -13,12 +13,13 @@ public class GrantsPage extends PageObject { } public List getGrantsList() { - return driver.findElements(By.cssSelector("span.h6")); + return driver.findElements(By.className("grant-row")); } public boolean findGrantByTitle(String grantTitle) { return getGrantsList() .stream() + .map(el -> el.findElement(By.cssSelector("span.h6"))) .anyMatch(webElement -> webElement.getText().equals(grantTitle)); } @@ -35,4 +36,31 @@ public class GrantsPage extends PageObject { public void getFirstGrant() { driver.findElement(By.xpath("//*[@id=\"grants\"]/div/div[2]/div[1]/div[1]/div/a[1]")).click(); } + + public WebElement getFirstGrantWithoutClick() { + return driver.findElement(By.xpath("//*[@id=\"grants\"]/div/div[2]/div[1]/div[1]")); + } + + public String getGrantTitle(WebElement webElement) { + return webElement.findElement(By.cssSelector("span.h6")).getText(); + } + + public WebElement getGrantByTitle(String title) { + List list = getGrantsList(); + for (int i = 0; i < list.size(); i++) { + if (getGrantTitle(list.get(i)).equals(title)) { + return list.get(i); + } + } + return null; + } + + public Integer getAuthorsCount(WebElement webElement) { + String authors = webElement.findElement(By.className("text-muted")).getText(); + if (!authors.equals("")) { + String[] mas = authors.split(","); + return mas.length; + } + return 0; + } }