Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement these Commands: default, removesem, and viewcommit. Add tests. #212

Merged
merged 13 commits into from Oct 25, 2019
@@ -0,0 +1,50 @@
package seedu.address.logic.commands.storage;

import static java.util.Objects.requireNonNull;

import seedu.address.logic.commands.Command;
import seedu.address.logic.commands.CommandResult;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.Model;
import seedu.address.model.ModulesInfo;
import seedu.address.model.studyplan.StudyPlan;
import seedu.address.model.util.DefaultStudyPlanUtil;

/**
* Creates a new recommended study plan based on
* https://www.comp.nus.edu.sg/images/resources/content/undergraduates/study_planner-CS2019.pdf.
*/
public class DefaultStudyPlanCommand extends Command {

public static final String COMMAND_WORD = "default";

public static final String MESSAGE_USAGE = COMMAND_WORD + ": Creates a new recommended sample study plan.";
public static final String MESSAGE_SUCCESS = "New sample study plan added!";
public static final String MESSAGE_DUPLICATE_STUDYPLAN = "This study plan already exists in the module planner";

@Override
public CommandResult execute(Model model) throws CommandException {
requireNonNull(model);

ModulesInfo modulesInfo = model.getModulesInfo();
StudyPlan defaultStudyPlan = DefaultStudyPlanUtil.getDefaultStudyPlan(modulesInfo);

if (model.hasStudyPlan(defaultStudyPlan)) {
throw new CommandException(MESSAGE_DUPLICATE_STUDYPLAN);
}

model.addStudyPlan(defaultStudyPlan);
defaultStudyPlan.setActivated(true);
model.activateStudyPlan(defaultStudyPlan.getIndex());

return new CommandResult(MESSAGE_SUCCESS, true, false);
}

/*
@Override
public boolean equals(Object other) {
return other == this // short circuit if same object
|| other instanceof DefaultStudyPlanCommand; // instanceof handles nulls
}
*/
}
@@ -0,0 +1,55 @@
package seedu.address.logic.commands.storage;

import static java.util.Objects.requireNonNull;

import seedu.address.logic.commands.Command;
import seedu.address.logic.commands.CommandResult;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.Model;
import seedu.address.model.semester.SemesterName;
import seedu.address.model.studyplan.StudyPlan;

/**
* Deletes all modules inside the specified semester in the current active study plan.
*/
public class DeleteSemesterCommand extends Command {

public static final String COMMAND_WORD = "removesem";

public static final String MESSAGE_USAGE = COMMAND_WORD
+ ": Deletes all modules inside the specified semester in the current active study plan.\n"
+ "Parameters: SEMESTER_NAME\n"
+ "Example: " + COMMAND_WORD + " y1s2";

public static final String MESSAGE_DELETE_SEMESTER_SUCCESS = "Deleted Semester: %1$s";
public static final String MESSAGE_NO_ACTIVE_STUDYPLAN = "You don't have any study plan currently. Create now!";

private final SemesterName semesterName;

public DeleteSemesterCommand(SemesterName semesterName) {
requireNonNull(semesterName);
this.semesterName = semesterName;
}

@Override
public CommandResult execute(Model model) throws CommandException {
requireNonNull(model);

StudyPlan activeStudyPlan = model.getActiveStudyPlan();

if (activeStudyPlan == null) {
return new CommandResult(MESSAGE_NO_ACTIVE_STUDYPLAN);
}

model.deleteAllModulesInSemester(semesterName);

return new CommandResult(String.format(MESSAGE_DELETE_SEMESTER_SUCCESS, semesterName.toString()));
}

@Override
public boolean equals(Object other) {
return other == this // short circuit if same object
|| (other instanceof DeleteSemesterCommand // instanceof handles nulls
&& semesterName.equals(((DeleteSemesterCommand) other).semesterName)); // state check
}
}
@@ -1,57 +1,69 @@
//package seedu.address.logic.commands.storage;
//
//import static java.util.Objects.requireNonNull;
//import static seedu.address.logic.commands.storage.ViewCommitHistoryCommand.MESSAGE_NO_COMMIT_HISTORY;
//
//import seedu.address.logic.commands.Command;
//import seedu.address.logic.commands.CommandResult;
//import seedu.address.model.Model;
//import seedu.address.model.studyplan.StudyPlan;
//import seedu.address.model.studyplan.exceptions.StudyPlanNotFoundException;
//import seedu.address.model.versiontracking.CommitList;
//import seedu.address.model.versiontracking.exception.StudyPlanCommitManagerNotFoundException;
//
///**
// * Represents a command for the user to view the version of the current active study plan for a particular commit.
// * This does not discard the commits after the specified commit.
// */
//public class ViewCommitCommand extends Command {
//
// public static final String COMMAND_WORD = "viewcommit";
// public static final String MESSAGE_USAGE = COMMAND_WORD
// + ": Views the study plan commit identified by the index number used in the displayed commit list.\n"
// + "Parameters: PLAN_INDEX.COMMIT_NUMBER (both must be non-negative integers)\n";
// public static String MESSAGE_SUCCESS = "Here is your study plan for this commit. Please do not modify it. ";
// public static final String MESSAGE_NO_SUCH_COMMIT = "The commit index you've entered is invalid!";
//
// private int studyPlanIndex;
// private int commitNumber;
//
// public ViewCommitCommand(int studyPlanIndex, int commitNumber) {
// this.studyPlanIndex = studyPlanIndex;
// this.commitNumber = commitNumber;
// }
//
// @Override
// public CommandResult execute(Model model) {
// requireNonNull(model);
//
// // TODO: THIS IS NOT IMPLEMENTED YET.
//
// StudyPlan activeStudyPlan = model.getActiveStudyPlan();
// if (activeStudyPlan == null) {
// throw new StudyPlanNotFoundException();
// }
//
// try {
// int activeStudyPlanIndex = activeStudyPlan.getIndex();
// CommitList commitList = model.getCommitListByStudyPlanIndex(activeStudyPlanIndex);
// String commitHistoryText = commitList.toString();
//
// return new CommandResult(MESSAGE_SUCCESS + commitHistoryText);
// } catch (StudyPlanCommitManagerNotFoundException e) {
// return new CommandResult(MESSAGE_NO_COMMIT_HISTORY);
// }
//
// }
//}
package seedu.address.logic.commands.storage;

