Skip to content

Commit

Permalink
Merge pull request nus-cs2103-AY2223S2#102 from ARPspoofing/activity-…
Browse files Browse the repository at this point in the history
…events

Activity events
  • Loading branch information
ARPspoofing authored Mar 18, 2023
2 parents f428c14 + 253474d commit 4708e6e
Show file tree
Hide file tree
Showing 11 changed files with 286 additions and 1 deletion.
23 changes: 23 additions & 0 deletions docs/AddEventActivityDiagram.puml
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 src/main/java/seedu/address/logic/commands/AddRecurCommand.java
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));
}
}
2 changes: 1 addition & 1 deletion src/main/java/seedu/address/logic/parser/AddLabParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public AddLabCommand parse(String args) throws ParseException {
String newArgs = args.trim().replaceFirst("Lab", "");
ArgumentMultimap argMultimap =
ArgumentTokenizer.tokenize(args, PREFIX_LAB);

System.out.println("newArgs" + args);
//Make the user not create lab and students with the same command
if (arePrefixesAbsent(argMultimap, PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL,
PREFIX_PHOTO, PREFIX_ADDRESS, PREFIX_REMARK, PREFIX_PERFORMANCE,
Expand Down
106 changes: 106 additions & 0 deletions src/main/java/seedu/address/logic/parser/AddRecurParser.java
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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import seedu.address.logic.commands.AddCommand;
import seedu.address.logic.commands.AddLabCommand;
import seedu.address.logic.commands.AddRecurCommand;
import seedu.address.logic.commands.AddStudentToEventCommand;
import seedu.address.logic.commands.AddTutorialCommand;
import seedu.address.logic.commands.ClearCommand;
Expand Down Expand Up @@ -89,6 +90,9 @@ public Command parseCommand(String userInput) throws ParseException {
case AddTutorialCommand.COMMAND_WORD:
return new AddTutorialParser().parse(arguments);

case AddRecurCommand.COMMAND_WORD:
return new AddRecurParser().parse(arguments);

case AddStudentToEventCommand.COMMAND_WORD:
return new AddStudentToEventParser().parse(arguments);

Expand Down
2 changes: 2 additions & 0 deletions src/main/java/seedu/address/logic/parser/CliSyntax.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,6 @@ public class CliSyntax {
public static final Prefix PREFIX_TAG = new Prefix("t/");
public static final Prefix PREFIX_TUTORIAL = new Prefix("Tutorial/");
public static final Prefix PREFIX_LAB = new Prefix("Lab/");
public static final Prefix PREFIX_RECUR = new Prefix("Recur/");
public static final Prefix PREFIX_COUNT = new Prefix("-n");
}
32 changes: 32 additions & 0 deletions src/main/java/seedu/address/logic/parser/ParserUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import seedu.address.commons.core.index.Index;
import seedu.address.commons.util.StringUtil;
import seedu.address.logic.parser.exceptions.ParseException;
import seedu.address.model.event.Event;
import seedu.address.model.person.Address;
import seedu.address.model.person.Email;
import seedu.address.model.person.Name;
Expand Down Expand Up @@ -170,6 +171,37 @@ public static String parseLabName(String name) throws ParseException {
return trimmedName;
}

/**
* Parses a {@code String name}.
* Leading and trailing whitespaces will be trimmed.
*
* @throws ParseException if the given {@code name} is invalid.
*/
public static String parseRecurName(String name) throws ParseException {
requireNonNull(name);
String trimmedName = name.trim();
//Add custom regex
//if (!Name.isValidName(trimmedName)) {
// throw new ParseException(Name.MESSAGE_CONSTRAINTS);
//}
return trimmedName;
}

/**
* Parses a {@code String name}.
* Leading and trailing whitespaces will be trimmed.
*
* @throws ParseException if the given {@code name} is invalid.
*/
public static int parseRecurCount(String count) throws ParseException {
requireNonNull(count);
String trimmedCount = count.trim();
if (!Event.isValidCount(trimmedCount)) {
throw new ParseException(Event.MESSAGE_CONSTRAINTS);
}
return Integer.parseInt(trimmedCount);
}

/**
* Parses {@code String performance} into a {@code Performance} object.
*/
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/seedu/address/model/event/Consultation.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ public String getName() {
return super.getName();
}

public void setName(String name) {
super.setName(name);
}

/**
* Gets the list of students
* @return students
Expand Down
33 changes: 33 additions & 0 deletions src/main/java/seedu/address/model/event/Event.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,14 @@
*/
public abstract class Event {

public static final String MESSAGE_CONSTRAINTS = "Repititon for recur must be a number between 0 and 10";

private String name;
private LocalDate eventDate;
private final List<Person> students;
private final List<File> attachments;
private final List<Note> notes;

/**
* Constructor with name parameter only. The time of the event will be
* assumed to be the current time the constructor is executed
Expand Down Expand Up @@ -97,6 +100,10 @@ public String getName() {
return this.name;
}

public void setName(String name) {
this.name = name;
}

public boolean hasMatchByName(String name) {
return this.name.equals(name);
}
Expand Down Expand Up @@ -213,4 +220,30 @@ public void removeNote(Note note) {
notes.remove(note);
}

/**
* Checks if input {@code String count} is valid
* @param count Input string to check upon
* @return Whether the count event is a validated integer
*/
public static boolean isValidCount(String count) {
boolean validInteger = true;
for (int i = 0; i < count.length(); i++) {
if (!Character.isDigit(count.charAt(i))) {
validInteger = false;
}
}
int convertedNumber = 0;
try {
convertedNumber = Integer.parseInt(count);
} catch (NumberFormatException nfe) {
return false;
}
if (validInteger) {
if (convertedNumber < 0 || convertedNumber > 10) {
validInteger = false;
}
}
return validInteger;
}

}
4 changes: 4 additions & 0 deletions src/main/java/seedu/address/model/event/Lab.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ public String getName() {
return super.getName();
}

public void setName(String name) {
super.setName(name);
}

/**
* Gets the list of students
*
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/seedu/address/model/event/Tutorial.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ public String getName() {
return super.getName();
}

public void setName(String name) {
super.setName(name);
}

/**
* Gets the list of students
*
Expand Down

0 comments on commit 4708e6e

Please sign in to comment.