Ejemplo n.º 1
0
  public StopWithArrivalsAndDeparturesV2Bean getStopWithArrivalAndDepartures(
      StopWithArrivalsAndDeparturesBean sad) {
    StopWithArrivalsAndDeparturesV2Bean bean = new StopWithArrivalsAndDeparturesV2Bean();

    bean.setStopId(sad.getStop().getId());
    addToReferences(sad.getStop());

    List<ArrivalAndDepartureV2Bean> ads = new ArrayList<ArrivalAndDepartureV2Bean>();
    for (ArrivalAndDepartureBean ad : sad.getArrivalsAndDepartures())
      ads.add(getArrivalAndDeparture(ad));
    bean.setArrivalsAndDepartures(ads);

    List<String> nearbyStopIds = new ArrayList<String>();
    for (StopBean nearbyStop : sad.getNearbyStops()) {
      nearbyStopIds.add(nearbyStop.getId());
      addToReferences(nearbyStop);
    }
    bean.setNearbyStopIds(nearbyStopIds);

    List<ServiceAlertBean> situations = sad.getSituations();
    if (!CollectionsLibrary.isEmpty(situations)) {
      List<String> situationIds = new ArrayList<String>();
      for (ServiceAlertBean situation : situations) {
        addToReferences(situation);
        situationIds.add(situation.getId());
      }
      bean.setSituationIds(situationIds);
    }

    return bean;
  }
Ejemplo n.º 2
0
  public TripDetailsV2Bean getTripDetails(TripDetailsBean tripDetails) {

    TripDetailsV2Bean bean = new TripDetailsV2Bean();

    bean.setTripId(tripDetails.getTripId());
    bean.setServiceDate(tripDetails.getServiceDate());

    if (tripDetails.getFrequency() != null)
      bean.setFrequency(getFrequency(tripDetails.getFrequency()));

    TripBean trip = tripDetails.getTrip();
    if (trip != null) addToReferences(trip);

    TripStopTimesBean stopTimes = tripDetails.getSchedule();
    if (stopTimes != null) bean.setSchedule(getTripStopTimes(stopTimes));

    List<ServiceAlertBean> situations = tripDetails.getSituations();
    if (!CollectionsLibrary.isEmpty(situations)) {
      List<String> situationIds = new ArrayList<String>();
      for (ServiceAlertBean situation : situations) {
        addToReferences(situation);
        situationIds.add(situation.getId());
      }
      bean.setSituationIds(situationIds);
    }

    return bean;
  }
Ejemplo n.º 3
0
 public boolean isSituationExcludedForApplication(ServiceAlertBean situation) {
   List<SituationAffectsBean> affects = situation.getAllAffects();
   if (affects == null) return false;
   Set<String> applicationIds = new HashSet<String>();
   for (SituationAffectsBean affect : affects) {
     if (affect.getApplicationId() != null) applicationIds.add(affect.getApplicationId());
   }
   if (CollectionsLibrary.isEmpty(applicationIds)) return false;
   if (_applicationKey == null) return true;
   return !_applicationKey.contains(_applicationKey);
 }
  public TransitLegV2Bean getTransitLeg(TransitLegBean leg) {

    TransitLegV2Bean bean = new TransitLegV2Bean();

    TripBean trip = leg.getTrip();
    if (trip != null) {
      bean.setTripId(trip.getId());
      _factory.addToReferences(trip);
    }

    bean.setServiceDate(leg.getServiceDate());
    bean.setVehicleId(leg.getVehicleId());

    FrequencyBean frequency = leg.getFrequency();
    if (frequency != null) {
      FrequencyV2Bean freqBean = _factory.getFrequency(frequency);
      bean.setFrequency(freqBean);
    }

    StopBean fromStop = leg.getFromStop();
    if (fromStop != null) {
      bean.setFromStopId(fromStop.getId());
      bean.setFromStopSequence(leg.getFromStopSequence());
      _factory.addToReferences(fromStop);
    }

    bean.setScheduledDepartureTime(leg.getScheduledDepartureTime());
    bean.setPredictedDepartureTime(leg.getPredictedDepartureTime());
    bean.setScheduledDepartureInterval(
        _factory.getTimeInterval(leg.getScheduledDepartureInterval()));
    bean.setPredictedDepartureInterval(
        _factory.getTimeInterval(leg.getPredictedDepartureInterval()));

    StopBean toStop = leg.getToStop();
    if (toStop != null) {
      bean.setToStopId(toStop.getId());
      bean.setToStopSequence(leg.getToStopSequence());
      _factory.addToReferences(toStop);
    }

    bean.setScheduledArrivalTime(leg.getScheduledArrivalTime());
    bean.setPredictedArrivalTime(leg.getPredictedArrivalTime());
    bean.setScheduledArrivalInterval(_factory.getTimeInterval(leg.getScheduledArrivalInterval()));
    bean.setPredictedArrivalInterval(_factory.getTimeInterval(leg.getPredictedArrivalInterval()));

    bean.setRouteShortName(leg.getRouteShortName());
    bean.setRouteLongName(leg.getRouteLongName());
    bean.setTripHeadsign(leg.getTripHeadsign());
    bean.setPath(leg.getPath());

    List<ServiceAlertBean> situations = leg.getSituations();
    if (!CollectionsLibrary.isEmpty(situations)) {
      List<String> situationIds = new ArrayList<String>(situations.size());
      for (ServiceAlertBean situation : situations) {
        situationIds.add(situation.getId());
        _factory.addToReferences(situation);
      }
      bean.setSituationIds(situationIds);
    }

    return bean;
  }
