Skip to content
This repository has been archived by the owner on Jan 12, 2024. It is now read-only.

Commit

Permalink
Merge pull request #59 from NTNU-BIDATA-IDATG1003-2023/dev
Browse files Browse the repository at this point in the history
release: FP
  • Loading branch information
erikbjo authored Dec 9, 2023
2 parents 1c61575 + 5600662 commit e9fd77d
Show file tree
Hide file tree
Showing 19 changed files with 338 additions and 140 deletions.
54 changes: 37 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,16 @@
STUDENT NAME = Erik Bjørnsen
STUDENT ID = erbj

## Project description
## Project description 📝

Train Dispatch System is a system for dispatching trains. It only shows the trains connected with Oslo S.
<p>
Train Dispatch System is a Java application made to manage train departures.
The application is made with Spring Boot and Maven, and uses Derby as a database.
The user-interface is made with Spring Shell.
Exam project for the course IDATG1003 at NTNU Gjøvik.
</p>

## How to run the project
## How to run the project 🚀

1. Clone the repository with:
```bash
Expand All @@ -30,10 +35,10 @@ or
2. Run the program with:

```bash
java -jar tds-*version*.jar
java -jar tds-3.jar
```

## How to run the tests
## How to run the tests 🧪

1. Clone the repository
2. Run the tests with:
Expand All @@ -42,7 +47,18 @@ java -jar tds-*version*.jar
./mvnw clean test
```

## Project structure
## How to use the program 🖥

When the program is running, you can use the following command to get help:
```tds
help
```

## Contact 📧

If you have any questions, you can contact me [here](mailto:[email protected])

## Project structure 📁

```
root
Expand All @@ -54,15 +70,17 @@ root
│ │ │ └── erbj
│ │ │ └── tds
│ │ │ ├── dao
│ │ │ │ ├──DAO.java
│ │ │ │ ├──DepartureDAO.java
│ │ │ │ ├──StationDAO.java
│ │ │ │ ├──TrainDAO.java
│ │ │ │ └──WagonDAO.java
│ │ │ │ ├──Dao.java
│ │ │ │ ├──DepartureDao.java
│ │ │ │ ├──StationDao.java
│ │ │ │ ├──TrainDao.java
│ │ │ │ └──WagonDao.java
│ │ │ │
│ │ │ ├── model
│ │ │ │ ├── Departure.java
│ │ │ │ ├── DepartureBuilder.java
│ │ │ │ ├── departures
│ │ │ │ │ ├── Departure.java
│ │ │ │ │ └── DepartureBuilder.java
│ │ │ │ │
│ │ │ │ ├── Station.java
│ │ │ │ ├── Train.java
│ │ │ │ ├── Wagon.java
Expand All @@ -86,7 +104,7 @@ root
│ │ │ │ │ └── TimeController.java
│ │ │ │ │
│ │ │ │ └── utilites
│ │ │ │ ├── ANSIColors.java
│ │ │ │ ├── AnsiColors.java
│ │ │ │ ├── Colorize.java
│ │ │ │ ├── Printer.java
│ │ │ │ ├── SortUtility.java
Expand Down Expand Up @@ -118,8 +136,10 @@ root
└── README.md
```

## Link to repository
## Troubleshooting 🛠

