2
2
3
3
import org .apache .http .NameValuePair ;
4
4
import org .apache .http .client .utils .URLEncodedUtils ;
5
+ import org .bson .codecs .pojo .annotations .BsonIgnore ;
5
6
import org .bson .conversions .Bson ;
6
7
import org .opentripplanner .middleware .auth .Auth0UserProfile ;
7
8
import org .opentripplanner .middleware .auth .Permission ;
@@ -136,17 +137,22 @@ public class MonitoredTrip extends Model {
136
137
*/
137
138
public boolean notifyOnItineraryChange = true ;
138
139
139
- private transient JourneyState journeyState ;
140
-
141
- private transient List <NameValuePair > parsedParams ;
142
-
143
140
public MonitoredTrip () {
144
141
}
145
142
146
- public MonitoredTrip (OtpDispatcherResponse otpDispatcherResponse ) {
143
+ public MonitoredTrip (OtpDispatcherResponse otpDispatcherResponse ) throws URISyntaxException {
147
144
queryParams = otpDispatcherResponse .requestUri .getQuery ();
148
145
TripPlan plan = otpDispatcherResponse .getResponse ().plan ;
149
146
itinerary = plan .itineraries .get (0 );
147
+
148
+ // extract trip time from parsed params
149
+ List <NameValuePair > parsedParams = getParsedParams ();
150
+ for (NameValuePair parsedParam : parsedParams ) {
151
+ if (parsedParam .getName ().equals ("time" )) {
152
+ tripTime = parsedParam .getValue ();
153
+ break ;
154
+ }
155
+ }
150
156
initializeFromItinerary ();
151
157
}
152
158
@@ -250,10 +256,8 @@ private Bson tripIdFilter() {
250
256
* Get the journey state for this trip.
251
257
*/
252
258
public JourneyState retrieveJourneyState () {
253
- // first return the journeyState for this trip if it has already been fetched
254
- if (journeyState != null ) return journeyState ;
255
- // hasn't been fetched, attempt to retrieve from the db
256
- journeyState = Persistence .journeyStates .getOneFiltered (tripIdFilter ());
259
+ // attempt to retrieve from the db
260
+ JourneyState journeyState = Persistence .journeyStates .getOneFiltered (tripIdFilter ());
257
261
// If journey state does not exist, create and persist.
258
262
if (journeyState == null ) {
259
263
journeyState = new JourneyState (this );
@@ -300,19 +304,14 @@ public boolean delete() {
300
304
}
301
305
302
306
public List <NameValuePair > getParsedParams () throws URISyntaxException {
303
- // use the transient value of parsedParams if it is available
304
- if (parsedParams != null ) return parsedParams ;
305
-
306
- // need to parse the params
307
- parsedParams = URLEncodedUtils .parse (
307
+ return URLEncodedUtils .parse (
308
308
new URI (String .format ("http://example.com/%s" , queryParams )),
309
309
UTF_8
310
310
);
311
- return parsedParams ;
312
311
}
313
312
314
313
public boolean isArriveBy () throws URISyntaxException {
315
- for (NameValuePair param : parsedParams ) {
314
+ for (NameValuePair param : getParsedParams () ) {
316
315
if (param .getName ().equals ("arriveBy" )) {
317
316
return param .getValue ().equals ("true" );
318
317
}
@@ -328,6 +327,7 @@ public boolean isArriveBy() throws URISyntaxException {
328
327
* use the local time at the destination. Therefore, this method will return the timezone at the destination if this
329
328
* trip is an arriveBy trip, or the timezone at the origin if the trip is a depart at trip.
330
329
*/
330
+ @ BsonIgnore
331
331
public ZoneId getTimezoneForTargetLocation () throws URISyntaxException {
332
332
double lat , lon ;
333
333
if (isArriveBy ()) {
@@ -353,13 +353,15 @@ public ZoneId getTimezoneForTargetLocation() throws URISyntaxException {
353
353
/**
354
354
* Returns the target hour of the day that the trip is either departing at or arriving by
355
355
*/
356
+ @ BsonIgnore
356
357
public int getHour () {
357
358
return Integer .valueOf (tripTime .split (":" )[0 ]);
358
359
}
359
360
360
361
/**
361
362
* Returns the target minute of the hour that the trip is either departing at or arriving by
362
363
*/
364
+ @ BsonIgnore
363
365
public int getMinute () {
364
366
return Integer .valueOf (tripTime .split (":" )[1 ]);
365
367
}
0 commit comments