134 |
if (type == FetchTrainType.BOTH) { //if we have both S-tog and regional order by departure/arrival time |
if (type == FetchTrainType.BOTH) { //if we have both S-tog and regional order by departure/arrival time |
135 |
Collections.sort( departureBean.entries, departureTimeComparator); |
Collections.sort( departureBean.entries, departureTimeComparator); |
136 |
} |
} |
137 |
|
|
138 |
|
System.out.println("Trit: " + settings.isTritinfoEnabled() + " " + station.getTritStation() ); |
139 |
|
if ( settings.isTritinfoEnabled() && station.getTritStation() != -1) { |
140 |
|
try { |
141 |
|
injectTritinfoData(departureBean, station); |
142 |
|
} catch (Exception ex) { //det er ikke kritisk at vi får perron numre med |
143 |
|
ex.printStackTrace(); |
144 |
|
} |
145 |
|
} |
146 |
|
|
147 |
|
|
148 |
return departureBean; |
return departureBean; |
552 |
|
|
553 |
return number; |
return number; |
554 |
} |
} |
555 |
|
|
556 |
|
|
557 |
|
private void injectTritinfoData(DepartureBean departureBean, StationEntry station) throws Exception { |
558 |
|
String uri = "http://tritinfo.pallas.dk/webtavle?page=stationcontent&staid=" + station.getTritStation(); |
559 |
|
logger.fine("URI:" + uri); |
560 |
|
System.out.println("URI:" + uri); |
561 |
|
|
562 |
|
|
563 |
|
JsoupInvocation wrapper = new JsoupInvocation( new URL(uri), settings.getReplyTimeout() ); |
564 |
|
CircuitBreaker breaker = CircuitBreakerManager.getManager().getCircuitBreaker("tritinfo"); |
565 |
|
|
566 |
|
Element page = (Element) breaker.invoke(wrapper); |
567 |
|
|
568 |
|
Element table = page.getElementsByClass("passages").get(0); |
569 |
|
|
570 |
|
Elements trains = table.getElementsByClass("train"); |
571 |
|
|
572 |
|
for (int i=0; i<trains.size(); i++) { |
573 |
|
Element train = trains.get(i); |
574 |
|
|
575 |
|
//String trainType = train.getElementsByClass("trainType").get(0).text(); |
576 |
|
String trainNumber = train.getElementsByClass("trainNumber").get(0).text(); |
577 |
|
|
578 |
|
Elements trackElems = train.getElementsByClass("plannedTrack"); |
579 |
|
if (trackElems.size() == 0) { |
580 |
|
trackElems = train.getElementsByClass("expectedTrack"); |
581 |
|
} |
582 |
|
String track = trackElems.get(0).text(); |
583 |
|
String trackType = train.getElementsByClass("trackType").get(0).text(); |
584 |
|
|
585 |
|
|
586 |
|
String platform = track + " " + trackType; |
587 |
|
|
588 |
|
for (DepartureEntry entry : departureBean.entries) { |
589 |
|
String entryTrainId = entry.getTrainNumber().split(" ")[1]; |
590 |
|
if ( entryTrainId.equals(trainNumber)) { |
591 |
|
|
592 |
|
entry.setPlatform(platform); |
593 |
|
break; |
594 |
|
} |
595 |
|
} |
596 |
|
} |
597 |
|
} |
598 |
|
|
599 |
|
|
600 |
//test |
//test |