From 2012a58fc21419821199a172fac177fdb1c0cd21 Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Mon, 10 Jun 2019 12:15:01 +0400 Subject: [PATCH] show active grants --- src/main/java/ru/ulstu/grant/page/KiasPage.java | 13 +++++-------- .../java/ru/ulstu/grant/service/GrantScheduler.java | 2 +- .../java/ru/ulstu/grant/service/GrantService.java | 2 +- .../java/ru/ulstu/grant/service/KiasService.java | 4 +--- 4 files changed, 8 insertions(+), 13 deletions(-) diff --git a/src/main/java/ru/ulstu/grant/page/KiasPage.java b/src/main/java/ru/ulstu/grant/page/KiasPage.java index 0a83b43..49d54a0 100644 --- a/src/main/java/ru/ulstu/grant/page/KiasPage.java +++ b/src/main/java/ru/ulstu/grant/page/KiasPage.java @@ -1,12 +1,8 @@ package ru.ulstu.grant.page; -import com.gargoylesoftware.htmlunit.html.DomElement; import com.gargoylesoftware.htmlunit.html.DomNode; -import com.gargoylesoftware.htmlunit.html.DomNodeList; -import com.gargoylesoftware.htmlunit.html.HtmlAnchor; import com.gargoylesoftware.htmlunit.html.HtmlElement; import com.gargoylesoftware.htmlunit.html.HtmlPage; -import com.gargoylesoftware.htmlunit.html.HtmlTableDataCell; import com.gargoylesoftware.htmlunit.html.HtmlTableRow; import java.text.ParseException; @@ -39,7 +35,8 @@ public class KiasPage { } public String getGrantTitle(DomNode grant) { - return ((DomNode)grant.getFirstByXPath("td[@class='tertiary']/a")).getTextContent(); + return ((DomNode) grant.getFirstByXPath("td[2]")).getTextContent() + " " + + ((DomNode) grant.getFirstByXPath("td[@class='tertiary']/a")).getTextContent(); } public Date parseDeadLineDate(DomNode grantElement) throws ParseException { @@ -49,10 +46,10 @@ public class KiasPage { } private String getFirstDeadline(DomNode grantElement) { - return ((DomNode)grantElement.getFirstByXPath("td[5]")).getTextContent(); + return ((DomNode) grantElement.getFirstByXPath("td[5]")).getTextContent(); } - public boolean isTrGrantLine(DomNode grantElement) { - return !((HtmlTableRow)grantElement).getAttribute("class").contains("pagerSavedHeightSpacer"); + public boolean isTableRowGrantLine(DomNode grantElement) { + return !((HtmlTableRow) grantElement).getAttribute("class").contains("pagerSavedHeightSpacer"); } } diff --git a/src/main/java/ru/ulstu/grant/service/GrantScheduler.java b/src/main/java/ru/ulstu/grant/service/GrantScheduler.java index a2950a6..d026911 100644 --- a/src/main/java/ru/ulstu/grant/service/GrantScheduler.java +++ b/src/main/java/ru/ulstu/grant/service/GrantScheduler.java @@ -27,7 +27,7 @@ public class GrantScheduler { @Scheduled(cron = "0 0 8 * * MON", zone = "Europe/Samara") public void checkDeadlineBeforeWeek() { log.debug("GrantScheduler.checkDeadlineBeforeWeek started"); - grantNotificationService.sendDeadlineNotifications(grantService.findAll(), IS_DEADLINE_NOTIFICATION_BEFORE_WEEK); + grantNotificationService.sendDeadlineNotifications(grantService.findAllActive(), IS_DEADLINE_NOTIFICATION_BEFORE_WEEK); log.debug("GrantScheduler.checkDeadlineBeforeWeek finished"); } diff --git a/src/main/java/ru/ulstu/grant/service/GrantService.java b/src/main/java/ru/ulstu/grant/service/GrantService.java index 99387c7..ea0a454 100644 --- a/src/main/java/ru/ulstu/grant/service/GrantService.java +++ b/src/main/java/ru/ulstu/grant/service/GrantService.java @@ -326,7 +326,7 @@ public class GrantService extends BaseService { return convert(findAllActive(), GrantDto::new); } - private List findAllActive() { + public List findAllActive() { return grantRepository.findAllActive(); } diff --git a/src/main/java/ru/ulstu/grant/service/KiasService.java b/src/main/java/ru/ulstu/grant/service/KiasService.java index 56474fa..b5ddd36 100644 --- a/src/main/java/ru/ulstu/grant/service/KiasService.java +++ b/src/main/java/ru/ulstu/grant/service/KiasService.java @@ -1,9 +1,7 @@ package ru.ulstu.grant.service; import com.gargoylesoftware.htmlunit.WebClient; -import com.gargoylesoftware.htmlunit.html.DomElement; import com.gargoylesoftware.htmlunit.html.DomNode; -import com.gargoylesoftware.htmlunit.html.HtmlElement; import com.gargoylesoftware.htmlunit.html.HtmlPage; import org.springframework.stereotype.Service; import ru.ulstu.configuration.ApplicationProperties; @@ -58,7 +56,7 @@ public class KiasService { private List getGrantsFromPage(KiasPage kiasPage) throws ParseException { List grants = new ArrayList<>(); for (DomNode grantElement : kiasPage.getPageOfGrants()) { - if (kiasPage.isTrGrantLine(grantElement)) { + if (kiasPage.isTableRowGrantLine(grantElement)) { GrantDto grantDto = new GrantDto( kiasPage.getGrantTitle(grantElement), kiasPage.parseDeadLineDate(grantElement));