-
Notifications
You must be signed in to change notification settings - Fork 20
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
feat(server side): add OSM geo data importer #27
Open
Plyasunkov
wants to merge
1
commit into
VladimirBalun:develop
Choose a base branch
from
Plyasunkov:develop
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
ServerSide/resourceserver/src/main/java/ru.servers.resourceserver/geodata/GEOImporter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* Copyright 2018 Vladimir Balun | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limita | ||
*/ | ||
|
||
package ru.servers.resourceserver.geodata; | ||
|
||
import ru.servers.resourceserver.network.HTTPException; | ||
|
||
import java.io.IOException; | ||
|
||
public interface GEOImporter { | ||
/** | ||
* latWest - latitudeWest | ||
* lonSouth - longitudeSouth | ||
* latEast - latitudeEast | ||
* lonNorth - longitudeNorth | ||
*/ | ||
String importGeoData(double latWest, double lonSouth, double latEast, double lonNorth) throws HTTPException, IOException; | ||
|
||
} |
74 changes: 74 additions & 0 deletions
74
ServerSide/resourceserver/src/main/java/ru.servers.resourceserver/geodata/OSMImporter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* | ||
* Copyright 2018 Vladimir Balun | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limita | ||
*/ | ||
|
||
package ru.servers.resourceserver.geodata; | ||
import com.squareup.okhttp.OkHttpClient; | ||
import com.squareup.okhttp.Request; | ||
import com.squareup.okhttp.Response; | ||
import lombok.extern.log4j.Log4j; | ||
import ru.servers.resourceserver.network.HTTPException; | ||
import ru.servers.resourceserver.network.HTTPStatusCode; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.util.Properties; | ||
|
||
@Log4j | ||
public class OSMImporter implements GEOImporter { | ||
|
||
private static String serverAddress; | ||
private static String downloadGeoDataURL; | ||
|
||
public OSMImporter () throws IOException{ | ||
try (InputStream inputStream = getClass().getResourceAsStream("/osm.properties")) { | ||
Properties properties = new Properties(); | ||
properties.load(inputStream); | ||
serverAddress = properties.getProperty("osm.serverAddress"); | ||
downloadGeoDataURL = properties.getProperty("osm.url.downloadGeoData "); | ||
} catch (IOException e) { | ||
throw new IOException("File with OSM server properties was not read."); | ||
} | ||
} | ||
|
||
/** | ||
* latWest - latitudeWest | ||
* lonSouth - longitudeSouth | ||
* latEast - latitudeEast | ||
* lonNorth - longitudeNorth | ||
*/ | ||
@Override | ||
public String importGeoData(double latWest, double lonSouth, double latEast, double lonNorth) throws HTTPException { | ||
try { | ||
OkHttpClient client = new OkHttpClient(); | ||
Request request = new Request.Builder().url(composeURL(latWest, lonSouth, latEast, lonNorth)).build(); | ||
Response response = client.newCall(request).execute(); | ||
if (response.code() == HTTPStatusCode.OK) { | ||
return response.body().string(); | ||
} else if (response.code() == HTTPStatusCode.BAD_REQUEST) { | ||
throw new HTTPException("Incorrect request to OSM server."); | ||
} else { | ||
throw new HTTPException("Inner OSM server error."); | ||
} | ||
} catch (IOException e) { | ||
throw new HTTPException(e.getMessage()); | ||
} | ||
} | ||
|
||
private String composeURL(double latWest, double lonSouth, double latEast, double lonNorth) { | ||
return serverAddress + downloadGeoDataURL + latWest + "," + lonSouth + "," + latEast + "," + lonNorth; | ||
} | ||
|
||
} |
29 changes: 29 additions & 0 deletions
29
ServerSide/resourceserver/src/main/java/ru.servers.resourceserver/network/HTTPException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* Copyright 2018 Vladimir Balun | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limita | ||
*/ | ||
|
||
package ru.servers.resourceserver.network; | ||
|
||
public class HTTPException extends Exception { | ||
|
||
public HTTPException(String message) { | ||
super(message); | ||
} | ||
|
||
public String getMessage(){ | ||
return super.getMessage(); | ||
} | ||
|
||
} |
24 changes: 24 additions & 0 deletions
24
...erSide/resourceserver/src/main/java/ru.servers.resourceserver/network/HTTPStatusCode.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
* Copyright 2018 Vladimir Balun | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limita | ||
*/ | ||
|
||
package ru.servers.resourceserver.network; | ||
|
||
public class HTTPStatusCode { | ||
|
||
public static final short OK = 200; | ||
public static final short BAD_REQUEST = 400; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Server API properties | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Need to remove empty line. |
||
osm.serverAddress = http://www.openstreetmap.org | ||
osm.url.downloadGeoData = /api/0.6/map?bbox= |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to add additional empty line before comment.