use of org.onebusaway.gtfs_realtime.model.AlertModel in project onebusaway-application-modules by camsys.
the class AlertConvertor method readFeedEntity.
@Override
public AlertModel readFeedEntity(FeedEntity entity, long timestamp) {
if (entity.hasAlert()) {
AlertModel alrt = new AlertModel();
alrt.setTimestamp(new Date(timestamp));
Alert alert = entity.getAlert();
for (TimeRange tr : alert.getActivePeriodList()) {
TimeRangeModel timeRange = readTimeRange(tr);
if (timeRange != null) {
timeRange.setAlert(alrt);
alrt.addTimeRangeModel(timeRange);
}
}
for (EntitySelector es : alert.getInformedEntityList()) {
EntitySelectorModel entitySelector = readEntitySelector(es);
if (entitySelector != null) {
entitySelector.setAlert(alrt);
alrt.addEntitySelectorModel(entitySelector);
}
}
if (alert.hasCause()) {
String cause = alert.getCause().getValueDescriptor().getFullName();
cause = cause.substring(cause.lastIndexOf('.') + 1);
alrt.setCause(cause);
}
if (alert.hasEffect()) {
String effect = alert.getEffect().getValueDescriptor().getFullName();
effect = effect.substring(effect.lastIndexOf('.') + 1);
alrt.setEffect(effect);
}
if (alert.hasUrl()) {
alrt.setUrl(alert.getUrl().getTranslation(0).getText());
}
if (alert.hasHeaderText()) {
alrt.setHeaderText(alert.getHeaderText().getTranslation(0).getText());
}
if (alert.hasDescriptionText()) {
alrt.setDescriptionText(alert.getDescriptionText().getTranslation(0).getText());
}
return alrt;
}
return null;
}
use of org.onebusaway.gtfs_realtime.model.AlertModel in project onebusaway-application-modules by camsys.
the class FeedServiceImpl method readAlerts.
@Override
public List<AlertModel> readAlerts(FeedMessage alerts, GtfsRealtimeEntitySource entitySource) {
List<AlertModel> updates = GtfsRealtimeConversionLibrary.readAlerts(alerts);
for (AlertModel alert : updates) {
// Update EntitySelectors to include the agency
for (EntitySelectorModel esm : alert.getEntitySelectors()) {
String agencyId = getAgencyId(entitySource);
if (StringUtils.isEmpty(agencyId) && esm.getAgencyId() != null && esm.getAgencyId().length() > 0) {
agencyId = esm.getAgencyId();
}
addAgencyIdToTripId(esm, agencyId, entitySource);
addAgencyIdToRouteId(esm, agencyId, entitySource);
addAgencyIdToStopId(esm, agencyId, entitySource);
}
_persistor.persist(alert);
}
return updates;
}
use of org.onebusaway.gtfs_realtime.model.AlertModel in project onebusaway-application-modules by camsys.
the class FeedServiceImplTest method testReadAlerts.
@Test
public void testReadAlerts() {
// Create GTFS Feed with service alerts
FeedEntity alertEntityA = createAlert("alertA", TEST_1, DESC_1, CAUSE_1, EFFECT_1, URL_1, TIME_START_1, TIME_END_1, AGENCY_1, ROUTE_1, STOP_1);
FeedEntity alertEntityB = createAlert("alertB", TEST_2, DESC_2, CAUSE_2, EFFECT_2, URL_2, TIME_START_2, TIME_END_2, AGENCY_2, ROUTE_2, STOP_2);
FeedEntity alertEntityC = createAlert("alertC", TEST_3, DESC_3, CAUSE_3, EFFECT_3, URL_3, TIME_START_3, TIME_END_3, AGENCY_3, ROUTE_3, STOP_3);
// Create FeedMessage
FeedMessage.Builder alerts = createFeed();
alerts.addEntity(alertEntityA);
alerts.addEntity(alertEntityB);
alerts.addEntity(alertEntityC);
FeedMessage alert = alerts.build();
_feedService.readAlerts(alert, _entitySource);
Collection<AlertModel> alertsFromDB = null;
// the AlertThread, which actually writes to the DB.
try {
TimeUnit.SECONDS.sleep(15);
} catch (Exception ignoredEx) {
}
// Get data that was persisted to the database
try {
alertsFromDB = (Collection<AlertModel>) _template.find("from AlertModel");
} catch (Exception ex) {
ex.getMessage();
_log.info("find failed: " + ex.getMessage());
}
// Check persisted data against the original value.
_log.info("results size: " + alertsFromDB.size());
assertEquals(3, alertsFromDB.size());
for (AlertModel alertFromDB : alertsFromDB) {
String header = alertFromDB.getHeaderText();
String desc = alertFromDB.getDescriptionText();
String cause = alertFromDB.getCause();
String effect = alertFromDB.getEffect();
String url = alertFromDB.getUrl();
long timeStart = 0L;
long timeEnd = 0L;
List<TimeRangeModel> timeRanges = alertFromDB.getTimeRanges();
for (TimeRangeModel tr : timeRanges) {
timeStart = tr.getStart();
timeEnd = tr.getEnd();
}
String agency = "";
String route = "";
String stop = "";
List<EntitySelectorModel> entitySelectors = alertFromDB.getEntitySelectors();
for (EntitySelectorModel es : entitySelectors) {
agency = es.getAgencyId();
route = es.getRouteId();
stop = es.getStopId();
}
if (header.equals(TEST_1)) {
assertEquals(TEST_1, header);
assertEquals(DESC_1, desc);
assertEquals(CAUSE_1.toString(), cause);
assertEquals(EFFECT_1.toString(), effect);
assertEquals(URL_1.toString(), url);
assertEquals(TIME_START_1, timeStart);
assertEquals(TIME_END_1, timeEnd);
assertEquals(AGENCY_1, agency);
assertEquals(ROUTE_1, route);
assertEquals(STOP_1, stop);
} else if (header.equals(TEST_2)) {
assertEquals(TEST_2, header);
assertEquals(DESC_2, desc);
assertEquals(CAUSE_2.toString(), cause);
assertEquals(EFFECT_2.toString(), effect);
assertEquals(URL_2.toString(), url);
assertEquals(TIME_START_2, timeStart);
assertEquals(TIME_END_2, timeEnd);
assertEquals(AGENCY_2, agency);
// Verify that agency has
assertEquals(AGENCY_2 + "_" + ROUTE_2, route);
// been prepended to
// route.
assertEquals(STOP_2, stop);
} else if (header.equals(TEST_3)) {
assertEquals(TEST_3, header);
assertEquals(DESC_3, desc);
assertEquals(CAUSE_3.toString(), cause);
assertEquals(EFFECT_3.toString(), effect);
assertEquals(URL_3.toString(), url);
assertEquals(TIME_START_3, timeStart);
assertEquals(TIME_END_3, timeEnd);
assertEquals(AGENCY_3, agency);
assertEquals(ROUTE_3, route);
// Verify that agency has
assertEquals(AGENCY_3 + "_" + STOP_3, stop);
// been prepended to stop.
}
}
}
Aggregations