Skip to content
This repository was archived by the owner on May 5, 2021. It is now read-only.

Commit b047ad2

Browse files
lgallgal
authored andcommitted
SORMAS-Foundation#2087 update geocoding to work with any custom external service
1 parent 1000d53 commit b047ad2

10 files changed

Lines changed: 154 additions & 354 deletions

File tree

SERVER_CUSTOMIZATION.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ The following properties are currently configurable:
3131
* **Rscript executable** *(rscript.executable)*: The location of the Rscript executable. If you've installed Rscript on your server and specify the path here (the default should work for Linux systems as long as you've used the default install path), network diagrams for transmission chains will be shown in the web app.
3232
* **Symptom journal interface**: Properties used to connect to an external symptom journal service. *interface.symptomjournal.url* is the URL to the website that SORMAS should connect to; *interface.symptomjournal.authurl* is the URL used to authenticate SORMAS at the external service; *interface.symptomjournal.clientid* and *interface.symptomjournal.secret* are the credentials used for the authentication process.
3333
* **Custom branding**: Properties used to apply a custom branding to SORMAS that overrides its name and default logo. Using these properties also alters the sidebar and adds another customizable area to it. If you want to use this feature, set *custombranding* to true. *custombranding.name* is the name that you want to use, *custombranding.logo.path* is the path to the logo that should be used.
34+
* **Geocoding** Properties used to integrate an external geocoding service for obtaining the geo coordinates of addresses.
35+
*geocodingServiceUrlTemplate* is the url for searching for address details, *${street}*, *${houseNumber}*, *${postalCode}*, and *${city}* placeholders will be replaced with the actual address fields when searching;
36+
*geocodingLongitudeJsonPath* and *geocodingLatitudeJsonPath* are used to obtain the longitude and latitude of the address in the result of the geocoding service request
3437

