show active grants

environments/staging/deployments/93
Anton Romanov 5 years ago
parent 9ba4476f80
commit 2012a58fc2

@ -1,12 +1,8 @@
package ru.ulstu.grant.page; package ru.ulstu.grant.page;
import com.gargoylesoftware.htmlunit.html.DomElement;
import com.gargoylesoftware.htmlunit.html.DomNode; 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.HtmlElement;
import com.gargoylesoftware.htmlunit.html.HtmlPage; import com.gargoylesoftware.htmlunit.html.HtmlPage;
import com.gargoylesoftware.htmlunit.html.HtmlTableDataCell;
import com.gargoylesoftware.htmlunit.html.HtmlTableRow; import com.gargoylesoftware.htmlunit.html.HtmlTableRow;
import java.text.ParseException; import java.text.ParseException;
@ -39,7 +35,8 @@ public class KiasPage {
} }
public String getGrantTitle(DomNode grant) { 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 { public Date parseDeadLineDate(DomNode grantElement) throws ParseException {
@ -49,10 +46,10 @@ public class KiasPage {
} }
private String getFirstDeadline(DomNode grantElement) { private String getFirstDeadline(DomNode grantElement) {
return ((DomNode)grantElement.getFirstByXPath("td[5]")).getTextContent(); return ((DomNode) grantElement.getFirstByXPath("td[5]")).getTextContent();
} }
public boolean isTrGrantLine(DomNode grantElement) { public boolean isTableRowGrantLine(DomNode grantElement) {
return !((HtmlTableRow)grantElement).getAttribute("class").contains("pagerSavedHeightSpacer"); return !((HtmlTableRow) grantElement).getAttribute("class").contains("pagerSavedHeightSpacer");
} }
} }

@ -27,7 +27,7 @@ public class GrantScheduler {
@Scheduled(cron = "0 0 8 * * MON", zone = "Europe/Samara") @Scheduled(cron = "0 0 8 * * MON", zone = "Europe/Samara")
public void checkDeadlineBeforeWeek() { public void checkDeadlineBeforeWeek() {
log.debug("GrantScheduler.checkDeadlineBeforeWeek started"); 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"); log.debug("GrantScheduler.checkDeadlineBeforeWeek finished");
} }

@ -326,7 +326,7 @@ public class GrantService extends BaseService {
return convert(findAllActive(), GrantDto::new); return convert(findAllActive(), GrantDto::new);
} }
private List<Grant> findAllActive() { public List<Grant> findAllActive() {
return grantRepository.findAllActive(); return grantRepository.findAllActive();
} }

@ -1,9 +1,7 @@
package ru.ulstu.grant.service; package ru.ulstu.grant.service;
import com.gargoylesoftware.htmlunit.WebClient; import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.html.DomElement;
import com.gargoylesoftware.htmlunit.html.DomNode; import com.gargoylesoftware.htmlunit.html.DomNode;
import com.gargoylesoftware.htmlunit.html.HtmlElement;
import com.gargoylesoftware.htmlunit.html.HtmlPage; import com.gargoylesoftware.htmlunit.html.HtmlPage;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import ru.ulstu.configuration.ApplicationProperties; import ru.ulstu.configuration.ApplicationProperties;
@ -58,7 +56,7 @@ public class KiasService {
private List<GrantDto> getGrantsFromPage(KiasPage kiasPage) throws ParseException { private List<GrantDto> getGrantsFromPage(KiasPage kiasPage) throws ParseException {
List<GrantDto> grants = new ArrayList<>(); List<GrantDto> grants = new ArrayList<>();
for (DomNode grantElement : kiasPage.getPageOfGrants()) { for (DomNode grantElement : kiasPage.getPageOfGrants()) {
if (kiasPage.isTrGrantLine(grantElement)) { if (kiasPage.isTableRowGrantLine(grantElement)) {
GrantDto grantDto = new GrantDto( GrantDto grantDto = new GrantDto(
kiasPage.getGrantTitle(grantElement), kiasPage.getGrantTitle(grantElement),
kiasPage.parseDeadLineDate(grantElement)); kiasPage.parseDeadLineDate(grantElement));

Loading…
Cancel
Save