Skip to content

Commit

Permalink
Merge pull request #20 from olech2412/19-implement-journeys
Browse files Browse the repository at this point in the history
19 implement journeys
  • Loading branch information
olech2412 authored Feb 20, 2024
2 parents 6c0f05d + 3bd409d commit 89684f9
Show file tree
Hide file tree
Showing 15 changed files with 476 additions and 9 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>de.olech2412.adapter</groupId>
<artifactId>db-adapter-v6</artifactId>
<version>2.1.0</version>
<version>2.2.0</version>
<name>db-adapter-v6</name>
<description>This is an adapter for this rest-api: https://github.com/derhuerst/db-rest.
It can be used as a maven dependency and provides all models
Expand Down Expand Up @@ -49,7 +49,7 @@
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.22.0</version>
<version>2.22.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.projectlombok/lombok -->
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ private void buildRequestList() {
.build(),
new Request.RequestBuilder()
.setApiEndpoint(RequestPath.STATIONS)
.build(),
new Request.RequestBuilder()
.setApiEndpoint(RequestPath.JOURNEYS)
.build()
);
}
Expand Down
24 changes: 23 additions & 1 deletion src/main/java/de/olech2412/adapter/dbadapter/DB_Adapter_v6.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import de.olech2412.adapter.dbadapter.gsonadapter.GeographicCoordinatesAdapter;
import de.olech2412.adapter.dbadapter.gsonadapter.LocalDateTimeAdapter;
import de.olech2412.adapter.dbadapter.gsonadapter.LocalDateTimeAdapterForTrip;
import de.olech2412.adapter.dbadapter.model.journey.Journey;
import de.olech2412.adapter.dbadapter.model.station.Station;
import de.olech2412.adapter.dbadapter.model.station.sub.GeographicCoordinates;
import de.olech2412.adapter.dbadapter.model.stop.Stop;
Expand Down Expand Up @@ -111,7 +112,6 @@ public Result<Stop, Error> getStopById(Integer id, List<Parameter<?>> parameters
log.error(String.format("Error while getting stop by id %s: %s", id, result.getError().getError()));
return Result.error(result.getError());
} else {
Result<Stop, Error> stopResult = Result.success(gson.fromJson(result.getData(), Stop.class));
return Result.success(gson.fromJson(result.getData(), Stop.class));
}
}
Expand All @@ -137,6 +137,28 @@ public Result<Station, Error> getStationById(Integer id, List<Parameter<?>> para
}
}

/**
* Get a journey with the given parameters
*
* @param parameters the parameters of the journey from and to are necessary
* @return the journey or an error
* @throws IOException if the request fails
*/
public Result<Journey[], Error> getJourney(List<Parameter<?>> parameters) throws IOException {
String parameter = ParameterEvaluator.convertToString(parameters);
Request request = getRequest(RequestPath.JOURNEYS);
request.setApiEndpoint(request.getApiEndpoint() + parameter);
Result<JsonObject, Error> result = performRequest(request);

if (!result.isSuccess()) {
log.error(String.format("Error while getting journey: %s", result.getError().getError()));
return Result.error(result.getError());
} else {
JsonArray jsonArray = result.getData().getAsJsonArray("journeys");
return Result.success(gson.fromJson(jsonArray, Journey[].class));
}
}