3538
## Importing Infrastructure Data
3639
When you start a SORMAS server for the first time, some default infrastructure data is generated to ensure that the server is usable and the default users can be created. It is recommended (and, unless you're working on a demo server, necessary) to archive this default data and import the official infrastructure data of the country or part of the country that you intend to use SORMAS in instead.

sormas-api/src/main/java/de/symeda/sormas/api/ConfigFacade.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,11 @@ public interface ConfigFacade {
9090

9191
int getMapZoom();
9292

93-
String getGeocodingOsgtsEndpoint();
93+
String getGeocodingServiceUrlTemplate();
94+
95+
String getGeocodingLongitudeJsonPath();
96+
97+
String getGeocodingLatitudeJsonPath();
9498

9599
SymptomJournalConfig getSymptomJournalConfig();
96100

sormas-backend/pom.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,13 @@
166166
<artifactId>microprofile-config-api</artifactId>
167167
</dependency>
168168

169+
<!-- JsonPath -->
170+
<dependency>
171+
<groupId>com.jayway.jsonpath</groupId>
172+
<artifactId>json-path</artifactId>
173+
<version>2.4.0</version>
174+
</dependency>
175+
169176
</dependencies>
170177

171178
<build>

sormas-backend/src/main/java/de/symeda/sormas/backend/common/ConfigFacadeEjb.java

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,9 @@ public class ConfigFacadeEjb implements ConfigFacade {
105105
public static final String DAYS_AFTER_CASE_GETS_ARCHIVED = "daysAfterCaseGetsArchived";
106106
private static final String DAYS_AFTER_EVENT_GETS_ARCHIVED = "daysAfterEventGetsArchived";
107107

108-
private static final String GEOCODING_OSGTS_ENDPOINT = "geocodingOsgtsEndpoint";
108+
private static final String GEOCODING_SERVICE_URL_TEMPLATE = "geocodingServiceUrlTemplate";
109+
private static final String GEOCODING_LONGITUDE_JSON_PATH = "geocodingLongitudeJsonPath";
110+
private static final String GEOCODING_LATITUDE_JSON_PATH = "geocodingLatitudeJsonPath";
109111

110112
private static final String SORMAS2SORMAS_FILES_PATH = "sormas2sormas.path";
111113
private static final String SORMAS2SORMAS_SERVER_ACCESS_DATA_FILE_NAME = "sormas2sormas.serverAccessDataFileName";
@@ -362,8 +364,18 @@ public int getDaysAfterEventGetsArchived() {
362364
}
363365

364366
@Override
365-
public String getGeocodingOsgtsEndpoint() {
366-
return getProperty(GEOCODING_OSGTS_ENDPOINT, null);
367+
public String getGeocodingServiceUrlTemplate() {
368+
return getProperty(GEOCODING_SERVICE_URL_TEMPLATE, null);
369+
}
370+
371+
@Override
372+
public String getGeocodingLongitudeJsonPath() {
373+
return getProperty(GEOCODING_LONGITUDE_JSON_PATH, null);
374+
}
375+
376+
@Override
377+
public String getGeocodingLatitudeJsonPath() {
378+
return getProperty(GEOCODING_LATITUDE_JSON_PATH, null);
367379
}
368380

369381
@Override

sormas-backend/src/main/java/de/symeda/sormas/backend/geocoding/GeocodingFacadeEjb.java

Lines changed: 3 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,6 @@
1717
*******************************************************************************/
1818
package de.symeda.sormas.backend.geocoding;
1919

20-
import java.util.Arrays;
21-
import java.util.regex.Pattern;
22-
import java.util.stream.Collectors;
23-
import java.util.stream.Stream;
24-
2520
import javax.ejb.EJB;
2621
import javax.ejb.Stateless;
2722

@@ -33,36 +28,6 @@
3328
@Stateless(name = "GeocodingFacade")
3429
public class GeocodingFacadeEjb implements GeocodingFacade {
3530

36-
/**
37-
* @see https://www.bkg.bund.de/SharedDocs/Produktinformationen/BKG/DE/P-Download/Doku-Geokodierungsdienst.pdf?__blob=publicationFile&v=3
38-
* 4.3.1.10 Sonderzeichen
39-
*/
40-
//@formatter:off
41-
private static final Pattern TO_BE_ESCAPED = Pattern
42-
.compile(
43-
Stream
44-
.of(
45-
"&&",
46-
"||",
47-
"+",
48-
"-",
49-
"!",
50-
"(",
51-
")",
52-
"{",
53-
"}",
54-
"[",
55-
"]",
56-
"^",
57-
"\"",
58-
"~",
59-
"*",
60-
"?",
61-
":")
62-
.map(Pattern::quote)
63-
.collect(Collectors.joining("|")));
64-
//@formatter:on
65-
6631
@EJB
6732
private GeocodingService geocodingService;
6833

@@ -74,49 +39,10 @@ public boolean isEnabled() {
7439
@Override
7540
public GeoLatLon getLatLon(String street, String houseNumber, String postalCode, String city) {
7641

77-
if (StringUtils.isBlank(street)) {
78-
return null;
42+
if (StringUtils.isNotBlank(street) && (StringUtils.isNotBlank(city) || StringUtils.isNotBlank(postalCode))) {
43+
return geocodingService.getLatLon(new LocationQuery(houseNumber, street, postalCode, city));
7944
}
8045

81-
String textValue = join(", ", join(" ", street, houseNumber.replaceAll("\\s", " ")), join(" ", postalCode, city));
82-
83-
String query = textValue;
84-
// Stream.of(
85-
// property("text", textValue),
86-
// property("ort", city),
87-
// property("plz", postalCode),
88-
// property("strasse", address)
89-
// )
90-
// .filter(Objects::nonNull)
91-
// .collect(Collectors.joining(" AND "));
92-
93-
if (StringUtils.isBlank(query)) {
94-
return null;
95-
}
96-
97-
return geocodingService.getLatLon(query);
98-
}
99-
100-
private String join(String delimiter, String... values) {
101-
102-
String result = Arrays.stream(values).filter(StringUtils::isNotBlank).collect(Collectors.joining(delimiter));
103-
if (StringUtils.isBlank(result)) {
104-
return null;
105-
} else {
106-
return result;
107-
}
108-
}
109-
110-
private static String property(String key, String value) {
111-
112-
if (StringUtils.isBlank(value)) {
113-
return "";
114-
}
115-
116-
return key + ":\"" + escape(value.trim()) + "\" ";
117-
}
118-
119-
static String escape(String raw) {
120-
return TO_BE_ESCAPED.matcher(raw.replace("\\", "\\\\")).replaceAll("\\\\$0");
46+
return null;
12147
}
12248
}

0 commit comments

Comments
 (0)