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

Commit

Permalink
release: FP
Browse files Browse the repository at this point in the history
  • Loading branch information
erikbjo committed Dec 9, 2023
1 parent 9fb0e67 commit 5600662
Show file tree
Hide file tree
Showing 13 changed files with 82 additions and 84 deletions.
30 changes: 18 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@ STUDENT ID = erbj

## 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 🚀

Expand All @@ -30,7 +35,7 @@ or
2. Run the program with:

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

## How to run the tests 🧪
Expand All @@ -51,8 +56,7 @@ help

## Contact 📧

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

## Project structure 📁

Expand All @@ -66,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 @@ -98,7 +104,7 @@ root
│ │ │ │ │ └── TimeController.java
│ │ │ │ │
│ │ │ │ └── utilites
│ │ │ │ ├── ANSIColors.java
│ │ │ │ ├── AnsiColors.java
│ │ │ │ ├── Colorize.java
│ │ │ │ ├── Printer.java
│ │ │ │ ├── SortUtility.java
Expand Down
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);

}
}
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;
}
}
38 changes: 21 additions & 17 deletions src/main/java/no/ntnu/erbj/tds/ui/commands/CreateCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* Commands for creating objects.
*
* @author Erik
* @version 2.0
* @version 3.0
*/
@ShellComponent
@EnableTransactionManagement
Expand Down Expand Up @@ -53,33 +53,37 @@ public CreateCommands(
public void createWagon() {
Scanner scanner = new Scanner(System.in);
TdsLogger logger = TdsLogger.getInstance();
Printer.printEnterWagonType();
for (WagonType value : WagonType.values()) {
logger.info(value.toString());
}

String wagonType = scanner.nextLine();
boolean isWagonTypeValid = false;
String wagonType;
Printer.printEnterWagonType();

if ("exit".equalsIgnoreCase(wagonType)) {
Printer.printExitString();
return;
}
do {
wagonType = scanner.nextLine();

WagonType safeWagonType;
try {
safeWagonType = WagonType.getWagonTypeByString(wagonType);
} catch (IllegalArgumentException e) {
Printer.printInvalidInput("wagon type");
return;
}
if (wagonType.equalsIgnoreCase("exit")) {
Printer.printExitString();
return;
}

try {
WagonType.getWagonTypeByString(wagonType);
isWagonTypeValid = true; // If no exception is thrown, the wagon type is valid.
} catch (IllegalArgumentException e) {
Printer.printInvalidInput("wagon type");
}
} while (!isWagonTypeValid);

Wagon wagon = new Wagon(safeWagonType);
Wagon wagon = new Wagon(WagonType.getWagonTypeByString(wagonType));

try {
wagonDao.add(wagon);
Printer.printAddedToDatabase();
} catch (Exception e) {
TdsLogger.getInstance().warn(e.getMessage());
Printer.printException(e); // Unexpected exception
}
}

Expand Down Expand Up @@ -111,7 +115,7 @@ public void createTrain() {
Printer.printTrainNumberNotUnique();
}

} while (!isTrainNumberValid);
} while (!isTrainNumberValid || train == null);

try {
trainDao.add(train);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* Commands for manipulating departure objects.
*
* @author Erik
* @version 2.0
* @version 3.0
*/
@ShellComponent
@EnableTransactionManagement
Expand Down Expand Up @@ -120,8 +120,8 @@ public void searchByTrainNumber(String trainNumber) {

departures =
departures
.stream()
.filter( // filter by departure.train CONTAINS trainNumber, so 1234 will match 12345 etc
.stream() // filter by departure.train CONTAINS trainNumber, so 1234 will match 12345
.filter(
departure ->
departure
.getTrain()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
* These methods are extracted to this class to avoid code duplication.
*
* @author erik
* @version 2.0
* @version 3.0
*/
@ShellComponent
public class HelperCommands {
Expand Down
25 changes: 12 additions & 13 deletions src/main/java/no/ntnu/erbj/tds/ui/commands/TimeCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* Commands for manipulating the current time.
*
* @author Erik
* @version 2.0
* @version 3.0
*/
@ShellComponent
public class TimeCommands {
Expand All @@ -35,8 +35,8 @@ public String getCurrentTime() {
/** Sets the current time. */
@ShellMethod(
value =
"Set the current time. Also deletes departures that have a departure time " +
"before the new time. Takes a parameter in format: HH:mm",
"Set the current time. Also deletes departures that have a departure time "
+ "before the new time. Takes a parameter in format: HH:mm",
key = "time set")
public void setCurrentTime(String time) {
String[] timeSplit = time.split(":");
Expand All @@ -61,34 +61,33 @@ public void setCurrentTime(String time) {
/** Increments the current time by one minute. */
@ShellMethod(
value =
"Increment minutes by one. Also deletes departures that have a departure time before the new time.",
key = {"m++", "time increment minutes"})
"Increment minutes by one. "
+ "Also deletes departures that have a departure time before the new time.",
key = "m++")
public void incrementMinutes() {
TimeController.incrementMinutes();
departureDao.removeDeparturesBeforeLocalTime(TimeController.getCurrentTime());
}

/** Decrements the current time by one minute. */
@ShellMethod(
value = "Decrement minutes by one.",
key = {"m--", "time-decrement-minutes"})
@ShellMethod(value = "Decrement minutes by one.", key = "m--")
public void decrementMinutes() {
TimeController.decrementMinutes();
}

/** Increments the current time by one hour. */
@ShellMethod(
value = "Increment hours by one. Also deletes departures that have a departure time before the new time.",
key = {"h++", "time increment hours"})
value =
"Increment hours by one. "
+ "Also deletes departures that have a departure time before the new time.",
key = "h++")
public void incrementHours() {
TimeController.incrementHours();
departureDao.removeDeparturesBeforeLocalTime(TimeController.getCurrentTime());
}

/** Decrements the current time by one hour. */
@ShellMethod(
value = "Decrement hours by one.",
key = {"h--", "time decrement hours"})
@ShellMethod(value = "Decrement hours by one.", key = "h--")
public void decrementHours() {
TimeController.decrementHours();
}
Expand Down
16 changes: 3 additions & 13 deletions src/main/java/no/ntnu/erbj/tds/ui/commands/TrainCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,35 +16,25 @@
* Commands for manipulating train objects.
*
* @author Erik
* @version 2.0
* @version 3.0
*/
@ShellComponent
@EnableTransactionManagement
public class TrainCommands {
private final TrainDao trainDao;
private final WagonDao wagonDao;
private final WagonCommands wagonCommands;
private final CreateCommands createCommands;
private final HelperCommands helperCommands;

/**
* TrainCommands constructor. Uses constructor injection to get beans.
*
* @param trainDao injects the trainDAO object.
* @param wagonDao injects the wagonDAO object.
* @param wagonCommands injects the wagonCommands object.
* @param createCommands injects the createCommands object.
* @param helperCommands injects the helperCommands object.
*/
public TrainCommands(
TrainDao trainDao,
WagonDao wagonDao,
WagonCommands wagonCommands,
CreateCommands createCommands,
HelperCommands helperCommands) {
public TrainCommands(TrainDao trainDao, WagonDao wagonDao, HelperCommands helperCommands) {
this.trainDao = trainDao;
this.wagonDao = wagonDao;
this.wagonCommands = wagonCommands;
this.createCommands = createCommands;
this.helperCommands = helperCommands;
}

Expand Down
Loading

0 comments on commit 5600662

Please sign in to comment.