for (org.onebusaway.gtfs.model.Agency gtfsAgency : reader.getAgencies()) {
if(!agencyIdMap.containsKey(gtfsAgency.getId()))
{
Agency agency = new Agency(gtfsAgency);
agency.save();
agencyIdMap.put(agency.gtfsAgencyId, BigInteger.valueOf(agency.id));
primaryAgencyId = BigInteger.valueOf(agency.id);
agencyCount++;
}
else
primaryAgencyId = agencyIdMap.get(gtfsAgency.getId());
}
Agency primaryAgency = Agency.findById(primaryAgencyId.longValue());
agencyTask.completeTask("Imported " + agencyCount + " agencies.", GtfsSnapshotMergeTaskStatus.SUCCESS);
Logger.info("Agencies loaded: " + agencyCount.toString());
Logger.info("GtfsImporter: importing routes...");
GtfsSnapshotMergeTask routeTask = new GtfsSnapshotMergeTask(snapshotMerge);
routeTask.startTask();
for (org.onebusaway.gtfs.model.Route gtfsRoute : store.getAllRoutes()) {
BigInteger agencyId = agencyIdMap.get(gtfsRoute.getAgency().getId());
BigInteger routeId = Route.nativeInsert(snapshotMerge.em(), gtfsRoute, agencyId);
routeIdMap.put(gtfsRoute.getId().toString(), routeId );
routeCount++;
}
if(agencyCount > 1)
primaryAgencyId = null;
routeTask.completeTask("Imported " + routeCount + " routes.", GtfsSnapshotMergeTaskStatus.SUCCESS);
Logger.info("Routes loaded:" + routeCount.toString());
Logger.info("GtfsImporter: importing stops...");
GtfsSnapshotMergeTask stopTask = new GtfsSnapshotMergeTask(snapshotMerge);
stopTask.startTask();
for (org.onebusaway.gtfs.model.Stop gtfsStop : store.getAllStops()) {
BigInteger stopId = Stop.nativeInsert(snapshotMerge.em(), gtfsStop, primaryAgencyId);
stopIdMap.put(gtfsStop.getId().toString(), stopId );
stopCount++;
}
stopTask.completeTask("Imported " + stopCount + " stops.", GtfsSnapshotMergeTaskStatus.SUCCESS);
Logger.info("Stops loaded: " + stopCount);
Logger.info("GtfsImporter: importing Shapes...");
Logger.info("Calculating agency centroid for stops...");
Point centroid = Stop.findCentroid(primaryAgencyId);
Logger.info("Center: " + centroid.getCoordinate().y + ", " + centroid.getCoordinate().x);
primaryAgency.defaultLat = centroid.getCoordinate().y;
primaryAgency.defaultLon = centroid.getCoordinate().x;
primaryAgency.save();
GtfsSnapshotMergeTask tripShapeTask = new GtfsSnapshotMergeTask(snapshotMerge);
tripShapeTask.startTask();
// import points