Skip to content

Commit

Permalink
Merge pull request #196 from HSLdevcom/DT-2541
Browse files Browse the repository at this point in the history
DT-2541
  • Loading branch information
pailakka authored Mar 28, 2018
2 parents f96469a + b8cc71f commit 04457f7
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1823,6 +1823,11 @@ public IndexGraphQLSchema(GraphIndex index) {
.type(Scalars.GraphQLInt)
.dataFetcher(environment -> ((BikeRentalStation) environment.getSource()).spacesAvailable)
.build())
.field(GraphQLFieldDefinition.newFieldDefinition()
.name("state")
.type(Scalars.GraphQLString)
.dataFetcher(environment -> ((BikeRentalStation) environment.getSource()).state)
.build())
.field(GraphQLFieldDefinition.newFieldDefinition()
.name("realtime")
.type(Scalars.GraphQLBoolean)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ public class BikeRentalStation implements Serializable, Cloneable {
@JsonSerialize
public boolean isFloatingBike = false;

@XmlAttribute
@JsonSerialize
public String state = ""; // additional state info: on, off, closed, etc

/**
* List of compatible network names. Null (default) to be compatible with all.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,23 +52,15 @@ public SmooveBikeRentalDataSource() {
*/
public BikeRentalStation makeStation(JsonNode node) {
// TODO: final winter maintenance value not known yet
if (node.path("style").asText().equals("Winter state")) {
return null;
}
BikeRentalStation station = new BikeRentalStation();
station.id = node.path("name").asText().split("\\s", 2)[0];
station.name = new NonLocalizedString(node.path("name").asText().split("\\s", 2)[1]);
station.state = node.path("style").asText();
try {
station.y = Double.parseDouble(node.path("coordinates").asText().split(",")[0].trim());
station.x = Double.parseDouble(node.path("coordinates").asText().split(",")[1].trim());
if (node.path("operative").asText().equals("true") &&
node.path("style").asText().equals("Station on")) {
station.bikesAvailable = node.path("avl_bikes").asInt();
station.spacesAvailable = node.path("free_slots").asInt();
} else {
station.bikesAvailable = 0;
station.spacesAvailable = 0;
}
station.bikesAvailable = node.path("avl_bikes").asInt();
station.spacesAvailable = node.path("free_slots").asInt();
return station;
} catch (NumberFormatException e) {
// E.g. coordinates is empty
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

/* This program is free software: you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public License
as published by the Free Software Foundation, either version 3 of
Expand Down Expand Up @@ -66,11 +67,9 @@ public void testSmoove() {
BikeRentalStation fake = rentalStations.get(1);
assertEquals("Fake", fake.name.toString());
assertEquals("B05", fake.id);
assertEquals("Station off", fake.state);
assertEquals(24.0, fake.x);
assertEquals(60.0, fake.y);
// operative: false overrides available bikes and slots
assertEquals(0, fake.spacesAvailable);
assertEquals(0, fake.bikesAvailable);

BikeRentalStation foo = rentalStations.get(2);
assertEquals("Foo", foo.name.toString());
Expand Down
2 changes: 1 addition & 1 deletion src/test/resources/bike/smoove.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"name" : "B05 Fake",
"operative" : false,
"coordinates" : "60, 24",
"style" : "Station on",
"style" : "Station off",
"avl_bikes" : 5,
"free_slots" : 5,
"total_slots" : 5
Expand Down

0 comments on commit 04457f7

Please sign in to comment.