From 20e1c668e4dddf90cf6dfe69db7de49b09fea415 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=20Erik=20St=C3=B8wer?= Date: Sun, 9 Jun 2024 22:18:07 +0200 Subject: [PATCH] VehicleTypesCapacity and vehicleDocksCapacity --- .../mapper/entitymapper/StationMapper.java | 67 +++++++++++++++++-- .../entur/lamassu/model/entities/Station.java | 18 +++++ .../model/entities/VehicleDocksCapacity.java | 43 ++++++++++++ .../model/entities/VehicleTypeCapacity.java | 11 --- .../model/entities/VehicleTypesCapacity.java | 43 ++++++++++++ src/main/resources/graphql/schema.graphqls | 17 ++++- 6 files changed, 181 insertions(+), 18 deletions(-) create mode 100644 src/main/java/org/entur/lamassu/model/entities/VehicleDocksCapacity.java create mode 100644 src/main/java/org/entur/lamassu/model/entities/VehicleTypesCapacity.java diff --git a/src/main/java/org/entur/lamassu/mapper/entitymapper/StationMapper.java b/src/main/java/org/entur/lamassu/mapper/entitymapper/StationMapper.java index 3a98dc9a..283ea393 100644 --- a/src/main/java/org/entur/lamassu/mapper/entitymapper/StationMapper.java +++ b/src/main/java/org/entur/lamassu/mapper/entitymapper/StationMapper.java @@ -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; @@ -121,6 +123,7 @@ public Station mapStation( station.setCapacity( stationInformation.getCapacity() != null ? stationInformation.getCapacity() : null ); + station.setVehicleCapacity( stationInformation.getVehicleTypesCapacity() != null ? mapVehicleCapacities( @@ -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( @@ -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( @@ -292,10 +313,29 @@ private List mapVehicleCapacities( mapped.setVehicleType( vehicleTypes.get(vehicleCapacity.getVehicleTypeIds().getFirst()) ); + mapped.setCount(vehicleCapacity.getCount()); + return mapped; + } + + private List mapVehicleTypesCapacity( + List vehicleTypesCapacity, + Map vehicleTypes + ) { + return vehicleTypesCapacity + .stream() + .map(v -> mapVehicleTypeCapacity(v, vehicleTypes)) + .toList(); + } + + private VehicleTypesCapacity mapVehicleTypeCapacity( + GBFSVehicleTypesCapacity vehicleTypesCapacity, + Map 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; } @@ -305,11 +345,11 @@ private List mapVehicleTypeCapacities( ) { return vehicleCapacity .stream() - .map(entry -> mapVehicleDocksCapacity(entry, vehicleTypes)) + .map(entry -> mapVehicleDocksCapacityToVehicleTypeCapacity(entry, vehicleTypes)) .toList(); } - private VehicleTypeCapacity mapVehicleDocksCapacity( + private VehicleTypeCapacity mapVehicleDocksCapacityToVehicleTypeCapacity( GBFSVehicleDocksCapacity vehicleDocksCapacity, Map vehicleTypes ) { @@ -317,6 +357,25 @@ private VehicleTypeCapacity mapVehicleDocksCapacity( mapped.setVehicleType( vehicleTypes.get(vehicleDocksCapacity.getVehicleTypeIds().getFirst()) ); + mapped.setCount(vehicleDocksCapacity.getCount()); + return mapped; + } + + private List mapVehicleDocksCapacityToVehicleTypeCapacity( + List vehicleDocksCapacity, + Map vehicleTypes + ) { + return vehicleDocksCapacity + .stream() + .map(v -> mapVehicleDocksCapacity(v, vehicleTypes)) + .toList(); + } + + private VehicleDocksCapacity mapVehicleDocksCapacity( + GBFSVehicleDocksCapacity vehicleDocksCapacity, + Map vehicleTypes + ) { + var mapped = new VehicleDocksCapacity(); mapped.setVehicleTypes( vehicleDocksCapacity.getVehicleTypeIds().stream().map(vehicleTypes::get).toList() ); diff --git a/src/main/java/org/entur/lamassu/model/entities/Station.java b/src/main/java/org/entur/lamassu/model/entities/Station.java index a72a2adf..9d36dbe4 100644 --- a/src/main/java/org/entur/lamassu/model/entities/Station.java +++ b/src/main/java/org/entur/lamassu/model/entities/Station.java @@ -40,7 +40,9 @@ public class Station implements LocationEntity { private String contactPhone; private Integer capacity; private List vehicleCapacity; + private List vehicleDocksCapacity; private List vehicleTypeCapacity; + private List vehicleTypesCapacity; private Boolean isValetStation; private Boolean isChargingStation; private RentalUris rentalUris; @@ -198,6 +200,14 @@ public void setVehicleCapacity(List vehicleCapacity) { this.vehicleCapacity = vehicleCapacity; } + public List getVehicleDocksCapacity() { + return vehicleDocksCapacity; + } + + public void setVehicleDocksCapacity(List vehicleDocksCapacity) { + this.vehicleDocksCapacity = vehicleDocksCapacity; + } + public List getVehicleTypeCapacity() { return vehicleTypeCapacity; } @@ -206,6 +216,14 @@ public void setVehicleTypeCapacity(List vehicleTypeCapacity this.vehicleTypeCapacity = vehicleTypeCapacity; } + public List getVehicleTypesCapacity() { + return vehicleTypesCapacity; + } + + public void setVehicleTypesCapacity(List vehicleTypesCapacity) { + this.vehicleTypesCapacity = vehicleTypesCapacity; + } + public Boolean getValetStation() { return isValetStation; } diff --git a/src/main/java/org/entur/lamassu/model/entities/VehicleDocksCapacity.java b/src/main/java/org/entur/lamassu/model/entities/VehicleDocksCapacity.java new file mode 100644 index 00000000..39c9ec7f --- /dev/null +++ b/src/main/java/org/entur/lamassu/model/entities/VehicleDocksCapacity.java @@ -0,0 +1,43 @@ +/* + * + * + * * Licensed under the EUPL, Version 1.2 or – as soon they will be approved by + * * the European Commission - subsequent versions of the EUPL (the "Licence"); + * * You may not use this work except in compliance with the Licence. + * * You may obtain a copy of the Licence at: + * * + * * https://joinup.ec.europa.eu/software/page/eupl + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the Licence is distributed on an "AS IS" basis, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the Licence for the specific language governing permissions and + * * limitations under the Licence. + * + */ + +package org.entur.lamassu.model.entities; + +import java.util.List; + +public class VehicleDocksCapacity { + + private List vehicleTypes; + private Integer count; + + public List getVehicleTypes() { + return vehicleTypes; + } + + public void setVehicleTypes(List vehicleTypes) { + this.vehicleTypes = vehicleTypes; + } + + public Integer getCount() { + return count; + } + + public void setCount(Integer count) { + this.count = count; + } +} diff --git a/src/main/java/org/entur/lamassu/model/entities/VehicleTypeCapacity.java b/src/main/java/org/entur/lamassu/model/entities/VehicleTypeCapacity.java index 7783dc8a..8a310cc5 100644 --- a/src/main/java/org/entur/lamassu/model/entities/VehicleTypeCapacity.java +++ b/src/main/java/org/entur/lamassu/model/entities/VehicleTypeCapacity.java @@ -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 vehicleTypes; - private Integer count; public VehicleType getVehicleType() { @@ -37,14 +34,6 @@ public void setVehicleType(VehicleType vehicleType) { this.vehicleType = vehicleType; } - public List getVehicleTypes() { - return vehicleTypes; - } - - public void setVehicleTypes(List vehicleTypes) { - this.vehicleTypes = vehicleTypes; - } - public Integer getCount() { return count; } diff --git a/src/main/java/org/entur/lamassu/model/entities/VehicleTypesCapacity.java b/src/main/java/org/entur/lamassu/model/entities/VehicleTypesCapacity.java new file mode 100644 index 00000000..9540f2ff --- /dev/null +++ b/src/main/java/org/entur/lamassu/model/entities/VehicleTypesCapacity.java @@ -0,0 +1,43 @@ +/* + * + * + * * Licensed under the EUPL, Version 1.2 or – as soon they will be approved by + * * the European Commission - subsequent versions of the EUPL (the "Licence"); + * * You may not use this work except in compliance with the Licence. + * * You may obtain a copy of the Licence at: + * * + * * https://joinup.ec.europa.eu/software/page/eupl + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the Licence is distributed on an "AS IS" basis, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the Licence for the specific language governing permissions and + * * limitations under the Licence. + * + */ + +package org.entur.lamassu.model.entities; + +import java.util.List; + +public class VehicleTypesCapacity { + + private List vehicleTypes; + private Integer count; + + public List getVehicleTypes() { + return vehicleTypes; + } + + public void setVehicleTypes(List vehicleTypes) { + this.vehicleTypes = vehicleTypes; + } + + public Integer getCount() { + return count; + } + + public void setCount(Integer count) { + this.count = count; + } +} diff --git a/src/main/resources/graphql/schema.graphqls b/src/main/resources/graphql/schema.graphqls index 8165807d..6089d86e 100644 --- a/src/main/resources/graphql/schema.graphqls +++ b/src/main/resources/graphql/schema.graphqls @@ -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 @@ -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! }