Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
145 changes: 145 additions & 0 deletions LockdownTravellerServer/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
# Index
* [Build and Run Commands](#build-and-run-commands)
* [List of tables](#list-of-tables);
* [Description of tables](#description-of-tables);
* [Admin](#admin);
* [Basic_Train_Info](#basic_train_info)
* [Booking_Info](#booking_info)
* [Notification](#notification)
* [Route_Info](#route_info)
* [User](#user)
* [Vacancy_Info](#vacancy_info)

# Build and Run Commands.

~/checker-framework-3.7.0/checker/bin/javac -processor nullness *.java -d ./bin

java -classpath ~/Lockdown_Traveller/LockdownTravellerServer/src/bin/:/usr/share/java/mysql-connector-java-8.0.21.jar Server

# List of tables.

| Tables | Needed in minimal version?|
|:---------------:|:-------------------------:|
|Admin | Yes |
|Basic_Train_Info | Yes |
|Booking_Info | Yes |
|Notification | Yes |
|Platform_No | No |
|Route_Info | Yes |
|User | Yes |
|Vacancy_Info | Yes |


# Description of tables.

#### Admin
Stores information related to admin login.

| Field | Type | Null | Key | Default | Extra |
|----------|-------------|------|-----|---------|-------|
| Username | varchar(20) | NO | | NULL | |
| Password | varchar(64) | NO | | NULL | |
| Admin_ID | int | NO | | NULL | |


#### Basic_Train_Info

Stores basic information about the train, like its name, number of different
types of coaches and number of seats in them, fare for each type of coach,
days on which the trains run.

| Field | Type | Null | Key | Default | Needed in minimal version? |
|------------------|-------------|------|-----|---------|:-----:|
| Train_ID | varchar(5) | NO | PRI | NULL | |
| Train_Name | varchar(30) | NO | | NULL | |
| Days_Running | varchar(7) | NO | | NULL | |
| Cancelled_Till | date | YES | | NULL | No|
| FirstAC_Coaches | int | YES | | NULL | |
| SecondAC_Coaches | int | YES | | NULL | |
| ThirdAC_Coaches | int | YES | | NULL | |
| Sleeper_Coaches | int | YES | | NULL | |
| FirstAC_Seats | int | YES | | NULL | |
| SecondAC_Seats | int | YES | | NULL | |
| ThirdAC_Seats | int | YES | | NULL | |
| Sleeper_Seats | int | YES | | NULL | |
| FirstAC_Fare | int | YES | | NULL | |
| SecondAC_Fare | int | YES | | NULL | |
| ThirdAC_Fare | int | YES | | NULL | |
| Sleeper_Fare | int | YES | | NULL | |
| Rerouted_Till | date | YES | | NULL | No|
| Added_Till | date | YES | | NULL | No|

#### Booking_Info

Stores relevant information about each booking. Things liked which user booked
a seat, who will travel on the seat, is the booking confirmed or in waiting.

| Field | Type | Null | Key | Default | Extra |
|------------------|-------------|------|-----|---------|-------|
| Booking_ID | varchar(10) | NO | PRI | NULL | |
| PNR | varchar(5) | NO | | NULL | |
| User_ID | varchar(20) | NO | MUL | NULL | |
| Passenger_Name | varchar(40) | NO | | NULL | |
| Passenger_Age | int | NO | | NULL | |
| Passenger_Gender | varchar(10) | NO | | NULL | |
| Booking_Status | varchar(10) | NO | | NULL | |

#### Notification

Stores notification details. The notification itself, the user to give the
notification to and whether or not the notification has already been seen once.

| Field | Type | Null | Key | Default | Extra |
|----------------|--------------|------|-----|---------|-------|
| User_ID | varchar(20) | NO | | NULL | |
| Message | varchar(500) | NO | | NULL | |
| Pending_Status | int | NO | | NULL | |

#### Route_Info

Stores the stations each train will visit and various information like arrival
departure times etc.

| Field | Type | Null | Key | Default | Extra |
|------------------|-------------|------|-----|---------|-------|
| Train_ID | varchar(5) | NO | MUL | NULL | |
| Train_Name | varchar(30) | NO | | NULL | |
| Station | varchar(20) | NO | | NULL | |
| Station_No | int | NO | | NULL | |
| City_Code | varchar(3) | NO | | NULL | |
| Arrival | varchar(4) | YES | | NULL | |
| Departure | varchar(4) | YES | | NULL | |
| Day_No | int | NO | | NULL | |
| Distance_Covered | int | NO | | NULL | |
| Rerouted | int | YES | | NULL | |
| inCurrentRoute | int | NO | | NULL | |

#### User

Stores detail of the users of the application.

| Field | Type | Null | Key | Default | Extra |
|-------------|-------------|------|-----|---------|-------|
| User_ID | varchar(20) | NO | PRI | NULL | |
| First_Name | varchar(20) | NO | | NULL | |
| Last_Name | varchar(20) | NO | | NULL | |
| Gender | varchar(10) | NO | | NULL | |
| Age | int | NO | | NULL | |
| Email_ID | varchar(50) | NO | | NULL | |
| Phone_No | varchar(15) | NO | | NULL | |
| Username | varchar(20) | NO | | NULL | |
| Password | varchar(64) | NO | | NULL | |
| Total_Spend | int | NO | | 0 | |

#### Vacancy_Info

Stores seats which have been booked from a particular station to another.

| Field | Type | Null | Key | Default | Extra |
|------------|-------------|------|-----|---------|-------|
| Train_ID | varchar(5) | NO | | NULL | |
| Booking_ID | varchar(15) | NO | MUL | NULL | |
| Date | date | NO | | NULL | |
| Station | varchar(20) | NO | | NULL | |
| Station_No | int | NO | | NULL | |
| Seat_No | varchar(10) | NO | | NULL | |
15 changes: 12 additions & 3 deletions LockdownTravellerServer/src/AdminLoginRequestHandler.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import org.checkerframework.checker.initialization.qual.Initialized;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;

import java.io.ObjectOutputStream;
import java.sql.Connection;
import java.sql.PreparedStatement;
Expand Down Expand Up @@ -42,22 +46,27 @@ public void sendQuery() {
* @params Queries.
* @return Response to the admin login query.
*/
public AdminLoginResponse adminLoginRequest(String query) {
public @Nullable AdminLoginResponse adminLoginRequest(String query) {
try {
System.out.println("Prepared statement");
PreparedStatement validateLogin = connection.prepareStatement(query);
validateLogin.setString(1, adminLoginRequest.getUsername());
validateLogin.setString(2, adminLoginRequest.getPassword());
System.out.println("going to execute");
ResultSet adminCredentials = validateLogin.executeQuery();
@Initialized @NonNull ResultSet adminCredentials = validateLogin.executeQuery(); // This @NonNull here is
// not redundant because without it, there is a dereference.of.nullable warning in the while clause in the
// else block below. Same with the @Initialized annotation.

// Check if the result set is empty. If empty send failure as object response.
if (!adminCredentials.next()) {
System.out.println("fail");
return new AdminLoginResponse("failure", "");
} else {
do {
System.out.println("success");
return new AdminLoginResponse("success", adminCredentials.getString("Admin_ID"));
@SuppressWarnings("assignment.type.incompatible") // Admin_ID cannot be null. Refer the README.
@NonNull String s = adminCredentials.getString("Admin_ID");
return new AdminLoginResponse("success", s);
} while (adminCredentials.next());
}
} catch (SQLException e) {
Expand Down
56 changes: 44 additions & 12 deletions LockdownTravellerServer/src/BookingHistoryRequestHandler.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;

import java.io.ObjectOutputStream;
import java.sql.Connection;
import java.sql.PreparedStatement;
Expand Down Expand Up @@ -53,7 +57,7 @@ public void sendQuery() {
* @params Queries.
* @return Response to the Booking history request.
*/
public BookingHistoryResponse bookinghistory(BookingHistoryRequest historyRequest, String query1, String query2, String query3) {
public @Nullable BookingHistoryResponse bookinghistory(BookingHistoryRequest historyRequest, String query1, String query2, String query3) {

// All fields that will be a part of the response object.
ArrayList<ArrayList<String>> bookingID = new ArrayList<>();
Expand All @@ -71,39 +75,67 @@ public BookingHistoryResponse bookinghistory(BookingHistoryRequest historyReques
getPnr.setString(1, historyRequest.getUserid());
resultSet = getPnr.executeQuery();
while(resultSet.next()) {
pnr.add(resultSet.getString("PNR"));

@SuppressWarnings("assignment.type.incompatible") // PNR cannot be null. Refer the README.
@NonNull String s = resultSet.getString("PNR");
pnr.add(s);
}
final int n = pnr.size();
for(int i = 0; i < n; i++) {
System.out.println(pnr.get(i));
PreparedStatement perPnrQuery = connection.prepareStatement(query2);
String confirmedBookingID = "";
@MonotonicNonNull String confirmedBookingID = null;
perPnrQuery.setString(1, pnr.get(i));
ResultSet bookingForPnr = perPnrQuery.executeQuery();
bookingID.add(new ArrayList<>());
name.add(new ArrayList<>());
age.add(new ArrayList<>());
gender.add(new ArrayList<>());
while(bookingForPnr.next()) {
bookingID.get(i).add(bookingForPnr.getString("Booking_ID"));
if(bookingForPnr.getString("Booking_Status").equals("Confirmed"))
confirmedBookingID = bookingForPnr.getString("Booking_ID");
name.get(i).add(bookingForPnr.getString("Passenger_Name"));
@SuppressWarnings("assignment.type.incompatible") // Booking_ID cannot be null. Refer the README.
@NonNull String s = bookingForPnr.getString("Booking_ID");
bookingID.get(i).add(s);

@SuppressWarnings("assignment.type.incompatible") // Booking_Status cannot be null. Refer the README.
@NonNull String bookingStatus = bookingForPnr.getString("Booking_Status");
if(bookingStatus.equals("Confirmed")) {
@SuppressWarnings("assignment.type.incompatible") // Booking ID cannot be null. Refer the README.
@NonNull String confirmedId = bookingForPnr.getString("Booking_ID");
confirmedBookingID = confirmedId;
}

@SuppressWarnings("assignment.type.incompatible") // Passenger_Name cannot be null. Refer the README.
@NonNull String pName = bookingForPnr.getString("Passenger_Name");
name.get(i).add(pName);

age.get(i).add(bookingForPnr.getInt("Passenger_Age"));
gender.get(i).add(bookingForPnr.getString("Passenger_Gender"));

@SuppressWarnings("assignment.type.incompatible") // Gender cannot be null. Refer the README.
@NonNull String pGender = bookingForPnr.getString("Passenger_Gender");
gender.get(i).add(pGender);
}
PreparedStatement otherDetails = connection.prepareStatement(query3);
if(!confirmedBookingID.equals("")) {
if(confirmedBookingID != null) {
otherDetails.setString(1, confirmedBookingID);
otherDetails.setString(2, confirmedBookingID);
otherDetails.setString(3, confirmedBookingID);
System.out.println(otherDetails.toString());
ResultSet others = otherDetails.executeQuery();
others.next();
source.add(others.getString("Station"));
date.add(others.getString("Date"));
System.out.println(query3);
@SuppressWarnings("assignment.type.incompatible") // Station cannot be null. Refer the README.
@NonNull String s = others.getString("Station");
source.add(s);

@SuppressWarnings("assignment.type.incompatible") // Date cannot be null. Refer the README.
@NonNull String pDate = others.getString("Date");
date.add(pDate);

others.next();
destination.add("Station");

@SuppressWarnings("assignment.type.incompatible") // Station cannot be null. Refer the README.
@NonNull String pDestination = others.getString("Station");
destination.add(pDestination);
} else {
source.add("N/A");
destination.add("N/A");
Expand Down
Loading