Skip to content

Commit

Permalink
Add entity to walk steps
Browse files Browse the repository at this point in the history
  • Loading branch information
HenrikSundell committed Oct 2, 2024
1 parent 1d19a05 commit 67f4b1b
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
import org.opentripplanner.apis.gtfs.datafetchers.serviceTimeRangeImpl;
import org.opentripplanner.apis.gtfs.datafetchers.stepImpl;
import org.opentripplanner.apis.gtfs.datafetchers.stopAtDistanceImpl;
import org.opentripplanner.apis.gtfs.model.StepEntity;
import org.opentripplanner.apis.gtfs.model.StopPosition;
import org.opentripplanner.apis.support.graphql.LoggingDataFetcherExceptionHandler;
import org.opentripplanner.ext.actuator.MicrometerGraphQLInstrumentation;
Expand Down Expand Up @@ -124,6 +125,7 @@ protected static GraphQLSchema buildSchema() {
.type("Node", type -> type.typeResolver(new NodeTypeResolver()))
.type("PlaceInterface", type -> type.typeResolver(new PlaceInterfaceTypeResolver()))
.type("StopPosition", type -> type.typeResolver(new StopPosition() {}))
.type("StepEntity", type -> type.typeResolver(new StepEntity() {}))
.type("FareProduct", type -> type.typeResolver(new FareProductTypeResolver()))
.type("AlertEntity", type -> type.typeResolver(new AlertEntityTypeResolver()))
.type(typeWiring.build(AgencyImpl.class))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ public DataFetcher<String> exit() {
}

@Override
public DataFetcher<String> entrance() {
return environment -> getSource(environment).getEntrance();
public DataFetcher<Object> entity() {
return environment -> getSource(environment).getEntity();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,11 @@ public interface GraphQLEmissions {
public DataFetcher<org.opentripplanner.framework.model.Grams> co2();
}

/** Station entrance/exit */
public interface GraphQLEntrance {
public DataFetcher<String> name();
}

/** A 'medium' that a fare product applies to, for example cash, 'Oyster Card' or 'DB Navigator App'. */
public interface GraphQLFareMedium {
public DataFetcher<String> id();
Expand Down Expand Up @@ -977,6 +982,9 @@ public interface GraphQLRoutingError {
public DataFetcher<GraphQLInputField> inputField();
}

/** Entity to a step */
public interface GraphQLStepEntity extends TypeResolver {}

/**
* Stop can represent either a single public transport stop, where passengers can
* board and/or disembark vehicles, or a station, which contains multiple stops.
Expand Down Expand Up @@ -1428,7 +1436,7 @@ public interface GraphQLStep {

public DataFetcher<Iterable<org.opentripplanner.model.plan.ElevationProfile.Step>> elevationProfile();

public DataFetcher<String> entrance();
public DataFetcher<Object> entity();

public DataFetcher<String> exit();

Expand Down
19 changes: 19 additions & 0 deletions src/main/java/org/opentripplanner/apis/gtfs/model/StepEntity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package org.opentripplanner.apis.gtfs.model;

import graphql.TypeResolutionEnvironment;
import graphql.schema.GraphQLObjectType;
import org.opentripplanner.apis.gtfs.generated.GraphQLDataFetchers;

public interface StepEntity extends GraphQLDataFetchers.GraphQLStepEntity {
record Entrance(String name) implements StepEntity {}

@Override
default GraphQLObjectType getType(TypeResolutionEnvironment env) {
var schema = env.getSchema();
Object o = env.getObject();
if (o instanceof Entrance) {
return schema.getObjectType("Entrance");
}
return null;
}
}
13 changes: 7 additions & 6 deletions src/main/java/org/opentripplanner/model/plan/WalkStep.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import org.opentripplanner.apis.gtfs.model.StepEntity;
import org.opentripplanner.framework.geometry.WgsCoordinate;
import org.opentripplanner.framework.i18n.I18NString;
import org.opentripplanner.framework.lang.DoubleUtils;
Expand Down Expand Up @@ -44,7 +45,7 @@ public final class WalkStep {
private final boolean walkingBike;

private final String exit;
private final String entrance;
private final StepEntity entity;
private final ElevationProfile elevationProfile;
private final boolean stayOn;

Expand All @@ -57,7 +58,7 @@ public final class WalkStep {
I18NString directionText,
Set<StreetNote> streetNotes,
String exit,
String entrance,
StepEntity entity,
ElevationProfile elevationProfile,
boolean bogusName,
boolean walkingBike,
Expand All @@ -78,7 +79,7 @@ public final class WalkStep {
this.walkingBike = walkingBike;
this.area = area;
this.exit = exit;
this.entrance = entrance;
this.entity = entity;
this.elevationProfile = elevationProfile;
this.stayOn = stayOn;
this.edges = List.copyOf(Objects.requireNonNull(edges));
Expand Down Expand Up @@ -134,10 +135,10 @@ public String getExit() {
}

/**
* When entering or exiting a public transport station, the entrance name
* Entity related to a step e.g. building entrance/exit.
*/
public String getEntrance() {
return entrance;
public Object getEntity() {
return entity;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import java.util.List;
import java.util.Set;
import javax.annotation.Nullable;
import org.opentripplanner.apis.gtfs.model.StepEntity;
import org.opentripplanner.apis.gtfs.model.StepEntity.Entrance;
import org.opentripplanner.framework.geometry.WgsCoordinate;
import org.opentripplanner.framework.i18n.I18NString;
import org.opentripplanner.framework.lang.DoubleUtils;
Expand All @@ -25,7 +27,7 @@ public class WalkStepBuilder {
private RelativeDirection relativeDirection;
private ElevationProfile elevationProfile;
private String exit;
private String entrance;
private StepEntity entity;
private boolean stayOn = false;
/**
* Distance used for appending elevation profiles
Expand Down Expand Up @@ -75,8 +77,8 @@ public WalkStepBuilder withExit(String exit) {
return this;
}

public WalkStepBuilder withEntrance(String entrance) {
this.entrance = entrance;
public WalkStepBuilder withEntrance(Entrance entrance) {
this.entity = entrance;
return this;
}

Expand Down Expand Up @@ -162,7 +164,7 @@ public WalkStep build() {
directionText,
streetNotes,
exit,
entrance,
entity,
elevationProfile,
bogusName,
walkingBike,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import javax.annotation.Nonnull;
import org.locationtech.jts.geom.Coordinate;
import org.locationtech.jts.geom.Geometry;
import org.opentripplanner.apis.gtfs.model.StepEntity.Entrance;
import org.opentripplanner.framework.geometry.DirectionUtils;
import org.opentripplanner.framework.geometry.WgsCoordinate;
import org.opentripplanner.framework.i18n.I18NString;
Expand Down Expand Up @@ -394,7 +395,9 @@ private void setStationEntrance(State backState) {
entranceEdge = entranceState.getBackEdge();
}
if (entranceState.getVertex() instanceof StationEntranceVertex) {
current.withEntrance(((StationEntranceVertex) entranceState.getVertex()).getEntranceName());
current.withEntrance(
new Entrance(((StationEntranceVertex) entranceState.getVertex()).getEntranceName())
);
}
}

Expand Down
13 changes: 11 additions & 2 deletions src/main/resources/org/opentripplanner/apis/gtfs/schema.graphqls
Original file line number Diff line number Diff line change
Expand Up @@ -2607,6 +2607,15 @@ type serviceTimeRange {
start: Long
}

"Station entrance/exit"
type Entrance {
"Name of a station entrance/exit"
name: String
}

"Entity to a step"
union StepEntity = Entrance

type step {
"The cardinal (compass) direction (e.g. north, northeast) taken when engaging this step."
absoluteDirection: AbsoluteDirection
Expand All @@ -2628,8 +2637,6 @@ type step {
elevationProfile: [elevationProfileComponent]
"When exiting a highway or traffic circle, the exit name/number."
exit: String
"Name of entrance to a public transport station"
entrance: String
"The latitude of the start of the step."
lat: Float
"The longitude of the start of the step."
Expand All @@ -2642,6 +2649,8 @@ type step {
streetName: String
"Is this step walking with a bike?"
walkingBike: Boolean
"Step entity e.g. an entrance"
entity: StepEntity
}

type stopAtDistance implements Node {
Expand Down

0 comments on commit 67f4b1b

Please sign in to comment.