Skip to content

Commit

Permalink
Merge 98a4d62 into 1a11dd0
Browse files Browse the repository at this point in the history
  • Loading branch information
lumos309 authored Oct 8, 2019
2 parents 1a11dd0 + 98a4d62 commit 12a7959
Show file tree
Hide file tree
Showing 19 changed files with 416 additions and 95 deletions.
5 changes: 5 additions & 0 deletions src/main/java/seedu/tarence/logic/LogicManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import seedu.tarence.commons.core.LogsCenter;
import seedu.tarence.logic.commands.Command;
import seedu.tarence.logic.commands.CommandResult;
import seedu.tarence.logic.commands.ConfirmNoCommand;
import seedu.tarence.logic.commands.ConfirmYesCommand;
import seedu.tarence.logic.commands.exceptions.CommandException;
import seedu.tarence.logic.parser.ApplicationParser;
import seedu.tarence.logic.parser.exceptions.ParseException;
Expand Down Expand Up @@ -43,6 +45,9 @@ public CommandResult execute(String commandText) throws CommandException, ParseE

CommandResult commandResult;
Command command = applicationParser.parseCommand(commandText);
if (!(command instanceof ConfirmYesCommand) && !(command instanceof ConfirmNoCommand)) {
model.getPendingCommand(); // clear any pending commands if user has entered a different command
}
commandResult = command.execute(model);

