Esempio n. 1
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;
  }
  public LegBean reverseLeg(LegV2Bean bean) {

    LegBean leg = new LegBean();

    leg.setStartTime(bean.getStartTime());
    leg.setEndTime(bean.getEndTime());
    leg.setFrom(_factory.reversePoint(bean.getFrom()));
    leg.setTo(_factory.reversePoint(bean.getTo()));
    leg.setDistance(bean.getDistance());
    if (_factory.isStringSet(bean.getMode())) leg.setMode(bean.getMode());

    TransitLegV2Bean transitLegBean = bean.getTransitLeg();
    if (transitLegBean != null) {
      TransitLegBean transitLeg = reverseTransitLeg(transitLegBean);
      leg.setTransitLeg(transitLeg);
    }

    List<StreetLegV2Bean> streetLegBeans = bean.getStreetLegs();
    if (!CollectionsLibrary.isEmpty(streetLegBeans)) {
      List<StreetLegBean> streetLegs = new ArrayList<StreetLegBean>();
      for (StreetLegV2Bean streetLegBean : streetLegBeans) {
        StreetLegBean streetLeg = reverseStreetLeg(streetLegBean);
        streetLegs.add(streetLeg);
      }
      leg.setStreetLegs(streetLegs);
    }

    return leg;
  }
  public LegV2Bean getLeg(LegBean leg) {

    LegV2Bean bean = new LegV2Bean();

    bean.setStartTime(leg.getStartTime());
    bean.setEndTime(leg.getEndTime());
    bean.setFrom(_factory.getPoint(leg.getFrom()));
    bean.setTo(_factory.getPoint(leg.getTo()));
    bean.setDistance(leg.getDistance());
    bean.setMode(leg.getMode());

    TransitLegBean transitLeg = leg.getTransitLeg();
    if (transitLeg != null) {
      TransitLegV2Bean transitLegBean = getTransitLeg(transitLeg);
      bean.setTransitLeg(transitLegBean);
    }

    List<StreetLegBean> streetLegs = leg.getStreetLegs();
    if (!CollectionsLibrary.isEmpty(streetLegs)) {
      List<StreetLegV2Bean> streetLegBeans = new ArrayList<StreetLegV2Bean>();
      for (StreetLegBean streetLeg : streetLegs) {
        StreetLegV2Bean streetLegBean = getStreetLeg(streetLeg);
        streetLegBeans.add(streetLegBean);
      }
      bean.setStreetLegs(streetLegBeans);
    }

    return bean;
  }
Esempio n. 4
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;
  }
Esempio n. 5
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;
  }
Esempio n. 6
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 ItineraryBean reverseItinerary(ItineraryV2Bean bean) {
   if (bean == null) return null;
   ItineraryBean itinerary = new ItineraryBean();
   itinerary.setStartTime(bean.getStartTime());
   itinerary.setEndTime(bean.getEndTime());
   itinerary.setProbability(bean.getProbability());
   List<LegV2Bean> legBeans = bean.getLegs();
   if (!CollectionsLibrary.isEmpty(legBeans)) {
     List<LegBean> legs = new ArrayList<LegBean>();
     for (LegV2Bean legBean : legBeans) {
       LegBean leg = reverseLeg(legBean);
       legs.add(leg);
     }
     itinerary.setLegs(legs);
   }
   return itinerary;
 }
  @PostConstruct
  public void start() {

    List<Module> modules = new ArrayList<Module>();
    modules.addAll(SiriCoreModule.getModules());
    Injector injector = Guice.createInjector(modules);

    _client = injector.getInstance(SiriClient.class);
    _lifecycleService = injector.getInstance(LifecycleService.class);

    _client.addServiceDeliveryHandler(_handler);

    if (_clientUrl != null) _client.setUrl(_clientUrl);
    if (_logRawXmlType != null) _client.setLogRawXmlType(_logRawXmlType);

    _lifecycleService.start();

    if (!CollectionsLibrary.isEmpty(_endpoints)) {

      SiriClientRequestFactory factory = new SiriClientRequestFactory();

      for (String endpoint : _endpoints) {

        Map<String, String> args = SiriLibrary.getLineAsMap(endpoint);
        SiriClientRequest request = factory.createSubscriptionRequest(args);

        SiriEndpointDetails context = new SiriEndpointDetails();

        String agencyId = args.get("AgencyId");
        if (agencyId != null) context.getDefaultAgencyIds().add(agencyId);

        String agencyIds = args.get("AgencyIds");
        if (agencyIds != null) {
          for (String id : agencyIds.split(",")) context.getDefaultAgencyIds().add(id);
        }

        request.setChannelContext(context);

        _client.handleRequest(request);
      }
    }
  }
  public ItinerariesV2Bean getItineraries(ItinerariesBean itineraries) {

    ItinerariesV2Bean bean = new ItinerariesV2Bean();

    bean.setFrom(getLocation(itineraries.getFrom()));
    bean.setTo(getLocation(itineraries.getTo()));

    List<ItineraryBean> its = itineraries.getItineraries();

    if (!CollectionsLibrary.isEmpty(its)) {
      List<ItineraryV2Bean> beans = new ArrayList<ItineraryV2Bean>(its.size());
      for (ItineraryBean itinerary : its) {
        ItineraryV2Bean itBean = getItinerary(itinerary);
        beans.add(itBean);
      }
      bean.setItineraries(beans);
    }

    return bean;
  }
  public ItineraryV2Bean getItinerary(ItineraryBean itinerary) {

    ItineraryV2Bean bean = new ItineraryV2Bean();

    bean.setStartTime(itinerary.getStartTime());
    bean.setEndTime(itinerary.getEndTime());
    bean.setProbability(itinerary.getProbability());
    bean.setSelected(itinerary.isSelected());

    List<LegBean> legs = itinerary.getLegs();
    if (!CollectionsLibrary.isEmpty(legs)) {
      List<LegV2Bean> legBeans = new ArrayList<LegV2Bean>(legs.size());
      for (LegBean leg : legs) {
        LegV2Bean legBean = getLeg(leg);
        legBeans.add(legBean);
      }
      bean.setLegs(legBeans);
    }

    return bean;
  }
Esempio n. 11
0
  private SituationConsequenceV2Bean getSituationConsequence(SituationConsequenceBean consequence) {

    SituationConsequenceV2Bean bean = new SituationConsequenceV2Bean();

    if (consequence.getEffect() != null)
      bean.setCondition(consequence.getEffect().toString().toLowerCase());

    if (_includeConditionDetails
        && (consequence.getDetourPath() != null
            || !CollectionsLibrary.isEmpty(consequence.getDetourStopIds()))) {
      SituationConditionDetailsV2Bean detailsBean = new SituationConditionDetailsV2Bean();
      if (consequence.getDetourPath() != null) {
        EncodedPolylineBean poly = new EncodedPolylineBean();
        poly.setPoints(consequence.getDetourPath());
        detailsBean.setDiversionPath(poly);
      }
      detailsBean.setDiversionStopIds(consequence.getDetourStopIds());
      bean.setConditionDetails(detailsBean);
    }
    return bean;
  }
  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;
  }