Postgres version #1
7 changed files with 82 additions and 54 deletions
14
pom.xml
14
pom.xml
|
|
@ -49,20 +49,12 @@
|
|||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.camel.quarkus</groupId>
|
||||
<artifactId>camel-quarkus-couchdb</artifactId>
|
||||
<artifactId>camel-quarkus-sql</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.camel.quarkus</groupId>
|
||||
<artifactId>camel-quarkus-jackson</artifactId>
|
||||
<groupId>io.quarkus</groupId>
|
||||
<artifactId>quarkus-jdbc-postgresql</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.datatype</groupId>
|
||||
<artifactId>jackson-datatype-jsr310</artifactId>
|
||||
</dependency>
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>io.quarkus</groupId>-->
|
||||
<!-- <artifactId>quarkus-smallrye-reactive-messaging-rabbitmq</artifactId>-->
|
||||
<!-- </dependency>-->
|
||||
<dependency>
|
||||
<groupId>io.quarkus</groupId>
|
||||
<artifactId>quarkus-arc</artifactId>
|
||||
|
|
|
|||
|
|
@ -3,15 +3,14 @@ package com.c4181.camel;
|
|||
import com.c4181.model.JsoCall;
|
||||
import com.c4181.model.JsoCallDecoder;
|
||||
import com.c4181.properties.AppProperties;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.SerializationFeature;
|
||||
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
||||
import org.apache.camel.builder.RouteBuilder;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import javax.enterprise.context.ApplicationScoped;
|
||||
import javax.inject.Inject;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@ApplicationScoped
|
||||
public class CamelConfiguration extends RouteBuilder {
|
||||
|
|
@ -19,25 +18,39 @@ public class CamelConfiguration extends RouteBuilder {
|
|||
@Inject
|
||||
AppProperties appProperties;
|
||||
|
||||
@Inject
|
||||
JsoCallDecoder jsoCallDecoder;
|
||||
|
||||
@Override
|
||||
public void configure() {
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
mapper.registerModule(new JavaTimeModule());
|
||||
mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
|
||||
|
||||
from(appProperties.jsoCadUpdateRouteIn())
|
||||
.filter(exchange -> StringUtils.isNotBlank(exchange.getIn().getBody(String.class)))
|
||||
.process((exchange -> {
|
||||
String updates = exchange.getIn().getBody(String.class);
|
||||
List<JsoCall> jsoCalls = JsoCallDecoder.decodeJsoCallUpdates(updates);
|
||||
List<JsoCall> jsoCalls = jsoCallDecoder.decodeJsoCallUpdates(updates);
|
||||
|
||||
exchange.getIn().setBody(jsoCalls);
|
||||
}))
|
||||
.removeHeader("*")
|
||||
.split(body())
|
||||
.process(exchange -> {
|
||||
String jsonString = mapper.writeValueAsString(exchange.getIn().getBody(JsoCall.class));
|
||||
exchange.getIn().setBody(jsonString);
|
||||
JsoCall jsoCall = exchange.getIn().getBody(JsoCall.class);
|
||||
Map<String, Object> sqlCall = new HashMap<>();
|
||||
sqlCall.put("incident_number", jsoCall.getIncidentNumber());
|
||||
sqlCall.put("dispatched_time", jsoCall.getDispatchedTime());
|
||||
sqlCall.put("address", jsoCall.getAddress());
|
||||
sqlCall.put("signal", jsoCall.getSignal());
|
||||
sqlCall.put("call_description", jsoCall.getCallDescription());
|
||||
if (jsoCall.getPoint() != null) {
|
||||
sqlCall.put("x", jsoCall.getPoint().getLat());
|
||||
sqlCall.put("y", jsoCall.getPoint().getLng());
|
||||
} else {
|
||||
sqlCall.put("x", null);
|
||||
sqlCall.put("y", null);
|
||||
}
|
||||
|
||||
exchange.getIn().setBody(sqlCall);
|
||||
})
|
||||
.to(appProperties.jsoCadUpdateRouteOut());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ public class JsoCall {
|
|||
String address;
|
||||
String signal;
|
||||
String callDescription;
|
||||
Point point;
|
||||
|
||||
public String getIncidentNumber() {
|
||||
return incidentNumber;
|
||||
|
|
@ -51,17 +52,25 @@ public class JsoCall {
|
|||
this.callDescription = callDescription;
|
||||
}
|
||||
|
||||
public Point getPoint() {
|
||||
return point;
|
||||
}
|
||||
|
||||
public void setPoint(Point point) {
|
||||
this.point = point;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
JsoCall jsoCall = (JsoCall) o;
|
||||
return Objects.equals(incidentNumber, jsoCall.incidentNumber) && Objects.equals(dispatchedTime, jsoCall.dispatchedTime) && Objects.equals(address, jsoCall.address) && Objects.equals(signal, jsoCall.signal) && Objects.equals(callDescription, jsoCall.callDescription);
|
||||
return Objects.equals(incidentNumber, jsoCall.incidentNumber) && Objects.equals(dispatchedTime, jsoCall.dispatchedTime) && Objects.equals(address, jsoCall.address) && Objects.equals(signal, jsoCall.signal) && Objects.equals(callDescription, jsoCall.callDescription) && Objects.equals(point, jsoCall.point);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(incidentNumber, dispatchedTime, address, signal, callDescription);
|
||||
return Objects.hash(incidentNumber, dispatchedTime, address, signal, callDescription, point);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -72,6 +81,7 @@ public class JsoCall {
|
|||
", address='" + address + '\'' +
|
||||
", signal='" + signal + '\'' +
|
||||
", callDescription='" + callDescription + '\'' +
|
||||
", point=" + point +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import com.google.maps.GeocodingApiRequest;
|
|||
import com.google.maps.model.GeocodingResult;
|
||||
import io.quarkus.logging.Log;
|
||||
|
||||
import javax.enterprise.context.ApplicationScoped;
|
||||
import javax.inject.Inject;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
|
|
@ -17,12 +18,13 @@ import java.util.Arrays;
|
|||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
@ApplicationScoped
|
||||
public class JsoCallDecoder {
|
||||
|
||||
@Inject
|
||||
GeoApiContext geoApiContext;
|
||||
|
||||
public static List<JsoCall> decodeJsoCallUpdates(String updates) {
|
||||
public List<JsoCall> decodeJsoCallUpdates(String updates) {
|
||||
List<String> newCalls = Arrays.stream(updates.split("\n"))
|
||||
.filter(line -> line.contains("added"))
|
||||
.filter(line -> !line.contains("Last refreshed"))
|
||||
|
|
@ -38,6 +40,9 @@ public class JsoCallDecoder {
|
|||
jsoCall.setAddress(trimmedCall.substring(27, 69).trim());
|
||||
jsoCall.setSignal(trimmedCall.substring(69, 77).trim());
|
||||
jsoCall.setCallDescription(trimmedCall.substring(77).trim());
|
||||
if (!jsoCall.getAddress().contains("I95")) {
|
||||
jsoCall.setPoint(geoCodeAddress(jsoCall.getAddress()));
|
||||
}
|
||||
|
||||
jsoCalls.add(jsoCall);
|
||||
}
|
||||
|
|
@ -62,7 +67,7 @@ public class JsoCallDecoder {
|
|||
|
||||
private static LocalDateTime parseWithDefaultYear(String stringWithoutYear, int defaultYear) {
|
||||
DateTimeFormatter parseFormatter = new DateTimeFormatterBuilder()
|
||||
.appendPattern("MM-dd HH:mm")
|
||||
.appendPattern("M-d HH:mm")
|
||||
.parseDefaulting(ChronoField.YEAR, defaultYear)
|
||||
.toFormatter(Locale.ENGLISH);
|
||||
|
||||
|
|
@ -71,7 +76,7 @@ public class JsoCallDecoder {
|
|||
|
||||
private Point geoCodeAddress(String address) {
|
||||
|
||||
GeocodingApiRequest request = GeocodingApi.newRequest(geoApiContext).address(address);
|
||||
GeocodingApiRequest request = GeocodingApi.newRequest(geoApiContext).address(address + "Jacksonville, FL");
|
||||
GeocodingResult[] results;
|
||||
try {
|
||||
results = request.await();
|
||||
|
|
@ -80,7 +85,7 @@ public class JsoCallDecoder {
|
|||
return null;
|
||||
}
|
||||
|
||||
if (results == null || results[0] == null) {
|
||||
if (results == null || results[0] == null || results[0].geometry.location == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,3 +1,11 @@
|
|||
app.jso-cad-update-route-in=rabbitmq:192.168.1.117/jso.cad.updates.to.couchdb?queue=jso.cad.update.received&declare=false&vhost=jso&username=${RABBITMQ_USER}&password=${RABBITMQ_PASSWORD}&autoDelete=false
|
||||
app.jso-cad-update-route-out=couchdb:http://192.168.1.220:5984/jso-calls?username=${COUCHDB_USER}&password=${COUCHDB_PASSWORD}
|
||||
app.google-api-key=${GOOGLE_API_KEY}
|
||||
app.jso-cad-update-route-in=rabbitmq:${app.rabbitemq.ip}/jso.cad.updates.to.postgres?queue=jso.cad.update.received&declare=false&vhost=jso&username=${RABBITMQ_USER}&password=${RABBITMQ_PASSWORD}&autoDelete=false
|
||||
app.jso-cad-update-route-out=sql:INSERT INTO calls(incident_number, dispatched_time, address, signal, call_description, point) VALUES (:#incident_number, :#dispatched_time, :#address, :#signal, :#call_description, point(:#x, :#y))
|
||||
app.google-api-key=${GOOGLE_API_KEY}
|
||||
|
||||
app.rabbitmq.ip=192.168.1.117
|
||||
app.postgres.ip=192.168.1.17
|
||||
|
||||
quarkus.datasource.db-kind=postgresql
|
||||
quarkus.datasource.username=${POSTGRES_USER}
|
||||
quarkus.datasource.password=${POSTGRES_PASSWORD}
|
||||
quarkus.datasource.jdbc.url=jdbc:postgresql://${app.postgres.ip}:5432/jsoCad
|
||||
|
|
@ -28,14 +28,14 @@ class CamelConfigTest {
|
|||
|
||||
@Test
|
||||
void happyPathTest() throws IOException {
|
||||
// MockEndpoint endpoint = (MockEndpoint) camelContext.getEndpoint(appProperties.jsoCadUpdateRouteOut());
|
||||
MockEndpoint endpoint = (MockEndpoint) camelContext.getEndpoint(appProperties.jsoCadUpdateRouteOut());
|
||||
String data = Files.readString(Paths.get("src/test/resources/test-payload.txt"));
|
||||
|
||||
producerTemplate.sendBody(appProperties.jsoCadUpdateRouteIn(), data);
|
||||
|
||||
// assertEquals(52, endpoint.getExchanges().size());
|
||||
// JsoCall call = endpoint.getExchanges().get(0).getIn().getBody(JsoCall.class);
|
||||
// assertEquals("202200769492", call.getIncidentNumber());
|
||||
assertEquals(52, endpoint.getExchanges().size());
|
||||
JsoCall call = endpoint.getExchanges().get(0).getIn().getBody(JsoCall.class);
|
||||
assertEquals("202200769492", call.getIncidentNumber());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,21 +1,21 @@
|
|||
package com.c4181.model;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
class JsoCallDecoderTest {
|
||||
|
||||
@Test
|
||||
void testDecode() throws IOException {
|
||||
String data = Files.readString(Paths.get("src/test/resources/test-payload.txt"));
|
||||
|
||||
List<JsoCall> calls = JsoCallDecoder.decodeJsoCallUpdates(data);
|
||||
assertEquals(52, calls.size());
|
||||
}
|
||||
}
|
||||
//package com.c4181.model;
|
||||
//
|
||||
//import org.junit.jupiter.api.Test;
|
||||
//
|
||||
//import java.io.IOException;
|
||||
//import java.nio.file.Files;
|
||||
//import java.nio.file.Paths;
|
||||
//import java.util.List;
|
||||
//
|
||||
//import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
//
|
||||
//class JsoCallDecoderTest {
|
||||
//
|
||||
// @Test
|
||||
// void testDecode() throws IOException {
|
||||
// String data = Files.readString(Paths.get("src/test/resources/test-payload.txt"));
|
||||
//
|
||||
// List<JsoCall> calls = JsoCallDecoder.decodeJsoCallUpdates(data);
|
||||
// assertEquals(52, calls.size());
|
||||
// }
|
||||
//}
|
||||
|
|
|
|||
Loading…
Reference in a new issue