Ejemplo n.º 5
0
 public void addToReferences(ServiceAlertBean situation) {
   if (isSituationExcludedForApplication(situation)) return;
   if (!shouldAddReferenceWithId(_references.getSituations(), situation.getId())) return;
   SituationV2Bean bean = getSituation(situation);
   _references.addSituation(bean);
 }
Ejemplo n.º 6
0
  public SituationV2Bean getSituation(ServiceAlertBean situation) {

    SituationV2Bean bean = new SituationV2Bean();

    bean.setId(situation.getId());
    bean.setCreationTime(situation.getCreationTime());

    if (!CollectionsLibrary.isEmpty(situation.getActiveWindows())) {
      List<TimeRangeV2Bean> activeWindows = new ArrayList<TimeRangeV2Bean>();
      for (TimeRangeBean activeWindow : situation.getActiveWindows())
        activeWindows.add(getTimeRange(activeWindow));
      bean.setActiveWindows(activeWindows);
    }

    if (!CollectionsLibrary.isEmpty(situation.getPublicationWindows())) {
      List<TimeRangeV2Bean> publicationWindows = new ArrayList<TimeRangeV2Bean>();
      for (TimeRangeBean publicationWindow : situation.getPublicationWindows())
        publicationWindows.add(getTimeRange(publicationWindow));
      bean.setPublicationWindows(publicationWindows);
    }

    if (!CollectionsLibrary.isEmpty(situation.getAllAffects())) {
      List<SituationAffectsV2Bean> affects = new ArrayList<SituationAffectsV2Bean>();
      for (SituationAffectsBean affect : situation.getAllAffects())
        affects.add(getSituationAffects(affect));
      bean.setAllAffects(affects);
    }

    if (!CollectionsLibrary.isEmpty(situation.getConsequences())) {
      List<SituationConsequenceV2Bean> beans = new ArrayList<SituationConsequenceV2Bean>();
      for (SituationConsequenceBean consequence : situation.getConsequences()) {
        SituationConsequenceV2Bean consequenceBean = getSituationConsequence(consequence);
        beans.add(consequenceBean);
      }
      bean.setConsequences(beans);
    }

    bean.setReason(situation.getReason());

    bean.setSummary(getBestString(situation.getSummaries()));
    bean.setDescription(getBestString(situation.getDescriptions()));
    bean.setUrl(getBestString(situation.getUrls()));

    ESeverity severity = situation.getSeverity();
    if (severity != null) {
      String[] codes = severity.getTpegCodes();
      bean.setSeverity(codes[0]);
    }

    return bean;
  }
Ejemplo n.º 7
0
  public ArrivalAndDepartureV2Bean getArrivalAndDeparture(ArrivalAndDepartureBean ad) {

    TripBean trip = ad.getTrip();
    RouteBean route = trip.getRoute();
    StopBean stop = ad.getStop();

    ArrivalAndDepartureV2Bean bean = new ArrivalAndDepartureV2Bean();

    bean.setTripId(trip.getId());
    addToReferences(trip);

    bean.setServiceDate(ad.getServiceDate());
    bean.setVehicleId(ad.getVehicleId());
    bean.setStopId(stop.getId());
    addToReferences(stop);
    bean.setStopSequence(ad.getStopSequence());
    bean.setBlockTripSequence(ad.getBlockTripSequence());

    bean.setRouteId(route.getId());
    addToReferences(route);

    String routeShortName = ad.getRouteShortName();
    if (routeShortName == null || routeShortName.isEmpty())
      routeShortName = trip.getRouteShortName();
    if (routeShortName == null || routeShortName.isEmpty()) routeShortName = route.getShortName();
    bean.setRouteShortName(routeShortName);

    bean.setRouteLongName(route.getLongName());

    String tripHeadsign = ad.getTripHeadsign();
    if (tripHeadsign == null || tripHeadsign.isEmpty()) tripHeadsign = trip.getTripHeadsign();
    bean.setTripHeadsign(tripHeadsign);

    bean.setArrivalEnabled(ad.isArrivalEnabled());
    bean.setDepartureEnabled(ad.isDepartureEnabled());

    bean.setScheduledArrivalTime(ad.getScheduledArrivalTime());
    bean.setScheduledDepartureTime(ad.getScheduledDepartureTime());

    bean.setScheduledArrivalInterval(getTimeInterval(ad.getScheduledArrivalInterval()));
    bean.setScheduledDepartureInterval(getTimeInterval(ad.getScheduledDepartureInterval()));

    if (ad.getFrequency() != null) bean.setFrequency(getFrequency(ad.getFrequency()));

    bean.setStatus(ad.getStatus());

    if (ad.isDistanceFromStopSet()) bean.setDistanceFromStop(ad.getDistanceFromStop());

    bean.setNumberOfStopsAway(ad.getNumberOfStopsAway());

    bean.setPredicted(ad.isPredicted());
    bean.setLastUpdateTime(ad.getLastUpdateTime());

    List<ServiceAlertBean> situations = ad.getSituations();
    if (situations != null && !situations.isEmpty()) {
      List<String> situationIds = new ArrayList<String>();
      for (ServiceAlertBean situation : situations) {
        situationIds.add(situation.getId());
        addToReferences(situation);
      }
      bean.setSituationIds(situationIds);
    }

    return bean;
  }