try {
Expand Down
20 changes: 11 additions & 9 deletions src/main/java/seedu/tarence/logic/commands/AddTutorialCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,22 @@ public class AddTutorialCommand extends Command {

public static final String COMMAND_WORD = "addTutorial";

public static final String MESSAGE_USAGE = COMMAND_WORD + ": Adds a Tutorial to the Application. "
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Adds a Tutorial to the Application.\n"
+ "Parameters: "
+ PREFIX_TUTORIAL_NAME + "TUTORIAL_NAME "
+ PREFIX_TUTORIAL_DAY + "TUTORIAL_DAY "
+ PREFIX_TUTORIAL_START_TIME + "TUTORIAL_START_TIME "
+ PREFIX_TUTORIAL_WEEKS + "TUTORIAL_WEEK "
+ PREFIX_TUTORIAL_DURATION_IN_MINUTES + "TUTORIAL_DURATION_IN_MINUTES "
+ "Example: " + COMMAND_WORD + " "
+ PREFIX_TUTORIAL_NAME + "LAB SESSION "
+ PREFIX_TUTORIAL_NAME + "NAME "
+ PREFIX_TUTORIAL_DAY + "DAY "
+ PREFIX_TUTORIAL_START_TIME + "START_TIME "
+ PREFIX_TUTORIAL_WEEKS + "WEEKS "
+ PREFIX_TUTORIAL_DURATION_IN_MINUTES + "DURATION_IN_MINUTES\n"
+ "Examples: " + COMMAND_WORD + " "
+ PREFIX_TUTORIAL_NAME + "Lab 01 "
+ PREFIX_MODULE + "PC1431 "
+ PREFIX_TUTORIAL_DAY + "MONDAY "
+ PREFIX_TUTORIAL_START_TIME + "1200 "
+ PREFIX_TUTORIAL_WEEKS + "7,10,12 "
+ PREFIX_TUTORIAL_DURATION_IN_MINUTES + "120";
+ PREFIX_TUTORIAL_DURATION_IN_MINUTES + "120\n"
+ "Omit w/WEEKS field for default range (weeks 3-13), or specify in the form of a list (e.g. 1,2,3), a "
+ "range (4-6), or 'odd' or 'even' for those weeks only.";

public static final String MESSAGE_DUPLICATE_TUTORIAL = "Wow, this tutorial already exists!";
public static final String MESSAGE_INVALID_MODULE = "Error: No such module exists.";
Expand Down
50 changes: 50 additions & 0 deletions src/main/java/seedu/tarence/logic/commands/ConfirmNoCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package seedu.tarence.logic.commands;

import seedu.tarence.commons.core.Messages;
import seedu.tarence.logic.commands.exceptions.CommandException;
import seedu.tarence.model.Model;

/**
* Represent the user declining a previously stored command.
* When executed, removes the stored command from the application.
*/
public class ConfirmNoCommand extends Command {

public static final String COMMAND_WORD = "n";

public static final String MESSAGE_CONFIRM_NO_SUCCESS = "Command cancelled";

public static final String[] COMMAND_SYNONYMS = {COMMAND_WORD, "no"};

@Override
public CommandResult execute(Model model) throws CommandException {
if (!model.hasPendingCommand()) {
/*
* While this is technically not an unknown command, from the user's point of view it is an illegal command.
* We can only check for the validity of this command here and not in the ApplicationParser, to which the
* model is not available. Hence, the exception is only thrown at this point.
*/
throw new CommandException(Messages.MESSAGE_UNKNOWN_COMMAND);
}
model.getPendingCommand();
return new CommandResult(MESSAGE_CONFIRM_NO_SUCCESS);
}

/**
* Returns true if user command matches command word or any defined synonyms, and false otherwise.
*
* @param userCommand command word from user.
* @return whether user command matches specified command word or synonyms.
*/
public static boolean isMatchingCommandWord(String userCommand) {
for (String synonym : COMMAND_SYNONYMS) {
if (synonym.equals(userCommand.toLowerCase())) {
return true;
}
}
return false;
}

}


48 changes: 48 additions & 0 deletions src/main/java/seedu/tarence/logic/commands/ConfirmYesCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package seedu.tarence.logic.commands;

import seedu.tarence.commons.core.Messages;
import seedu.tarence.logic.commands.exceptions.CommandException;
import seedu.tarence.model.Model;

/**
* Represent the user confirming a previously stored command.
* When executed, retrieves and execute the stored command, and returns its {@code CommandResult}.
*/
public class ConfirmYesCommand extends Command {

public static final String COMMAND_WORD = "y";

public static final String[] COMMAND_SYNONYMS = {COMMAND_WORD, "yes", "confirm"};

// returns the result of executing the stored pending command
@Override
public CommandResult execute(Model model) throws CommandException {
if (!model.hasPendingCommand()) {
/*
* While this is technically not an unknown command, from the user's point of view it is an illegal command.
* We can only check for the validity of this command here and not in the ApplicationParser, to which the
* model is not available. Hence, the exception is only thrown at this point.
*/
throw new CommandException(Messages.MESSAGE_UNKNOWN_COMMAND);
}
return model.getPendingCommand().execute(model);
}

/**
* Returns true if user command matches command word or any defined synonyms, and false otherwise.
*
* @param userCommand command word from user.
* @return whether user command matches specified command word or synonyms.
*/
public static boolean isMatchingCommandWord(String userCommand) {
for (String synonym : COMMAND_SYNONYMS) {
if (synonym.equals(userCommand.toLowerCase())) {
return true;
}
}
return false;
}

}


42 changes: 25 additions & 17 deletions src/main/java/seedu/tarence/logic/commands/DeleteModuleCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,20 @@
import seedu.tarence.model.module.Module;

/**
* Deletes a person identified using it's displayed index from T.A.rence.
* // todo: disallow deleting non-empty modules?
* Deletes a person identified using its displayed index from T.A.rence.
*/
public class DeleteModuleCommand extends Command {

public static final String COMMAND_WORD = "deleteMod";

public static final String MESSAGE_DELETE_MODULE_SUCCESS = "Deleted Module: %1$s";
public static final String MESSAGE_CONFIRM_DELETE_NONEMPTY_MODULE = "WARNING: Module %1$s "
+ "contains %2$d tutorial(s). Are you sure you want to delete it?\n"
+ "(y/n)";

public static final String MESSAGE_USAGE = COMMAND_WORD
+ ": Deletes the module identified by either the index number used in the displayed module list,\n"
+ "or the specified module code.\n"
+ "Parameters: INDEX (must be a positive integer)\n"
+ "Examples: " + COMMAND_WORD + " 1"
+ COMMAND_WORD + " m/GER1000";

Expand All @@ -49,30 +50,37 @@ public DeleteModuleCommand(ModCode modCode) {
public CommandResult execute(Model model) throws CommandException {
requireNonNull(model);
ObservableList<Module> lastShownList = model.getFilteredModuleList();
Module moduleToDelete = null;

if (targetIndex.isPresent()) {
if (targetIndex.get().getZeroBased() >= lastShownList.size()) {
throw new CommandException(Messages.MESSAGE_INVALID_MODULE_DISPLAYED_INDEX);
}
moduleToDelete = lastShownList.get(targetIndex.get().getZeroBased());
} else {
if (!model.hasModuleOfCode(targetModCode.get())) {
throw new CommandException(Messages.MESSAGE_INVALID_MODULE_IN_APPLICATION);
}

Module moduleToDelete = lastShownList.get(targetIndex.get().getZeroBased());
model.deleteModule(moduleToDelete);
return new CommandResult(String.format(MESSAGE_DELETE_MODULE_SUCCESS, moduleToDelete));
}


if (!model.hasModuleOfCode(targetModCode.get())) {
throw new CommandException(Messages.MESSAGE_INVALID_MODULE_IN_APPLICATION);
for (Module module : lastShownList) {
if (module.getModCode().equals(targetModCode.get())) {
moduleToDelete = module;
break;
}
}
}

for (Module module : lastShownList) {
if (module.getModCode().equals(targetModCode.get())) {
model.deleteModule(module);
return new CommandResult(String.format(MESSAGE_DELETE_MODULE_SUCCESS, module));
}
requireNonNull(moduleToDelete);
if (!moduleToDelete.getTutorials().isEmpty()) {
model.storePendingCommand(new DeleteModuleVerifiedCommand(moduleToDelete));
return new CommandResult(String.format(MESSAGE_CONFIRM_DELETE_NONEMPTY_MODULE,
moduleToDelete,
moduleToDelete.getTutorials().size()));
}

return null;
model.deleteTutorialsFromModule(moduleToDelete);
model.deleteModule(moduleToDelete);
return new CommandResult(String.format(MESSAGE_DELETE_MODULE_SUCCESS, moduleToDelete));
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package seedu.tarence.logic.commands;

import seedu.tarence.logic.commands.exceptions.CommandException;
import seedu.tarence.model.Model;
import seedu.tarence.model.module.Module;

/**
* Represents a followup to {@code DeletedModuleCommand} where the {@code Module} to be deleted has been verified as
* a valid one in the application.
*/
public class DeleteModuleVerifiedCommand extends Command {

private Module moduleToDelete;

DeleteModuleVerifiedCommand(Module moduleToDelete) {
this.moduleToDelete = moduleToDelete;
}

@Override
public CommandResult execute(Model model) throws CommandException {
model.deleteTutorialsFromModule(moduleToDelete);
model.deleteModule(moduleToDelete);
return new CommandResult(String.format(DeleteModuleCommand.MESSAGE_DELETE_MODULE_SUCCESS,
moduleToDelete));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ public class DeleteTutorialCommand extends Command {
public static final String COMMAND_WORD = "deleteTutorial";

public static final String MESSAGE_DELETE_TUTORIAL_SUCCESS = "Deleted Tutorial: %1$s";
public static final String MESSAGE_CONFIRM_DELETE_NONEMPTY_TUTORIAL = "WARNING: Tutorial %1$s "
+ "contains %2$d student(s). Are you sure you want to delete it?\n"
+ "(y/n)";

public static final String MESSAGE_USAGE = COMMAND_WORD
+ ": Deletes the tutorial identified by the index number used in the displayed tutorial list.\n"
Expand Down Expand Up @@ -60,26 +63,22 @@ public DeleteTutorialCommand(TutName tutName) {
public CommandResult execute(Model model) throws CommandException {
requireNonNull(model);
List<Tutorial> lastShownList = model.getFilteredTutorialList();
Tutorial tutorialToDelete = null;

if (targetIndex.isPresent()) {
if (targetIndex.get().getZeroBased() >= lastShownList.size()) {
throw new CommandException(Messages.MESSAGE_INVALID_TUTORIAL_DISPLAYED_INDEX);
}

Tutorial tutorialToDelete = lastShownList.get(targetIndex.get().getZeroBased());
model.deleteTutorial(tutorialToDelete);
return new CommandResult(String.format(MESSAGE_DELETE_TUTORIAL_SUCCESS, tutorialToDelete));
}

if (targetModCode.isPresent()) {
tutorialToDelete = lastShownList.get(targetIndex.get().getZeroBased());
} else if (targetModCode.isPresent()) {
if (!model.hasTutorialInModule(targetModCode.get(), targetTutName.get())) {
throw new CommandException(Messages.MESSAGE_INVALID_TUTORIAL_IN_MODULE);
}
for (Tutorial tutorial : lastShownList) {
if (tutorial.getTutName().equals(targetTutName.get())
&& tutorial.getModCode().equals(targetModCode.get())) {
model.deleteTutorial(tutorial);
return new CommandResult(String.format(MESSAGE_DELETE_TUTORIAL_SUCCESS, tutorial));
tutorialToDelete = tutorial;
break;
}
}
} else {
Expand All @@ -91,13 +90,23 @@ public CommandResult execute(Model model) throws CommandException {
}
for (Tutorial tutorial : lastShownList) {
if (tutorial.getTutName().equals(targetTutName.get())) {
model.deleteTutorial(tutorial);
return new CommandResult(String.format(MESSAGE_DELETE_TUTORIAL_SUCCESS, tutorial));
tutorialToDelete = tutorial;
break;
}
}
}

return null;
requireNonNull(tutorialToDelete);
if (!tutorialToDelete.getStudents().isEmpty()) {
model.storePendingCommand(new DeleteTutorialVerifiedCommand(tutorialToDelete));
return new CommandResult(String.format(MESSAGE_CONFIRM_DELETE_NONEMPTY_TUTORIAL,
tutorialToDelete,
tutorialToDelete.getStudents().size()));
}

model.deleteStudentsFromTutorial(tutorialToDelete);
model.deleteTutorial(tutorialToDelete);
return new CommandResult(String.format(MESSAGE_DELETE_TUTORIAL_SUCCESS, tutorialToDelete));
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package seedu.tarence.logic.commands;

import seedu.tarence.logic.commands.exceptions.CommandException;
import seedu.tarence.model.Model;
import seedu.tarence.model.tutorial.Tutorial;

/**
* Represents a followup to {@code DeletedTutorialCommand} where the {@code Tutorial} to be deleted has been verified as
* a valid one in the application.
*/
public class DeleteTutorialVerifiedCommand extends Command {

private Tutorial tutorialToDelete;

DeleteTutorialVerifiedCommand(Tutorial tutorialToDelete) {
this.tutorialToDelete = tutorialToDelete;
}

@Override
public CommandResult execute(Model model) throws CommandException {
model.deleteStudentsFromTutorial(tutorialToDelete);
model.deleteTutorial(tutorialToDelete);
return new CommandResult(String.format(DeleteTutorialCommand.MESSAGE_DELETE_TUTORIAL_SUCCESS,
tutorialToDelete));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import seedu.tarence.logic.commands.AddStudentCommand;
import seedu.tarence.logic.commands.AddTutorialCommand;
import seedu.tarence.logic.commands.Command;
import seedu.tarence.logic.commands.ConfirmNoCommand;
import seedu.tarence.logic.commands.ConfirmYesCommand;
import seedu.tarence.logic.commands.DeleteModuleCommand;
import seedu.tarence.logic.commands.DeleteStudentCommand;
import seedu.tarence.logic.commands.DeleteTutorialCommand;
Expand Down Expand Up @@ -68,6 +70,10 @@ public Command parseCommand(String userInput) throws ParseException {
return new AddModuleCommandParser().parse(arguments);
} else if (AddTutorialCommand.isMatchingCommandWord(commandWord)) {
return new AddTutorialCommandParser().parse(arguments);
} else if (ConfirmNoCommand.isMatchingCommandWord(commandWord)) {
return new ConfirmNoCommand();
} else if (ConfirmYesCommand.isMatchingCommandWord(commandWord)) {
return new ConfirmYesCommand();
} else {
throw new ParseException(MESSAGE_UNKNOWN_COMMAND);
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/seedu/tarence/logic/parser/ParserUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public static ModCode parseModCode(String modCode) throws ParseException {
if (!ModCode.isValidModCode(trimmedModCode)) {
throw new ParseException(ModCode.MESSAGE_CONSTRAINTS);
}
return new ModCode(trimmedModCode);
return new ModCode(trimmedModCode.toUpperCase());
}

/**
Expand Down
Loading

0 comments on commit 12a7959

Please sign in to comment.