Skip to content

Commit

Permalink
Merge pull request #49 from shengiv/branch-Modify-Flight-Details
Browse files Browse the repository at this point in the history
Add modify flight details for both flight and passenger list
  • Loading branch information
JordanKwua authored Oct 26, 2022
2 parents ee7156e + 7a3933d commit 8d95463
Show file tree
Hide file tree
Showing 18 changed files with 386 additions and 41 deletions.
6 changes: 3 additions & 3 deletions DeleteFlightCommand.log
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
<!DOCTYPE log SYSTEM "logger.dtd">
<log>
<record>
<date>2022-10-24T04:00:44.842875800Z</date>
<millis>1666584044842</millis>
<nanos>875800</nanos>
<date>2022-10-25T18:57:09.983263Z</date>
<millis>1666724229983</millis>
<nanos>263000</nanos>
<sequence>4</sequence>
<logger>seedu.duke.command.flightcommand.DeleteFlightCommand</logger>
<level>INFO</level>
Expand Down
4 changes: 4 additions & 0 deletions ListFlights-logger.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="windows-1252" standalone="no"?>
<!DOCTYPE log SYSTEM "logger.dtd">
<log>
</log>
Empty file removed ListFlights-logger.log.lck
Empty file.
31 changes: 22 additions & 9 deletions src/main/java/seedu/duke/SkyControl.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package seedu.duke;

