Package models.transit

Examples of models.transit.Trip


    public static void getTrip(Long id, Long patternId, Long calendarId, Long agencyId) {
        try {
            if(id != null)
            {
                Trip trip = Trip.findById(id);
                if(trip != null)
                    renderJSON(Api.toJson(trip, false));
                else
                    notFound();
            }
View Full Code Here


        }
    }
   
    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;
View Full Code Here

            // check if gtfsRouteId is specified, if not create from DB id
             if(trip.gtfsTripId == null) {
                trip.gtfsTripId = "TRIP_" + trip.id.toString();
            }

             Trip updatedTrip = Trip.em().merge(trip.toTrip());
            
            // update the stop times
            // TODO: how to detect deleted StopTimes (i.e. route no longer stops here)?
            for (StopTimeWithDeletion stopTime : trip.stopTimes) {
                if (Boolean.TRUE.equals(stopTime.deleted)) {
                    StopTime.delete("id = ? AND trip = ?", stopTime.id, updatedTrip);
                }
                else {
                    StopTime updatedStopTime = StopTime.em().merge(stopTime.toStopTime());
                    // this was getting lost somehow
                    updatedStopTime.trip = updatedTrip;
                    updatedStopTime.save();
                }
            }
           
            updatedTrip.save();

            renderJSON(Api.toJson(updatedTrip, false));
        } catch (Exception e) {
            e.printStackTrace();
            badRequest();
View Full Code Here

    public static void deleteTrip(Long id) {
        if(id == null)
            badRequest();

        Trip trip = Trip.findById(id);

        if(trip == null)
            badRequest();

        StopTime.delete("trip = ?", trip);
        trip.delete();

        ok();
    }
View Full Code Here

     */
    public static class TripWithStopTimes extends Trip {
        List<StopTimeWithDeletion> stopTimes;
       
        public Trip toTrip () {
            Trip ret = new Trip();
            ret.blockId = this.blockId;
            ret.endTime = this.endTime;
            ret.gtfsTripId = this.gtfsTripId;
            ret.headway = this.headway;
            ret.id = this.id;
View Full Code Here

             }
             else if(lineNum > 6)
             {
               if(!csvLine[0].isEmpty())
               {
                 Trip trip = new Trip();
                
                 trip.pattern = pattern;
                 trip.serviceCalendar = calendar;
                
                 trip.blockId = csvLine[2];
                 trip.tripHeadsign = csvLine[3];
                 trip.tripShortName = csvLine[4];
                
                 trip.useFrequency = false;
                
                 trip.save();
                
                 Integer firstTimepoint = null;
                 Integer columnCount = 0;
                 Integer previousTime = 0;
                 Integer dayOffset = 0;
View Full Code Here

TOP

Related Classes of models.transit.Trip

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.