Skip to content

Commit

Permalink
Merge pull request #475 from entur/feature/add-v3-fields
Browse files Browse the repository at this point in the history
Add v3 fields
  • Loading branch information
testower authored Jun 12, 2024
2 parents df91081 + 9bd9af8 commit 11f57fc
Show file tree
Hide file tree
Showing 19 changed files with 419 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ private org.entur.lamassu.model.entities.GeofencingZones.Rule mapRule(GBFSRule r
var mapped = new org.entur.lamassu.model.entities.GeofencingZones.Rule();
mapped.setVehicleTypeIds(rule.getVehicleTypeIds());
mapped.setRideAllowed(rule.getRideStartAllowed() && rule.getRideEndAllowed());
mapped.setRideStartAllowed(rule.getRideStartAllowed());
mapped.setRideEndAllowed(rule.getRideEndAllowed());
mapped.setRideThroughAllowed(rule.getRideThroughAllowed());
mapped.setMaximumSpeedKph(
rule.getMaximumSpeedKph() != null ? rule.getMaximumSpeedKph() : null
Expand Down
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 All @@ -147,6 +168,11 @@ public Station mapStation(
? stationStatus.getNumVehiclesAvailable()
: null
);
station.setNumVehiclesAvailable(
stationStatus.getNumVehiclesAvailable() != null
? stationStatus.getNumVehiclesAvailable()
: null
);
station.setVehicleTypesAvailable(
stationStatus.getVehicleTypesAvailable() != null
? mapVehicleTypesAvailable(
Expand All @@ -162,6 +188,11 @@ public Station mapStation(
? stationStatus.getNumVehiclesDisabled()
: null
);
station.setNumVehiclesDisabled(
stationStatus.getNumVehiclesDisabled() != null
? stationStatus.getNumVehiclesDisabled()
: null
);
station.setNumDocksAvailable(
stationStatus.getNumDocksAvailable() != null
? stationStatus.getNumDocksAvailable()
Expand Down Expand Up @@ -282,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 @@ -295,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
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@
import org.entur.lamassu.model.entities.RentalApp;
import org.entur.lamassu.model.entities.RentalApps;
import org.entur.lamassu.model.entities.System;
import org.entur.lamassu.model.entities.TranslatedString;
import org.entur.lamassu.model.provider.FeedProvider;
import org.mobilitydata.gbfs.v3_0.system_information.GBFSAndroid;
import org.mobilitydata.gbfs.v3_0.system_information.GBFSAttributionOrganizationName;
import org.mobilitydata.gbfs.v3_0.system_information.GBFSBrandAssets;
import org.mobilitydata.gbfs.v3_0.system_information.GBFSData;
import org.mobilitydata.gbfs.v3_0.system_information.GBFSIos;
Expand Down Expand Up @@ -71,6 +73,7 @@ public System mapSystem(GBFSData systemInformation, FeedProvider feedProvider) {
var system = new System();
system.setId(systemInformation.getSystemId());
system.setLanguage(feedProvider.getLanguage());
system.setLanguages(systemInformation.getLanguages());
system.setName(
translationMapper.mapTranslatedString(
systemInformation
Expand All @@ -94,6 +97,7 @@ public System mapSystem(GBFSData systemInformation, FeedProvider feedProvider) {
.toList()
)
);
system.setOpeningHours(systemInformation.getOpeningHours());
system.setOperator(mapOperator(systemInformation.getOperator(), feedProvider));
system.setUrl(systemInformation.getUrl());
system.setPurchaseUrl(systemInformation.getPurchaseUrl());
Expand Down Expand Up @@ -130,7 +134,11 @@ public System mapSystem(GBFSData systemInformation, FeedProvider feedProvider) {
.orElse(null)
);
system.setPrivacyLastUpdated(systemInformation.getPrivacyLastUpdated());
system.setAttributionOrganizationName(
mapAttributionOrganizationName(systemInformation.getAttributionOrganizationName())
);
system.setRentalApps(mapRentalApps(systemInformation.getRentalApps()));
system.setTerminationDate(systemInformation.getTerminationDate());
return system;
}

Expand All @@ -149,6 +157,23 @@ private BrandAssets mapBrandAssets(GBFSBrandAssets brandAssets) {
return mapped;
}

private TranslatedString mapAttributionOrganizationName(
List<GBFSAttributionOrganizationName> attributionOrganizationName
) {
if (attributionOrganizationName == null) {
return null;
}

var mapped = new TranslatedString();
mapped.setTranslation(
attributionOrganizationName
.stream()
.map(name -> translationMapper.mapTranslation(name.getLanguage(), name.getText()))
.toList()
);
return mapped;
}

private RentalApps mapRentalApps(GBFSRentalApps sourceRentalApps) {
if (sourceRentalApps == null) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public VehicleType mapVehicleType(
PropulsionType.valueOf(vehicleType.getPropulsionType().name())
);
mapped.setEcoLabel(mapEcoLabels(vehicleType.getEcoLabels()));
mapped.setEcoLabels(mapEcoLabels(vehicleType.getEcoLabels()));
mapped.setMaxRangeMeters(vehicleType.getMaxRangeMeters());
mapped.setName(
translationMapper.mapTranslatedString(
Expand All @@ -76,6 +77,21 @@ public VehicleType mapVehicleType(
.toList()
)
);
mapped.setDescription(
translationMapper.mapTranslatedString(
Optional
.ofNullable(vehicleType.getDescription())
.orElse(Collections.emptyList())
.stream()
.map(description ->
translationMapper.mapTranslation(
description.getLanguage(),
description.getText()
)
)
.toList()
)
);
mapped.setVehicleAccessories(
mapVehicleAccessories(vehicleType.getVehicleAccessories())
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ public static class Rule implements Serializable {

private List<String> vehicleTypeIds;
private Boolean rideAllowed;
private Boolean rideStartAllowed;
private Boolean rideEndAllowed;
private Boolean rideThroughAllowed;
private Integer maximumSpeedKph;
private Boolean stationParking;
Expand All @@ -168,6 +170,22 @@ public void setRideAllowed(Boolean rideAllowed) {
this.rideAllowed = rideAllowed;
}

public Boolean getRideStartAllowed() {
return rideStartAllowed;
}

public void setRideStartAllowed(Boolean rideStartAllowed) {
this.rideStartAllowed = rideStartAllowed;
}

public Boolean getRideEndAllowed() {
return rideEndAllowed;
}

public void setRideEndAllowed(Boolean rideEndAllowed) {
this.rideEndAllowed = rideEndAllowed;
}

public Boolean getRideThroughAllowed() {
return rideThroughAllowed;
}
Expand Down
36 changes: 36 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,13 +40,17 @@ 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;
private Integer numBikesAvailable;
private Integer numVehiclesAvailable;
private List<VehicleTypeAvailability> vehicleTypesAvailable;
private Integer numBikesDisabled;
private Integer numVehiclesDisabled;
private Integer numDocksAvailable;
private List<VehicleDocksAvailability> vehicleDocksAvailable;
private Integer numDocksDisabled;
Expand Down Expand Up @@ -196,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 @@ -204,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 Expand Up @@ -236,6 +256,14 @@ public void setNumBikesAvailable(Integer numBikesAvailable) {
this.numBikesAvailable = numBikesAvailable;
}

public Integer getNumVehiclesAvailable() {
return numVehiclesAvailable;
}

public void setNumVehiclesAvailable(Integer numVehiclesAvailable) {
this.numVehiclesAvailable = numVehiclesAvailable;
}

public List<VehicleTypeAvailability> getVehicleTypesAvailable() {
return vehicleTypesAvailable;
}
Expand All @@ -254,6 +282,14 @@ public void setNumBikesDisabled(Integer numBikesDisabled) {
this.numBikesDisabled = numBikesDisabled;
}

public Integer getNumVehiclesDisabled() {
return numVehiclesDisabled;
}

public void setNumVehiclesDisabled(Integer numVehiclesDisabled) {
this.numVehiclesDisabled = numVehiclesDisabled;
}

public Integer getNumDocksAvailable() {
return numDocksAvailable;
}
Expand Down
Loading

0 comments on commit 11f57fc

Please sign in to comment.