Final Edition #9
15
ReadMe.md
15
ReadMe.md
@ -1,11 +1,16 @@
|
||||
# Springboot weather service
|
||||
|
||||
#### GIT:
|
||||
|
||||
# Springboot Service for Weather and Venues
|
||||
***
|
||||
### GIT:
|
||||
- Create a new branch
|
||||
- `add`, `commit` and `push` the branch to Gitea
|
||||
- Create a `pull request` at Gitea from your branch to 'develop'
|
||||
|
||||
***
|
||||
###Access:
|
||||
|
||||
#### The _URI_ to access the current weather data:
|
||||
https://group-4-75.pvt.dsv.su.se/weather-0.0.1-SNAPSHOT/weather
|
||||
https://group-4-75.pvt.dsv.su.se/target/info.war/weather
|
||||
#### The _URI_ to access the current venue data:
|
||||
https://group-4-75.pvt.dsv.su.se/target/info.war/venue
|
||||
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
package com.smhi.weather;
|
||||
package com.data.service;
|
||||
|
||||
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
|
@ -1,4 +1,4 @@
|
||||
package com.smhi.weather;
|
||||
package com.data.service;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
@ -1,12 +1,12 @@
|
||||
package com.smhi.weather.controllers;
|
||||
package com.data.service.controllers;
|
||||
|
||||
import com.data.service.services.OpenWeatherService;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import com.smhi.weather.services.OpenWeatherService;
|
||||
import com.smhi.weather.vo.OpenResponce;
|
||||
import com.data.service.voWeather.OpenResponse;
|
||||
|
||||
|
||||
@RestController
|
||||
@ -18,7 +18,7 @@ public class MainController {
|
||||
}
|
||||
|
||||
@GetMapping("/weather")
|
||||
public OpenResponce index() {
|
||||
public OpenResponse index() {
|
||||
System.out.println("Open responce:");
|
||||
try {
|
||||
return weatherService.getWeatherInfo();
|
@ -1,7 +1,7 @@
|
||||
package com.smhi.weather.controllers;
|
||||
package com.data.service.controllers;
|
||||
|
||||
import com.smhi.weather.services.OpenVenueService;
|
||||
import com.smhi.weather.voVenue.OpenVenueResponse;
|
||||
import com.data.service.services.OpenVenueService;
|
||||
import com.data.service.voVenue.OpenVenueResponse;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
@ -1,8 +1,8 @@
|
||||
package com.smhi.weather.services;
|
||||
package com.data.service.services;
|
||||
|
||||
import com.data.service.voVenue.VenueObject;
|
||||
import com.fasterxml.jackson.core.*;
|
||||
import com.smhi.weather.voVenue.OpenVenueResponse;
|
||||
import com.smhi.weather.voVenue.VenueObject;
|
||||
import com.data.service.voVenue.OpenVenueResponse;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.IOException;
|
||||
@ -19,8 +19,7 @@ import static java.time.temporal.ChronoUnit.SECONDS;
|
||||
|
||||
@Service
|
||||
public class OpenVenueService {
|
||||
final String tempURI = "https://openstreetgs.stockholm.se/geoservice/api/b8e20fd7-5654-465e-8976-35b4de902b41/wfs?service=wfs&version=2.0.0&request=GetFeature&typeName=Markupplatelse&srsName=EPSG:4326&CQL_FILTER=Kategorityp=%271.411I,%20Uteservering%20B-läge%27%20&outputFormat=application/json";
|
||||
// final String tempURI = "https://openstreetgs.stockholm.se/geoservice/api/b8e20fd7-5654-465e-8976-35b4de902b41/wfs?service=wfs&version=2.0.0&request=GetFeature&typeName=Markupplatelse&CQL_FILTER=Kategorityp=%271.411I,%20Uteservering%20B-läge%27%20&outputFormat=application/json";
|
||||
final String URI_String = "https://openstreetgs.stockholm.se/geoservice/api/b8e20fd7-5654-465e-8976-35b4de902b41/wfs?service=wfs&version=2.0.0&request=GetFeature&typeName=Markupplatelse&srsName=EPSG:4326&CQL_FILTER=Kategorityp=%271.411I,%20Uteservering%20B-läge%27%20&outputFormat=application/json";
|
||||
final String apiKey = "b8e20fd7-5654-465e-8976-35b4de902b41";
|
||||
final static int NO_DAYS_BETWEEN_FETCH = 14;
|
||||
private List<VenueObject> data;
|
||||
@ -30,9 +29,7 @@ public class OpenVenueService {
|
||||
// Pre load data...
|
||||
try {
|
||||
this.getVenueInfo();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} catch (InterruptedException e) {
|
||||
} catch (IOException | InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
@ -56,17 +53,17 @@ public class OpenVenueService {
|
||||
|
||||
if (isCacheOK(this.lastFetch)) {
|
||||
logInfo("Cache OK");
|
||||
logInfo("Current data: " + data);
|
||||
// logInfo("Current data: " + data);
|
||||
OpenVenueResponse openVenueResponse = new OpenVenueResponse();
|
||||
openVenueResponse.setVenueObjects(data);
|
||||
return openVenueResponse;
|
||||
}
|
||||
|
||||
logInfo("getVenueInfo: ");
|
||||
/* logInfo("getVenueInfo: ");
|
||||
String uri = buildURI(apiKey);
|
||||
logInfo("URI: " + uri);
|
||||
logInfo("URI: " + uri);*/
|
||||
|
||||
HttpRequest request = createNewRequest(uri);
|
||||
HttpRequest request = createNewRequest(URI_String);
|
||||
HttpResponse<String> response = handleResponse(request);
|
||||
|
||||
|
||||
@ -78,8 +75,6 @@ public class OpenVenueService {
|
||||
|
||||
return ovr;
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
private HttpResponse<String> handleResponse(HttpRequest request) throws IOException, InterruptedException {
|
||||
@ -95,7 +90,7 @@ public class OpenVenueService {
|
||||
HttpRequest request = null;
|
||||
try {
|
||||
request = HttpRequest.newBuilder()
|
||||
.uri(new URI(tempURI))
|
||||
.uri(new URI(uri))
|
||||
.timeout(Duration.of(60, SECONDS))
|
||||
.GET()
|
||||
.build();
|
||||
@ -117,38 +112,6 @@ public class OpenVenueService {
|
||||
|
||||
}
|
||||
|
||||
/* for (Feature feature : root.getFeatures()) {
|
||||
if (feature.getProperties().getPopulärnamn() != null) {
|
||||
// double[] tempCoordinates = new double[2];
|
||||
// tempCoordinates[0] = feature.getGeometry().getCoordinates().get(0);
|
||||
// tempCoordinates[1] = feature.getGeometry().getCoordinates().get(1);
|
||||
venueObject.setName(feature.getProperties().getPopulärnamn().toString());
|
||||
// System.out.println(feature.getProperties().getPopulärnamn());
|
||||
// venueObject.setCoordinates(tempCoordinates);
|
||||
venueObject.setAddress(feature.getProperties().getPlats_1());
|
||||
System.out.println(feature.getProperties().getPlats_1());
|
||||
// venueObject.setStreetNumber(feature.getProperties().getGatunr_1().toString());
|
||||
venueResponse.setVenueObject(venueObject);
|
||||
}
|
||||
}*/
|
||||
|
||||
/* private OpenResponce buildResult(Root root) {
|
||||
OpenResponce responce = new OpenResponce();
|
||||
DataVO dvo = new DataVO();
|
||||
for (TimeSeries ts : root.timeSeries) {
|
||||
for (Parameter p : ts.parameters) {
|
||||
if (p.getName().equalsIgnoreCase("t")) {
|
||||
dvo.setTemp(p.getValues().get(0));
|
||||
}
|
||||
if (p.getName().equalsIgnoreCase("Wsymb2")) {
|
||||
dvo.setWsymb2(p.getValues().get(0).intValue());
|
||||
responce.setDataVO(dvo);
|
||||
return responce;
|
||||
}
|
||||
}
|
||||
}
|
||||
return responce;
|
||||
}*/
|
||||
|
||||
|
||||
private void logInfo(String msg) {
|
||||
@ -161,7 +124,7 @@ public class OpenVenueService {
|
||||
}
|
||||
|
||||
private void skipToken(JsonParser parser, String tokenValue) throws IOException {
|
||||
if (null == tokenValue) {
|
||||
if (tokenValue == null) {
|
||||
parser.nextToken(); // skip first..
|
||||
return;
|
||||
}
|
||||
@ -173,11 +136,10 @@ public class OpenVenueService {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private boolean isBlockStart(String tv) {
|
||||
return null != tv && tv.equals("type:Feature");
|
||||
return tv != null && tv.equals("type:Feature");
|
||||
}
|
||||
|
||||
private List<VenueObject> parseJSON(String data) {
|
||||
@ -197,12 +159,12 @@ public class OpenVenueService {
|
||||
// starting parsing of JSON String
|
||||
while (parser.nextToken() != JsonToken.END_OBJECT) {
|
||||
String token = parser.getCurrentName();
|
||||
String tv = token + ":" + getTokenText(parser);
|
||||
// logInfo(":" + tv + ":" + inBlock );
|
||||
skipToken(parser, tv);
|
||||
String token_value = token + ":" + getTokenText(parser);
|
||||
// logInfo(":" + token_value + ":" + inBlock );
|
||||
skipToken(parser, token_value);
|
||||
|
||||
if (true == isBlockStart(tv)) {
|
||||
if (true == inBlock) {
|
||||
if (isBlockStart(token_value)) {
|
||||
if (inBlock) {
|
||||
VenueObject d = VenueObject.buildVO(lst);
|
||||
// logInfo("\t->" + d);
|
||||
dataVenueObjects.add(d);
|
||||
@ -214,34 +176,23 @@ public class OpenVenueService {
|
||||
}
|
||||
|
||||
if ("coordinates".equals(token)) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("coordinates:");
|
||||
parser.nextToken();
|
||||
// next token will be '[' which means JSON array
|
||||
sb.append(parser.getText()).append(";");
|
||||
parser.nextToken();
|
||||
sb.append(parser.getText());
|
||||
parser.nextToken();
|
||||
parser.nextToken(); // "]"
|
||||
parser.nextToken(); // "}"
|
||||
// logInfo(":->" + sb.toString());
|
||||
lst.add(sb.toString());
|
||||
handleCoordinates(parser, lst);
|
||||
continue;
|
||||
}
|
||||
|
||||
// Simple props...
|
||||
for (String str : asTokens) {
|
||||
if (str.equals(token)) {
|
||||
// logInfo(":->" + tv);
|
||||
lst.add(tv);
|
||||
// logInfo(":->" + token_value);
|
||||
lst.add(token_value);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
// ÅÄÖ problem: "Populärnamn", "Tillstånd_tom"
|
||||
if ((token.startsWith("Popul") && token.endsWith("rnamn")) ||
|
||||
(token.startsWith("Tillst") && token.endsWith("nd_tom"))) {
|
||||
// logInfo(":->" + tv);
|
||||
lst.add(tv);
|
||||
// logInfo(":->" + token_value);
|
||||
lst.add(token_value);
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -258,21 +209,27 @@ public class OpenVenueService {
|
||||
|
||||
dataVenueObjects.add(VenueObject.buildVO(lst));
|
||||
|
||||
/*
|
||||
**
|
||||
*/
|
||||
/*logInfo("---Loop.DataVO---" );
|
||||
for (VenueObject venue : dataVenueObjects) {
|
||||
logInfo("\t" + venue) ;
|
||||
}
|
||||
logInfo("---Loop.DataVO---" + dataVenueObjects.size());*/
|
||||
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
return createFilteredList(dataVenueObjects);
|
||||
}
|
||||
|
||||
private void handleCoordinates(JsonParser parser, List<String> lst) throws IOException {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("coordinates:");
|
||||
parser.nextToken();
|
||||
// next token will be '[' (JSON array)
|
||||
sb.append(parser.getText()).append(";");
|
||||
parser.nextToken();
|
||||
sb.append(parser.getText());
|
||||
parser.nextToken();
|
||||
parser.nextToken(); // "]"
|
||||
parser.nextToken(); // "}"
|
||||
// logInfo(":->" + sb.toString());
|
||||
lst.add(sb.toString());
|
||||
}
|
||||
|
||||
private List<VenueObject> createFilteredList(List<VenueObject> dataVenueObjects) {
|
||||
Set<VenueObject> uniqueSet = new HashSet<>();
|
||||
|
@ -1,6 +1,6 @@
|
||||
package com.smhi.weather.services;
|
||||
package com.data.service.services;
|
||||
|
||||
import com.smhi.weather.vo.*;
|
||||
import com.data.service.voWeather.*;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.IOException;
|
||||
@ -23,7 +23,7 @@ public class OpenWeatherService {
|
||||
private final float LON = 18.0686f;
|
||||
private final float LAT = 59.3293f;
|
||||
|
||||
public OpenResponce getWeatherInfo() throws IOException, InterruptedException {
|
||||
public OpenResponse getWeatherInfo() throws IOException, InterruptedException {
|
||||
System.out.println("getWeatherInfo:");
|
||||
String uri = buildURI(WHAT, LON, LAT);
|
||||
System.out.println("URI: " + uri);
|
||||
@ -39,20 +39,46 @@ public class OpenWeatherService {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
HttpResponse<String> responce = HttpClient.newBuilder()
|
||||
HttpResponse<String> response = HttpClient.newBuilder()
|
||||
.followRedirects(HttpClient.Redirect.ALWAYS)
|
||||
.build()
|
||||
.send(request, HttpResponse.BodyHandlers.ofString());
|
||||
|
||||
System.out.println("Responce.body: " + responce.body());
|
||||
System.out.println("Responce.body: " + response.body());
|
||||
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
com.smhi.weather.vo.Root root = objectMapper.readValue(responce.body(), com.smhi.weather.vo.Root.class);
|
||||
Root root = objectMapper.readValue(response.body(), Root.class);
|
||||
return buildResult(root);
|
||||
}
|
||||
|
||||
private OpenResponce buildResult(Root root) {
|
||||
OpenResponce responce = new OpenResponce();
|
||||
//for test
|
||||
public OpenResponse getWeatherInfo(String uri) throws IOException, InterruptedException {
|
||||
|
||||
HttpRequest request = null;
|
||||
try {
|
||||
request = HttpRequest.newBuilder()
|
||||
.uri(new URI(uri))
|
||||
.timeout(Duration.of(10, SECONDS))
|
||||
.GET()
|
||||
.build();
|
||||
} catch (URISyntaxException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
HttpResponse<String> response = HttpClient.newBuilder()
|
||||
.followRedirects(HttpClient.Redirect.ALWAYS)
|
||||
.build()
|
||||
.send(request, HttpResponse.BodyHandlers.ofString());
|
||||
|
||||
System.out.println("Responce.body: " + response.body());
|
||||
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
Root root = objectMapper.readValue(response.body(), Root.class);
|
||||
return buildResult(root);
|
||||
}
|
||||
|
||||
private OpenResponse buildResult(Root root) {
|
||||
OpenResponse responce = new OpenResponse();
|
||||
DataVO dvo = new DataVO();
|
||||
for (TimeSeries ts : root.timeSeries) {
|
||||
for (Parameter p : ts.parameters) {
|
@ -1,4 +1,4 @@
|
||||
package com.smhi.weather.voVenue;
|
||||
package com.data.service.voVenue;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
|
||||
@ -26,23 +26,3 @@ public class OpenVenueResponse implements Serializable {
|
||||
'}';
|
||||
}
|
||||
}
|
||||
/*@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public class OpenResponce implements Serializable{
|
||||
|
||||
private com.smhi.weather.vo.DataVO dataVO;
|
||||
|
||||
public DataVO getDataVO() {
|
||||
return dataVO;
|
||||
}
|
||||
|
||||
public void setDataVO(DataVO dataVO) {
|
||||
this.dataVO = dataVO;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "OpenResponce{" +
|
||||
"dataVO=" + dataVO +
|
||||
'}';
|
||||
}
|
||||
}*/
|
@ -1,4 +1,4 @@
|
||||
package com.smhi.weather.voVenue;
|
||||
package com.data.service.voVenue;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
@ -1,4 +1,4 @@
|
||||
package com.smhi.weather.vo;
|
||||
package com.data.service.voWeather;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
@ -1,4 +1,4 @@
|
||||
package com.smhi.weather.vo;
|
||||
package com.data.service.voWeather;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
@ -1,13 +1,13 @@
|
||||
package com.smhi.weather.vo;
|
||||
package com.data.service.voWeather;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public class OpenResponce implements Serializable{
|
||||
public class OpenResponse implements Serializable{
|
||||
|
||||
private com.smhi.weather.vo.DataVO dataVO;
|
||||
private DataVO dataVO;
|
||||
|
||||
public DataVO getDataVO() {
|
||||
return dataVO;
|
@ -1,4 +1,4 @@
|
||||
package com.smhi.weather.vo;
|
||||
package com.data.service.voWeather;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
@ -1,4 +1,4 @@
|
||||
package com.smhi.weather.vo;
|
||||
package com.data.service.voWeather;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
@ -1,4 +1,4 @@
|
||||
package com.smhi.weather.vo;
|
||||
package com.data.service.voWeather;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
@ -1,4 +1,4 @@
|
||||
package com.smhi.weather.vo;
|
||||
package com.data.service.voWeather;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
@ -1,148 +0,0 @@
|
||||
/*
|
||||
package com.smhi.weather.services;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonFactory;
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.core.JsonToken;
|
||||
import com.smhi.weather.voVenue.VenueObject;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ParseJson {
|
||||
|
||||
public ParseJson() {}
|
||||
|
||||
private void logInfo(String msg) {System.out.println(":>" + msg);}
|
||||
|
||||
private String getTokenText(JsonParser parser) throws IOException {
|
||||
parser.nextToken(); //next token contains value
|
||||
return parser.getText(); //getting text field
|
||||
}
|
||||
|
||||
private void skipToken(JsonParser parser, String tv) throws IOException {
|
||||
if ( null == tv ) {
|
||||
parser.nextToken(); // skip first..
|
||||
return;
|
||||
}
|
||||
|
||||
String[] asSkipp = {"features:["};
|
||||
for (String str : asSkipp) {
|
||||
if ( str.equals(tv) ) {
|
||||
parser.nextToken(); // skip..
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
private boolean isBlockStart(String tv) {
|
||||
return null != tv && tv.equals("type:Feature");
|
||||
}
|
||||
|
||||
private void parseJSON(String data) {
|
||||
// logInfo("parseJSON:\n" + data);
|
||||
List<VenueObject> dataVenueObjects = new ArrayList<>();
|
||||
try {
|
||||
JsonParser parser = new JsonFactory().createParser(data);
|
||||
|
||||
logInfo("---LOOP---");
|
||||
skipToken(parser, null);
|
||||
|
||||
String[] asTokens = {"Kategorityp", "Plats_1", "Arkivstatus",
|
||||
"VALID_TO", "Gatunr_1"};
|
||||
|
||||
List<String> lst = new ArrayList<String>();
|
||||
boolean inBlock = false;
|
||||
// starting parsing of JSON String
|
||||
while (parser.nextToken() != JsonToken.END_OBJECT) {
|
||||
String token = parser.getCurrentName();
|
||||
String tv = token + ":" + getTokenText(parser);
|
||||
// logInfo(":" + tv + ":" + inBlock );
|
||||
skipToken(parser, tv);
|
||||
|
||||
if ( true == isBlockStart(tv) ) {
|
||||
if ( true == inBlock ) {
|
||||
VenueObject d = VenueObject.buildVO(lst);
|
||||
logInfo("\t->" + d);
|
||||
dataVenueObjects.add(d);
|
||||
lst.clear();
|
||||
}
|
||||
|
||||
inBlock = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
if ("coordinates".equals(token)) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("coordinates:");
|
||||
parser.nextToken();
|
||||
// next token will be '[' which means JSON array
|
||||
sb.append(parser.getText()).append(":");
|
||||
sb.append(parser.getText());
|
||||
parser.nextToken();
|
||||
parser.nextToken();
|
||||
parser.nextToken(); // "]"
|
||||
parser.nextToken(); // "}"
|
||||
// logInfo(":->" + sb.toString());
|
||||
lst.add(sb.toString());
|
||||
continue;
|
||||
}
|
||||
|
||||
// Simple props...
|
||||
for (String str : asTokens) {
|
||||
if ( str.equals(token) ) {
|
||||
// logInfo(":->" + tv);
|
||||
lst.add(tv);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
// ÅÄÖ problem: "Populärnamn", "Tillstånd_tom"
|
||||
if ( (token.startsWith("Popul") && token.endsWith("rnamn")) ||
|
||||
(token.startsWith("Tillst") && token.endsWith("ånd_tom"))) {
|
||||
// logInfo(":->" + tv);
|
||||
lst.add(tv);
|
||||
continue;
|
||||
}
|
||||
|
||||
if ("CHANGE_DATE".equals(token)) {
|
||||
// Skip 3
|
||||
for ( int ii = 0; ii < 3; ++ii) {
|
||||
parser.nextToken();
|
||||
}
|
||||
}
|
||||
|
||||
} // while
|
||||
|
||||
parser.close();
|
||||
|
||||
dataVenueObjects.add(VenueObject.buildVO(lst));
|
||||
|
||||
*/
|
||||
/*
|
||||
**
|
||||
*//*
|
||||
|
||||
logInfo("---Loop.DataVO---" );
|
||||
for (VenueObject venue : dataVenueObjects) {
|
||||
logInfo("\t" + venue) ;
|
||||
}
|
||||
logInfo("---Loop.DataVO---" + dataVenueObjects.size());
|
||||
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
*/
|
||||
/*
|
||||
@Test
|
||||
public void parseJsonStreamToPOJO() throws IOException {
|
||||
// parseJSON(createStringFromFile("src/test/resources/post.json"));
|
||||
// parseJSON(createStringFromFile("src/test/resources/wfs-2.json"));
|
||||
parseJSON(createStringFromFile("src/test/resources/wfs-1.json"));
|
||||
}*//*
|
||||
|
||||
|
||||
|
||||
}
|
||||
*/
|
@ -1,33 +0,0 @@
|
||||
package com.smhi.weather.voVenue;
|
||||
|
||||
public class Crs{
|
||||
public String type;
|
||||
public Properties properties;
|
||||
|
||||
public Crs() {}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public Properties getProperties() {
|
||||
return properties;
|
||||
}
|
||||
|
||||
public void setProperties(Properties properties) {
|
||||
this.properties = properties;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Crs{" +
|
||||
"type='" + type + '\'' +
|
||||
", properties=" + properties +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
@ -1,62 +0,0 @@
|
||||
package com.smhi.weather.voVenue;
|
||||
|
||||
public class Feature{
|
||||
public String type;
|
||||
public String id;
|
||||
public Geometry geometry;
|
||||
public String geometry_name;
|
||||
public Properties properties;
|
||||
|
||||
public Feature() {}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Geometry getGeometry() {
|
||||
return geometry;
|
||||
}
|
||||
|
||||
public void setGeometry(Geometry geometry) {
|
||||
this.geometry = geometry;
|
||||
}
|
||||
|
||||
public String getGeometry_name() {
|
||||
return geometry_name;
|
||||
}
|
||||
|
||||
public void setGeometry_name(String geometry_name) {
|
||||
this.geometry_name = geometry_name;
|
||||
}
|
||||
|
||||
public Properties getProperties() {
|
||||
return properties;
|
||||
}
|
||||
|
||||
public void setProperties(Properties properties) {
|
||||
this.properties = properties;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Feature{" +
|
||||
"type='" + type + '\'' +
|
||||
", id='" + id + '\'' +
|
||||
", geometry=" + geometry +
|
||||
", geometry_name='" + geometry_name + '\'' +
|
||||
", properties=" + properties +
|
||||
'}';
|
||||
}
|
||||
}
|
@ -1,36 +0,0 @@
|
||||
package com.smhi.weather.voVenue;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class Geometry{
|
||||
public String type;
|
||||
public ArrayList<Double> coordinates;
|
||||
|
||||
public Geometry() {}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public ArrayList<Double> getCoordinates() {
|
||||
return coordinates;
|
||||
}
|
||||
|
||||
public void setCoordinates(ArrayList<Double> coordinates) {
|
||||
this.coordinates = coordinates;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Geometry{" +
|
||||
"type='" + type + '\'' +
|
||||
", coordinates=" + coordinates +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,342 +0,0 @@
|
||||
package com.smhi.weather.voVenue;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
public class Properties{
|
||||
@JsonProperty("OBJECT_ID")
|
||||
public int oBJECT_ID;
|
||||
@JsonProperty("VERSION_ID")
|
||||
public int vERSION_ID;
|
||||
@JsonProperty("FEATURE_TYPE_NAME")
|
||||
public String fEATURE_TYPE_NAME;
|
||||
@JsonProperty("FEATURE_TYPE_OBJECT_ID")
|
||||
public int fEATURE_TYPE_OBJECT_ID;
|
||||
@JsonProperty("FEATURE_TYPE_VERSION_ID")
|
||||
public int fEATURE_TYPE_VERSION_ID;
|
||||
@JsonProperty("MAIN_ATTRIBUTE_NAME")
|
||||
public String mAIN_ATTRIBUTE_NAME;
|
||||
@JsonProperty("MAIN_ATTRIBUTE_VALUE")
|
||||
public String mAIN_ATTRIBUTE_VALUE;
|
||||
@JsonProperty("MAIN_ATTRIBUTE_DESCRIPTION")
|
||||
public String mAIN_ATTRIBUTE_DESCRIPTION;
|
||||
@JsonProperty("Ärendekategori")
|
||||
public String ärendekategori;
|
||||
@JsonProperty("Ärendenummer")
|
||||
public String ärendenummer;
|
||||
@JsonProperty("Arkivstatus")
|
||||
public String arkivstatus;
|
||||
@JsonProperty("Populärnamn")
|
||||
public Object populärnamn;
|
||||
@JsonProperty("Kategorityp")
|
||||
public String kategorityp;
|
||||
@JsonProperty("Plats_1")
|
||||
public String plats_1;
|
||||
@JsonProperty("Gatunr_1")
|
||||
public Object gatunr_1;
|
||||
@JsonProperty("Tillstånd_from")
|
||||
public String tillstånd_from;
|
||||
@JsonProperty("Tillstånd_tom")
|
||||
public String tillstånd_tom;
|
||||
@JsonProperty("VALID_FROM")
|
||||
public long vALID_FROM;
|
||||
@JsonProperty("VALID_TO")
|
||||
public Object vALID_TO;
|
||||
@JsonProperty("CID")
|
||||
public long cID;
|
||||
@JsonProperty("EXTENT_NO")
|
||||
public int eXTENT_NO;
|
||||
@JsonProperty("EXTENT_TYPE")
|
||||
public int eXTENT_TYPE;
|
||||
@JsonProperty("LATERAL_POSITION")
|
||||
public int lATERAL_POSITION;
|
||||
@JsonProperty("LATERAL_DIST")
|
||||
public double lATERAL_DIST;
|
||||
@JsonProperty("POSITION")
|
||||
public double pOSITION;
|
||||
@JsonProperty("TRAFFIC_TYPES")
|
||||
public String tRAFFIC_TYPES;
|
||||
@JsonProperty("NET_ELEMENT_OBJECT_ID")
|
||||
public int nET_ELEMENT_OBJECT_ID;
|
||||
@JsonProperty("CREATE_DATE")
|
||||
public long cREATE_DATE;
|
||||
@JsonProperty("CHANGE_DATE")
|
||||
public long cHANGE_DATE;
|
||||
public String name;
|
||||
|
||||
public Properties() {}
|
||||
|
||||
public int getoBJECT_ID() {
|
||||
return oBJECT_ID;
|
||||
}
|
||||
|
||||
public void setoBJECT_ID(int oBJECT_ID) {
|
||||
this.oBJECT_ID = oBJECT_ID;
|
||||
}
|
||||
|
||||
public int getvERSION_ID() {
|
||||
return vERSION_ID;
|
||||
}
|
||||
|
||||
public void setvERSION_ID(int vERSION_ID) {
|
||||
this.vERSION_ID = vERSION_ID;
|
||||
}
|
||||
|
||||
public String getfEATURE_TYPE_NAME() {
|
||||
return fEATURE_TYPE_NAME;
|
||||
}
|
||||
|
||||
public void setfEATURE_TYPE_NAME(String fEATURE_TYPE_NAME) {
|
||||
this.fEATURE_TYPE_NAME = fEATURE_TYPE_NAME;
|
||||
}
|
||||
|
||||
public int getfEATURE_TYPE_OBJECT_ID() {
|
||||
return fEATURE_TYPE_OBJECT_ID;
|
||||
}
|
||||
|
||||
public void setfEATURE_TYPE_OBJECT_ID(int fEATURE_TYPE_OBJECT_ID) {
|
||||
this.fEATURE_TYPE_OBJECT_ID = fEATURE_TYPE_OBJECT_ID;
|
||||
}
|
||||
|
||||
public int getfEATURE_TYPE_VERSION_ID() {
|
||||
return fEATURE_TYPE_VERSION_ID;
|
||||
}
|
||||
|
||||
public void setfEATURE_TYPE_VERSION_ID(int fEATURE_TYPE_VERSION_ID) {
|
||||
this.fEATURE_TYPE_VERSION_ID = fEATURE_TYPE_VERSION_ID;
|
||||
}
|
||||
|
||||
public String getmAIN_ATTRIBUTE_NAME() {
|
||||
return mAIN_ATTRIBUTE_NAME;
|
||||
}
|
||||
|
||||
public void setmAIN_ATTRIBUTE_NAME(String mAIN_ATTRIBUTE_NAME) {
|
||||
this.mAIN_ATTRIBUTE_NAME = mAIN_ATTRIBUTE_NAME;
|
||||
}
|
||||
|
||||
public String getmAIN_ATTRIBUTE_VALUE() {
|
||||
return mAIN_ATTRIBUTE_VALUE;
|
||||
}
|
||||
|
||||
public void setmAIN_ATTRIBUTE_VALUE(String mAIN_ATTRIBUTE_VALUE) {
|
||||
this.mAIN_ATTRIBUTE_VALUE = mAIN_ATTRIBUTE_VALUE;
|
||||
}
|
||||
|
||||
public String getmAIN_ATTRIBUTE_DESCRIPTION() {
|
||||
return mAIN_ATTRIBUTE_DESCRIPTION;
|
||||
}
|
||||
|
||||
public void setmAIN_ATTRIBUTE_DESCRIPTION(String mAIN_ATTRIBUTE_DESCRIPTION) {
|
||||
this.mAIN_ATTRIBUTE_DESCRIPTION = mAIN_ATTRIBUTE_DESCRIPTION;
|
||||
}
|
||||
|
||||
public String getÄrendekategori() {
|
||||
return ärendekategori;
|
||||
}
|
||||
|
||||
public void setÄrendekategori(String ärendekategori) {
|
||||
this.ärendekategori = ärendekategori;
|
||||
}
|
||||
|
||||
public String getÄrendenummer() {
|
||||
return ärendenummer;
|
||||
}
|
||||
|
||||
public void setÄrendenummer(String ärendenummer) {
|
||||
this.ärendenummer = ärendenummer;
|
||||
}
|
||||
|
||||
public String getArkivstatus() {
|
||||
return arkivstatus;
|
||||
}
|
||||
|
||||
public void setArkivstatus(String arkivstatus) {
|
||||
this.arkivstatus = arkivstatus;
|
||||
}
|
||||
|
||||
public Object getPopulärnamn() {
|
||||
return populärnamn;
|
||||
}
|
||||
|
||||
public void setPopulärnamn(Object populärnamn) {
|
||||
this.populärnamn = populärnamn;
|
||||
}
|
||||
|
||||
public String getKategorityp() {
|
||||
return kategorityp;
|
||||
}
|
||||
|
||||
public void setKategorityp(String kategorityp) {
|
||||
this.kategorityp = kategorityp;
|
||||
}
|
||||
|
||||
public String getPlats_1() {
|
||||
return plats_1;
|
||||
}
|
||||
|
||||
public void setPlats_1(String plats_1) {
|
||||
this.plats_1 = plats_1;
|
||||
}
|
||||
|
||||
public Object getGatunr_1() {
|
||||
return gatunr_1;
|
||||
}
|
||||
|
||||
public void setGatunr_1(Object gatunr_1) {
|
||||
this.gatunr_1 = gatunr_1;
|
||||
}
|
||||
|
||||
public String getTillstånd_from() {
|
||||
return tillstånd_from;
|
||||
}
|
||||
|
||||
public void setTillstånd_from(String tillstånd_from) {
|
||||
this.tillstånd_from = tillstånd_from;
|
||||
}
|
||||
|
||||
public String getTillstånd_tom() {
|
||||
return tillstånd_tom;
|
||||
}
|
||||
|
||||
public void setTillstånd_tom(String tillstånd_tom) {
|
||||
this.tillstånd_tom = tillstånd_tom;
|
||||
}
|
||||
|
||||
public long getvALID_FROM() {
|
||||
return vALID_FROM;
|
||||
}
|
||||
|
||||
public void setvALID_FROM(long vALID_FROM) {
|
||||
this.vALID_FROM = vALID_FROM;
|
||||
}
|
||||
|
||||
public Object getvALID_TO() {
|
||||
return vALID_TO;
|
||||
}
|
||||
|
||||
public void setvALID_TO(Object vALID_TO) {
|
||||
this.vALID_TO = vALID_TO;
|
||||
}
|
||||
|
||||
public long getcID() {
|
||||
return cID;
|
||||
}
|
||||
|
||||
public void setcID(long cID) {
|
||||
this.cID = cID;
|
||||
}
|
||||
|
||||
public int geteXTENT_NO() {
|
||||
return eXTENT_NO;
|
||||
}
|
||||
|
||||
public void seteXTENT_NO(int eXTENT_NO) {
|
||||
this.eXTENT_NO = eXTENT_NO;
|
||||
}
|
||||
|
||||
public int geteXTENT_TYPE() {
|
||||
return eXTENT_TYPE;
|
||||
}
|
||||
|
||||
public void seteXTENT_TYPE(int eXTENT_TYPE) {
|
||||
this.eXTENT_TYPE = eXTENT_TYPE;
|
||||
}
|
||||
|
||||
public int getlATERAL_POSITION() {
|
||||
return lATERAL_POSITION;
|
||||
}
|
||||
|
||||
public void setlATERAL_POSITION(int lATERAL_POSITION) {
|
||||
this.lATERAL_POSITION = lATERAL_POSITION;
|
||||
}
|
||||
|
||||
public double getlATERAL_DIST() {
|
||||
return lATERAL_DIST;
|
||||
}
|
||||
|
||||
public void setlATERAL_DIST(double lATERAL_DIST) {
|
||||
this.lATERAL_DIST = lATERAL_DIST;
|
||||
}
|
||||
|
||||
public double getpOSITION() {
|
||||
return pOSITION;
|
||||
}
|
||||
|
||||
public void setpOSITION(double pOSITION) {
|
||||
this.pOSITION = pOSITION;
|
||||
}
|
||||
|
||||
public String gettRAFFIC_TYPES() {
|
||||
return tRAFFIC_TYPES;
|
||||
}
|
||||
|
||||
public void settRAFFIC_TYPES(String tRAFFIC_TYPES) {
|
||||
this.tRAFFIC_TYPES = tRAFFIC_TYPES;
|
||||
}
|
||||
|
||||
public int getnET_ELEMENT_OBJECT_ID() {
|
||||
return nET_ELEMENT_OBJECT_ID;
|
||||
}
|
||||
|
||||
public void setnET_ELEMENT_OBJECT_ID(int nET_ELEMENT_OBJECT_ID) {
|
||||
this.nET_ELEMENT_OBJECT_ID = nET_ELEMENT_OBJECT_ID;
|
||||
}
|
||||
|
||||
public long getcREATE_DATE() {
|
||||
return cREATE_DATE;
|
||||
}
|
||||
|
||||
public void setcREATE_DATE(long cREATE_DATE) {
|
||||
this.cREATE_DATE = cREATE_DATE;
|
||||
}
|
||||
|
||||
public long getcHANGE_DATE() {
|
||||
return cHANGE_DATE;
|
||||
}
|
||||
|
||||
public void setcHANGE_DATE(long cHANGE_DATE) {
|
||||
this.cHANGE_DATE = cHANGE_DATE;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Properties{" +
|
||||
"oBJECT_ID=" + oBJECT_ID +
|
||||
", vERSION_ID=" + vERSION_ID +
|
||||
", fEATURE_TYPE_NAME='" + fEATURE_TYPE_NAME + '\'' +
|
||||
", fEATURE_TYPE_OBJECT_ID=" + fEATURE_TYPE_OBJECT_ID +
|
||||
", fEATURE_TYPE_VERSION_ID=" + fEATURE_TYPE_VERSION_ID +
|
||||
", mAIN_ATTRIBUTE_NAME='" + mAIN_ATTRIBUTE_NAME + '\'' +
|
||||
", mAIN_ATTRIBUTE_VALUE='" + mAIN_ATTRIBUTE_VALUE + '\'' +
|
||||
", mAIN_ATTRIBUTE_DESCRIPTION='" + mAIN_ATTRIBUTE_DESCRIPTION + '\'' +
|
||||
", ärendekategori='" + ärendekategori + '\'' +
|
||||
", ärendenummer='" + ärendenummer + '\'' +
|
||||
", arkivstatus='" + arkivstatus + '\'' +
|
||||
", populärnamn=" + populärnamn +
|
||||
", kategorityp='" + kategorityp + '\'' +
|
||||
", plats_1='" + plats_1 + '\'' +
|
||||
", gatunr_1=" + gatunr_1 +
|
||||
", tillstånd_from='" + tillstånd_from + '\'' +
|
||||
", tillstånd_tom='" + tillstånd_tom + '\'' +
|
||||
", vALID_FROM=" + vALID_FROM +
|
||||
", vALID_TO=" + vALID_TO +
|
||||
", cID=" + cID +
|
||||
", eXTENT_NO=" + eXTENT_NO +
|
||||
", eXTENT_TYPE=" + eXTENT_TYPE +
|
||||
", lATERAL_POSITION=" + lATERAL_POSITION +
|
||||
", lATERAL_DIST=" + lATERAL_DIST +
|
||||
", pOSITION=" + pOSITION +
|
||||
", tRAFFIC_TYPES='" + tRAFFIC_TYPES + '\'' +
|
||||
", nET_ELEMENT_OBJECT_ID=" + nET_ELEMENT_OBJECT_ID +
|
||||
", cREATE_DATE=" + cREATE_DATE +
|
||||
", cHANGE_DATE=" + cHANGE_DATE +
|
||||
'}';
|
||||
}
|
||||
}
|
@ -1,85 +0,0 @@
|
||||
package com.smhi.weather.voVenue;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
|
||||
public class Root{
|
||||
public String type;
|
||||
public ArrayList<Feature> features;
|
||||
public int totalFeatures;
|
||||
public int numberMatched;
|
||||
public int numberReturned;
|
||||
public Date timeStamp;
|
||||
public Crs crs;
|
||||
|
||||
public Root() {}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public ArrayList<Feature> getFeatures() {
|
||||
return features;
|
||||
}
|
||||
|
||||
public void setFeatures(ArrayList<Feature> features) {
|
||||
this.features = features;
|
||||
}
|
||||
|
||||
public int getTotalFeatures() {
|
||||
return totalFeatures;
|
||||
}
|
||||
|
||||
public void setTotalFeatures(int totalFeatures) {
|
||||
this.totalFeatures = totalFeatures;
|
||||
}
|
||||
|
||||
public int getNumberMatched() {
|
||||
return numberMatched;
|
||||
}
|
||||
|
||||
public void setNumberMatched(int numberMatched) {
|
||||
this.numberMatched = numberMatched;
|
||||
}
|
||||
|
||||
public int getNumberReturned() {
|
||||
return numberReturned;
|
||||
}
|
||||
|
||||
public void setNumberReturned(int numberReturned) {
|
||||
this.numberReturned = numberReturned;
|
||||
}
|
||||
|
||||
public Date getTimeStamp() {
|
||||
return timeStamp;
|
||||
}
|
||||
|
||||
public void setTimeStamp(Date timeStamp) {
|
||||
this.timeStamp = timeStamp;
|
||||
}
|
||||
|
||||
public Crs getCrs() {
|
||||
return crs;
|
||||
}
|
||||
|
||||
public void setCrs(Crs crs) {
|
||||
this.crs = crs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Root{" +
|
||||
"type='" + type + '\'' +
|
||||
", features=" + features +
|
||||
", totalFeatures=" + totalFeatures +
|
||||
", numberMatched=" + numberMatched +
|
||||
", numberReturned=" + numberReturned +
|
||||
", timeStamp=" + timeStamp +
|
||||
", crs=" + crs +
|
||||
'}';
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package com.smhi.weather;
|
||||
package com.data.service;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
@ -0,0 +1,41 @@
|
||||
package com.data.service.services;
|
||||
|
||||
import com.data.service.voVenue.OpenVenueResponse;
|
||||
import com.data.service.voVenue.VenueObject;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Random;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class OpenVenueServiceTest {
|
||||
|
||||
@Test
|
||||
void getVenueInfoReturnsVenueResponse() throws IOException, InterruptedException {
|
||||
OpenVenueService openVenueService = new OpenVenueService();
|
||||
OpenVenueResponse response = openVenueService.getVenueInfo();
|
||||
|
||||
assertNotNull(response);
|
||||
}
|
||||
|
||||
@Test
|
||||
void validateRandomObjectContainsCoordinates() throws IOException, InterruptedException {
|
||||
OpenVenueService openVenueService = new OpenVenueService();
|
||||
OpenVenueResponse response = openVenueService.getVenueInfo();
|
||||
|
||||
Random rnd = new Random();
|
||||
int randomObjectNumber = rnd.nextInt(response.getVenueObjects().size() -1);
|
||||
|
||||
VenueObject object = response.getVenueObjects().get(randomObjectNumber);
|
||||
|
||||
assertNotNull(object.getCoordinates());
|
||||
|
||||
System.out.println(object);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
package com.data.service.services;
|
||||
|
||||
import com.data.service.voWeather.OpenResponse;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class OpenWeatherServiceTest {
|
||||
|
||||
@Test
|
||||
void getWeatherInfoContainsData() throws IOException, InterruptedException {
|
||||
OpenWeatherService weatherService = new OpenWeatherService();
|
||||
OpenResponse response = weatherService.getWeatherInfo();
|
||||
|
||||
assertNotNull(response.getDataVO());
|
||||
System.out.println(response.getDataVO());
|
||||
}
|
||||
|
||||
@Test
|
||||
void dataWsymb2IsIntegerLessThanTwentySeven() throws IOException, InterruptedException {
|
||||
OpenWeatherService weatherService = new OpenWeatherService();
|
||||
OpenResponse response = weatherService.getWeatherInfo();
|
||||
|
||||
assertTrue(response.getDataVO().getWsymb2() < 27);
|
||||
}
|
||||
|
||||
@Test
|
||||
void getWeatherInfoThrowsExceptionWithWrongUri() {
|
||||
OpenWeatherService weatherService = new OpenWeatherService();
|
||||
|
||||
Exception e = assertThrows(
|
||||
Exception.class, () -> weatherService.getWeatherInfo("https://opendata-download-metanalys.smhi.se/api/category/masan/version/2/geotype/point/lon/18.0686/lat/59.3293/data.json"),
|
||||
"Expected to throw exception with wrong URI"
|
||||
);
|
||||
|
||||
assertTrue(e.getMessage().contains("404"));
|
||||
}
|
||||
}
|
@ -1,12 +0,0 @@
|
||||
package com.smhi.weather;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
class OpenWeatherServiceTest {
|
||||
|
||||
@Test
|
||||
void getWeatherInfo() {
|
||||
}
|
||||
}
|
@ -1,91 +0,0 @@
|
||||
package com.smhi.weather;
|
||||
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.smhi.weather.voVenue.Feature;
|
||||
import com.smhi.weather.voVenue.Properties;
|
||||
import com.smhi.weather.voVenue.Root;
|
||||
import org.json.JSONException;
|
||||
import org.junit.Test;
|
||||
import org.junit.Assert;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.skyscreamer.jsonassert.JSONParser.parseJSON;
|
||||
|
||||
public class VenueParseDataTest {
|
||||
|
||||
@Test
|
||||
public void parseJsonToPOJO() throws IOException {
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
||||
|
||||
String path = "src/test/resources/test-b.json";
|
||||
|
||||
String data = createStringFromFile(path);
|
||||
System.out.println("Before mapper");
|
||||
Root root = mapper.readValue(data, com.smhi.weather.voVenue.Root.class);
|
||||
System.out.println("After mapper");
|
||||
|
||||
Assert.assertNotNull(root);
|
||||
/*if (root.geometry.coordinates.get(0) != null) {
|
||||
Assert.assertTrue(root.geometry.coordinates.get(0) == 18.07116);
|
||||
}*/
|
||||
|
||||
// System.out.println(data);
|
||||
// System.out.println(root.toString());
|
||||
System.out.println(root.getFeatures().get(0).getGeometry().getCoordinates().get(0));
|
||||
// System.out.println(root.getCrs().getProperties());
|
||||
// System.out.println(root);
|
||||
Set<String> venues = new HashSet<>();
|
||||
|
||||
for (Feature feature : root.getFeatures()) {
|
||||
if (feature.getProperties().getPopulärnamn() != null) {
|
||||
// System.out.println(feature.getProperties().getPopulärnamn() + " : " + feature.getProperties().getArkivstatus());
|
||||
venues.add(feature.getProperties().getPopulärnamn().toString());
|
||||
}
|
||||
}
|
||||
int count = 0;
|
||||
for (String venue : venues) {
|
||||
count++;
|
||||
System.out.println(count + ": " + venue);
|
||||
}
|
||||
|
||||
/*for (Feature feature : root.features) {
|
||||
if (feature.getProperties().getTillstånd_tom().contains("202")) {
|
||||
System.out.println(feature.getProperties().getTillstånd_tom());
|
||||
if (feature.getProperties().getPopulärnamn() != null) {
|
||||
System.out.println(feature.getProperties().getPopulärnamn() + " : " + feature.getProperties().getArkivstatus());
|
||||
}
|
||||
}
|
||||
*//*if (feature.getProperties().arkivstatus.equalsIgnoreCase("pågående")) {
|
||||
System.out.println(feature.getProperties().getPopulärnamn() + " : " + feature.getProperties().getArkivstatus());
|
||||
}*//*
|
||||
}*/
|
||||
|
||||
}
|
||||
|
||||
private String createStringFromFile(String path) throws IOException {
|
||||
String result;
|
||||
|
||||
result = new String(Files.readAllBytes(Paths.get(path)));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/* @Test
|
||||
public void parseJsonStreamToPOJO() throws IOException, JSONException {
|
||||
ParseJson parser = new ParseJson();
|
||||
// parseJSON(createStringFromFile("src/test/resources/post.json"));
|
||||
// parseJSON(createStringFromFile("src/test/resources/wfs-2.json"));
|
||||
parser.parseJSON(createStringFromFile("src/test/resources/wfs.json"));
|
||||
}*/
|
||||
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user