import seedu.duke.command.Command;
import seedu.duke.command.flightcommand.DeleteFlightCommand;
import seedu.duke.command.flightcommand.AddFlightCommand;
import seedu.duke.command.flightcommand.DeleteFlightCommand;
import seedu.duke.command.flightcommand.ListFlightCommand;
import seedu.duke.command.flightcommand.ModifyFlightNumCommand;
import seedu.duke.command.flightcommand.ModifyGateNumCommand;
import seedu.duke.command.passengercommand.AddPassengerCommand;
import seedu.duke.command.passengercommand.DeletePassengerCommand;
import seedu.duke.command.passengercommand.ListPassengerCommand;
Expand All @@ -21,6 +23,7 @@ public class SkyControl {
private OperationList flights;
private static boolean isPassenger = false;
private static boolean isFlight = false;
private static boolean isModify = false;
private static boolean isAdd = false;


Expand All @@ -33,15 +36,22 @@ public SkyControl() {
flights = new FlightList();
}

private void executeEntity(String lineInput, Command command) {
private void executeEntity(String lineInput, Command command) throws SkyControlException {
assert lineInput != null;
checkEntity(lineInput);
if (isPassenger) {
executePassengerCommand(lineInput, command);
} else if (isFlight) {
command.execute(flights, lineInput);
} else {
command.execute(flights, lineInput);
try {
if (isPassenger) {
executePassengerCommand(lineInput, command);
} else if (isFlight) {
command.execute(flights, lineInput);
} else if (isModify) {
command.execute(flights, lineInput);
command.execute(passengers, lineInput);
} else {
command.execute(flights, lineInput);
}
} catch (SkyControlException e) {
ui.showError(e.getMessage());
}
}

Expand All @@ -56,9 +66,10 @@ private void executePassengerCommand(String lineInput, Command command) {
}
}

private void checkEntity(String lineInput) {
private void checkEntity(String lineInput) throws SkyControlException {
isPassenger = Parser.isPassengerEntity(lineInput);
isFlight = Parser.isFlightEntity(lineInput);
isModify = Parser.isModifyCommand(lineInput);
if (isPassenger) {
isAdd = Parser.getAdd(lineInput);
}
Expand All @@ -72,6 +83,8 @@ private void setUpAllLogger() {
DeleteFlightCommand.setUpLogger();
AddFlightCommand.setupLogger();
ListFlightCommand.setupLogger();
ModifyFlightNumCommand.setupLogger();
ModifyGateNumCommand.setupLogger();
}

public void run() {
Expand Down
11 changes: 10 additions & 1 deletion src/main/java/seedu/duke/command/Command.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

public abstract class Command extends Parser {
public static final int MIN_LENGTH = 2;
public static final int START_INDEX = 3;
protected static Ui ui = new Ui();
protected static final int DETAIL_INDEX = 1;

Expand All @@ -30,6 +31,14 @@ public static void getPassengerDetail(String lineInput) throws SkyControlExcepti
}
}

public static String getFlightNumFromModifyCmd(String[] inputWords) {
return inputWords[DETAIL_INDEX].toUpperCase();
}

public static String getModifiedDetail(String[] inputWords) {
return inputWords[2].substring(START_INDEX).toUpperCase();
}

public static void checkBlankDetailInput() throws SkyControlException {
if (passengerDetailArray.length < MIN_LENGTH) {
throw new SkyControlException(ui.getBlankOpsError());
Expand All @@ -49,7 +58,7 @@ public void checkFlightDetailSync(OperationList flights,
}
}

public abstract void execute(OperationList operations, String lineInput);
public abstract void execute(OperationList operations, String lineInput) throws SkyControlException;

public boolean isExit() {
return false;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package seedu.duke.command.flightcommand;

import seedu.duke.command.Command;
import seedu.duke.exceptions.SkyControlException;
import seedu.duke.operationlist.OperationList;

import java.io.IOException;
import java.util.logging.Logger;
import java.util.logging.LogManager;
import java.util.logging.Level;
import java.util.logging.ConsoleHandler;
import java.util.logging.FileHandler;

public class ModifyFlightNumCommand extends Command {
private static final Logger LOGGER = Logger.getLogger(ModifyFlightNumCommand.class.getName());

public static void setupLogger() {
LogManager.getLogManager().reset();
ModifyFlightNumCommand.LOGGER.setLevel(Level.ALL);
ConsoleHandler consoleHandler = new ConsoleHandler();
consoleHandler.setLevel(Level.SEVERE);
ModifyFlightNumCommand.LOGGER.addHandler(consoleHandler);
createFileHandle();
ModifyFlightNumCommand.LOGGER.log(Level.INFO, ui.getLoggerStartUpMessage());
}

private static void createFileHandle() {
try {
FileHandler fileHandler = new FileHandler("ModifyFlightNum-logger.log");
fileHandler.setLevel(Level.WARNING);
ModifyFlightNumCommand.LOGGER.addHandler(fileHandler);
} catch (IOException e) {
ModifyFlightNumCommand.LOGGER.log(Level.SEVERE, ui.getLoggerError(), e);
}
}

public void execute(OperationList entityList, String lineInput) throws SkyControlException {
inputWords = lineInput.split("\\s+");
String flightNum = getFlightNumFromModifyCmd(inputWords);
String newFlightNum = getModifiedDetail(inputWords);
entityList.modifyFlightNum(flightNum, newFlightNum);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package seedu.duke.command.flightcommand;

import seedu.duke.command.Command;
import seedu.duke.exceptions.SkyControlException;
import seedu.duke.operationlist.OperationList;

import java.io.IOException;
import java.util.logging.Logger;
import java.util.logging.LogManager;
import java.util.logging.Level;
import java.util.logging.ConsoleHandler;
import java.util.logging.FileHandler;

public class ModifyGateNumCommand extends Command {
private static final Logger LOGGER = Logger.getLogger(ModifyGateNumCommand.class.getName());

public static void setupLogger() {
LogManager.getLogManager().reset();
ModifyGateNumCommand.LOGGER.setLevel(Level.ALL);
ConsoleHandler consoleHandler = new ConsoleHandler();
consoleHandler.setLevel(Level.SEVERE);
ModifyGateNumCommand.LOGGER.addHandler(consoleHandler);
createFileHandle();
ModifyGateNumCommand.LOGGER.log(Level.INFO, ui.getLoggerStartUpMessage());
}

private static void createFileHandle() {
try {
FileHandler fileHandler = new FileHandler("ModifyGateNum-logger.log");
fileHandler.setLevel(Level.WARNING);
ModifyGateNumCommand.LOGGER.addHandler(fileHandler);
} catch (IOException e) {
ModifyGateNumCommand.LOGGER.log(Level.SEVERE, ui.getLoggerError(), e);
}
}

public void execute(OperationList entityList, String lineInput) throws SkyControlException {
inputWords = lineInput.split("\\s+");
String flightNum = getFlightNumFromModifyCmd(inputWords);
String newGateNum = getModifiedDetail(inputWords);
entityList.modifyGateNum(flightNum, newGateNum);
}
}
63 changes: 63 additions & 0 deletions src/main/java/seedu/duke/operationlist/FlightList.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,69 @@ private void checkValidFlightNumber(String substring) throws SkyControlException
}
}

//@@author shengiv
@Override
public void modifyFlightNum(String flightNum, String newFlightNum) throws SkyControlException {
FlightInfo flight = findFlightInfo(flightNum);
getFlightAttributes(flight);
flightNumber = newFlightNum;
validateModificationDetails(flight);
flight.setFlightNum(newFlightNum);
flights.add(flight);
flightIndex++;
ui.showUpdatedFlightNumber(flightNum, newFlightNum);
}

@Override
public void modifyGateNum(String flightNum, String newGateNum) throws SkyControlException {
FlightInfo flight = findFlightInfo(flightNum);
getFlightAttributes(flight);
gateNumber = newGateNum;
validateModificationDetails(flight);
flight.setGateNum(newGateNum);
flights.add(flight);
flightIndex++;
ui.showUpdatedGateNumber(flightNum, newGateNum);
}

private void getFlightAttributes(FlightInfo flight) {
flightNumber = flight.getFlightNumber();
airline = flight.getAirline();
destination = flight.getDestination();
departureTime = flight.getDepartureTime();
gateNumber = flight.getGateNum();
checkIn = flight.getCheckLn();
}

private static FlightInfo findFlightInfo(String flightNum) throws SkyControlException {
FlightInfo modifiedFlight = null;
for (FlightInfo flight : flights) {
if (flight.getFlightNumber().equals(flightNum)) {
modifiedFlight = flight;
flights.remove(flight);
flightIndex--;
break;
}
}
if (modifiedFlight == null) {
throw new SkyControlException(ui.getFlightNotFoundMessage(flightNum));
} else {
return modifiedFlight;
}
}

private void validateModificationDetails(FlightInfo flight) throws SkyControlException {
try {
validateDetailFormat();
checkFlightNumberDuplicates();
checkAvailableGateNumber();
} catch (Exception e) {
flights.add(flight);
flightIndex++;
throw new SkyControlException(e.getMessage());
}
}

//@@author Franky4566
@Override
public void listOperation() {
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/seedu/duke/operationlist/OperationList.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,8 @@ private void resetSync() {
public abstract void deleteOperation(String detail) throws SkyControlException;

public abstract void listOperation();

public abstract void modifyFlightNum(String flightNum, String newFlightNum) throws SkyControlException;

public abstract void modifyGateNum(String flightNum, String newFlightNum) throws SkyControlException;
}
42 changes: 36 additions & 6 deletions src/main/java/seedu/duke/operationlist/PassengerList.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,16 @@ public void addOperation(String passengerDetail) throws SkyControlException {
Ui.showAddedPassenger(passenger);
}

@Override
public void modifyFlightNum(String flightNum, String newFlightNum) {
modifyPassengersFlightNum(flightNum, newFlightNum);
}

@Override
public void modifyGateNum(String flightNum, String newGateNum) {
modifyPassengersGateNum(flightNum, newGateNum);
}

//@@author ivanthengwr
private void checkPassengerDetails() throws SkyControlException {
if (isExceedNameLength) {
Expand Down Expand Up @@ -113,6 +123,26 @@ private void checkPassengerDuplicate() throws SkyControlException {
}
}

private void modifyPassengersFlightNum(String flightNum, String newFlightNum) {
getNumberOfPassengers();
for (int i = 0; i < numOfPassengers; i++) {
PassengerInfo passenger = passengers.get(i);
if (passenger.getFlightNumber().equals(flightNum)) {
passenger.setFlightNumber(newFlightNum);
}
}
}

private void modifyPassengersGateNum(String flightNum, String newGateNum) {
getNumberOfPassengers();
for (int i = 0; i < numOfPassengers; i++) {
PassengerInfo passenger = passengers.get(i);
if (passenger.getFlightNumber().equals(flightNum)) {
passenger.setGateNumber(newGateNum);
}
}
}

//@@author ivanthengwr
@Override
public void deleteOperation(String passengerDetail) throws SkyControlException {
Expand Down Expand Up @@ -294,9 +324,9 @@ private void validateDetailFormat() {
isExceedNameLength = name.length() > NAME_LENGTH_LIMIT;
isWrongNameFormat = !name.matches(REGEX_LETTER);
isWrongDepartureFormat = isValidTime(departureTime);
isWrongFlightNumFormat = isValidFlightNumber();
isWrongFlightNumFormat = isValidFlightNumber(flightNumber);
isWrongBoardingTimeFormat = isValidTime(boardingTime);
isWrongGateNumberFormat = isValidGateNumber();
isWrongGateNumberFormat = isValidGateNumber(gateNumber);
isWrongBoardingGroupFormat = isValidBoardingGroup();
isWrongSeatNumberFormat = isValidSeatNumber();
}
Expand Down Expand Up @@ -326,7 +356,7 @@ private boolean isValidBoardingGroup() {
}
}

private boolean isValidGateNumber() {
private boolean isValidGateNumber(String gateNumber) {
boolean isNotValidLength = gateNumber.length() > MAX_GN_LENGTH
|| gateNumber.length() < MIN_GN_LENGTH;
boolean isNotValidNumber = !gateNumber.matches(REGEX_NUMBER);
Expand All @@ -344,11 +374,11 @@ private boolean isValidTime(String time) {
return isNotValidTime;
}

private boolean isValidFlightNumber() {
private boolean isValidFlightNumber(String flightNumber) {
int lenOfFlightNum = flightNumber.length();
if (lenOfFlightNum < FN_MIN_LENGTH) {
return isWrongFlightNumFormat = true;
} else if (isValidFlightNumberTag()) {
} else if (isValidFlightNumberTag(flightNumber)) {
int numOfDigits = checkNumOfDigits();
if (isValidFLightNum(numOfDigits)) {
return isWrongFlightNumFormat;
Expand All @@ -374,7 +404,7 @@ private int checkNumOfDigits() {
return numOfDigits;
}

private boolean isValidFlightNumberTag() {
private boolean isValidFlightNumberTag(String flightNumber) {
boolean isValidFlightNumberTag;
isValidFlightNumberTag = Character.isLetter(flightNumber.charAt(FIRST_INDEX))
&& Character.isLetter(flightNumber.charAt(SECOND_INDEX));
Expand Down
Loading

0 comments on commit 8d95463

Please sign in to comment.