Changeset View
Changeset View
Standalone View
Standalone View
src/it/reyboz/bustorino/backend/mato/MapiArrivalRequest.java
Show First 20 Lines • Show All 41 Lines • ▼ Show 20 Lines | |||||
public class MapiArrivalRequest extends MapiVolleyRequest<Palina> { | public class MapiArrivalRequest extends MapiVolleyRequest<Palina> { | ||||
private final String stopName; | private final String stopName; | ||||
private final Date startingTime; | private final Date startingTime; | ||||
private final int timeRange, numberOfDepartures; | private final int timeRange, numberOfDepartures; | ||||
private final AtomicReference<Fetcher.Result> reqRes; | private final AtomicReference<Fetcher.Result> reqRes; | ||||
private final String DEBUG_TAG = "BusTO-MAPIArrivalReq"; | |||||
public MapiArrivalRequest(String stopName, Date startingTime, int timeRange, | public MapiArrivalRequest(String stopName, Date startingTime, int timeRange, | ||||
int numberOfDepartures, | int numberOfDepartures, | ||||
AtomicReference<Fetcher.Result> res, | AtomicReference<Fetcher.Result> res, | ||||
Response.Listener<Palina> listener, | Response.Listener<Palina> listener, | ||||
@Nullable Response.ErrorListener errorListener) { | @Nullable Response.ErrorListener errorListener) { | ||||
super(MatoAPIFetcher.QueryType.ARRIVALS, listener, errorListener); | super(MatoAPIFetcher.QueryType.ARRIVALS, listener, errorListener); | ||||
this.stopName = stopName; | this.stopName = stopName; | ||||
this.startingTime = startingTime; | this.startingTime = startingTime; | ||||
Show All 24 Lines | public byte[] getBody() throws AuthFailureError { | ||||
data.put("variables", variables); | data.put("variables", variables); | ||||
data.put("query", MatoQueries.QUERY_ARRIVALS); | data.put("query", MatoQueries.QUERY_ARRIVALS); | ||||
} catch (JSONException e) { | } catch (JSONException e) { | ||||
e.printStackTrace(); | e.printStackTrace(); | ||||
throw new AuthFailureError("Error with JSON enconding",e); | throw new AuthFailureError("Error with JSON enconding",e); | ||||
} | } | ||||
String requestBody = data.toString(); | String requestBody = data.toString(); | ||||
Log.d("MapiArrivalBusTO", "Request variables: "+ variables); | Log.d(DEBUG_TAG, "Request variables: "+ variables); | ||||
return requestBody.getBytes(); | return requestBody.getBytes(); | ||||
} | } | ||||
@Override | @Override | ||||
protected Response<Palina> parseNetworkResponse(NetworkResponse response) { | protected Response<Palina> parseNetworkResponse(NetworkResponse response) { | ||||
if(response.statusCode != 200) { | if(response.statusCode != 200) { | ||||
reqRes.set(Fetcher.Result.SERVER_ERROR); | reqRes.set(Fetcher.Result.SERVER_ERROR); | ||||
Show All 17 Lines | protected Response<Palina> parseNetworkResponse(NetworkResponse response) { | ||||
//valid stop | //valid stop | ||||
stopFound = true; | stopFound = true; | ||||
break; | break; | ||||
} | } | ||||
} | } | ||||
} | } | ||||
if (!stopFound){ | if (!stopFound){ | ||||
Log.w("MapiArrival-Busto", "No stop found: "+p); | Log.w(DEBUG_TAG, "No stop found: "+p); | ||||
reqRes.set(Fetcher.Result.NOT_FOUND); | reqRes.set(Fetcher.Result.NOT_FOUND); | ||||
return Response.error(new VolleyError("Stop not found")); | return Response.error(new VolleyError("Stop not found")); | ||||
} | } | ||||
} catch (JSONException e) { | } catch (JSONException e) { | ||||
e.printStackTrace(); | e.printStackTrace(); | ||||
Log.e("BusTO:MapiRequest", "Error parsing JSON: "+stringResponse); | Log.e(DEBUG_TAG, "Error parsing JSON: "+stringResponse); | ||||
reqRes.set(Fetcher.Result.PARSER_ERROR); | reqRes.set(Fetcher.Result.PARSER_ERROR); | ||||
return Response.error(new VolleyError("Error parsing the response in JSON", | return Response.error(new VolleyError("Error parsing the response in JSON", | ||||
e)); | e)); | ||||
} | } | ||||
reqRes.set(Fetcher.Result.OK); | reqRes.set(Fetcher.Result.OK); | ||||
/* | |||||
for (Route r: p.queryAllRoutes()){ | |||||
Log.d(DEBUG_TAG, "route "+r.getGtfsId()+" has "+r.passaggi.size()+" passaggi"); | |||||
} | |||||
*/ | |||||
return Response.success(p, HttpHeaderParser.parseCacheHeaders(response)); | return Response.success(p, HttpHeaderParser.parseCacheHeaders(response)); | ||||
} | } | ||||
public class StopNotFoundError extends VolleyError{ | public class StopNotFoundError extends VolleyError{ | ||||
public StopNotFoundError(String message) { | public StopNotFoundError(String message) { | ||||
super(message); | super(message); | ||||
} | } | ||||
public StopNotFoundError() { | public StopNotFoundError() { | ||||
super(); | super(); | ||||
} | } | ||||
} | } | ||||
} | } |
Public contents are in Creative Commons Attribution-ShareAlike 4.0 (CC-BY-SA) or GNU Free Documentation License (at your option) unless otherwise noted. · Contact / Register