Search in sources :

Example 1 with FeedInfo

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;
}
Also used : PropertyTranslation(org.onebusaway.gtfs.model.translation.PropertyTranslation) Translation(org.onebusaway.gtfs.model.Translation) TranslationServiceData(org.onebusaway.gtfs.model.translation.TranslationServiceData) PropertyTranslation(org.onebusaway.gtfs.model.translation.PropertyTranslation) FeedInfo(org.onebusaway.gtfs.model.FeedInfo)

Example 2 with FeedInfo

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);
    }
}
Also used : ExternalServicesBridgeFactory(org.onebusaway.cloud.api.ExternalServicesBridgeFactory) HashMap(java.util.HashMap) Stop(org.onebusaway.gtfs.model.Stop) Pathway(org.onebusaway.gtfs.model.Pathway) FeedInfo(org.onebusaway.gtfs.model.FeedInfo) PathwayUtil(org.onebusaway.gtfs_transformer.util.PathwayUtil) ExternalServices(org.onebusaway.cloud.api.ExternalServices) File(java.io.File)

Example 3 with FeedInfo

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;
}
Also used : FeedInfo(org.onebusaway.gtfs.model.FeedInfo)

Example 4 with FeedInfo

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());
}
Also used : ServiceDate(org.onebusaway.gtfs.model.calendar.ServiceDate) StringReader(java.io.StringReader) FeedInfo(org.onebusaway.gtfs.model.FeedInfo) Test(org.junit.Test)

Example 5 with FeedInfo

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);
    }
}
Also used : Agency(org.onebusaway.gtfs.model.Agency) FeedInfo(org.onebusaway.gtfs.model.FeedInfo)

Aggregations

FeedInfo (org.onebusaway.gtfs.model.FeedInfo)6 Test (org.junit.Test)2 Agency (org.onebusaway.gtfs.model.Agency)2 Stop (org.onebusaway.gtfs.model.Stop)2 File (java.io.File)1 StringReader (java.io.StringReader)1 HashMap (java.util.HashMap)1 ExternalServices (org.onebusaway.cloud.api.ExternalServices)1 ExternalServicesBridgeFactory (org.onebusaway.cloud.api.ExternalServicesBridgeFactory)1 GtfsRelationalDaoImpl (org.onebusaway.gtfs.impl.GtfsRelationalDaoImpl)1 Pathway (org.onebusaway.gtfs.model.Pathway)1 Route (org.onebusaway.gtfs.model.Route)1 StopTime (org.onebusaway.gtfs.model.StopTime)1 Translation (org.onebusaway.gtfs.model.Translation)1 Trip (org.onebusaway.gtfs.model.Trip)1 ServiceDate (org.onebusaway.gtfs.model.calendar.ServiceDate)1 PropertyTranslation (org.onebusaway.gtfs.model.translation.PropertyTranslation)1 TranslationServiceData (org.onebusaway.gtfs.model.translation.TranslationServiceData)1 PathwayUtil (org.onebusaway.gtfs_transformer.util.PathwayUtil)1