use of com.google.transit.realtime.GtfsRealtime.EntitySelector in project onebusaway-application-modules by camsys.
the class FeedServiceImplTest method createAlert.
private FeedEntity createAlert(String alertId, String header, String desc, Alert.Cause cause, Alert.Effect effect, String url, long startTime, long endTime, String agency, String route, String stop) {
Alert.Builder alertBldr = Alert.newBuilder();
// Header
Translation translation = Translation.newBuilder().setLanguage("en").setText(header).build();
TranslatedString trnStr = TranslatedString.newBuilder().addTranslation(translation).build();
alertBldr.setHeaderText(trnStr);
// Description
translation = Translation.newBuilder().setLanguage("en").setText(desc).build();
trnStr = TranslatedString.newBuilder().addTranslation(translation).build();
alertBldr.setDescriptionText(trnStr);
// Cause
alertBldr.setCause(cause);
// Effect
alertBldr.setEffect(effect);
// URL
translation = Translation.newBuilder().setLanguage("en").setText(url).build();
trnStr = TranslatedString.newBuilder().addTranslation(translation).build();
alertBldr.setUrl(trnStr);
// Build TimeRangeEntity
TimeRange timeRange = createTimeRange(startTime, endTime);
alertBldr.addActivePeriod(timeRange);
// Build EntitySelectorEntity
EntitySelector entitySelector = createEntitySelector(agency, route, stop);
alertBldr.addInformedEntity(entitySelector);
FeedEntity.Builder alertEntity = FeedEntity.newBuilder();
alertEntity.setId(alertId);
alertEntity.setAlert(alertBldr.build());
return alertEntity.build();
}
use of com.google.transit.realtime.GtfsRealtime.EntitySelector in project onebusaway-application-modules by camsys.
the class GtfsRealtimeAlertLibrary method getAlertAsServiceAlert.
public ServiceAlert.Builder getAlertAsServiceAlert(AgencyAndId id, Alert alert, Map agencyIdMap) {
ServiceAlert.Builder b = ServiceAlert.newBuilder();
b.setCreationTime(SystemTime.currentTimeMillis());
b.setModifiedTime(SystemTime.currentTimeMillis());
b.setId(ServiceAlertLibrary.id(id));
for (GtfsRealtime.TimeRange range : alert.getActivePeriodList()) {
ServiceAlerts.TimeRange.Builder rangeBuilder = ServiceAlerts.TimeRange.newBuilder();
if (range.hasStart())
rangeBuilder.setStart(range.getStart());
if (range.hasEnd())
rangeBuilder.setEnd(range.getEnd());
b.addActiveWindow(rangeBuilder);
}
if (alert.hasCause())
b.setCause(convertCause(alert.getCause()));
if (alert.hasHeaderText())
b.setSummary(convertTranslatedString(alert.getHeaderText()));
if (alert.hasDescriptionText())
b.setDescription(convertTranslatedString(alert.getDescriptionText()));
if (alert.hasEffect()) {
Consequence.Builder consequence = Consequence.newBuilder();
consequence.setEffect(convertEffect(alert.getEffect()));
b.addConsequence(consequence);
}
for (EntitySelector selector : alert.getInformedEntityList()) {
Affects.Builder affects = getEntitySelectorAsAffects(selector, agencyIdMap);
b.addAffects(affects);
}
if (alert.hasUrl())
b.setUrl(convertTranslatedString(alert.getUrl()));
return b;
}
Aggregations