/**
* Get the request from the api configuration
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package de.olech2412.adapter.dbadapter.model.journey;

import de.olech2412.adapter.dbadapter.model.journey.sub.Leg;
import de.olech2412.adapter.dbadapter.model.journey.sub.Price;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

import java.util.List;

/**
* Represents a journey from one location to another.
*/
@Getter
@Setter
@ToString
public class Journey {
/**
* The type of the journey.
*/
private String type;

/**
* The legs of the journey. Each leg represents a part of the journey.
*/
private List<Leg> legs;

/**
* The refresh token for the journey. This can be used to update the journey information.
*/
private String refreshToken;

/**
* The price of the journey.
*/
private Price price;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package de.olech2412.adapter.dbadapter.model.journey.sub;

import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

/**
* The Feature class represents a feature in a journey.
* It contains a type, properties and geometry of the feature.
*/
@Getter
@Setter
@ToString
public class Feature {
// The type of the feature
private String type;

// The properties of the feature
private Properties properties;

// The geometry of the feature
private Geometry geometry;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package de.olech2412.adapter.dbadapter.model.journey.sub;

import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

import java.util.List;

/**
* The Geometry class represents the geometric coordinates of a location.
* It contains a type and a list of coordinates.
*/
@Getter
@Setter
@ToString
public class Geometry {
// The type of the geometry
private String type;

// The coordinates of the geometry
private List<Double> coordinates;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
package de.olech2412.adapter.dbadapter.model.journey.sub;

import de.olech2412.adapter.dbadapter.model.stop.Stop;
import de.olech2412.adapter.dbadapter.model.stop.sub.Line;
import de.olech2412.adapter.dbadapter.model.trip.sub.Remark;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

import java.util.List;

/**
* Represents a leg of a journey.
*/
@Getter
@Setter
@ToString
public class Leg {
/**
* The origin stop of the leg.
*/
private Stop origin;

/**
* The destination stop of the leg.
*/
private Stop destination;

/**
* The departure time of the leg.
*/
private String departure;

/**
* The planned departure time of the leg.
*/
private String plannedDeparture;

/**
* The delay in departure of the leg in minutes.
*/
private int departureDelay;

/**
* The arrival time of the leg.
*/
private String arrival;

/**
* The planned arrival time of the leg.
*/
private String plannedArrival;

/**
* The delay in arrival of the leg in minutes.
*/
private int arrivalDelay;

/**
* Indicates if the leg is reachable.
*/
private boolean reachable;

/**
* The trip ID of the leg.
*/
private String tripId;

/**
* The line of the leg.
*/
private Line line;

/**
* The direction of the leg.
*/
private String direction;

/**
* The current location of the leg.
*/
private Location currentLocation;

/**
* The arrival platform of the leg.
*/
private String arrivalPlatform;

/**
* The planned arrival platform of the leg.
*/
private String plannedArrivalPlatform;

/**
* The type of arrival prognosis of the leg.
*/
private String arrivalPrognosisType;

/**
* The departure platform of the leg.
*/
private String departurePlatform;

/**
* The planned departure platform of the leg.
*/
private String plannedDeparturePlatform;

/**
* The type of departure prognosis of the leg.
*/
private String departurePrognosisType;

/**
* The remarks for the leg.
*/
private List<Remark> remarks;

/**
* The load factor of the leg.
*/
private String loadFactor;

/**
* The stopovers of the leg.
*/
private List<Stopover> stopovers;

/**
* The geometry of the leg.
*/
private Polyline polyline;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package de.olech2412.adapter.dbadapter.model.journey.sub;

/**
* Represents a location in the system.
*/
public class Location {
/**
* The type of the location.
*/
private String type;

/**
* The ID of the location.
*/
private String id;

/**
* The latitude of the location.
*/
private double latitude;

/**
* The longitude of the location.
*/
private double longitude;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package de.olech2412.adapter.dbadapter.model.journey.sub;

import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

import java.util.List;

/**
* The Polyline class represents a polyline in a journey.
* It contains a type and a list of features associated with the polyline.
*/
@Getter
@Setter
@ToString
public class Polyline {
// The type of the polyline
private String type;

// A list of features associated with the polyline
private List<Feature> features;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package de.olech2412.adapter.dbadapter.model.journey.sub;

/**
* Represents the price of a journey.
*/
public class Price {
/**
* The amount of the price.
*/
private double amount;

/**
* The currency of the price.
*/
private String currency;

/**
* A hint related to the price.
*/
private String hint;
}
Loading

0 comments on commit 89684f9

Please sign in to comment.