41 |
Map<String, DepartureBean> cache; |
Map<String, DepartureBean> cache; |
42 |
|
|
43 |
StationDAO stationDao = new StationDAO(); |
StationDAO stationDao = new StationDAO(); |
44 |
|
TritinfoFetcher tritinfo; |
45 |
|
|
46 |
|
|
47 |
private TraininfoSettings settings; |
private TraininfoSettings settings; |
83 |
public DepartureFetcher(TraininfoSettings settings) { |
public DepartureFetcher(TraininfoSettings settings) { |
84 |
this.settings = settings; |
this.settings = settings; |
85 |
cache = new TimeoutMap<String,DepartureBean>( settings.getCacheTimeout() ); |
cache = new TimeoutMap<String,DepartureBean>( settings.getCacheTimeout() ); |
86 |
|
|
87 |
|
tritinfo = new TritinfoFetcher(settings); |
88 |
} |
} |
89 |
|
|
90 |
|
|
141 |
//System.out.println("Trit: " + settings.isTritinfoEnabled() + " " + station.getTritStation() ); |
//System.out.println("Trit: " + settings.isTritinfoEnabled() + " " + station.getTritStation() ); |
142 |
if ( settings.isTritinfoEnabled() && station.getTritStation() != -1) { |
if ( settings.isTritinfoEnabled() && station.getTritStation() != -1) { |
143 |
try { |
try { |
144 |
injectTritinfoData(departureBean, station); |
tritinfo.injectTritinfoData(departureBean, station); |
145 |
} catch (Exception ex) { //det er ikke kritisk at vi får perron numre med |
} catch (Exception ex) { //det er ikke kritisk at vi får perron numre med |
146 |
logger.warning("tritinfo failed with " + ex.getClass().getName() + ": " + ex.getMessage() ); |
logger.warning("tritinfo failed with " + ex.getClass().getName() + ": " + ex.getMessage() ); |
147 |
} |
} |
556 |
return number; |
return number; |
557 |
} |
} |
558 |
|
|
|
|
|
|
private void injectTritinfoData(DepartureBean departureBean, StationEntry station) throws Exception { |
|
|
String uri = "http://tritinfo.pallas.dk/webtavle?page=stationcontent&staid=" + station.getTritStation(); |
|
|
logger.fine("URI:" + uri); |
|
|
|
|
|
|
|
|
JsoupInvocation wrapper = new JsoupInvocation( new URL(uri), settings.getReplyTimeout() ); |
|
|
CircuitBreaker breaker = CircuitBreakerManager.getManager().getCircuitBreaker("tritinfo"); |
|
|
|
|
|
Element page = (Element) breaker.invoke(wrapper); |
|
|
|
|
|
Element table = page.getElementsByClass("passages").get(0); |
|
|
|
|
|
Elements trains = table.getElementsByClass("train"); |
|
|
|
|
|
for (int i=0; i<trains.size(); i++) { |
|
|
Element train = trains.get(i); |
|
|
|
|
|
//String trainType = train.getElementsByClass("trainType").get(0).text(); |
|
|
String trainNumber = train.getElementsByClass("trainNumber").get(0).text(); |
|
|
|
|
|
Elements trackElems = train.getElementsByClass("plannedTrack"); |
|
|
if (trackElems.size() == 0) { |
|
|
trackElems = train.getElementsByClass("expectedTrack"); |
|
|
} |
|
|
String track = trackElems.get(0).text().trim(); |
|
|
String trackType = train.getElementsByClass("trackType").get(0).text().trim(); |
|
|
|
|
|
|
|
|
String platform = track; |
|
|
if ( !trackType.equals("")) { |
|
|
platform += trackType; |
|
|
} |
|
|
|
|
|
for (DepartureEntry entry : departureBean.entries) { |
|
|
String entryTrainId = entry.getTrainNumber().split(" ")[1]; |
|
|
if ( entryTrainId.equals(trainNumber)) { |
|
|
|
|
|
entry.setPlatform(platform); |
|
|
break; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
559 |
|
|
560 |
|
|
561 |
//test |
//test |