Examples of AgencyAndId


Examples of org.onebusaway.gtfs.model.AgencyAndId

       
        for(ServiceCalendar calendar : calendars)
        {
          org.onebusaway.gtfs.model.ServiceCalendar c = new org.onebusaway.gtfs.model.ServiceCalendar();
         
          AgencyAndId calendarId = new AgencyAndId();
         
          calendarId.setAgencyId(gtfsAgencyId);
          calendarId.setId(calendar.getId().toString());
       
          c.setServiceId(calendarId);
         
          c.setStartDate(new ServiceDate(snapshotExport.calendarFrom)); // calendar.startDate

          c.setEndDate(new ServiceDate(snapshotExport.calendarTo)); // calendar.endDate
         
          c.setMonday(calendar.monday? 1 : 0);
          c.setTuesday(calendar.tuesday? 1 : 0);
          c.setWednesday(calendar.wednesday? 1 : 0);
          c.setThursday(calendar.thursday? 1 : 0);
          c.setFriday(calendar.friday? 1 : 0);
          c.setSaturday(calendar.saturday? 1 : 0);
          c.setSunday(calendar.sunday? 1 : 0);
       
          store.saveEntity(c);
         
          List<ServiceCalendarDate> calendarDates = ServiceCalendarDate.find("calendar = ?", calendar).fetch();
         
          for(ServiceCalendarDate calendarDate : calendarDates)
          {
            org.onebusaway.gtfs.model.ServiceCalendarDate cDate = new org.onebusaway.gtfs.model.ServiceCalendarDate();
           
            cDate.setServiceId(calendarId);
           
            cDate.setDate(new ServiceDate(calendarDate.date));
           
            cDate.setExceptionType(calendarDate.exceptionType == ServiceCalendarDateType.ADDED? 1 : 0);
           
            store.saveEntity(cDate);
          }
         
          List<Trip> trips = Trip.find("serviceCalendar = ?", calendar).fetch();
         
          for(Trip trip : trips)
          { 
            List<TripPatternStop> patternStopTimes = TripPatternStop.find("pattern = ? order by stopSequence", trip.pattern).fetch();
           
            if(trip.useFrequency == null || patternStopTimes == null || (trip.useFrequency && patternStopTimes.size() == 0) || !trip.pattern.route.agency.id.equals(agency.id) || (trip.useFrequency && trip.headway.equals(0)) || (trip.useFrequency && trip.startTime.equals(trip.endTime)))
              continue;

            if(!routeList.containsKey(trip.pattern.route.id))
            {
              Route route = trip.pattern.route;
             
              org.onebusaway.gtfs.model.Route r = new org.onebusaway.gtfs.model.Route();
             
              AgencyAndId routeId = new AgencyAndId();
             
              routeId.setAgencyId(gtfsAgencyId);
             
              if(route.gtfsRouteId != null && !route.gtfsRouteId.isEmpty())
                routeId.setId(route.gtfsRouteId);
              else
                routeId.setId(route.id.toString());
              Logger.info(gtfsAgencyId + " " + routeId);
              r.setId(routeId);
              r.setAgency(a);
             
              if(route.routeColor != null && !route.routeColor.isEmpty())
                r.setColor(route.routeColor.replace("#", ""));
             
              if(route.routeDesc != null)
                r.setDesc(route.routeDesc.replace("\n", "").replace("\r", ""));
             
              r.setLongName(route.routeLongName);
              r.setShortName(route.routeShortName);
              r.setType(Route.mapGtfsRouteType(route.routeType));
              r.setUrl(route.routeUrl);
             
              store.saveEntity(r);
             
              routeList.put(route.id, r);
            }
           
            if(trip.pattern.shape != null && !shapeList.containsKey(trip.pattern.shape.id))
            {
              TripShape shape = trip.pattern.shape;
             
              AgencyAndId shapeId = new AgencyAndId();
             
              shapeId.setAgencyId(gtfsAgencyId);
              shapeId.setId(shape.id.toString());
             
              int sequence = 0;
             
              for(Coordinate coordinate : shape.shape.getCoordinates())
              {
                org.onebusaway.gtfs.model.ShapePoint coord = new org.onebusaway.gtfs.model.ShapePoint();
               
                coord.setShapeId(shapeId);
               
                coord.setLon(coordinate.x);
                coord.setLat(coordinate.y);
                coord.setSequence(sequence);
               
                sequence++;
               
                store.saveEntity(coord);
              }
             
              shapeList.put(shape.id, shapeId);
            }
           
           
           
           
            org.onebusaway.gtfs.model.Trip t = new org.onebusaway.gtfs.model.Trip();
           
            AgencyAndId tripId = new AgencyAndId();
           
            tripId.setAgencyId(gtfsAgencyId);
            tripId.setId(trip.getId().toString());
           
            t.setId(tripId);
            t.setRoute(routeList.get(trip.pattern.route.id));
            t.setRouteShortName(trip.pattern.route.routeShortName);
            t.setTripHeadsign(trip.pattern.name);
            t.setServiceId(calendarId);
           
            if(trip.wheelchairBoarding != null){
              if(trip.wheelchairBoarding.equals(AttributeAvailabilityType.AVAILABLE))
                t.setWheelchairAccessible(1);
              else if(trip.wheelchairBoarding.equals(AttributeAvailabilityType.UNAVAILABLE))
                t.setWheelchairAccessible(2);
              else
                t.setWheelchairAccessible(0);
            }
            else if(trip.pattern.route.wheelchairBoarding != null) {
              if(trip.pattern.route.wheelchairBoarding.equals(AttributeAvailabilityType.AVAILABLE))
                t.setWheelchairAccessible(1);
              else if(trip.pattern.route.wheelchairBoarding.equals(AttributeAvailabilityType.UNAVAILABLE))
                t.setWheelchairAccessible(2);
              else
                t.setWheelchairAccessible(0);
             
            }
           
            if(trip.pattern.shape != null)
              t.setShapeId(shapeList.get(trip.pattern.shape.id));
            else
              Logger.error("trip " + trip.tripHeadsign + " is missing shape");
           
            t.setBlockId(trip.blockId);
           
            store.saveEntity(t);
           
           
           
           
            if(trip.useFrequency != null && trip.useFrequency && trip.headway > 0)
            {
              org.onebusaway.gtfs.model.Frequency f = new org.onebusaway.gtfs.model.Frequency();
                     
              f.setTrip(t);
             
              f.setStartTime(trip.startTime);
              f.setEndTime(trip.endTime);
              f.setHeadwaySecs(trip.headway);
             
              store.saveEntity(f);
             
             
             
              Integer cumulativeTime = 0;
             
              for(TripPatternStop stopTime : patternStopTimes)
              {
                if(!stopList.containsKey(stopTime.stop.id))
                {
                  Stop stop = stopTime.stop;
                 
                  AgencyAndId stopId = new AgencyAndId();
                 
                  stopId.setAgencyId(gtfsAgencyId);
             
                  if(stop.gtfsStopId != null && !stop.gtfsStopId.isEmpty())
                    stopId.setId(stop.gtfsStopId);
                  else
                    stopId.setId("STOP_" + stop.id.toString());
                 
                  org.onebusaway.gtfs.model.Stop s = new org.onebusaway.gtfs.model.Stop();
                 
                  s.setId(stopId);
                 
                  s.setCode(stop.stopCode);
                 
                  if(stop.stopName == null || stop.stopName.isEmpty())
                    s.setName(stop.id.toString());
                  else
                    s.setName(stop.stopName.replace("\n", "").replace("\r", ""));
                 
                  if(stop.stopDesc != null && !stop.stopName.isEmpty())
                    s.setDesc(stop.stopDesc.replace("\n", "").replace("\r", ""));
                 
                  s.setUrl(stop.stopUrl);
                 
                  s.setLon(stop.locationPoint().getX());
                  s.setLat(stop.locationPoint().getY());
                 
                 
                  if(stop.wheelchairBoarding != null && stop.wheelchairBoarding.equals(AttributeAvailabilityType.AVAILABLE))
                    s.setWheelchairBoarding(1);
                  else if(stop.wheelchairBoarding != null && stop.wheelchairBoarding.equals(AttributeAvailabilityType.UNAVAILABLE))
                    s.setWheelchairBoarding(2);
                  else
                    s.setWheelchairBoarding(0);
                 
                  store.saveEntity(s);
                                 
                  stopList.put(stop.id, s);
                }
               
                org.onebusaway.gtfs.model.StopTime st = new org.onebusaway.gtfs.model.StopTime();
               
                if(stopTime.defaultTravelTime != null) {
                 
                  // need to flag negative travel times in the patterns!
                  if(stopTime.defaultTravelTime < 0)
                    cumulativeTime -= stopTime.defaultTravelTime;
                  else
                    cumulativeTime += stopTime.defaultTravelTime; 
                }
                 
               
                st.setArrivalTime(cumulativeTime);
               
                if(stopTime.defaultDwellTime != null) {
                 
                  // need to flag negative dwell times in the patterns!
                  if(stopTime.defaultDwellTime < 0)
                    cumulativeTime -= stopTime.defaultDwellTime;
                  else
                    cumulativeTime += stopTime.defaultDwellTime;
                }
                 
               
                st.setDepartureTime(cumulativeTime);
               
                st.setTrip(t);
                st.setStop(stopList.get(stopTime.stop.id));
                st.setStopSequence(stopTime.stopSequence);
         
                     
                store.saveEntity(st);
              }

            }
            else
            {
           
              List<StopTime> stopTimes = StopTime.find("trip = ? order by stopSequence", trip).fetch();
             
              for(StopTime stopTime : stopTimes)
              {
                if(!stopList.containsKey(stopTime.stop.id))
                {
                  Stop stop = stopTime.stop;
                 
                  AgencyAndId stopId = new AgencyAndId();
                 
                  stopId.setAgencyId(gtfsAgencyId);
                 
                  if(stop.gtfsStopId != null && !stop.gtfsStopId.isEmpty())
                    stopId.setId(stop.gtfsStopId);
                  else
                    stopId.setId(stop.id.toString());
                 
                  org.onebusaway.gtfs.model.Stop s = new org.onebusaway.gtfs.model.Stop();
                 
                  s.setId(stopId);
                 
View Full Code Here

Examples of org.onebusaway.gtfs.model.AgencyAndId

        String id = journey.getOperatorId() + "-"
            + journey.getJourneyIdentifier();
        if (journies.size() > 1) {
          id += "-" + i;
        }
        trip.setId(new AgencyAndId(journey.getOperatorId(), id));
        trip.setRoute(getRouteForJourney(journey));
        trip.setServiceId(getServiceIdForJourney(journey));

        AgencyAndId routeId = trip.getRoute().getId();
        RouteMetadata metadata = getMetadataForRouteId(routeId);

        String directionName = metadata.getDirectionNameForDirectionId(journey.getRouteDirection());
        if (!isEmpty(directionName)) {
          trip.setTripHeadsign(directionName);
View Full Code Here

Examples of org.onebusaway.gtfs.model.AgencyAndId

    }
    return metadata;
  }

  private Route getRouteForJourney(JourneyHeaderElement journey) {
    AgencyAndId routeId = getRouteIdForJourney(journey);
    Route route = _dao.getRouteForId(routeId);
    if (route == null) {
      route = new Route();
      route.setAgency(getAgencyForId(routeId.getAgencyId()));
      route.setId(routeId);
      route.setShortName(journey.getRouteIdentifier());
      route.setType(getRouteTypeForJourney(journey));
      RouteMetadata metaData = _routeMetadataById.get(routeId);
      if (metaData != null) {
View Full Code Here

Examples of org.onebusaway.gtfs.model.AgencyAndId

  private AgencyAndId getRouteId(String operatorId, String routeId) {
    // Note that we include the operator id in the id portion as well
    // because
    // the route identifiers are not unique by themselves in the output
    // GTFS.
    return new AgencyAndId(operatorId, operatorId + "-" + routeId);
  }
View Full Code Here

Examples of org.onebusaway.gtfs.model.AgencyAndId

              + desc);
    }
  }

  private AgencyAndId getServiceIdForJourney(JourneyHeaderElement journey) {
    AgencyAndId serviceId = constructServiceIdForJourney(journey);
    ServiceCalendar calendar = _dao.getCalendarForServiceId(serviceId);
    if (calendar == null) {
      calendar = new ServiceCalendar();
      calendar.setServiceId(serviceId);
      calendar.setStartDate(getServiceDate(journey.getStartDate()));
View Full Code Here

Examples of org.onebusaway.gtfs.model.AgencyAndId

    }
    throw new AtcoCifException("no stop found with id " + stopId);
  }

  private Stop getNaptanStop(NaPTANStop naptanStop) {
    AgencyAndId id = id(naptanStop.getAtcoCode());
    Stop stop = _dao.getStopForId(id);
    if (stop == null) {
      stop = new Stop();
      stop.setId(id);
      stop.setName(naptanStop.getCommonName());
View Full Code Here

Examples of org.onebusaway.gtfs.model.AgencyAndId

    return location;
  }

  private Stop getAtcoStop(LocationElement location) {
    String locationId = location.getLocationId();
    AgencyAndId id = id(locationId);
    Stop stop = _dao.getStopForId(id);
    if (stop == null) {
      LocationProvider locationSource = _additionalLocationById.get(locationId);
      if (locationSource == null) {
        throw new AtcoCifException("found location with id=" + locationId
            + " but no additional location information found");
      }

      LocationProvider nxLocationSource = _nxLocationGeoDetailById.get(locationId);
      if (nxLocationSource != null) {
        locationSource = nxLocationSource;
      }

      if (locationSource.getLat() == 0.0 || locationSource.getLon() == 0.0) {
        if (_stopsWithNoLocationInfo.add(locationId)) {
          _log.info("stop with no location: " + locationId);
          _prunedStopsWithNoLocationInfoCount++;
        }
        if (!_keepStopsWithNoLocationInfo) {
          return null;
        }
      }
      String name = location.getName();
      NationalExpressLocationNameElement nxNameElement = _nxLocationNamesById.get(locationId);
      if (nxNameElement != null && !nxNameElement.getShortName().isEmpty()) {
        name = nxNameElement.getShortName();
      }

      stop = new Stop();
      stop.setId(id(locationId));
      stop.setName(name);
      stop.setLat(locationSource.getLat());
      stop.setLon(locationSource.getLon());

      String clusterId = _clusterIdByLocationId.get(locationId);
      if (clusterId != null) {
        AgencyAndId stationId = id(clusterId + "-station");
        stop.setParentStation(stationId.getId());
        List<Stop> stops = _stopsByClusterId.get(clusterId);
        if (stops == null) {
          stops = new ArrayList<Stop>();
          _stopsByClusterId.put(clusterId, stops);
        }
View Full Code Here

Examples of org.onebusaway.gtfs.model.AgencyAndId

    return stop;
  }

  private Stop getGreaterManchesterRowListStop(
      GreaterManchesterTimetableRowListElement rowList) {
    AgencyAndId id = id(rowList.getLocationReference());
    Stop stop = _dao.getStopForId(id);
    if (stop == null) {
      stop = new Stop();
      stop.setId(id);
      stop.setName(rowList.getFullLocation());
View Full Code Here

Examples of org.onebusaway.gtfs.model.AgencyAndId

      applicableFiles.add(path);
    }
  }

  private AgencyAndId id(String id) {
    return new AgencyAndId(_agencyId, id);
  }
View Full Code Here

Examples of org.onebusaway.gtfs.model.AgencyAndId

    @Override
    public void startElement(Element element) {
      if (element instanceof JourneyHeaderElement) {
        JourneyHeaderElement journey = (JourneyHeaderElement) element;
        AgencyAndId journeyId = new AgencyAndId(journey.getOperatorId(),
            journey.getJourneyIdentifier());
        List<JourneyHeaderElement> journies = _journeysById.get(journeyId);
        if (journies == null) {
          journies = new ArrayList<JourneyHeaderElement>();
          _journeysById.put(journeyId, journies);
        }
        journies.add(journey);
        AgencyAndId routeId = getRouteIdForJourney(journey);
        RouteMetadata metadata = getMetadataForRouteId(routeId);
        metadata.addDirection(journey.getRouteDirection());
      } else if (element instanceof LocationElement) {
        LocationElement location = (LocationElement) element;
        _locationById.put(location.getLocationId(), location);
      } else if (element instanceof AdditionalLocationElement) {
        AdditionalLocationElement location = (AdditionalLocationElement) element;
        _additionalLocationById.put(location.getLocationId(), location);
      } else if (element instanceof ClusterElement) {
        ClusterElement cluster = (ClusterElement) element;
        _clusterIdByLocationId.put(cluster.getLocationId(), cluster.getId());
      } else if (element instanceof VehicleTypeElement) {
        VehicleTypeElement vehicle = (VehicleTypeElement) element;
        _vehicleTypesById.put(vehicle.getId(), vehicle);
      } else if (element instanceof RouteDescriptionElement) {
        RouteDescriptionElement route = (RouteDescriptionElement) element;
        AgencyAndId id = new AgencyAndId(route.getOperatorId(),
            route.getOperatorId() + "-" + route.getRouteNumber());
        RouteMetadata metadata = getMetadataForRouteId(id);
        metadata.addRouteDescription(route);
      } else if (element instanceof OperatorElement) {
        OperatorElement operator = (OperatorElement) element;
        OperatorElement existing = _operatorsById.put(operator.getOperatorId(),
            operator);
        if (existing != null) {
          _log.info("!");
        }
      } else if (element instanceof NationalExpressLocationNameElement) {
        NationalExpressLocationNameElement nxNameElement = (NationalExpressLocationNameElement) element;
        _nxLocationNamesById.put(nxNameElement.getLocationId(), nxNameElement);
      } else if (element instanceof NationalExpressLocationGeoDetailElement) {
        NationalExpressLocationGeoDetailElement nxGeoDetailElement = (NationalExpressLocationGeoDetailElement) element;
        _nxLocationGeoDetailById.put(nxGeoDetailElement.getLocationId(),
            nxGeoDetailElement);
      } else if (element instanceof NationalExpressOperatorElement) {
        NationalExpressOperatorElement nxElement = (NationalExpressOperatorElement) element;
        _nxOperatorsById.put(nxElement.getId(), nxElement);
      } else if (element instanceof NationalExpressRouteDetailsElement) {
        NationalExpressRouteDetailsElement details = (NationalExpressRouteDetailsElement) element;
        AgencyAndId routeId = getRouteId(details.getOperatorId(),
            details.getRouteId());
        RouteMetadata metadata = getMetadataForRouteId(routeId);
        metadata.addNXRouteDetails(details);
      } else if (element instanceof GreaterManchesterTimetableRowListElement) {
        GreaterManchesterTimetableRowListElement rowList = (GreaterManchesterTimetableRowListElement) element;
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.