Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added parsing of county #51

Merged
merged 6 commits into from
Jul 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions converter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ nominatim: true
nominatimEmail:

openCageDataURL: https://api.opencagedata.com/geocode/v1/json
openCageDataKey:
openCageData: false
openCageDataKey: ${OCD_KEY}
openCageData: true

gisgraphyGeocodingURL: https://premium2.gisgraphy.com/geocoding/
gisgraphyReverseGeocodingURL: https://premium2.gisgraphy.com/reversegeocoding/
gisgraphySearchURL: https://premium2.gisgraphy.com/fulltext/
gisgraphyAPIKey:
gisgraphyGeocodingURL: ${GIS_GEO_URL}
gisgraphyReverseGeocodingURL: ${GIS_REV_GEO_URL}
gisgraphySearchURL: ${GIS_SEARCH_URL}
gisgraphyAPIKey: ${GIS_KEY}

# e.g. to restrict for local access
# ipWhiteList:"localhost,127.0.0.1"
Expand Down
12 changes: 10 additions & 2 deletions src/main/java/com/graphhopper/converter/ConverterApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import io.dropwizard.Application;
import io.dropwizard.client.JerseyClientBuilder;
import io.dropwizard.client.JerseyClientConfiguration;
import io.dropwizard.configuration.EnvironmentVariableSubstitutor;
import io.dropwizard.configuration.SubstitutingSourceProvider;
import io.dropwizard.setup.Bootstrap;
import io.dropwizard.setup.Environment;
import io.dropwizard.util.Duration;
Expand All @@ -34,7 +36,13 @@ public String getName() {

@Override
public void initialize(Bootstrap<ConverterConfiguration> bootstrap) {
// nothing to do yet
// Enable variable substitution with environment variables
bootstrap.setConfigurationSourceProvider(
new SubstitutingSourceProvider(bootstrap.getConfigurationSourceProvider(),
new EnvironmentVariableSubstitutor(false)
)
);

}

@Override
Expand Down Expand Up @@ -65,7 +73,7 @@ public void run(ConverterConfiguration converterConfiguration, Environment envir

if (converterConfiguration.isGisgraphy()) {
final ConverterResourceGisgraphy resource = new ConverterResourceGisgraphy(
converterConfiguration.getGisgraphyGeocodingURL(), converterConfiguration.getGisgraphyReverseGeocodingURL(),converterConfiguration.getGisgraphySearchURL(),converterConfiguration.getGisgraphyAPIKey(), client);
converterConfiguration.getGisgraphyGeocodingURL(), converterConfiguration.getGisgraphyReverseGeocodingURL(), converterConfiguration.getGisgraphySearchURL(), converterConfiguration.getGisgraphyAPIKey(), client);
environment.jersey().register(resource);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ public abstract class AbstractAddress {
@JsonProperty
public String state;
@JsonProperty
public String county;
@JsonProperty
public String town;
@JsonProperty
public String village;
Expand Down
16 changes: 14 additions & 2 deletions src/main/java/com/graphhopper/converter/api/GHEntry.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,21 @@ public class GHEntry {
private String country;
private String city;
private String state;
private String county;
private String street;
private String houseNumber;
private String postcode;
private String osmValue;

public GHEntry(Long osmId, String type, double lat, double lng, String name, String osmValue, String country, String city, String state, String street, String houseNumber, String postcode, Extent extent) {
public GHEntry(Long osmId, String type, double lat, double lng, String name, String osmValue, String country, String city, String state, String county, String street, String houseNumber, String postcode, Extent extent) {
this.osmId = osmId;
this.osmType = type;
this.point = new Point(lat, lng);
this.name = name;
this.country = country;
this.city = city;
this.state = state;
this.county = county;
this.street = street;
this.houseNumber = houseNumber;
this.postcode = postcode;
Expand All @@ -43,7 +45,7 @@ public GHEntry(Long osmId, String type, double lat, double lng, String name, Str
}

public GHEntry(Long osmId, String type, double lat, double lng, String name, String osmValue, AbstractAddress address, Extent extent) {
this(osmId, type, lat, lng, name, osmValue, address.country, address.getGHCity(), address.state, address.getStreetName(), address.houseNumber, address.postcode, extent);
this(osmId, type, lat, lng, name, osmValue, address.country, address.getGHCity(), address.state, address.county, address.getStreetName(), address.houseNumber, address.postcode, extent);
}

public GHEntry(){}
Expand Down Expand Up @@ -78,6 +80,16 @@ public String getState() {
return state;
}

@JsonProperty
public void setCounty(String county) {
this.county = county;
}

@JsonProperty
public String getCounty() {
return county;
}

@JsonProperty
public String getCity() {
return city;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class GisgraphyAddressEntry {
private long sourceId;

private String countryCode;

private String country;

private String city;
Expand Down Expand Up @@ -146,8 +146,8 @@ public String getDisplayName() {
public String getCountry() {
return country;
}
public void setCountry(String country){

public void setCountry(String country) {
this.country = country;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,6 @@ public OCDComponents() {
public String type;
@JsonProperty("country_code")
public String countryCode;
@JsonProperty("county")
public String county;
}

public OpenCageDataEntry() {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/graphhopper/converter/core/Converter.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public static GHEntry convertFromGisgraphyAddress(GisgraphyAddressEntry gisgraph
GHEntry rsp = new GHEntry(null, null, gisgraphyEntry.getLat(),
gisgraphyEntry.getLng(), gisgraphyEntry.getDisplayName(), null,
gisgraphyEntry.getCountry(), gisgraphyEntry.getCity(),
gisgraphyEntry.getState(), gisgraphyEntry.getStreetName(),
gisgraphyEntry.getState(), null, gisgraphyEntry.getStreetName(),
gisgraphyEntry.getHouseNumber(), gisgraphyEntry.getZipCode(), null);
return rsp;
}
Expand All @@ -25,7 +25,7 @@ public static GHEntry convertFromGisgraphySearch(GisgraphySearchEntry gisgraphyE
GHEntry rsp = new GHEntry(null, null, gisgraphyEntry.getLat(),
gisgraphyEntry.getLng(), gisgraphyEntry.getLabel(), null,
gisgraphyEntry.getCountry(), gisgraphyEntry.getIsIn(),
gisgraphyEntry.getAdm1Name(), gisgraphyEntry.getName(),
gisgraphyEntry.getAdm1Name(), null, gisgraphyEntry.getName(),
gisgraphyEntry.getHouseNumber(), gisgraphyEntry.getZipCode(), null);
return rsp;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,10 @@ public Response handle(@QueryParam("q") @DefaultValue("") String query,
WebTarget target = jerseyClient.
target(url).
queryParam("q", reverse ? point : query).
queryParam("key", key).
queryParam("limit", limit);

target = target.queryParam("key", key);

if (!find_osm_id) {
target = target.queryParam("no_annotations", "1");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,113 +1,112 @@
package com.graphhopper.converter.resource;

import static junit.framework.TestCase.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
import com.graphhopper.converter.ConverterApplication;
import com.graphhopper.converter.ConverterConfiguration;
import com.graphhopper.converter.api.GHResponse;
import io.dropwizard.client.JerseyClientBuilder;
import io.dropwizard.testing.ResourceHelpers;
import io.dropwizard.testing.junit.DropwizardAppRule;

import javax.ws.rs.client.Client;
import javax.ws.rs.core.Response;

import org.glassfish.jersey.client.ClientProperties;
import org.junit.ClassRule;
import org.junit.Test;

import com.graphhopper.converter.ConverterApplication;
import com.graphhopper.converter.ConverterConfiguration;
import com.graphhopper.converter.api.GHResponse;
import javax.ws.rs.client.Client;
import javax.ws.rs.core.Response;

import static junit.framework.TestCase.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;

/**
* @author Robin Boldt
*/
public class ConverterResourceGisgraphyTest {
@ClassRule
public static final DropwizardAppRule<ConverterConfiguration> RULE =
new DropwizardAppRule<>(ConverterApplication.class, ResourceHelpers.resourceFilePath("converter.yml"));

@Test
public void testHandleForward() {
Client client = new JerseyClientBuilder(RULE.getEnvironment()).build("test forward client");

client.property(ClientProperties.CONNECT_TIMEOUT, 100000);
client.property(ClientProperties.READ_TIMEOUT, 100000);

Response response = client.target(
String.format("http://localhost:%d/gisgraphy?q=berlin", RULE.getLocalPort()))
.request()
.get();

assertThat(response.getStatus()).isEqualTo(200);
GHResponse entry = response.readEntity(GHResponse.class);
assertTrue(entry.getHits().size()>0);

//now try with an Address
response = client.target(
String.format("http://localhost:%d/gisgraphy?q=103+avenue+des+champs+elysees,paris", RULE.getLocalPort()))
.request()
.get();

assertThat(response.getStatus()).isEqualTo(200);
entry = response.readEntity(GHResponse.class);
assertTrue(entry.getHits().size()>0);
}

@Test
public void testHandleReverse() {
Client client = new JerseyClientBuilder(RULE.getEnvironment()).build("test reverse client");

client.property(ClientProperties.CONNECT_TIMEOUT, 100000);
client.property(ClientProperties.READ_TIMEOUT, 100000);

Response response = client.target(
String.format("http://localhost:%d/gisgraphy/?point=52.5487429714954,-1.81602098644987&reverse=true", RULE.getLocalPort()))
.request()
.get();

assertThat(response.getStatus()).isEqualTo(200);
GHResponse entry = response.readEntity(GHResponse.class);
assertTrue(entry.getHits().size()>0);

}

@Test
public void testHandleAutocomplete() {
Client client = new JerseyClientBuilder(RULE.getEnvironment()).build("test autocomplete client");

client.property(ClientProperties.CONNECT_TIMEOUT, 100000);
client.property(ClientProperties.READ_TIMEOUT, 100000);

Response response = client.target(
String.format("http://localhost:%d/gisgraphy?q=pari&autocomplete=true", RULE.getLocalPort()))
.request()
.get();

assertThat(response.getStatus()).isEqualTo(200);
GHResponse entry = response.readEntity(GHResponse.class);
assertTrue(entry.getHits().size()>0);

}

@Test
public void testHandleAutocompleteWithReverseShouldThrows() {
Client client = new JerseyClientBuilder(RULE.getEnvironment()).build("test autocomplete-reverse client");

client.property(ClientProperties.CONNECT_TIMEOUT, 100000);
client.property(ClientProperties.READ_TIMEOUT, 100000);

Response response = null;
try {
response = client.target(
String.format("http://localhost:%d/gisgraphy?q=pari&point=52.5487429714954,-1.81602098644987&autocomplete=true&reverse=true", RULE.getLocalPort()))
.request()
.get();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

assertThat(response.getStatus()).isEqualTo(400);

}
@ClassRule
public static final DropwizardAppRule<ConverterConfiguration> RULE =
new DropwizardAppRule<>(ConverterApplication.class, ResourceHelpers.resourceFilePath("converter.yml"));

@Test
public void testHandleForward() {
Client client = new JerseyClientBuilder(RULE.getEnvironment()).build("test forward client");

client.property(ClientProperties.CONNECT_TIMEOUT, 100000);
client.property(ClientProperties.READ_TIMEOUT, 100000);

Response response = client.target(
String.format("http://localhost:%d/gisgraphy?q=berlin", RULE.getLocalPort()))
.request()
.get();

assertThat(response.getStatus()).isEqualTo(200);
GHResponse entry = response.readEntity(GHResponse.class);
assertTrue(entry.getHits().size() > 0);

//now try with an Address
response = client.target(
String.format("http://localhost:%d/gisgraphy?q=103+avenue+des+champs+elysees,paris", RULE.getLocalPort()))
.request()
.get();

assertThat(response.getStatus()).isEqualTo(200);
entry = response.readEntity(GHResponse.class);
assertTrue(entry.getHits().size() > 0);
}

@Test
public void testHandleReverse() {
Client client = new JerseyClientBuilder(RULE.getEnvironment()).build("test reverse client");

client.property(ClientProperties.CONNECT_TIMEOUT, 100000);
client.property(ClientProperties.READ_TIMEOUT, 100000);

Response response = client.target(
String.format("http://localhost:%d/gisgraphy/?point=52.5487429714954,-1.81602098644987&reverse=true", RULE.getLocalPort()))
.request()
.get();

assertThat(response.getStatus()).isEqualTo(200);
GHResponse entry = response.readEntity(GHResponse.class);
assertTrue(entry.getHits().size() > 0);

}

@Test
public void testHandleAutocomplete() {
Client client = new JerseyClientBuilder(RULE.getEnvironment()).build("test autocomplete client");

client.property(ClientProperties.CONNECT_TIMEOUT, 100000);
client.property(ClientProperties.READ_TIMEOUT, 100000);

Response response = client.target(
String.format("http://localhost:%d/gisgraphy?q=pari&autocomplete=true", RULE.getLocalPort()))
.request()
.get();

assertThat(response.getStatus()).isEqualTo(200);
GHResponse entry = response.readEntity(GHResponse.class);
assertTrue(entry.getHits().size() > 0);

}

@Test
public void testHandleAutocompleteWithReverseShouldThrows() {
Client client = new JerseyClientBuilder(RULE.getEnvironment()).build("test autocomplete-reverse client");

client.property(ClientProperties.CONNECT_TIMEOUT, 100000);
client.property(ClientProperties.READ_TIMEOUT, 100000);

Response response = null;
try {
response = client.target(
String.format("http://localhost:%d/gisgraphy?q=pari&point=52.5487429714954,-1.81602098644987&autocomplete=true&reverse=true", RULE.getLocalPort()))
.request()
.get();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

assertThat(response.getStatus()).isEqualTo(400);

}

}
Loading