[GitHub Classroom](https://github.com/NTNU-BIDATA-IDATG1003-2023/mappe-idatg1003-traindispatchsystem-erikbjo)
If you get any persistence errors, try to delete the tdsDB directory and run the program again.

## References
## Link to repository 🌐

[GitHub Classroom](https://github.com/NTNU-BIDATA-IDATG1003-2023/mappe-idatg1003-traindispatchsystem-erikbjo)
6 changes: 5 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</parent>
<groupId>no.ntnu.erbj</groupId>
<artifactId>tds</artifactId>
<version>2.1</version>
<version>3</version>
<name>tds</name>
<description>Train Dispatch System</description>
<properties>
Expand All @@ -20,6 +20,7 @@
</properties>

<dependencies>
<!-- Spring dependencies -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
Expand Down Expand Up @@ -82,6 +83,9 @@
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<mainClass>${mainClass}</mainClass>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand Down
4 changes: 1 addition & 3 deletions src/main/java/no/ntnu/erbj/tds/TdsApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
/**
* The main class of the application. This class is responsible for starting the application.
*
* @version 2.0
* @version 3.0
* @author Erik Bjørnsen
*/
@SpringBootApplication
Expand All @@ -24,8 +24,6 @@ public class TdsApplication {
* @param args The command line arguments.
*/
public static void main(String[] args) {

SpringApplication.run(TdsApplication.class, args);

}
}
21 changes: 20 additions & 1 deletion src/main/java/no/ntnu/erbj/tds/dao/DepartureDao.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package no.ntnu.erbj.tds.dao;

import jakarta.persistence.*;
import java.time.LocalTime;
import java.util.Iterator;
import java.util.List;
import java.util.Optional;
import no.ntnu.erbj.tds.model.departures.Departure;
import no.ntnu.erbj.tds.ui.utilities.Printer;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

Expand Down Expand Up @@ -69,8 +71,25 @@ public List<Departure> getAll() {
public Departure getByTrainNumber(String trainNumber) {
TypedQuery<Departure> query =
this.em.createQuery(
"SELECT d FROM Departure d WHERE d.train.id = :trainNumber", Departure.class);
"SELECT d FROM Departure d WHERE d.train.trainNumber = :trainNumber", Departure.class);
query.setParameter("trainNumber", trainNumber);
return query.getSingleResult();
}

/**
* Removes all departures before a given local time.
*
* @param localTime the local time to remove departures before.
*/
@Transactional
public void removeDeparturesBeforeLocalTime(LocalTime localTime) {
List<Departure> departures = getAll();
departures.forEach(
departure -> {
if (departure.getEstimatedArrival().isBefore(localTime)) {
em.remove(departure);
Printer.printRemovedTrainWithTrainNumber(departure.getTrain().getTrainNumber());
}
});
}
}
4 changes: 2 additions & 2 deletions src/main/java/no/ntnu/erbj/tds/dao/StationDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
import org.springframework.transaction.annotation.Transactional;

/**
* This class is a Data Access Object (DAO) for the Station class. It provides methods for
* accessing the database.
* This class is a Data Access Object (DAO) for the Station class. <br>
* It provides methods for accessing the database.
*
* @version 1.1
* @author Erik
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/no/ntnu/erbj/tds/model/Station.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ public class Station {
@Id @GeneratedValue private Long id;
private String name;
private String location;

@OneToMany(mappedBy = "station", cascade = CascadeType.ALL, orphanRemoval = true)
private List<Departure> departures;
private int
platforms; // Number of platforms at the station, to be remade into a list of platforms

private int platforms;

/**
* Constructor for the Station class. <br>
Expand Down
18 changes: 9 additions & 9 deletions src/main/java/no/ntnu/erbj/tds/model/WagonType.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,6 @@ public enum WagonType {
this.seats = seats;
}

/**
* Gets the number of seats for the wagon type.
*
* @return the number of seats
*/
public int getSeats() {
return seats;
}

/**
* Gets the wagon type from a string.
*
Expand All @@ -52,4 +43,13 @@ public static WagonType getWagonTypeByString(String wagonType) {
default -> throw new IllegalArgumentException("Invalid wagon type: " + wagonType);
};
}

/**
* Gets the number of seats for the wagon type.
*
* @return the number of seats
*/
public int getSeats() {
return seats;
}
}
40 changes: 38 additions & 2 deletions src/main/java/no/ntnu/erbj/tds/model/departures/Departure.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,32 @@ public void setDepartureTime(String departureTime) {
this.departureTime = parseTime(departureTime, "Departure time");
}

/**
* Sets the departure time of the departure. Uses LocalTime instead of String.
*
* @param departureTime the departure time of the departure.
* @throws IllegalArgumentException if the departure time is null.
*/
public void setDepartureLocalTime(LocalTime departureTime) {
if (departureTime == null) {
throw new IllegalArgumentException("Departure time cannot be null");
}
this.departureTime = departureTime;
}

/**
* Sets the delay of the departure. Uses LocalTime instead of String.
*
* @param delay the delay of the departure.
* @throws IllegalArgumentException if the delay is null.
*/
public void setDelayLocalTime(LocalTime delay) {
if (delay == null) {
throw new IllegalArgumentException("Delay cannot be null");
}
this.delay = delay;
}

/**
* Gets the line of the departure.
*
Expand Down Expand Up @@ -145,13 +171,14 @@ public int getTrack() {
}

/**
* Sets the track of the departure.
* Sets the track of the departure. If the track is -1, it means that the train is not assigned to
* a track.
*
* @param track the track of the departure.
* @throws IllegalArgumentException if the track is less than 1.
*/
public void setTrack(int track) {
if (track < 1) {
if (track < 1 && track != -1) {
throw new IllegalArgumentException("Track cannot be less than 1");
}
this.track = track;
Expand Down Expand Up @@ -208,4 +235,13 @@ public void setTrain(Train train) {
public Long getId() {
return id;
}

/**
* Gets the estimated arrival time of the departure.
*
* @return the estimated arrival time of the departure.
*/
public LocalTime getEstimatedArrival() {
return departureTime.plusHours(delay.getHour()).plusMinutes(delay.getMinute());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public int getTrack() {
* @throws IllegalArgumentException if the track is less than 1.
*/
public DepartureBuilder setTrack(int track) {
if (track < 1) {
if (track < 1 && track != -1) {
throw new IllegalArgumentException("Track cannot be less than 1");
}

Expand Down
Loading

0 comments on commit e9fd77d

Please sign in to comment.