Skip to content

Commit

Permalink
VehicleTypesCapacity and vehicleDocksCapacity
Browse files Browse the repository at this point in the history
  • Loading branch information
testower committed Jun 9, 2024
1 parent 43d3a40 commit 995ac26
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,11 @@
import org.entur.lamassu.model.entities.Station;
import org.entur.lamassu.model.entities.System;
import org.entur.lamassu.model.entities.VehicleDocksAvailability;
import org.entur.lamassu.model.entities.VehicleDocksCapacity;
import org.entur.lamassu.model.entities.VehicleType;
import org.entur.lamassu.model.entities.VehicleTypeAvailability;
import org.entur.lamassu.model.entities.VehicleTypeCapacity;
import org.entur.lamassu.model.entities.VehicleTypesCapacity;
import org.jetbrains.annotations.NotNull;
import org.mobilitydata.gbfs.v3_0.station_information.GBFSName;
import org.mobilitydata.gbfs.v3_0.station_information.GBFSShortName;
Expand Down Expand Up @@ -121,6 +123,7 @@ public Station mapStation(
station.setCapacity(
stationInformation.getCapacity() != null ? stationInformation.getCapacity() : null
);

station.setVehicleCapacity(
stationInformation.getVehicleTypesCapacity() != null
? mapVehicleCapacities(
Expand All @@ -129,6 +132,15 @@ public Station mapStation(
)
: null
);
station.setVehicleTypesCapacity(
stationInformation.getVehicleTypesCapacity() != null
? mapVehicleTypesCapacity(
stationInformation.getVehicleTypesCapacity(),
mapVehicleTypes(vehicleTypesFeed, pricingPlans, language)
)
: null
);

station.setVehicleTypeCapacity(
stationInformation.getVehicleDocksCapacity() != null
? mapVehicleTypeCapacities(
Expand All @@ -137,6 +149,15 @@ public Station mapStation(
)
: null
);
station.setVehicleDocksCapacity(
stationInformation.getVehicleDocksCapacity() != null
? mapVehicleDocksCapacityToVehicleTypeCapacity(
stationInformation.getVehicleDocksCapacity(),
mapVehicleTypes(vehicleTypesFeed, pricingPlans, language)
)
: null
);

station.setValetStation(stationInformation.getIsValetStation());
station.setChargingStation(stationInformation.getIsChargingStation());
station.setRentalUris(
Expand Down Expand Up @@ -292,10 +313,29 @@ private List<VehicleTypeCapacity> mapVehicleCapacities(
mapped.setVehicleType(
vehicleTypes.get(vehicleCapacity.getVehicleTypeIds().getFirst())
);
mapped.setCount(vehicleCapacity.getCount());
return mapped;
}

private List<VehicleTypesCapacity> mapVehicleTypesCapacity(
List<GBFSVehicleTypesCapacity> vehicleTypesCapacity,
Map<String, VehicleType> vehicleTypes
) {
return vehicleTypesCapacity
.stream()
.map(v -> mapVehicleTypeCapacity(v, vehicleTypes))
.toList();
}

private VehicleTypesCapacity mapVehicleTypeCapacity(
GBFSVehicleTypesCapacity vehicleTypesCapacity,
Map<String, VehicleType> vehicleTypes
) {
var mapped = new VehicleTypesCapacity();
mapped.setVehicleTypes(
vehicleCapacity.getVehicleTypeIds().stream().map(vehicleTypes::get).toList()
vehicleTypesCapacity.getVehicleTypeIds().stream().map(vehicleTypes::get).toList()
);
mapped.setCount(vehicleCapacity.getCount());
mapped.setCount(vehicleTypesCapacity.getCount());
return mapped;
}

Expand All @@ -305,18 +345,37 @@ private List<VehicleTypeCapacity> mapVehicleTypeCapacities(
) {
return vehicleCapacity
.stream()
.map(entry -> mapVehicleDocksCapacity(entry, vehicleTypes))
.map(entry -> mapVehicleDocksCapacityToVehicleTypeCapacity(entry, vehicleTypes))
.toList();
}

private VehicleTypeCapacity mapVehicleDocksCapacity(
private VehicleTypeCapacity mapVehicleDocksCapacityToVehicleTypeCapacity(
GBFSVehicleDocksCapacity vehicleDocksCapacity,
Map<String, VehicleType> vehicleTypes
) {
var mapped = new VehicleTypeCapacity();
mapped.setVehicleType(
vehicleTypes.get(vehicleDocksCapacity.getVehicleTypeIds().getFirst())
);
mapped.setCount(vehicleDocksCapacity.getCount());
return mapped;
}

private List<VehicleDocksCapacity> mapVehicleDocksCapacityToVehicleTypeCapacity(
List<GBFSVehicleDocksCapacity> vehicleDocksCapacity,
Map<String, VehicleType> vehicleTypes
) {
return vehicleDocksCapacity
.stream()
.map(v -> mapVehicleDocksCapacity(v, vehicleTypes))
.toList();
}

private VehicleDocksCapacity mapVehicleDocksCapacity(
GBFSVehicleDocksCapacity vehicleDocksCapacity,
Map<String, VehicleType> vehicleTypes
) {
var mapped = new VehicleDocksCapacity();
mapped.setVehicleTypes(
vehicleDocksCapacity.getVehicleTypeIds().stream().map(vehicleTypes::get).toList()
);
Expand Down
18 changes: 18 additions & 0 deletions src/main/java/org/entur/lamassu/model/entities/Station.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ public class Station implements LocationEntity {
private String contactPhone;
private Integer capacity;
private List<VehicleTypeCapacity> vehicleCapacity;
private List<VehicleDocksCapacity> vehicleDocksCapacity;
private List<VehicleTypeCapacity> vehicleTypeCapacity;
private List<VehicleTypesCapacity> vehicleTypesCapacity;
private Boolean isValetStation;
private Boolean isChargingStation;
private RentalUris rentalUris;
Expand Down Expand Up @@ -198,6 +200,14 @@ public void setVehicleCapacity(List<VehicleTypeCapacity> vehicleCapacity) {
this.vehicleCapacity = vehicleCapacity;
}

public List<VehicleDocksCapacity> getVehicleDocksCapacity() {
return vehicleDocksCapacity;
}

public void setVehicleDocksCapacity(List<VehicleDocksCapacity> vehicleDocksCapacity) {
this.vehicleDocksCapacity = vehicleDocksCapacity;
}

public List<VehicleTypeCapacity> getVehicleTypeCapacity() {
return vehicleTypeCapacity;
}
Expand All @@ -206,6 +216,14 @@ public void setVehicleTypeCapacity(List<VehicleTypeCapacity> vehicleTypeCapacity
this.vehicleTypeCapacity = vehicleTypeCapacity;
}

public List<VehicleTypesCapacity> getVehicleTypesCapacity() {
return vehicleTypesCapacity;
}

public void setVehicleTypesCapacity(List<VehicleTypesCapacity> vehicleTypesCapacity) {
this.vehicleTypesCapacity = vehicleTypesCapacity;
}

public Boolean getValetStation() {
return isValetStation;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,11 @@
package org.entur.lamassu.model.entities;

import java.io.Serializable;
import java.util.List;

public class VehicleTypeCapacity implements Serializable {

private VehicleType vehicleType;

private List<VehicleType> vehicleTypes;

private Integer count;

public VehicleType getVehicleType() {
Expand All @@ -37,14 +34,6 @@ public void setVehicleType(VehicleType vehicleType) {
this.vehicleType = vehicleType;
}

public List<VehicleType> getVehicleTypes() {
return vehicleTypes;
}

public void setVehicleTypes(List<VehicleType> vehicleTypes) {
this.vehicleTypes = vehicleTypes;
}

public Integer getCount() {
return count;
}
Expand Down
17 changes: 14 additions & 3 deletions src/main/resources/graphql/schema.graphqls
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,10 @@ type Station {
parkingHoop: Boolean
contactPhone: String
capacity: Int
vehicleCapacity: [VehicleTypeCapacity]
vehicleTypeCapacity: [VehicleTypeCapacity]
vehicleCapacity: [VehicleTypeCapacity] @deprecated(reason: "Use vehicleTypesCapacity")
vehicleTypesCapacity: [VehicleTypesCapacity]
vehicleTypeCapacity: [VehicleTypeCapacity] @deprecated(reason: "Use vehicleDocksCapacity")
vehicleDocksCapacity: [VehicleDocksCapacity]
isValetStation: Boolean
isChargingStation: Boolean
rentalUris: RentalUris
Expand Down Expand Up @@ -327,7 +329,16 @@ type Operator {
}

type VehicleTypeCapacity {
vehicleType: VehicleType! @deprecated(reason: "Use vehicleTypes instead")
vehicleType: VehicleType!
count: Int!
}

type VehicleDocksCapacity {
vehicleTypes: [VehicleType!]!
count: Int!
}

type VehicleTypesCapacity {
vehicleTypes: [VehicleType!]!
count: Int!
}
Expand Down

0 comments on commit 995ac26

Please sign in to comment.