develop
bvn13 2020-05-04 17:57:38 +03:00
parent 281695d604
commit 95d2f6c9b0
4 changed files with 56 additions and 10 deletions

View File

@ -0,0 +1,15 @@
package com.bvn13.covid19.scheduler.updater;
import lombok.Getter;
public class UpdaterException extends RuntimeException {
@Getter
private String body;
public UpdaterException(String message, String body) {
super(message);
this.body = body;
}
}

View File

@ -48,13 +48,13 @@ public class MailConfig {
StringUtils.isBlank(recipient) ||
StringUtils.isBlank(subject) ||
port <= 0 || port > 65536) {
throw new IllegalArgumentException("Mail endpoint has no arguments: " + constructEndpoint());
throw new IllegalArgumentException("Mail endpoint has no arguments: " + exceptionsEndpoint());
}
log.info("MAIL ENDPOINT: " + constructEndpoint());
log.info("MAIL ENDPOINT: " + exceptionsEndpoint());
}
public String constructEndpoint() {
public String exceptionsEndpoint() {
return "smtps://" + host + ":" + port +
"?username=" + username +
"&password=" + password +
@ -64,4 +64,14 @@ public class MailConfig {
"&debugMode=" + (debugMode ? "true" : "false");
}
public String reportEndpoint() {
return "smtps://" + host + ":" + port +
"?username=" + username +
"&password=" + password +
"&from=" + sender +
"&to=" + recipient +
"&subject=Test COVID19" +
"&debugMode=true";
}
}

View File

@ -16,6 +16,7 @@ limitations under the License.
package com.bvn13.covid19.scheduler.updater.stopcoronovirusrf;
import com.bvn13.covid19.scheduler.updater.UpdaterException;
import com.bvn13.covid19.scheduler.updater.stopcoronovirusrf.model.RowData;
import org.apache.camel.Exchange;
import org.apache.camel.Handler;
@ -57,7 +58,7 @@ public class StopcoronovirusRfSeleniumDataRetriever implements StopcoronovirusRf
List<WebElement> tableData = driver.findElements(By.cssSelector(".d-map__list > table > tbody > tr"));
if (tableData.size() <= 0) {
throw new IllegalStateException("Data not found!");
throw new UpdaterException("Data not found!", driver.getPageSource());
}
WebElement lastRow = driver.findElement(By.cssSelector(".d-map__list > table > tbody > tr:last-child"));
@ -65,7 +66,6 @@ public class StopcoronovirusRfSeleniumDataRetriever implements StopcoronovirusRf
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("window.scrollBy(0,10000)");
js.executeScript("arguments[0].scrollIntoView()",lastRow);
// js.executeScript("$(\".d-map__list > table > tbody\").animate({ scrollTop: \"10000px\" });");
List<RowData> rows = new ArrayList<>(tableData.size());
@ -77,6 +77,11 @@ public class StopcoronovirusRfSeleniumDataRetriever implements StopcoronovirusRf
.died(row.findElement(By.cssSelector("td.col-died")).getAttribute("innerText"))
.build();
Assert.isTrue(StringUtils.isNotBlank(rowData.getRegion()), "Broken data found after " + rows.size() + " rows");
rows.add(rowData);
}
if (rows.size() == 0) {
throw new UpdaterException("No data found!", driver.findElement(By.cssSelector(".d-map__list > table > tbody")).getAttribute("outerHTML"));
}
exchange.getIn().setHeader(StopcoronovirusRfUpdater.HEADER_DATE_OF_DATA, driver.findElement(By.cssSelector(".cv-section__title small")).getText());

View File

@ -16,13 +16,11 @@ limitations under the License.
package com.bvn13.covid19.scheduler.updater.stopcoronovirusrf;
import com.bvn13.covid19.scheduler.updater.UpdaterException;
import com.bvn13.covid19.scheduler.updater.stopcoronovirusrf.model.RowData;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.camel.Body;
import org.apache.camel.Handler;
import org.apache.camel.Header;
import org.apache.camel.LoggingLevel;
import org.apache.camel.*;
import org.apache.camel.builder.RouteBuilder;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
@ -54,7 +52,14 @@ public class StopcoronovirusRfUpdater extends RouteBuilder {
public void configure() throws Exception {
onException(RuntimeException.class)
.to(mailConfig.constructEndpoint());
.to(mailConfig.exceptionsEndpoint());
onException(UpdaterException.class)
.process((exchange) -> {
String body = exchange.getIn().getBody(UpdaterException.class).getBody();
exchange.getIn().setBody(body);
})
.to(mailConfig.exceptionsEndpoint());
from("timer:stopcoronovirusrf?delay=1000&period="+stopcoronovirusrfTimerMillis)
.log(LoggingLevel.DEBUG, log, "Start retrieving data from stopcoronovirus.rf")
@ -63,6 +68,12 @@ public class StopcoronovirusRfUpdater extends RouteBuilder {
.log(LoggingLevel.DEBUG, log, "Processed data count: ${body.size}")
;
from("timer:test?delay=1000&period=0")
.log(LoggingLevel.DEBUG, log, "Start sending test email")
.process(this::constructTestEmail)
.to(mailConfig.reportEndpoint())
.log(LoggingLevel.DEBUG, log, "End sending test email");
}
@Handler
@ -70,4 +81,9 @@ public class StopcoronovirusRfUpdater extends RouteBuilder {
service.saveRawData(dataDate, rawData);
}
@Handler
public void constructTestEmail(Exchange exchange) {
exchange.getIn().setBody("TEST MAIL");
}
}