Skip to content
Snippets Groups Projects
Commit 6260dc4e authored by Nikolaus Krismer's avatar Nikolaus Krismer
Browse files

removed reference to json library.... everything related to json is now

implemented with jackson
parent 031687cb
No related branches found
No related tags found
No related merge requests found
......@@ -80,7 +80,6 @@ dependencies {
compile group: 'com.fasterxml.jackson.core', name: 'jackson-core', version: '2.3.0'
compile group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.3.0'
compile group: 'com.google.code.findbugs', name: 'annotations', version: '2.0.3'
compile group: 'org.json', name: 'json', version:'20131018'
compile(group: 'org.postgis', name: 'postgis-jdbc', version:'1.3+') {
exclude(module: 'postgis-stubs')
}
......
......@@ -12,6 +12,7 @@ import java.util.List;
* used to track how many adjacent links have already been explored.
*/
public class Node implements Comparable<Node> {
// TODO: Check how we deal with empty ids (shouldn't they be null? by now they are Integer.MIN_VALUE)
private final int id;
private double distance;
private short nrAdjacentLinks;
......@@ -24,6 +25,10 @@ public class Node implements Comparable<Node> {
// Constructors
protected Node() {
id = Integer.MIN_VALUE;
}
public Node(final int nodeId) {
id = nodeId;
distance = Double.POSITIVE_INFINITY;
......
......@@ -2,38 +2,27 @@ package it.unibz.inf.isoga.datastructure;
import it.unibz.inf.isochrone.network.Node;
import com.fasterxml.jackson.annotation.JsonProperty;
/**
* The <code>QueryPoint</code> class represents a query point. Query points are particular pedestrian nodes with
* temporal distance equal to zero, since they are used as the starting point of the isochrone computation.
*
*
* @author Markus Innerebner
* @author Willi Cometti
* @version 3.0
*/
public class QueryPoint extends Node {
private final int x, y;
private int x;
private int y;
/**
* Class Constructor that creates a query point. Query points have a temporal distance equal to zero.
*
* @param nodeId the node ID
* @param x the x coordinate
* @param y the y coordinate
* Create a query point.
* Query points have a temporal distance equal to zero.
*/
public QueryPoint(final int nodeId, final int x, final int y) {
super(nodeId);
public QueryPoint() {
super();
setDistance(0);
this.x = x;
this.y = y;
}
public int getX() {
return x;
}
public int getY() {
return y;
}
@Override
......@@ -46,19 +35,37 @@ public class QueryPoint extends Node {
return getID() == other.getID() && x == other.x && y == other.y;
}
public int getX() {
return x;
}
public int getY() {
return y;
}
@Override
public int hashCode() {
return getID() + x + y;
}
@Override
public String toString() {
return "[" + getID() + ", (" + x + "," + y + ")]";
public boolean isClosed() {
return true;
}
@JsonProperty
public void setX(final int x) {
this.x = x;
}
@JsonProperty
public void setY(final int y) {
this.y = y;
}
@Override
public boolean isClosed() {
return true;
public String toString() {
return "[" + getID() + ", (" + x + "," + y + ")]";
}
}
......@@ -3,10 +3,10 @@ package it.unibz.inf.isoga.db;
import it.unibz.inf.isochrone.util.EnumContainer.QueryType;
import it.unibz.inf.isoga.network.RouteEntity;
import it.unibz.inf.isoga.service.dto.ResponsePoiFeature;
import it.unibz.inf.isoga.service.dto.ResponsePoiFeature.PoiFeature;
import it.unibz.inf.isoga.service.dto.ResponseWps;
import it.unibz.inf.isoga.service.dto.WpsFeature;
import it.unibz.inf.isoga.service.dto.WpsStatistic;
import it.unibz.inf.isoga.service.dto.ResponsePoiFeature.PoiFeature;
import it.unibz.inf.isoga.util.ConfigWeb;
import java.sql.CallableStatement;
......@@ -24,7 +24,6 @@ import java.util.SortedMap;
import java.util.TreeMap;
import org.apache.commons.dbutils.DbUtils;
import org.json.JSONException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -151,7 +150,7 @@ public final class DbUtility {
+ " PRIMARY KEY (\"ID\"))");
}
public static ResponsePoiFeature getPoiFeatures(final String sqlExpr, final ConfigWeb config) throws JSONException {
public static ResponsePoiFeature getPoiFeatures(final String sqlExpr, final ConfigWeb config) {
final ResponsePoiFeature result = new ResponsePoiFeature();
if (sqlExpr.equals("noResult")) {
result.setType("invalid");
......@@ -177,8 +176,6 @@ public final class DbUtility {
} catch (final SQLException e1) {
e1.printStackTrace();
}
} catch (final JSONException e) {
e.printStackTrace();
} finally {
DbUtils.closeQuietly(rSet);
DbUtils.closeQuietly(stmt);
......@@ -187,7 +184,7 @@ public final class DbUtility {
return result;
}
public static ResponseWps spatialIntersection2JSON(final String sqlExpr, final SqlQuery query, final ConfigWeb config) throws JSONException {
public static ResponseWps spatialIntersection2JSON(final String sqlExpr, final SqlQuery query, final ConfigWeb config) {
final boolean isSum = query.getQueryType().equals(QueryType.SUM);
final ResponseWps result = new ResponseWps(query.getQueryType().toString().toLowerCase());
if (sqlExpr.equals("noResult")) {
......@@ -299,8 +296,6 @@ public final class DbUtility {
} catch (final SQLException e1) {
e1.printStackTrace();
}
} catch (final JSONException e) {
e.printStackTrace();
} finally {
DbUtils.closeQuietly(rSet);
DbUtils.closeQuietly(stmt);
......
......@@ -10,8 +10,8 @@ import it.unibz.inf.isochrone.util.EnumContainer.Dataset;
import it.unibz.inf.isochrone.util.Query;
import it.unibz.inf.isoga.coverage.CoverageBuilder;
import it.unibz.inf.isoga.datastructure.QueryPoint;
import it.unibz.inf.isoga.db.DbUtility;
import it.unibz.inf.isoga.db.DatabaseWeb;
import it.unibz.inf.isoga.db.DbUtility;
import it.unibz.inf.isoga.network.MemoryBBoxOutput;
import it.unibz.inf.isoga.service.dto.RequestIsochrone;
import it.unibz.inf.isoga.service.dto.ResponseIsochrone;
......@@ -20,14 +20,12 @@ import it.unibz.inf.isoga.util.ConfigDataset;
import it.unibz.inf.isoga.util.ConfigWeb;
import java.sql.Connection;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
import javax.websocket.Session;
import org.json.JSONArray;
import org.json.JSONException;
/**
* @author Nikolaus Krismer
*/
......@@ -112,24 +110,10 @@ public class ServiceIsochrone extends AbstractService<RequestIsochrone, Response
return new MineX(query);
}
private Set<Location> locationsFromQueryPoints(final String qPoints, final ConfigWeb config) {
final Set<QueryPoint> queryPoints = new HashSet<QueryPoint>();
try {
final JSONArray arr = new JSONArray(qPoints);
for (int i = 0; i < arr.length(); i++) {
final JSONArray ordinates = (JSONArray) arr.get(i);
final int x = ordinates.getInt(0);
final int y = ordinates.getInt(1);
queryPoints.add(new QueryPoint(Integer.MIN_VALUE, x, y));
}
} catch (final JSONException e) {
e.printStackTrace();
}
private Set<Location> locationsFromQueryPoints(final Collection<QueryPoint> queryPoints, final ConfigWeb config) {
final Set<Location> locations = new HashSet<Location>(queryPoints.size());
final DatabaseWeb db = new DatabaseWeb(config);
for (final QueryPoint qPoint : queryPoints) {
locations.addAll(db.projectOnLinks(qPoint));
}
......
......@@ -3,11 +3,13 @@ package it.unibz.inf.isoga.service.dto;
import it.unibz.inf.isochrone.util.EnumContainer.Dataset;
import it.unibz.inf.isochrone.util.EnumContainer.Direction;
import it.unibz.inf.isochrone.util.EnumContainer.Mode;
import it.unibz.inf.isoga.datastructure.QueryPoint;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Collection;
import com.fasterxml.jackson.annotation.JsonProperty;
......@@ -22,7 +24,7 @@ public class RequestIsochrone implements IRequest {
private String datasetString;
private Boolean expirationMode;
private String modeString;
private String queryPoints;
private Collection<QueryPoint> queryPoints;
private Double speed;
private Long dmax;
......@@ -85,7 +87,7 @@ public class RequestIsochrone implements IRequest {
return Mode.valueOf(modeString.toUpperCase());
}
public String getQueryPoints() {
public Collection<QueryPoint> getQueryPoints() {
return queryPoints;
}
......@@ -157,7 +159,7 @@ public class RequestIsochrone implements IRequest {
}
@JsonProperty
public void setQueryPoints(final String queryPoints) {
public void setQueryPoints(final Collection<QueryPoint> queryPoints) {
this.queryPoints = queryPoints;
}
......
......@@ -27,11 +27,11 @@ import javax.websocket.OnOpen;
import javax.websocket.Session;
import javax.websocket.server.ServerEndpoint;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
@ServerEndpoint(value = "/websocket")
......@@ -61,11 +61,21 @@ public class JsonWebsocket {
LOGGER.debug("Websocket: Message from client \"" + clientId + "\": " + message);
final boolean emptyRequest = (message == null || message.trim().length() <= 0);
final JSONObject requestJson = (emptyRequest) ? new JSONObject() : new JSONObject(message);
if (emptyRequest) {
throw new IllegalArgumentException("Invalid request given... empty object");
}
final ObjectMapper mapper = new ObjectMapper();
JsonNode requestJsonNode = null;
try {
requestJsonNode = mapper.readValue(message.getBytes(), JsonNode.class);
} catch (final IOException e) {
throw new IllegalArgumentException("Invalid request given... can not be parsed to json object");
}
final Class<S> aService = this.<S, T, U>getService(requestJson);
final Class<S> aService = this.<S, T, U>getService(requestJsonNode);
if (aService == null) {
throw new IllegalArgumentException("Invalid request message given... service could not be found");
throw new IllegalArgumentException("Invalid request message given... referenced service could not be found");
}
S service = null;
......@@ -75,10 +85,9 @@ public class JsonWebsocket {
e.printStackTrace();
}
if (service == null) {
throw new IllegalStateException("Service \"" + aService.getClass().getSimpleName() + "\" could not be created!");
throw new IllegalStateException("Referenced service \"" + aService.getClass().getSimpleName() + "\" could not be created!");
}
final ObjectMapper mapper = new ObjectMapper();
T request = null;
try {
request = mapper.readValue(message, service.getRequestClass());
......@@ -125,12 +134,12 @@ public class JsonWebsocket {
// Private methods
private <S extends IService<T, U>, T extends IRequest, U extends IResponse> Class<S> getService(final JSONObject jsonObject) {
if (!jsonObject.has("action")) {
private <S extends IService<T, U>, T extends IRequest, U extends IResponse> Class<S> getService(final JsonNode jsonNode) {
if (!jsonNode.has("action") || !jsonNode.isTextual()) {
return null;
}
final String action = jsonObject.getString("action");
final String action = jsonNode.get("action").asText();
if (action == null || action.trim().length() <= 0) {
return null;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment