diff --git a/src/main/java/com/example/cosmos_serversb/entities/Location.java b/src/main/java/com/example/cosmos_serversb/entities/Location.java index b4a0667..e5099fc 100644 --- a/src/main/java/com/example/cosmos_serversb/entities/Location.java +++ b/src/main/java/com/example/cosmos_serversb/entities/Location.java @@ -1,18 +1,13 @@ package com.example.cosmos_serversb.entities; public class Location { - public double latitude; - public double longitude; + private double latitude; + private double longitude; public Location(){ } - public Location(double latitude, double longitude){ - setLatitude(latitude); - setLongitude(longitude); - } - public void setLatitude(double latitude) { this.latitude = latitude; } diff --git a/src/main/java/com/example/cosmos_serversb/entities/Shop.java b/src/main/java/com/example/cosmos_serversb/entities/Shop.java index dd45901..019a938 100644 --- a/src/main/java/com/example/cosmos_serversb/entities/Shop.java +++ b/src/main/java/com/example/cosmos_serversb/entities/Shop.java @@ -24,7 +24,10 @@ @JsonView(ShopsView.getShopsView.class) public int code; @JsonView(ShopsView.getShopsView.class) - public Location location; + public double latitude; + @JsonView(ShopsView.getShopsView.class) + public double longitude; + //public Location location; public Shop() { } @@ -32,7 +35,8 @@ public Shop(String genre, int code, double latitude, double longitude) { setGenre(genre); setCode(code); - setLocation(latitude, longitude); + setLatitude(latitude); + setLongitude(longitude); } public void setGenre(String genre) { this.genre = genre; @@ -50,13 +54,20 @@ return code; } - public void setLocation(double latitude, double longitude) { - location.setLatitude(latitude); - location.setLongitude(longitude); + public void setLatitude(double latitude) { + this.latitude = latitude; } - public Location getLocation() { - return location; + public double getLatitude() { + return latitude; + } + + public void setLongitude(double longitude) { + this.longitude = longitude; + } + + public double getLongitude() { + return longitude; } } \ No newline at end of file diff --git a/src/main/java/com/example/cosmos_serversb/models/Shops.java b/src/main/java/com/example/cosmos_serversb/models/Shops.java index 8a2c12e..e360265 100644 --- a/src/main/java/com/example/cosmos_serversb/models/Shops.java +++ b/src/main/java/com/example/cosmos_serversb/models/Shops.java @@ -6,8 +6,8 @@ import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; -import org.hibernate.Session; -import org.hibernate.SessionFactory; +//import org.hibernate.Session; +//import org.hibernate.SessionFactory; import javax.inject.Singleton; import java.io.*; @@ -19,13 +19,13 @@ public class Shops { private static Shops theInstance = null; - private static SessionFactory sessionFactory; + //private static SessionFactory sessionFactory; private static ArrayList shops = new ArrayList<>(); private static String baseURI="http://nitta-lab-www.is.konan-u.ac.jp/"; private static String AppName="cosmos"; private Shops() { - sessionFactory = SessionFactoryManager.getInstance().getSessionFactory(); + //sessionFactory = SessionFactoryManager.getInstance().getSessionFactory(); } public static Shops getInstance() { @@ -42,7 +42,7 @@ String location; String[] split; try { - URL url = new URL("https://map.yahooapis.jp/search/local/V1/localSearch?bbox=" + leftLatitude + "," + leftLongitude + "," + rightLatitude + "," + rightLongitude + "&gc=02&output=json&appid=dj00aiZpPTVzYzloUDJjS0VMSyZzPWNvbnN1bWVyc2VjcmV0Jng9MGE-"); + URL url = new URL("https://map.yahooapis.jp/search/local/V1/localSearch?bbox=" + leftLatitude + "," + leftLongitude + "," + rightLatitude + "," + rightLongitude + "&gc=02&results=90&output=json&appid=dj00aiZpPTVzYzloUDJjS0VMSyZzPWNvbnN1bWVyc2VjcmV0Jng9MGE-"); HttpURLConnection con = (HttpURLConnection) url.openConnection(); con.connect(); String tmp = ""; @@ -65,10 +65,10 @@ e.printStackTrace(); } - for (int i = 0; i < 90; i++) { - genre = jnode.get("Feature").get(0).get("Property").get("Genre").get(0).get("Name").asText(); - code = jnode.get("Feature").get(0).get("Property").get("Genre").get(0).get("Code").asText(); - location = jnode.get("Feature").get(0).get("Geometry").get("Coordinates").asText(); + for (int i = 0; i < 10; i++) { + genre = jnode.get("Feature").get(i).get("Property").get("Genre").get(0).get("Name").asText(); + code = jnode.get("Feature").get(i).get("Property").get("Genre").get(0).get("Code").asText(); + location = jnode.get("Feature").get(i).get("Geometry").get("Coordinates").asText(); split = location.split(","); Shop shop = new Shop(genre, Integer.parseInt(code), Double.parseDouble(split[0]), Double.parseDouble(split[1])); shops.add(shop); diff --git a/src/main/java/com/example/cosmos_serversb/resources/ShopsRest.java b/src/main/java/com/example/cosmos_serversb/resources/ShopsRest.java index 73599c5..2249fa2 100644 --- a/src/main/java/com/example/cosmos_serversb/resources/ShopsRest.java +++ b/src/main/java/com/example/cosmos_serversb/resources/ShopsRest.java @@ -22,10 +22,10 @@ @QueryParam("rightLatitude") String rightLatitude, @QueryParam("rightLongitude") String rightLongitude )throws JsonProcessingException { - SessionManager.getInstance().getSession(); + //SessionManager.getInstance().getSession(); ObjectMapper mapper = new ObjectMapper(); String json = mapper.writerWithView(ShopsView.getShopsView.class).writeValueAsString(Shops.getInstance().getShop(leftLatitude,leftLongitude,rightLatitude,rightLongitude)); - SessionManager.getInstance().closeSession(); + //SessionManager.getInstance().closeSession(); LogUtils.info("位置情報を取得"); return json; }