use of org.onebusaway.gtfs.model.FeedInfo in project onebusaway-gtfs-modules by OneBusAway.
the class TranslationServiceDataFactoryImpl method getTranslationServiceData.
@Override
public TranslationServiceData getTranslationServiceData() {
if (_dao.getAllFeedInfos().isEmpty()) {
_log.warn("No feed_info present, there will be no translations available.");
return null;
}
TranslationServiceData data = new TranslationServiceData();
FeedInfo feedInfo = _dao.getAllFeedInfos().iterator().next();
if (feedInfo.getDefaultLang() != null) {
data.setFeedLanguage(feedInfo.getDefaultLang());
} else {
data.setFeedLanguage(feedInfo.getLang());
}
for (Translation translation : _dao.getAllTranslations()) {
Class<?> type = getEntityTypeForTableName(translation.getTableName());
if (type == null) {
_log.error("No entity type for table_name {}, skipping.", translation.getTableName());
continue;
}
String propertyName = getPropertyNameByClassAndCsvName(type, translation.getFieldName());
if (propertyName == null) {
_log.error("No property for field_name {}, skipping.", translation.getFieldName());
continue;
}
PropertyTranslation propertyTranslation = new PropertyTranslation(propertyName, translation);
data.putTranslation(type, translation.getLanguage(), propertyTranslation);
}
return data;
}
use of org.onebusaway.gtfs.model.FeedInfo in project onebusaway-gtfs-modules by OneBusAway.
the class MTAEntrancesStrategy method run.
@Override
public void run(TransformContext context, GtfsMutableRelationalDao dao) {
ExternalServices es = new ExternalServicesBridgeFactory().getExternalServices();
Collection<FeedInfo> feedInfos = dao.getAllFeedInfos();
String feed = null;
if (feedInfos.size() > 0)
feed = feedInfos.iterator().next().getPublisherName();
File entrancesFile = new File(entrancesCsv);
if (!entrancesFile.exists()) {
es.publishMultiDimensionalMetric(getNamespace(), "MissingControlFiles", new String[] { "feed", "controlFileName" }, new String[] { feed, entrancesCsv }, 1);
throw new IllegalStateException("Entrances file does not exist: " + entrancesFile.getName());
}
if (elevatorsCsv != null) {
File elevatorsFile = new File(elevatorsCsv);
if (!elevatorsFile.exists()) {
es.publishMultiDimensionalMetric(getNamespace(), "MissingControlFiles", new String[] { "feed", "controlFileName" }, new String[] { feed, elevatorsCsv }, 1);
throw new IllegalStateException("Elevators file does not exist: " + elevatorsFile.getName());
}
}
agencyId = dao.getAllAgencies().iterator().next().getId();
newStops = new HashSet<>();
newPathways = new HashSet<>();
pathwayUtil = new PathwayUtil(agencyId, newPathways);
for (Pathway pathway : dao.getAllPathways()) {
stopIdsWithPathways.add(pathway.getFromStop().getId());
stopIdsWithPathways.add(pathway.getToStop().getId());
}
Map<String, StopGroup> stopGroups = new HashMap<>();
// For every stop that's not a station, add an entrance which is not wheelchair accessible, and a pathway.
for (Stop stop : dao.getAllStops()) {
if (stopsHaveParents) {
// Put stop into a stop-group with parent, uptown, downtown
String gid = stop.getLocationType() == LOCATION_TYPE_STOP ? stop.getParentStation() : stop.getId().getId();
if (gid == null) {
gid = stop.getId().getId();
// don't fret about this one, it's a shuttle stop
if (stop.getName().contains("SHUTTLE BUS STOP"))
continue;
_log.warn("stop {} didn't have a parent set--using own stop ID.", stop.getName());
continue;
}
StopGroup group = stopGroups.get(gid);
if (group == null) {
group = new StopGroup();
stopGroups.put(gid, group);
}
if (stop.getLocationType() == LOCATION_TYPE_STATION) {
group.parent = stop;
} else if (stop.getId().getId().endsWith("S")) {
group.downtown = stop;
} else if (stop.getId().getId().endsWith("N")) {
group.uptown = stop;
} else {
// it's a pathway, ignore
if (stop.getLocationType() >= 2)
continue;
// don't fret about this one, it's a shuttle stop
if (stop.getName().contains("SHUTTLE BUS STOP"))
continue;
_log.error("unexpected stop not of parent type but of {} for stop {}: {}", stop.getLocationType(), stop.getId(), stop.getName());
continue;
}
} else {
StopGroup group = new StopGroup();
group.parent = stop;
String gid = stop.getId().getId();
stopGroups.put(gid, group);
}
}
readEntranceData(stopGroups);
if (elevatorsCsv != null) {
readElevatorData(stopGroups, getComplexList(dao));
}
for (Stop s : newStops) {
dao.saveEntity(s);
}
for (Pathway pathway : newPathways) {
dao.saveEntity(pathway);
}
}
use of org.onebusaway.gtfs.model.FeedInfo in project onebusaway-gtfs-modules by OneBusAway.
the class FeedInfoFromAgencyStrategy method getFeedInfoFromAgency.
private FeedInfo getFeedInfoFromAgency(GtfsMutableRelationalDao dao, Agency agency) {
FeedInfo info = dao.getFeedInfoForId(agencyId);
if (info == null) {
info = new FeedInfo();
}
info.setId(agencyId);
info.setPublisherName(agency.getName());
info.setPublisherUrl(agency.getUrl());
if (agency.getLang() == null || agency.getLang().isEmpty()) {
info.setLang(defaultLang);
} else {
info.setLang(agency.getLang());
}
return info;
}
use of org.onebusaway.gtfs.model.FeedInfo in project onebusaway-gtfs-modules by OneBusAway.
the class GtfsMappingTest method testFeedInfo.
@Test
public void testFeedInfo() throws CsvEntityIOException, IOException {
StringBuilder b = new StringBuilder();
b.append("feed_publisher_name,feed_publisher_url,feed_lang,feed_start_date,feed_end_date,feed_version\n");
b.append("Test,http://test/,en,20110928,20120131,1.0\n");
_reader.readEntities(FeedInfo.class, new StringReader(b.toString()));
FeedInfo feedInfo = _dao.getFeedInfoForId("1");
assertEquals("Test", feedInfo.getPublisherName());
assertEquals("http://test/", feedInfo.getPublisherUrl());
assertEquals("en", feedInfo.getLang());
assertEquals(new ServiceDate(2011, 9, 28), feedInfo.getStartDate());
assertEquals(new ServiceDate(2012, 1, 31), feedInfo.getEndDate());
assertEquals("1.0", feedInfo.getVersion());
}
use of org.onebusaway.gtfs.model.FeedInfo in project onebusaway-gtfs-modules by OneBusAway.
the class FeedInfoFromAgencyStrategy method run.
@Override
public void run(TransformContext context, GtfsMutableRelationalDao dao) {
boolean foundAgency = false;
for (Agency agency : dao.getAllAgencies()) {
_log.info("comparing agency " + agency.getId() + " to " + agencyId);
if (agency.getId().equals(agencyId)) {
foundAgency = true;
_log.info("creating feed info from matched agency " + agencyId);
FeedInfo info = getFeedInfoFromAgency(dao, agency);
// if version already present leave it alone
if (info.getVersion() == null) {
addCreationTime(info, context);
dao.saveOrUpdateEntity(info);
} else {
_log.info("found feedVersion " + info.getVersion() + ", abandoning");
}
}
}
if (!foundAgency) {
// we didn't find the expected agency, try a default agency / first agency
Agency agency = dao.getAllAgencies().iterator().next();
FeedInfo info = getFeedInfoFromAgency(dao, agency);
_log.info("creating feed info from unmatched agency " + agency.getId());
addCreationTime(info, context);
dao.saveOrUpdateEntity(info);
}
}
Aggregations