import static java.util.Objects.requireNonNull;
import static seedu.address.logic.commands.storage.ViewCommitHistoryCommand.MESSAGE_NO_COMMIT_HISTORY;

import javafx.collections.ObservableList;
import seedu.address.logic.commands.Command;
import seedu.address.logic.commands.CommandResult;
import seedu.address.model.Model;
import seedu.address.model.semester.Semester;
import seedu.address.model.studyplan.StudyPlan;
import seedu.address.model.versiontracking.Commit;
import seedu.address.model.versiontracking.CommitList;
import seedu.address.model.versiontracking.exception.StudyPlanCommitManagerNotFoundException;
import seedu.address.ui.ResultViewType;

/**
* Represents a command for the user to view the version of the current active study plan for a particular commit.
* This does not discard the commits after the specified commit.
*/
public class ViewCommitCommand extends Command {

public static final String COMMAND_WORD = "viewcommit";
public static final String MESSAGE_USAGE = COMMAND_WORD
+ ": Views the study plan commit identified by the index number used in the displayed commit list.\n"
+ "Parameters: PLAN_INDEX.COMMIT_NUMBER (both must be non-negative integers)\n";
public static final String MESSAGE_SUCCESS = "Here is your study plan for this commit. Please do not modify it.";
public static final String MESSAGE_NO_SUCH_COMMIT = "The commit index you've entered is invalid!";
public static final String MESSAGE_NO_STUDYPLAN = "There's no active study plan. Create now!";
public static final String MESSAGE_NOT_ACTIVE_STUDYPLAN = "The study plan index does not match the active one.";

private int studyPlanIndex;
private int commitNumber;

public ViewCommitCommand(int studyPlanIndex, int commitNumber) {
this.studyPlanIndex = studyPlanIndex;
this.commitNumber = commitNumber;
}

@Override
public CommandResult execute(Model model) {
requireNonNull(model);

StudyPlan activeStudyPlan = model.getActiveStudyPlan();
if (activeStudyPlan == null) {
return new CommandResult(MESSAGE_NO_STUDYPLAN);
}

// if the index is different from active study plan, throw an error
if (activeStudyPlan.getIndex() != studyPlanIndex) {
return new CommandResult(MESSAGE_NOT_ACTIVE_STUDYPLAN);
}

try {
int activeStudyPlanIndex = activeStudyPlan.getIndex();
CommitList commitList = model.getCommitListByStudyPlanIndex(activeStudyPlanIndex);
Commit commit = commitList.getCommitByIndex(commitNumber);
StudyPlan studyPlan = commit.getStudyPlan();
ObservableList<Semester> semesters = studyPlan.getSemesters().asUnmodifiableObservableList();

return new CommandResult<>(MESSAGE_SUCCESS, ResultViewType.STUDY_PLAN, semesters);
} catch (StudyPlanCommitManagerNotFoundException e) {
return new CommandResult(MESSAGE_NO_COMMIT_HISTORY);
} catch (IndexOutOfBoundsException e) {
return new CommandResult(MESSAGE_NO_SUCH_COMMIT);
}

}
}
15 changes: 15 additions & 0 deletions src/main/java/seedu/address/logic/parser/ModulePlannerParser.java
Expand Up @@ -29,11 +29,14 @@
import seedu.address.logic.commands.storage.ActivateStudyPlanCommand;
import seedu.address.logic.commands.storage.CommitStudyPlanEditCommand;
import seedu.address.logic.commands.storage.CreateStudyPlanCommand;
import seedu.address.logic.commands.storage.DefaultStudyPlanCommand;
import seedu.address.logic.commands.storage.DeleteCommand;
import seedu.address.logic.commands.storage.DeleteCommitCommand;
import seedu.address.logic.commands.storage.DeleteSemesterCommand;
import seedu.address.logic.commands.storage.EditTitleCommand;
import seedu.address.logic.commands.storage.ListAllStudyPlansCommand;
import seedu.address.logic.commands.storage.RevertCommitCommand;
import seedu.address.logic.commands.storage.ViewCommitCommand;
import seedu.address.logic.commands.storage.ViewCommitHistoryCommand;
import seedu.address.logic.commands.verification.DescriptionCommand;
import seedu.address.logic.commands.verification.ValidModsCommand;
Expand All @@ -54,11 +57,14 @@
import seedu.address.logic.parser.storage.ActivateStudyPlanParser;
import seedu.address.logic.parser.storage.CommitStudyPlanEditsParser;
import seedu.address.logic.parser.storage.CreateStudyPlanCommandParser;
import seedu.address.logic.parser.storage.DefaultStudyPlanCommandParser;
import seedu.address.logic.parser.storage.DeleteCommitCommandParser;
import seedu.address.logic.parser.storage.DeleteSemesterCommandParser;
import seedu.address.logic.parser.storage.DeleteStudyPlanParser;
import seedu.address.logic.parser.storage.EditStudyPlanTitleParser;
import seedu.address.logic.parser.storage.ListAllStudyPlansParser;
import seedu.address.logic.parser.storage.RevertCommitParser;
import seedu.address.logic.parser.storage.ViewCommitCommandParser;
import seedu.address.logic.parser.storage.ViewCommitHistoryParser;
import seedu.address.logic.parser.verification.DescriptionCommandParser;
import seedu.address.logic.parser.verification.ValidModsCommandParser;
Expand Down Expand Up @@ -178,6 +184,15 @@ public Command parseCommand(String userInput) throws ParseException {
case DeleteCommitCommand.COMMAND_WORD:
return new DeleteCommitCommandParser().parse(arguments);

case DefaultStudyPlanCommand.COMMAND_WORD:
return new DefaultStudyPlanCommandParser().parse(arguments);

case DeleteSemesterCommand.COMMAND_WORD:
return new DeleteSemesterCommandParser().parse(arguments);

case ViewCommitCommand.COMMAND_WORD:
return new ViewCommitCommandParser().parse(arguments);

case RenameTagCommand.COMMAND_WORD:
return new RenameTagCommandParser().parse(arguments);

Expand Down
@@ -0,0 +1,21 @@
package seedu.address.logic.parser.storage;

import seedu.address.logic.commands.storage.DefaultStudyPlanCommand;
import seedu.address.logic.parser.Parser;
import seedu.address.logic.parser.exceptions.ParseException;

/**
* Parses input arguments and creates a new DefaultStudyPlanCommand object.
*/
public class DefaultStudyPlanCommandParser implements Parser<DefaultStudyPlanCommand> {
/**
* Parses the given {@code String} of arguments in the context of the
* DefaultStudyPlanCommand and returns an DefaultStudyPlanCommand object for
* execution.
*
* @throws ParseException if the user input does not conform the expected format.
*/
public DefaultStudyPlanCommand parse(String args) throws ParseException {
return new DefaultStudyPlanCommand();
}
}
@@ -0,0 +1,34 @@
package seedu.address.logic.parser.storage;

import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT;

import seedu.address.logic.commands.storage.DeleteSemesterCommand;
import seedu.address.logic.parser.Parser;
import seedu.address.logic.parser.exceptions.ParseException;
import seedu.address.model.semester.SemesterName;

/**
* Parses input arguments and creates a new DeleteSemesterCommand object.
*/
public class DeleteSemesterCommandParser implements Parser<DeleteSemesterCommand> {

/**
* Parses the given {@code String} of arguments in the context of the DeleteSemesterCommand
* and returns an DeleteSemesterCommand object for execution.
*
* @throws ParseException if the user input does not conform the expected format.
*/
public DeleteSemesterCommand parse(String args) throws ParseException {
String trimmedArgs = args.trim();
SemesterName semesterName = null;
try {
semesterName = SemesterName.valueOf(trimmedArgs.toUpperCase());
} catch (IllegalArgumentException e) {
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT,
DeleteSemesterCommand.MESSAGE_USAGE));
}

return new DeleteSemesterCommand(semesterName);
}

}

This file was deleted.