Skip to content

Commit

Permalink
Fix missaplied patch
Browse files Browse the repository at this point in the history
  • Loading branch information
mjanuszkiewicz-tt committed Aug 28, 2024
1 parent bf17e66 commit a764626
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ public class TraveltimeQueryBuilder extends AbstractQueryBuilder<TraveltimeQuery
private QueryBuilder prefilter;
@NonNull
private String output = "";
@NonNull
private String distanceOutput = "";

public TraveltimeQueryBuilder() {
}
Expand All @@ -53,6 +55,7 @@ public TraveltimeQueryBuilder(StreamInput in) throws IOException {
requestType = in.readOptionalEnum(RequestType.class);
prefilter = in.readOptionalNamedWriteable(QueryBuilder.class);
output = in.readString();
distanceOutput = in.readString();
}

@Override
Expand All @@ -65,6 +68,7 @@ protected void doWriteTo(StreamOutput out) throws IOException {
out.writeOptionalEnum(requestType);
out.writeOptionalNamedWriteable(prefilter);
out.writeString(output);
out.writeString(distanceOutput);
}

@Override
Expand All @@ -77,6 +81,7 @@ protected void doXContent(XContentBuilder builder, Params params) throws IOExcep
builder.field("requestType", requestType == null ? null : requestType.name());
builder.field("prefilter", prefilter);
builder.field("output", output);
builder.field("distance_output", distanceOutput);
}

@Override
Expand Down Expand Up @@ -116,14 +121,18 @@ protected Query doToQuery(SearchExecutionContext context) throws IOException {

Coordinates originCoord = Coordinates.builder().lat(origin.lat()).lng(origin.getLon()).build();

TraveltimeQueryParameters params = new TraveltimeQueryParameters(field, originCoord, limit, mode, country, requestType);
boolean includeDistance = !distanceOutput.isEmpty();
TraveltimeQueryParameters params = new TraveltimeQueryParameters(field, originCoord, limit, mode, country, requestType, includeDistance);
if (params.getMode() == null) {
if (defaultMode.isPresent()) {
params = params.withMode(defaultMode.get());
} else {
throw new IllegalStateException("Traveltime query requires either 'mode' field to be present or a default mode to be set in the config");
}
}
if(params.isIncludeDistance() && !Util.canUseDistance(params.getMode())) {
throw new IllegalStateException("Traveltime query with distance output cannot be used with public transportation mode");
}
if (params.getCountry() == null) {
if (defaultCountry.isPresent()) {
params = params.withCountry(defaultCountry.get());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ public class TraveltimeQueryBuilder extends AbstractQueryBuilder<TraveltimeQuery
private QueryBuilder prefilter;
@NonNull
private String output = "";
@NonNull
private String distanceOutput = "";


public TraveltimeQueryBuilder() {
}
Expand Down Expand Up @@ -117,14 +120,18 @@ protected Query doToQuery(SearchExecutionContext context) throws IOException {

Coordinates originCoord = Coordinates.builder().lat(origin.lat()).lng(origin.getLon()).build();

TraveltimeQueryParameters params = new TraveltimeQueryParameters(field, originCoord, limit, mode, country, requestType);
boolean includeDistance = !distanceOutput.isEmpty();
TraveltimeQueryParameters params = new TraveltimeQueryParameters(field, originCoord, limit, mode, country, requestType, includeDistance);
if (params.getMode() == null) {
if (defaultMode.isPresent()) {
params = params.withMode(defaultMode.get());
} else {
throw new IllegalStateException("Traveltime query requires either 'mode' field to be present or a default mode to be set in the config");
}
}
if(params.isIncludeDistance() && !Util.canUseDistance(params.getMode())) {
throw new IllegalStateException("Traveltime query with distance output cannot be used with public transportation mode");
}
if (params.getCountry() == null) {
if (defaultCountry.isPresent()) {
params = params.withCountry(defaultCountry.get());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ public class TraveltimeQueryBuilder extends AbstractQueryBuilder<TraveltimeQuery
private QueryBuilder prefilter;
@NonNull
private String output = "";
@NonNull
private String distanceOutput = "";

public TraveltimeQueryBuilder() {
}
Expand All @@ -54,6 +56,7 @@ public TraveltimeQueryBuilder(StreamInput in) throws IOException {
requestType = in.readOptionalEnum(RequestType.class);
prefilter = in.readOptionalNamedWriteable(QueryBuilder.class);
output = in.readString();
distanceOutput = in.readString();
}

@Override
Expand All @@ -66,6 +69,7 @@ protected void doWriteTo(StreamOutput out) throws IOException {
out.writeOptionalEnum(requestType);
out.writeOptionalNamedWriteable(prefilter);
out.writeString(output);
out.writeString(distanceOutput);
}

@Override
Expand All @@ -78,6 +82,7 @@ protected void doXContent(XContentBuilder builder, Params params) throws IOExcep
builder.field("requestType", requestType == null ? null : requestType.name());
builder.field("prefilter", prefilter);
builder.field("output", output);
builder.field("distance_output", distanceOutput);
}

@Override
Expand Down Expand Up @@ -117,7 +122,8 @@ protected Query doToQuery(SearchExecutionContext context) throws IOException {

Coordinates originCoord = Coordinates.builder().lat(origin.lat()).lng(origin.getLon()).build();

TraveltimeQueryParameters params = new TraveltimeQueryParameters(field, originCoord, limit, mode, country, requestType);
boolean includeDistance = !distanceOutput.isEmpty();
TraveltimeQueryParameters params = new TraveltimeQueryParameters(field, originCoord, limit, mode, country, requestType, includeDistance);
if (params.getMode() == null) {
if (defaultMode.isPresent()) {
params = params.withMode(defaultMode.get());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ public class TraveltimeQueryBuilder extends AbstractQueryBuilder<TraveltimeQuery
private QueryBuilder prefilter;
@NonNull
private String output = "";
@NonNull
private String distanceOutput = "";

public TraveltimeQueryBuilder() {
}
Expand All @@ -54,6 +56,7 @@ public TraveltimeQueryBuilder(StreamInput in) throws IOException {
requestType = in.readOptionalEnum(RequestType.class);
prefilter = in.readOptionalNamedWriteable(QueryBuilder.class);
output = in.readString();
distanceOutput = in.readString();
}

@Override
Expand All @@ -66,6 +69,7 @@ protected void doWriteTo(StreamOutput out) throws IOException {
out.writeOptionalEnum(requestType);
out.writeOptionalNamedWriteable(prefilter);
out.writeString(output);
out.writeString(distanceOutput);
}

@Override
Expand All @@ -78,6 +82,7 @@ protected void doXContent(XContentBuilder builder, Params params) throws IOExcep
builder.field("requestType", requestType == null ? null : requestType.name());
builder.field("prefilter", prefilter);
builder.field("output", output);
builder.field("distance_output", distanceOutput);
}

@Override
Expand Down Expand Up @@ -117,7 +122,8 @@ protected Query doToQuery(SearchExecutionContext context) throws IOException {

Coordinates originCoord = Coordinates.builder().lat(origin.lat()).lng(origin.getLon()).build();

TraveltimeQueryParameters params = new TraveltimeQueryParameters(field, originCoord, limit, mode, country, requestType);
boolean includeDistance = !distanceOutput.isEmpty();
TraveltimeQueryParameters params = new TraveltimeQueryParameters(field, originCoord, limit, mode, country, requestType, includeDistance);
if (params.getMode() == null) {
if (defaultMode.isPresent()) {
params = params.withMode(defaultMode.get());
Expand Down

0 comments on commit a764626

Please sign in to comment.