}
}
public static void createTrip() {
TripWithStopTimes tripWithStopTimes = null;
Trip trip = null;
try {
try {
tripWithStopTimes = mapper.readValue(params.get("body"), TripWithStopTimes.class);
} catch (Exception e) {
trip = mapper.readValue(params.get("body"), Trip.class);
}
if (tripWithStopTimes != null) {
trip = tripWithStopTimes.toTrip();
}
if(Route.findById(trip.pattern.route.id) == null)
badRequest();
// if endtime is before start time add a day (e.g 07:00-00:30 becomes 07:00-24:30)
if(trip != null && trip.useFrequency != null && trip.endTime != null && trip.useFrequency && trip.startTime != null && trip.endTime < trip.startTime) {
trip.endTime += (24 * 60 * 60 );
}
trip.save();
// check if gtfsRouteId is specified, if not create from DB id
if(trip.gtfsTripId == null) {
trip.gtfsTripId = "TRIP_" + trip.id.toString();
trip.save();
}
if (tripWithStopTimes != null && tripWithStopTimes.stopTimes != null) {
for (StopTimeWithDeletion stopTime: tripWithStopTimes.stopTimes) {
stopTime.trip = trip;