Skip to content

Commit

Permalink
temporary solution for NullPointerExceptions during GTFS file processing
Browse files Browse the repository at this point in the history
  • Loading branch information
evyatark committed Mar 22, 2019
1 parent d733d74 commit b37cf70
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,13 @@

import il.org.hasadna.siri_client.gtfs.crud.*;
import il.org.hasadna.siri_client.gtfs.crud.Calendar;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class GtfsDataManipulations {

private static Logger logger = LoggerFactory.getLogger(GtfsDataManipulations.class);

private GtfsCrud gtfsCrud;

private Map<ServiceId, Calendar> calendars;
Expand Down Expand Up @@ -123,6 +127,7 @@ public Collection<GtfsRecord> combineForSpecificRoute(LocalDate date, String rou
}

private GtfsRecord createGtfsRecord(Trip currTrip) {
try {
Calendar currCalendar = getCalendars().get(currTrip.getServiceId());

List<StopTime> tmpStopTimes = getStopTimes().get(currTrip.getTripId());
Expand All @@ -133,6 +138,12 @@ private GtfsRecord createGtfsRecord(Trip currTrip) {
StopTime currFirstStopTime = tmpStopTimes.stream().min(Comparator.comparing(StopTime::getStopSequence)).get();
Stop currFirstStop = getStops().get(currFirstStopTime.getStopId());
return new GtfsRecord(currTrip, currCalendar, currFirstStopTime, currFirstStop, currLastStopTime, currLastStop);
}
catch (Exception ex) {
logger.error("unexpected exception in createGtfsRecord", ex);
logger.error("currTrip: {}", currTrip.toString());
return null;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,15 @@ public SchedulingDataCreator() {
Function<GtfsRecord, String> f = new Function<GtfsRecord, String>() {
@Override
public String apply(GtfsRecord gtfsRecord) {
return gtfsRecord.getTrip().getRouteId();
if (gtfsRecord != null) {
return gtfsRecord.getTrip().getRouteId();
}
else {
logger.warn("null gtfsRecord!");
// returning some dummy routeId. So grouping will work, and all failed records will be grouped to routeId "99999999"
// which does not exist anyway
return "99999999999";
}
}
};

Expand Down

0 comments on commit b37cf70

Please sign in to comment.