added new edge case and updated error handling polices in camel route
This commit is contained in:
parent
8cfbf2756b
commit
e01e9a9484
4 changed files with 17 additions and 5 deletions
|
|
@ -3,6 +3,8 @@ package com.c4181.camel;
|
|||
import com.c4181.model.JsoCall;
|
||||
import com.c4181.model.JsoCallDecoder;
|
||||
import com.c4181.properties.AppProperties;
|
||||
import io.quarkus.logging.Log;
|
||||
import org.apache.camel.Exchange;
|
||||
import org.apache.camel.builder.RouteBuilder;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
|
|
@ -26,7 +28,8 @@ public class CamelConfiguration extends RouteBuilder {
|
|||
public void configure() {
|
||||
|
||||
errorHandler(deadLetterChannel(appProperties.deadLetterRoute())
|
||||
.log("Failed to process message. Sending to dead letter queue")
|
||||
.onExceptionOccurred(exchange ->
|
||||
Log.warnf("Failed to parse message in route %s. Sending to Dead Letter queue.", exchange.getProperty(Exchange.TO_ENDPOINT, String.class)))
|
||||
.useOriginalMessage());
|
||||
|
||||
from(appProperties.jsoCadUpdateRouteIn())
|
||||
|
|
@ -61,6 +64,7 @@ public class CamelConfiguration extends RouteBuilder {
|
|||
.to(appProperties.jsoCadUpdateRouteOut());
|
||||
|
||||
from("direct:processedCalls")
|
||||
.errorHandler(deadLetterChannel("log:dead?level=ERROR"))
|
||||
.filter(exchange -> exchange.getIn().getBody(JsoCall.class).getPoint() != null)
|
||||
.process(exchange -> {
|
||||
JsoCall jsoCall = exchange.getIn().getBody(JsoCall.class);
|
||||
|
|
|
|||
|
|
@ -34,13 +34,13 @@ public class JsoCallDecoder {
|
|||
.map(String::trim)
|
||||
.toList();
|
||||
|
||||
String pattern = "(\\d+)\\s+(\\d{1,2}-\\d{1,2} \\d{1,2}:\\d{1,2})\\s+(.+)\\s+( \\d+\\s?[\\w\\d]*)\\s+(\\D+)";
|
||||
String pattern = "(\\d+)\\s+(\\d{1,2}-\\d{1,2} \\d{1,2}:\\d{1,2})\\s+(.+)\\s+( \\d+\\s?[\\w\\d]*)\\s+(.+)";
|
||||
Pattern p = Pattern.compile(pattern);
|
||||
|
||||
List<JsoCall> jsoCalls = new ArrayList<>();
|
||||
for (String call : newCalls) {
|
||||
Matcher m = p.matcher(call);
|
||||
if (!m.matches() && m.groupCount() != 5) {
|
||||
if (!m.matches() || m.groupCount() != 5) {
|
||||
Log.warnf("Failed to parse call\n%s", call);
|
||||
continue;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ class JsoCallDecoderTest {
|
|||
|
||||
JsoCallDecoder decoder = new JsoCallDecoder();
|
||||
List<JsoCall> calls = decoder.decodeJsoCallUpdates(data);
|
||||
assertEquals(5, calls.size());
|
||||
assertEquals(6, calls.size());
|
||||
|
||||
JsoCall firstCall = calls.get(0);
|
||||
assertEquals("202200769492", firstCall.getIncidentNumber());
|
||||
|
|
@ -63,5 +63,12 @@ class JsoCallDecoderTest {
|
|||
assertEquals("BULLS BAY HWY / BEAVER ST W", fifthCall.getAddress());
|
||||
assertEquals("0 13", fifthCall.getSignal());
|
||||
assertEquals("ARMED SUSPICIOUS PERSON", fifthCall.getCallDescription());
|
||||
|
||||
JsoCall sixthCall = calls.get(5);
|
||||
assertEquals("202300004560", sixthCall.getIncidentNumber());
|
||||
assertNotNull(sixthCall.getDispatchedTime());
|
||||
assertEquals("3700 TOLEDO RD", sixthCall.getAddress());
|
||||
assertEquals("37", sixthCall.getSignal());
|
||||
assertEquals("UNVERIFIED 911 CALL", sixthCall.getCallDescription());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,3 +20,4 @@ JSO CAD
|
|||
(added ) 202200769409 12-31 11:18 1000 ST CLAIR ST 21CT BURGLARY CONVEYANCE TELESERVE
|
||||
(added ) 202300004101 1-3 08:29 12000 ATLANTIC BLVD 1050 TRAFFIC STOP
|
||||
(added ) 202300004011 1-3 07:37 BULLS BAY HWY / BEAVER ST W 0 13 ARMED SUSPICIOUS PERSON
|
||||
(added ) 202300004560 1-3 11:44 3700 TOLEDO RD 37 UNVERIFIED 911 CALL
|
||||
Loading…
Reference in a new issue