forked from nus-cs2103-AY2223S2/tp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request nus-cs2103-AY2223S2#102 from ARPspoofing/activity-…
…events Activity events
- Loading branch information
Showing
11 changed files
with
286 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
@startuml | ||
'https://plantuml.com/activity-diagram-beta | ||
|
||
start | ||
:Type event name; | ||
if () then ([know event date]) | ||
:Type event date; | ||
else ([else]) | ||
endif | ||
if () then ([know student details]) | ||
:Type student details; | ||
else ([else]) | ||
endif | ||
if () then ([attachment(s) available]) | ||
:Type attachment filepath; | ||
else ([else]) | ||
endif | ||
:Press enter; | ||
:TrAcker saves new tutorial list; | ||
:TrAcker displays new tutorial list; | ||
stop | ||
|
||
@enduml |
73 changes: 73 additions & 0 deletions
73
src/main/java/seedu/address/logic/commands/AddRecurCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package seedu.address.logic.commands; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
import static seedu.address.logic.commands.AddLabCommand.MESSAGE_DUPLICATE_LAB; | ||
import static seedu.address.logic.commands.AddTutorialCommand.MESSAGE_DUPLICATE_TUTORIAL; | ||
|
||
import seedu.address.logic.commands.exceptions.CommandException; | ||
import seedu.address.model.Model; | ||
import seedu.address.model.event.Event; | ||
import seedu.address.model.event.Lab; | ||
import seedu.address.model.event.Tutorial; | ||
|
||
/** | ||
* Adds a recurring event to the address book. | ||
*/ | ||
public class AddRecurCommand extends Command { | ||
|
||
//Change in next version | ||
public static final String COMMAND_WORD = "schedule"; | ||
|
||
public static final String MESSAGE_USAGE = "To customise in next version"; | ||
|
||
public static final String MESSAGE_SUCCESS = "New recurring event added: %1$s"; | ||
public static final String MESSAGE_DUPLICATE_RECUR = "This recurring event already exists in the address book"; | ||
|
||
private final Event toAdd; | ||
private final int count; | ||
private final boolean lab; | ||
private final boolean tutorial; | ||
private final boolean consultation; | ||
|
||
/** | ||
* Creates an AddRecur to add the specified {@code Recur} | ||
*/ | ||
public AddRecurCommand(Event recurring, boolean lab, boolean tutorial, boolean consultation, int count) { | ||
requireNonNull(recurring); | ||
toAdd = recurring; | ||
this.count = count; | ||
this.lab = lab; | ||
this.tutorial = tutorial; | ||
this.consultation = consultation; | ||
} | ||
|
||
@Override | ||
public CommandResult execute(Model model) throws CommandException { | ||
requireNonNull(model); | ||
|
||
if (tutorial && model.hasTutorial((Tutorial) toAdd)) { | ||
throw new CommandException(MESSAGE_DUPLICATE_TUTORIAL); | ||
} | ||
|
||
if (lab && model.hasLab((Lab) toAdd)) { | ||
throw new CommandException(MESSAGE_DUPLICATE_LAB); | ||
} | ||
|
||
for (int i = 0; i < count; i++) { | ||
toAdd.setName(toAdd.getName() + i + i); | ||
if (lab) { | ||
model.addLab((Lab) toAdd); | ||
} else if (tutorial) { | ||
model.addTutorial((Tutorial) toAdd); | ||
} | ||
} | ||
return new CommandResult(String.format(MESSAGE_SUCCESS, toAdd)); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
return other == this // short circuit if same object | ||
|| (other instanceof AddRecurCommand // instanceof handles nulls | ||
&& toAdd.equals(((AddRecurCommand) other).toAdd)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
106 changes: 106 additions & 0 deletions
106
src/main/java/seedu/address/logic/parser/AddRecurParser.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
package seedu.address.logic.parser; | ||
|
||
import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_ADDRESS; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_COUNT; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_EMAIL; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_LAB; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_PERFORMANCE; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_PHOTO; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_RECUR; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_REMARK; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_TUTORIAL; | ||
|
||
import java.util.stream.Stream; | ||
|
||
import seedu.address.logic.commands.AddRecurCommand; | ||
import seedu.address.logic.parser.exceptions.ParseException; | ||
import seedu.address.model.event.Lab; | ||
import seedu.address.model.event.Tutorial; | ||
|
||
/** | ||
* Parses input arguments and creates a new AddRecur object | ||
*/ | ||
public class AddRecurParser implements Parser<AddRecurCommand> { | ||
|
||
/** | ||
* Parses the given {@code String} of arguments in the context of the AddRecur | ||
* and returns an AddRecur object for execution. | ||
* | ||
* @throws ParseException if the user input does not conform the expected format | ||
*/ | ||
public AddRecurCommand parse(String args) throws ParseException { | ||
ArgumentMultimap argMultimap = | ||
ArgumentTokenizer.tokenize(args, PREFIX_RECUR); | ||
//Make the user not create (lab or tutorial) and students with the same command | ||
if (arePrefixesAbsent(argMultimap, PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, | ||
PREFIX_PHOTO, PREFIX_ADDRESS, PREFIX_REMARK, PREFIX_PERFORMANCE, | ||
PREFIX_TAG) && (!arePrefixesPresent(argMultimap, PREFIX_RECUR) | ||
|| !argMultimap.getPreamble().isEmpty())) { | ||
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddRecurCommand.MESSAGE_USAGE)); | ||
} | ||
String name = " " + ParserUtil.parseRecurName(argMultimap.getValue(PREFIX_RECUR).get()); | ||
if (isLab(name)) { | ||
return parseEvent(name, PREFIX_LAB); | ||
} else { | ||
return parseEvent(name, PREFIX_TUTORIAL); | ||
} | ||
} | ||
|
||
/** | ||
* Checks to if the recurring event is a lab or tutorial or consultation. | ||
* Do a typecasting for the respective events. | ||
* @param newArgs | ||
* @param prefix | ||
* @return AddRecurCommand | ||
* @throws ParseException | ||
*/ | ||
public AddRecurCommand parseEvent(String newArgs, Prefix prefix) throws ParseException { | ||
ArgumentMultimap argMultimap = | ||
ArgumentTokenizer.tokenize(newArgs, prefix, PREFIX_COUNT); | ||
//Make the user not create (lab or tutorial) and students with the same command | ||
if (arePrefixesAbsent(argMultimap, PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, | ||
PREFIX_PHOTO, PREFIX_ADDRESS, PREFIX_REMARK, PREFIX_PERFORMANCE, | ||
PREFIX_TAG) && (!arePrefixesPresent(argMultimap, prefix) | ||
|| !argMultimap.getPreamble().isEmpty())) { | ||
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddRecurCommand.MESSAGE_USAGE)); | ||
} | ||
int count = ParserUtil.parseRecurCount(argMultimap.getValue(PREFIX_COUNT).get()); | ||
String name = ParserUtil.parseLabName(argMultimap.getValue(prefix).get()); | ||
if (prefix.getPrefix().equals("Lab/")) { | ||
Lab lab = new Lab(name); | ||
return new AddRecurCommand(lab, true, false, false, count); | ||
} else { | ||
Tutorial tutorial = new Tutorial(name); | ||
return new AddRecurCommand(tutorial, false, true, false, count); | ||
} | ||
} | ||
|
||
boolean isLab(String newArgs) { | ||
return newArgs.trim().split("/")[0].equals("Lab"); | ||
} | ||
|
||
boolean isTutorial(String newArgs) { | ||
return newArgs.trim().split(" ")[0].equals("Tutorial"); | ||
} | ||
|
||
/** | ||
* Returns true if none of the prefixes contains empty {@code Optional} values in the given | ||
* {@code ArgumentMultimap}. | ||
*/ | ||
private static boolean arePrefixesPresent(ArgumentMultimap argumentMultimap, Prefix... prefixes) { | ||
return Stream.of(prefixes).allMatch(prefix -> argumentMultimap.getValue(prefix).isPresent()); | ||
} | ||
|
||
/** | ||
* Returns true if none of the prefixes contains command to add students (cannot add student and lab | ||
* using the same command.) | ||
* {@code ArgumentMultimap}. | ||
*/ | ||
private static boolean arePrefixesAbsent(ArgumentMultimap argumentMultimap, Prefix... prefixes) { | ||
return Stream.of(prefixes).noneMatch(prefix -> argumentMultimap.getValue(prefix).isPresent()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters