--- android/TrainInfoService/src/dk/thoerup/traininfoservice/banedk/DepartureFetcher.java 2011/03/31 17:13:19 1248 +++ android/TrainInfoService/src/dk/thoerup/traininfoservice/banedk/DepartureFetcher.java 2011/04/19 15:07:23 1305 @@ -16,8 +16,9 @@ import dk.thoerup.android.traininfo.common.StationBean.StationEntry; import dk.thoerup.circuitbreaker.CircuitBreaker; import dk.thoerup.circuitbreaker.CircuitBreakerManager; -import dk.thoerup.traininfoservice.StationDAO; import dk.thoerup.traininfoservice.Statistics; +import dk.thoerup.traininfoservice.TraininfoSettings; +import dk.thoerup.traininfoservice.db.StationDAO; public class DepartureFetcher { @@ -38,13 +39,12 @@ StationDAO stationDao = new StationDAO(); - private boolean useAzureSite; - private int replyTimeout; + + private TraininfoSettings settings; - public DepartureFetcher(boolean azureSite, int cacheTimeout, int replyTimeout) { - this.replyTimeout = replyTimeout; - useAzureSite = azureSite; - cache = new TimeoutMap(cacheTimeout); + public DepartureFetcher(TraininfoSettings settings) { + this.settings = settings; + cache = new TimeoutMap( settings.getCacheTimeout() ); } @@ -75,7 +75,7 @@ StationEntry station = stationDao.getById(stationID); departureBean.stationName = station.getName(); - + if (station.getRegional() != null && (type == FetchTrainType.REGIONAL||type == FetchTrainType.BOTH) ) { DepartureBean tempBean = lookupDepartures(station.getRegional(), TrainType.REGIONAL, arrival); departureBean.entries.addAll( tempBean.entries ); @@ -92,14 +92,16 @@ logger.info("No departures found for station " + stationID); } - Collections.sort( departureBean.entries ); + if (type == FetchTrainType.BOTH) { //if we have both S-tog and regional order by departure/arrival time + Collections.sort( departureBean.entries ); + } return departureBean; } public DepartureBean lookupDepartures(String stationcode, TrainType type, boolean arrival) throws Exception { - if (useAzureSite == true) { + if ( settings.getUseAzureSite() == true) { return lookupDeparturesAzureSite(stationcode, type, arrival); } else { return lookupDeparturesWwwSite(stationcode, type, arrival); @@ -141,7 +143,7 @@ String uri = "http://trafikinfo.bane.dk/Trafikinformation/AfgangAnkomst/" + arrivalDeparture + "/" + stationcode + "/" + typeString + "/UdvidetVisning"; logger.fine("URI: " + uri); - JsoupInvocation wrapper = new JsoupInvocation( new URL(uri), replyTimeout); + JsoupInvocation wrapper = new JsoupInvocation( new URL(uri), settings.getReplyTimeout() ); CircuitBreaker breaker = CircuitBreakerManager.getManager().getCircuitBreaker("banedk"); Document page = (Document) breaker.invoke(wrapper); @@ -247,7 +249,7 @@ logger.fine("URI:" + uri); - JsoupInvocation wrapper = new JsoupInvocation( new URL(uri), replyTimeout); + JsoupInvocation wrapper = new JsoupInvocation( new URL(uri), settings.getReplyTimeout() ); CircuitBreaker breaker = CircuitBreakerManager.getManager().getCircuitBreaker("banedk"); Element page = (Element) breaker.invoke(wrapper);