public static void getTrip(String id, String patternId, String calendarId, String agencyId) { if (agencyId == null) agencyId = session.get("agencyId"); if (agencyId == null) { badRequest(); return; } AgencyTx tx = VersionedDataStore.getAgencyTx(agencyId); try { if (id != null) { if (tx.trips.containsKey(id)) renderJSON(Base.toJson(tx.trips.get(id), false)); else notFound(); } else if (patternId != null && calendarId != null) { if (!tx.tripPatterns.containsKey(patternId) || !tx.calendars.containsKey(calendarId)) { notFound(); } else { renderJSON(Base.toJson(tx.getTripsByPatternAndCalendar(patternId, calendarId), false)); } } else if (patternId != null) { renderJSON(Base.toJson(tx.getTripsByPattern(patternId), false)); } else { renderJSON(Base.toJson(tx.trips.values(), false)); } } catch (Exception e) { tx.rollback(); e.printStackTrace(); badRequest(); } }