Skip to content

Commit

Permalink
Merge pull request #8 from goeuropa/feature/routes-details-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
wkulesza authored Apr 19, 2024
2 parents 1c15eb1 + d3e1257 commit 0a17317
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1032,6 +1032,15 @@ public Response getRouteDetails(

ipcRoutes = new ArrayList<IpcRoute>();
ipcRoutes.add(route);
} if (stopId != null) {

ipcRoutes = inter.getRoutesByStopId(stopId);

// If the stop doesn't exist then throw exception such that
// Bad Request with an appropriate message is returned.
if (ipcRoutes == null || ipcRoutes.isEmpty())
throw WebUtils.badRequestException("Routes for stop ID= " + stopId + " does not exist.");

} else {
// Multiple routes specified
ipcRoutes = inter.getRoutes(routeIdsOrShortNames);
Expand Down
43 changes: 24 additions & 19 deletions core/src/main/java/org/transitclock/service/ConfigServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,10 @@
import lombok.extern.slf4j.Slf4j;
import org.transitclock.Core;
import org.transitclock.core.dataCache.VehicleDataCache;
import org.transitclock.domain.structs.Agency;
import org.transitclock.domain.structs.Block;
import org.transitclock.domain.structs.Calendar;
import org.transitclock.domain.structs.Route;
import org.transitclock.domain.structs.Trip;
import org.transitclock.domain.structs.TripPattern;
import org.transitclock.domain.structs.VehicleConfig;
import org.transitclock.domain.structs.*;
import org.transitclock.gtfs.DbConfig;
import org.transitclock.service.contract.ConfigInterface;
import org.transitclock.service.dto.IpcBlock;
import org.transitclock.service.dto.IpcCalendar;
import org.transitclock.service.dto.IpcDirectionsForRoute;
import org.transitclock.service.dto.IpcRoute;
import org.transitclock.service.dto.IpcRouteSummary;
import org.transitclock.service.dto.IpcSchedule;
import org.transitclock.service.dto.IpcTrip;
import org.transitclock.service.dto.IpcTripPattern;
import org.transitclock.service.dto.*;

import java.util.ArrayList;
import java.util.Collection;
Expand Down Expand Up @@ -49,7 +36,7 @@ public static ConfigInterface instance() {
* automatically cause the object to continue to run and serve requests.
*
* @return the singleton ConfigServer object. Usually does not need to used since the server
* will be fully running.
* will be fully running.
*/
public static ConfigServiceImpl start() {
if (singleton == null) {
Expand Down Expand Up @@ -99,8 +86,7 @@ public Collection<IpcRouteSummary> getRoutes() {
* @see org.transitclock.ipc.interfaces.ConfigInterface#getRoute(java.lang.String)
*/
@Override
public IpcRoute getRoute(String routeIdOrShortName, String directionId, String stopId, String tripPatternId)
{
public IpcRoute getRoute(String routeIdOrShortName, String directionId, String stopId, String tripPatternId) {
// Determine the route
Route dbRoute = getRoute(routeIdOrShortName);
if (dbRoute == null) {
Expand Down Expand Up @@ -363,12 +349,31 @@ public List<String> getBlockIds(String serviceId) {
}

/* (non-Javadoc)
* @see org.transitclock.ipc.interfaces.ConfigInterface#getBlockIds()
* @see org.transitclock.ipc.interfaces.ConfigInterface#getServiceIdsWithBlockIds()
*/
@Override
public Map<String, List<String>> getServiceIdsWithBlockIds() {
return Core.getInstance()
.getDbConfig()
.getBlockIdsForAllServiceIds();
}

/* (non-Javadoc)
* @see org.transitclock.ipc.interfaces.ConfigInterface#getRoutesByStopId()
*/
@Override
public List<IpcRoute> getRoutesByStopId(String stopId) {
List<IpcRoute> routes = new ArrayList<>();
if (stopId != null) {
DbConfig dbConfig = Core.getInstance().getDbConfig();
if (dbConfig == null) return routes;

routes = dbConfig.getRoutes().stream()
.filter(dbRoute -> dbRoute.getStops().stream()
.anyMatch(stop -> stop.getId().equals(stopId)))
.map(dbRoute -> new IpcRoute(dbRoute, null, null, null))
.collect(Collectors.toList());
}
return routes;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,7 @@
package org.transitclock.service.contract;

import org.transitclock.domain.structs.Agency;
import org.transitclock.service.dto.IpcBlock;
import org.transitclock.service.dto.IpcCalendar;
import org.transitclock.service.dto.IpcDirectionsForRoute;
import org.transitclock.service.dto.IpcRoute;
import org.transitclock.service.dto.IpcRouteSummary;
import org.transitclock.service.dto.IpcSchedule;
import org.transitclock.service.dto.IpcTrip;
import org.transitclock.service.dto.IpcTripPattern;
import org.transitclock.service.dto.*;

import java.util.Collection;
import java.util.List;
Expand Down Expand Up @@ -182,4 +175,13 @@ IpcRoute getRoute(String routeIdOrShortName, String directionId, String stopId,
* @return Map of service IDs with belong block IDs
*/
Map<String, List<String>> getServiceIdsWithBlockIds();


/**
* Obtains list of routes which contained stops with following stop ID
*
* @param stopId
* @return list of IpcRoute
*/
List<IpcRoute> getRoutesByStopId(String stopId);
}

0 comments on commit 0a17317

Please sign in to comment.