Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
a46a47b
based on comments in branch cchau-trial-team_use_case-with-full_stati…
carmen-chau Nov 13, 2023
d4644e0
Merge branch 'cchau-trial-team_use_case-with-full_station_view'
jacqnnn Nov 13, 2023
99b1032
revised ApiTestFile to reflect GO Train API usuage and sample use case
carmen-chau Nov 20, 2023
b5742bc
actually push the modifications intended from prior commit for ApiTes…
carmen-chau Nov 20, 2023
9464ba0
fix naming of class to GOStationApiClass.java
carmen-chau Nov 20, 2023
625acc3
added ApiClassInterface.java as an interface that forms structure for…
carmen-chau Nov 20, 2023
15fc222
Modified GoStationApiClass.java's structure such that it inherits Api…
carmen-chau Nov 20, 2023
9608834
reworked structure of ApiClassInterface as well as GOStationApiClass
carmen-chau Nov 20, 2023
877c96b
incoperated the GoStationApiClass into the Station DAO, revised Main.…
carmen-chau Nov 20, 2023
e93e7c9
preliminary solution to set station amenities list to actual value, b…
carmen-chau Nov 20, 2023
cae6251
implemented changes to the UI [incld changes to presentor, interactor…
carmen-chau Nov 20, 2023
8cd8f91
renamed ApiClassInterface.java to TrainApiInterface.java. changed GOS…
carmen-chau Nov 20, 2023
6d24276
per TA feedback, moved the API class and interface to an API folder n…
carmen-chau Nov 20, 2023
03f0f56
moved the DAO Object file to a new folder called text_file that is ne…
carmen-chau Nov 20, 2023
9707bae
deleted grade-api.iml
jacqnnn Nov 21, 2023
bed6008
Merge branch 'cchau-station-amenities-use-case' of https://github.com…
jacqnnn Nov 21, 2023
8467cca
Created GOTrainsApiClass.java for checking all trains current location.
arandaaron04 Nov 21, 2023
67f015a
First GOTrainsApiClass.java test for pulling description
arandaaron04 Nov 21, 2023
f3d1d32
Created GOVehiclePositionApiClass.java will be used for pulling Long,…
arandaaron04 Nov 22, 2023
8d5f005
nothing
jacqnnn Nov 22, 2023
7e400e3
Merge branch 'aaran-API-pulling-long_latt' of https://github.com/Jaso…
jacqnnn Nov 22, 2023
7d0c757
Fixed GOTrainsApiClass.java and GOVehiclePositionApiClass.java
arandaaron04 Nov 22, 2023
1f3b17e
Fixed GOVehiclePositionApiClass.java, no more "UP".
arandaaron04 Nov 22, 2023
a16aa9a
Update TrainApiInterface.java
arandaaron04 Nov 22, 2023
357fab1
Added GOTrainScheduledTimeApiClass to retrieve train scheduled time t…
jacqnnn Nov 22, 2023
011d360
Merge branch 'aaran-API-pulling-long_latt' of https://github.com/Jaso…
jacqnnn Nov 22, 2023
63ac341
Added GOTrainApiClass to retrieve real time train info
jacqnnn Nov 22, 2023
b8faa09
Created Train Class and TrainInterface. Edited some comment in Api cl…
jacqnnn Nov 22, 2023
836bf89
Created TrainFactory
jacqnnn Nov 22, 2023
0a4c0d9
updated StationInfoView and StationInfoViewModel for show_incoming_ve…
jacqnnn Nov 22, 2023
44570e7
Found better API calls to retrieve vehicle info. Thus changed GOTrain…
jacqnnn Nov 22, 2023
397de09
updated StationInfo use case except Interactor
jacqnnn Nov 22, 2023
6101c97
edited train related code based on api call change
jacqnnn Nov 27, 2023
216b33c
changed List<Vehicle> incomingVehicleList into List<Train> type in St…
jacqnnn Nov 27, 2023
20190f4
updated ShowIncomingVehiclesState for StationInfoPresenter
jacqnnn Nov 27, 2023
aa3c1cf
Added ShowIncomingVehiclesView
jacqnnn Nov 27, 2023
03b1bcc
implemented ShowIncomingVehiclesViewModel and StationInfoPresenter
jacqnnn Nov 27, 2023
55c3a4a
implemented StationInfoController, StationInfoUseCaseFactory. Finishe…
jacqnnn Nov 27, 2023
14d6105
let FileStationDataAccessObject implement StationInfoDataAccessInterface
jacqnnn Nov 27, 2023
a7c3c65
added stationinfo related code in Main
jacqnnn Nov 27, 2023
8419d74
Tentative change for incomingVehicles class (changed it from Vehicle …
jacqnnn Nov 27, 2023
70d091a
GOVehiclePositionApiClass.java JavaDocs added.
arandaaron04 Nov 27, 2023
0297949
GOTrainsApiClass.java created.
arandaaron04 Nov 27, 2023
f738160
GOTrainsApiClass.java updated.
arandaaron04 Nov 27, 2023
2fa4067
GOTrainsApiClass.java JavaDocs added.
arandaaron04 Nov 27, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions src/ApiTestFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@


public class ApiTestFile {
private static final String API_URL = "https://api.translink.ca/rttiapi/v1/stops/55612?";
private static final String PARTIAL_API_URL = "OpenDataAPI/api/V1";

public static void getStopInformation() {
OkHttpClient client = new OkHttpClient().newBuilder()
.build();
HttpUrl httpUrl = new HttpUrl.Builder()
.scheme("https")
.host("api.translink.ca")
.addPathSegment("rttiapi")
.addPathSegment("v1")
.addPathSegment("stops")
.addPathSegment("55612?")
.addQueryParameter("apikey", System.getenv("API_KEY"))
.scheme("http")
.host("api.openmetrolinx.com")
.addPathSegment(PARTIAL_API_URL)
.addPathSegment("Stop")
.addPathSegment("Details")
.addPathSegment("UN") //getting station information for UN, which denotes Union Station
.addQueryParameter("key", System.getenv("API_KEY"))
.build();

Request request = new Request.Builder()
Expand Down
11 changes: 8 additions & 3 deletions src/app/Main.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package app;

import data_access.FileStationDataAccessObject;
import data_access.text_file.FileStationDataAccessObject;
import data_access.API.GOStationApiClass;
import entity.StationFactory;
import interface_adapter.search.SearchViewModel;
import interface_adapter.ViewManagerModel;
import interface_adapter.show_incoming_vehicles.ShowIncomingVehiclesState;
import interface_adapter.show_incoming_vehicles.ShowIncomingVehiclesViewModel;
import interface_adapter.station_info.StationInfoViewModel;
import view.SearchPanelView;
import view.StationInfoView;
Expand Down Expand Up @@ -38,6 +41,8 @@ public static void main(String[] args) {
// be observed by the Views.
SearchViewModel searchViewModel = new SearchViewModel();
StationInfoViewModel stationInfoViewModel = new StationInfoViewModel();
ShowIncomingVehiclesViewModel showIncomingVehiclesViewModel = new ShowIncomingVehiclesViewModel();


// Creating a DAO called stationDataAccessObject by reading from file revisedStopData.txt, with the creation of the object being done by StationFactory()
// Note: This process is wrapped in a try-catch block since it is possible that the code throws out an IOException (occurs when the txt file being read does not exist)
Expand All @@ -47,7 +52,7 @@ public static void main(String[] args) {
// TODO [Implementation question]: Is there suppose to be NO ARGUMENT for the StationFactory() instance passed inside?
FileStationDataAccessObject stationDataAccessObject;
try {
stationDataAccessObject = new FileStationDataAccessObject("./revisedStopData.txt", new StationFactory());
stationDataAccessObject = new FileStationDataAccessObject("./revisedStopData.txt", new StationFactory(), new GOStationApiClass());
} catch (IOException e) {
throw new RuntimeException(e);
}
Expand All @@ -58,7 +63,7 @@ public static void main(String[] args) {

// Creating an instance of StationInfoView. Note: Although this view should have its own use case, for now, since we are NOT displaying other data besides the station name, there is no useCaseFactory for this case
// This View is only linked to transition from the SearchPanelView (once the other use case are integrated into this view, this will NO LONGER be the case)
StationInfoView stationInfoView = new StationInfoView(stationInfoViewModel);
StationInfoView stationInfoView = StationInfoUseCaseFactory.create(viewManagerModel, stationInfoViewModel, stationDataAccessObject, showIncomingVehiclesViewModel);
views.add(stationInfoView, stationInfoView.viewName);

// When initially booting up the application, the stationPanel is the 1st panel displayed to viewers.
Expand Down
4 changes: 3 additions & 1 deletion src/app/SearchUseCaseFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,11 @@ private static SearchController createSearchUseCase(
// Notice how we pass this method's parameters to the Presenter.
SearchOutputBoundary searchOutputBoundary = new SearchPresenter(searchViewModel, stationInfoViewModel, viewManagerModel);

// TODO [Implementation question]: No need to use an instance of SearchUseCaseFactory right?

SearchInputBoundary searchInteractor = new SearchInteractor(
searchDataAccessObject, searchOutputBoundary);

return new SearchController(searchInteractor);
}
}
}
54 changes: 54 additions & 0 deletions src/app/StationInfoUseCaseFactory.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package app;

import interface_adapter.ViewManagerModel;
import interface_adapter.show_incoming_vehicles.ShowIncomingVehiclesViewModel;
import interface_adapter.station_info.StationInfoController;
import interface_adapter.station_info.StationInfoPresenter;
import interface_adapter.station_info.StationInfoViewModel;
import use_case.StationInfo.StationInfoDataAccessInterface;
import use_case.StationInfo.StationInfoInputBoundary;
import use_case.StationInfo.StationInfoInteractor;
import use_case.StationInfo.StationInfoOutputBoundary;
import view.StationInfoView;

import javax.swing.*;
import java.io.IOException;

public class StationInfoUseCaseFactory {

/** Prevent instantiation. */
private StationInfoUseCaseFactory() {}

public static StationInfoView create(
ViewManagerModel viewManagerModel,
StationInfoViewModel stationInfoViewModel,
StationInfoDataAccessInterface stationInfoDataAccessObject,
ShowIncomingVehiclesViewModel showIncomingVehiclesViewModel) {

try {
StationInfoController stationInfoController = createStationInfoUseCase(viewManagerModel,
stationInfoViewModel, stationInfoDataAccessObject, showIncomingVehiclesViewModel);
return new StationInfoView(stationInfoViewModel, stationInfoController);
} catch (IOException e) {
JOptionPane.showMessageDialog(null, "Could not open user data file.");
}

return null;
}

private static StationInfoController createStationInfoUseCase(
ViewManagerModel viewManagerModel,
StationInfoViewModel stationInfoViewModel,
StationInfoDataAccessInterface stationInfoDataAccessObject,
ShowIncomingVehiclesViewModel showIncomingVehiclesViewModel) throws IOException {

// Notice how we pass this method's parameters to the Presenter.
StationInfoOutputBoundary stationInfoOutputBoundary = new StationInfoPresenter(stationInfoViewModel,
showIncomingVehiclesViewModel, viewManagerModel);

StationInfoInputBoundary stationInfoInteractor = new StationInfoInteractor(
stationInfoDataAccessObject, stationInfoOutputBoundary);

return new StationInfoController(stationInfoInteractor);
}
}
57 changes: 57 additions & 0 deletions src/data_access/API/GOStationApiClass.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package data_access.API;

import okhttp3.HttpUrl;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class GOStationApiClass implements TrainApiInterface {

private final String PARTIAL_API_URL = "OpenDataAPI/api/V1";
public GOStationApiClass () {
}
public List<String> retrieveStationAmenities(String stationId){
OkHttpClient client = new OkHttpClient().newBuilder()
.build();
HttpUrl httpUrl = new HttpUrl.Builder()
.scheme("http")
.host("api.openmetrolinx.com")
.addPathSegment(PARTIAL_API_URL)
.addPathSegment("Stop")
.addPathSegment("Details")
.addPathSegment(stationId) //getting station information for the station with the id denoted by stationId
.addQueryParameter("key", API_KEY)
.build();

Request request = new Request.Builder()
.url(httpUrl)
.addHeader("content-type", "application/json")
.build();
try {
// TODO: Do we need additional error checking based on error codes in Metadata?
Response response = client.newCall(request).execute();
String fullStopJsonData = response.body().string();
JSONObject fullStopJsonObj = new JSONObject(fullStopJsonData); // This is where the metadata is located at
JSONObject stopJsonDataObj = fullStopJsonObj.getJSONObject("Stop");
JSONArray amenitiesJsonArray = stopJsonDataObj.getJSONArray("Facilities");
List<String> amenitiesList = new ArrayList<String>();
for (int i = 0; i < amenitiesJsonArray.length(); i++) {
JSONObject currAmenitiesEntry = amenitiesJsonArray.getJSONObject(i);
amenitiesList.add(currAmenitiesEntry.getString("Description"));
//System.out.println(currAmenitiesEntry.getString("Description")); // For debugging purposes
}
return amenitiesList;

} catch (IOException | JSONException e) {
throw new RuntimeException(e);
}

}
}
70 changes: 70 additions & 0 deletions src/data_access/API/GOTrainsApiClass.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package data_access.API;

import okhttp3.HttpUrl;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class GOTrainsApiClass implements TrainApiInterface {

private final String PARTIAL_API_URL = "OpenDataAPI/api/V1";
public GOTrainsApiClass () {
}

/**
* Searches for all trains and their information including ID and position.
*
* @param stationId ID of station for incoming trains
* @return API information
*/
public List<String> retrieveTrains(String stationId){
OkHttpClient client = new OkHttpClient().newBuilder()
.build();
HttpUrl httpUrl = new HttpUrl.Builder()
.scheme("http")
.host("api.openmetrolinx.com")
.addPathSegment(PARTIAL_API_URL)
.addPathSegment("ServiceataGlance")
.addPathSegment("Trains")
.addPathSegment("All")
// TODO: may need for future
// .addPathSegment(stationId) //getting station information for the station with the id denoted by stationId
.addQueryParameter("key", API_KEY)
.build();

Request request = new Request.Builder()
.url(httpUrl)
.addHeader("content-type", "application/json")
.build();

/**
* Search for information
*/
try {
Response response = client.newCall(request).execute();
String trainJsonData = response.body().string();
JSONObject metaDataJsonObj = new JSONObject(trainJsonData); // This is where the Metadata is located at
JSONObject tripsJsonDataObj = metaDataJsonObj.getJSONObject("Trips");
JSONArray tripJsonArray = tripsJsonDataObj.getJSONArray("Trip");
List<String> tripList = new ArrayList<String>();
for (int i = 0; i < tripJsonArray.length(); i++) {
JSONObject currTripEntry = tripJsonArray.getJSONObject(i);
tripList.add(currTripEntry.getString("id")); // left at "id" for now, to be changed to vehicle
//System.out.println(currAmenitiesEntry.getString("Description")); // For debugging purposes
System.out.println(httpUrl);
}
return tripList; // do not print this yet, wait for full change

} catch (IOException | JSONException e) {
throw new RuntimeException(e);
}

}
}
75 changes: 75 additions & 0 deletions src/data_access/API/GOVehicleApiClass.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package data_access.API;

import okhttp3.HttpUrl;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import static data_access.API.TrainApiInterface.API_KEY;

public class GOVehicleApiClass {
private final String PARTIAL_API_URL = "OpenDataAPI/api/V1";
public GOVehicleApiClass() {
}
public List<List<String>> retrieveVehicleInfo(String stationId){
OkHttpClient client = new OkHttpClient().newBuilder()
.build();
HttpUrl httpUrl = new HttpUrl.Builder()
.scheme("http")
.host("api.openmetrolinx.com")
.addPathSegment(PARTIAL_API_URL)
.addPathSegment("Stop")
.addPathSegment("NextService")
.addPathSegment(stationId)
.addQueryParameter("key", API_KEY)
.build();

Request request = new Request.Builder()
.url(httpUrl)
.addHeader("content-type", "application/json")
.build();
try {
Response response = client.newCall(request).execute();
String trainInfoJsonData = response.body().string();
JSONObject headerPositionJsonObj = new JSONObject(trainInfoJsonData); // This is where the header is located at

JSONObject stationServiceJsonObj = headerPositionJsonObj.getJSONObject("NextService");
JSONArray vehiclesJsonArray = stationServiceJsonObj.getJSONArray("Lines");

List<List<String>> vehiclesList = new ArrayList<>();
for (int i = 0; i < vehiclesJsonArray.length(); i++) {
JSONObject currtripEntry = vehiclesJsonArray.getJSONObject(i);
List<String> vehiclesInfoList = new ArrayList<>();
vehiclesInfoList.add(currtripEntry.getString("LineCode")); // parent line id of the station
vehiclesInfoList.add(currtripEntry.getString("LineName")); // parent line full name
vehiclesInfoList.add(currtripEntry.getString("ServiceType"));
// indicates if vehicle is a train or a bus. Train is "T", Bus is "B"
vehiclesInfoList.add(currtripEntry.getString("DirectionName")); // Vehicle display name
vehiclesInfoList.add(currtripEntry.getString("ScheduledDepartureTime"));
// vehicle scheduled departure time from this station
vehiclesInfoList.add(currtripEntry.getString("ComputedDepartureTime"));
// vehicle actual departure time from this station
vehiclesInfoList.add(currtripEntry.getString("TripNumber"));
// We could calculate delay based on Computed Departure time and Scheduled departure time of a Certain Vehicle

vehiclesList.add(vehiclesInfoList); //add trainInfoList in trainList

System.out.println(vehiclesInfoList); // For debugging purposes

System.out.println(httpUrl);
}
return vehiclesList; // do not print this yet, wait for full change

} catch (IOException | JSONException e) {
throw new RuntimeException(e);
}

}
}
Loading