Skip to content

Commit

Permalink
Merge pull request nus-cs2103-AY2122S1#96 from okyntary/link-ccas-and…
Browse files Browse the repository at this point in the history
…-reminders

Link ccas and reminders
  • Loading branch information
weiquu authored Oct 22, 2021
2 parents 48dc6b1 + 9ea8ff8 commit 2c934a5
Show file tree
Hide file tree
Showing 14 changed files with 229 additions and 46 deletions.
12 changes: 12 additions & 0 deletions docs/DeveloperGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,17 @@ Classes used by multiple components are in the `seedu.addressbook.commons` packa

This section describes some noteworthy details on how certain features are implemented.

### Storage

The current Storage mechanism is split into two main sections: `AddressBook` storage, for all ePoch-related data, and `UserPrefs` storage, for all user preference-related data.
Whenever ePoch needs to save or update its storage, it converts the relevant object into a `.json` object with the `saveJsonFile` method in `jsonUtil`.

There are three main classes types in ePoch that need to be saved: `Person`, `Cca`, and `Reminder`. Each of these classes is converted to its corresponding `JsonAdapted` class,
to be made suitable for `.json` conversion. Because each `Cca` object contains a `Set` of `Person`s and `Reminder`s as members, `JsonAdaptedPerson` and `JsonAdaptedReminder` will be stored within `JsonAdaptedCca` as well.

Alternatives considered: instead of storing whole `Person` and `Reminder` objects in `Cca` objects, the alternative of storing unique identifiers for them `Pid`, `Rid` etc was considered. In the end, this possibility was rejected
because of how time-consuming refactoring the entire project to use this new system would be.

### CCAs

A CCA has:
Expand Down Expand Up @@ -204,6 +215,7 @@ The `CcaExpelCommand` class has two Indexes, the index of the CCA to be expelled
It implements the `execute` method which handles the logic of the expel command.
The `getFilteredCcaList` and `getFilteredPersonList` method is called to obtain a List of CCAs and Persons, `lastShownCcaList` and `lastShownPersonList` respectively.
If the gives Indexes exist in `lastShownCcaList` and `lastShownPersonList`, the corresponding Person is expelled from the corresponding CCA using the `expelPersonFromCca` method defined in the `ModelManager`.
>>>>>>> 48dc6b1455d2d7f6d9cfc11d7f503f8cc2e9928d
### \[Proposed\] Undo/redo feature

Expand Down
6 changes: 6 additions & 0 deletions docs/diagrams/StorageClassDiagram.puml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ Class JsonAddressBookStorage
Class JsonSerializableAddressBook
Class JsonAdaptedPerson
Class JsonAdaptedTag
Class JsonAdaptedCca
Class JsonAdaptedReminder
}

}
Expand All @@ -38,6 +40,10 @@ JsonUserPrefsStorage .up.|> UserPrefsStorage
JsonAddressBookStorage .up.|> AddressBookStorage
JsonAddressBookStorage ..> JsonSerializableAddressBook
JsonSerializableAddressBook --> "*" JsonAdaptedPerson
JsonSerializableAddressBook --> "*" JsonAdaptedCca
JsonSerializableAddressBook --> "*" JsonAdaptedReminder
JsonAdaptedCca --> "*" JsonAdaptedPerson
JsonAdaptedCca --> "*" JsonAdaptedReminder
JsonAdaptedPerson --> "*" JsonAdaptedTag

@enduml
Binary file modified docs/images/StorageClassDiagram.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import seedu.address.model.cca.Cca;
import seedu.address.model.cca.CcaName;
import seedu.address.model.person.Person;
import seedu.address.model.reminder.Reminder;
import seedu.address.model.tag.Tag;

/**
Expand Down Expand Up @@ -89,9 +90,10 @@ private static Cca createEditedCca(Cca ccaToEdit, EditCcaDescriptor editCcaDescr

CcaName updatedName = editCcaDescriptor.getName().orElse(ccaToEdit.getName());
Set<Person> copyOfPersonArrayList = ccaToEdit.getPersonArrayList();
Set<Reminder> copyOfReminders = ccaToEdit.getReminders();
Set<Tag> updatedTags = editCcaDescriptor.getTags().orElse(ccaToEdit.getTags());

return new Cca(updatedName, copyOfPersonArrayList, updatedTags);
return new Cca(updatedName, copyOfPersonArrayList, copyOfReminders, updatedTags);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,18 @@
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME;
import static seedu.address.logic.parser.CliSyntax.PREFIX_START_DATE;

import java.util.List;

import seedu.address.commons.core.Messages;
import seedu.address.commons.core.index.Index;
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.cca.Cca;
import seedu.address.model.reminder.Reminder;


/**
* Adds a Reminder to the address book.
*/
Expand All @@ -30,27 +36,49 @@ public class ReminderAddCommand extends Command {

public static final String MESSAGE_SUCCESS = "New Reminder added: %1$s";
public static final String MESSAGE_DUPLICATE_REMINDER = "This Reminder already exists in the address book";
private static final String MESSAGE_MISSING_CCA = "This CCA does not exist in the address book";
private static final String MESSAGE_PRESENT_REMINDER = "This reminder (%1$s) is already part of this CCA (%2$s)";

private final Reminder toAdd;
private Cca ccaToAddInto;
private final Index targetCcaIndex;

/**
* Creates an ReminderAddCommand to add the specified {@code Reminder}
*/
public ReminderAddCommand(Reminder reminder) {
public ReminderAddCommand(Reminder reminder, Index targetCcaIndex) {
requireNonNull(reminder);
toAdd = reminder;
this.toAdd = reminder;
this.targetCcaIndex = targetCcaIndex;
}

@Override
public CommandResult execute(Model model) throws CommandException {
requireNonNull(model);
List<Cca> lastShownCcaList = model.getFilteredCcaList();
if (targetCcaIndex.getZeroBased() >= lastShownCcaList.size()) {
throw new CommandException(Messages.MESSAGE_INVALID_CCA_DISPLAYED_INDEX);
}

this.ccaToAddInto = lastShownCcaList.get(targetCcaIndex.getZeroBased());
if (ccaToAddInto == null) {
throw new CommandException(MESSAGE_MISSING_CCA);
}

if (model.hasReminder(toAdd)) {
throw new CommandException(MESSAGE_DUPLICATE_REMINDER);
}

model.addReminder(toAdd);
return new CommandResult(String.format(MESSAGE_SUCCESS, toAdd));
boolean success = model.addReminder(toAdd, ccaToAddInto);

if (success) {
model.setCca(ccaToAddInto, ccaToAddInto);
model.updateFilteredCcaList(Model.PREDICATE_SHOW_ALL_CCAS);
return new CommandResult(String.format(MESSAGE_SUCCESS, toAdd.getName(), ccaToAddInto.getName()));
} else {
throw new CommandException(
String.format(MESSAGE_PRESENT_REMINDER, toAdd.getName(), ccaToAddInto.getName()));
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package seedu.address.logic.parser.reminder;

import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT;
import static seedu.address.logic.parser.CliSyntax.PREFIX_CCA_ID;
import static seedu.address.logic.parser.CliSyntax.PREFIX_FREQUENCY;
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME;
import static seedu.address.logic.parser.CliSyntax.PREFIX_OCCURRENCES;
Expand All @@ -11,6 +12,7 @@
import java.util.stream.Stream;

import seedu.address.commons.core.LogsCenter;
import seedu.address.commons.core.index.Index;
import seedu.address.logic.LogicManager;
import seedu.address.logic.commands.reminder.ReminderAddCommand;
import seedu.address.logic.parser.ArgumentMultimap;
Expand All @@ -34,8 +36,8 @@ public class ReminderAddCommandParser implements Parser<ReminderAddCommand> {
* @throws ParseException if the user input does not conform the expected format
*/
public ReminderAddCommand parse(String args) throws ParseException {
ArgumentMultimap argMultimap =
ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_START_DATE, PREFIX_FREQUENCY, PREFIX_OCCURRENCES);
ArgumentMultimap argMultimap = ArgumentTokenizer.tokenize(args, PREFIX_CCA_ID, PREFIX_NAME, PREFIX_START_DATE,
PREFIX_FREQUENCY, PREFIX_OCCURRENCES);

if (!arePrefixesPresent(argMultimap, PREFIX_NAME, PREFIX_START_DATE)
|| !argMultimap.getPreamble().isEmpty()) {
Expand All @@ -45,6 +47,7 @@ public ReminderAddCommand parse(String args) throws ParseException {
ReminderName reminderName = ParserUtil.parseReminderName(argMultimap.getValue(PREFIX_NAME).get());
ReminderStartDate reminderStartDate = ParserUtil.parseReminderStartDate(
argMultimap.getValue(PREFIX_START_DATE).get());
Index ccaIndex = ParserUtil.parseIndex(argMultimap.getValue(PREFIX_CCA_ID).get());
ReminderFrequency reminderFrequency = argMultimap.getValue(PREFIX_FREQUENCY).isPresent()
? ParserUtil.parseReminderFrequency(argMultimap.getValue(PREFIX_FREQUENCY).get())
: ParserUtil.parseReminderFrequency("");
Expand All @@ -56,7 +59,7 @@ public ReminderAddCommand parse(String args) throws ParseException {
Reminder reminder = new Reminder(reminderName, reminderStartDate, reminderFrequency, reminderOccurrence);
logger.log(Level.INFO, "New reminder created.");

return new ReminderAddCommand(reminder);
return new ReminderAddCommand(reminder, ccaIndex);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/seedu/address/model/Model.java
Original file line number Diff line number Diff line change
Expand Up @@ -156,5 +156,5 @@ public interface Model {
* Adds the given reminder.
* {@code reminder} must not already exist in the address book.
*/
void addReminder(Reminder reminder);
boolean addReminder(Reminder reminder, Cca ccaToAddInto);
}
8 changes: 6 additions & 2 deletions src/main/java/seedu/address/model/ModelManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,13 @@ public void deleteReminder(Reminder target) {
}

@Override
public void addReminder(Reminder reminder) {
public boolean addReminder(Reminder reminder, Cca ccaToAddInto) {
addressBook.addReminder(reminder);
updateFilteredCcaList(PREDICATE_SHOW_ALL_CCAS);
boolean success = ccaToAddInto.addReminder(reminder);
if (success) {
updateFilteredCcaList(PREDICATE_SHOW_ALL_CCAS);
}
return success;
}

//=========== Filtered Person List Accessors =============================================================
Expand Down
79 changes: 58 additions & 21 deletions src/main/java/seedu/address/model/cca/Cca.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,17 @@
import java.util.Set;

import seedu.address.model.person.Person;
import seedu.address.model.reminder.Reminder;
import seedu.address.model.tag.Tag;


public class Cca {

// Identity fields
private final CcaName ccaName;

// Data fields
private Set<Person> personArrayList = new HashSet<>();
private Set<Reminder> reminders = new HashSet<>();
private final Set<Tag> tags = new HashSet<>();

/**
Expand All @@ -25,24 +26,34 @@ public class Cca {
public Cca(CcaName ccaName) {
requireAllNonNull(ccaName);
this.ccaName = ccaName;
this.personArrayList = new HashSet<>();
}

/**
* Every field must be present and not null.
* Constructor using ccaName and tags
* @param ccaName Name of Cca
* @param tags Tags to initialize Cca with
*/
public Cca(CcaName ccaName, Set<Tag> tags) {
requireAllNonNull(ccaName);
this.ccaName = ccaName;
this.personArrayList = new HashSet<>();
this.tags.addAll(tags);
}

/**
* Every field must be present and not null.
*
* Constructor using ccaName, personArrayList, reminders, and tags
* @param ccaName Name of Cca
* @param personArrayList list of associated members
* @param reminders list of associated reminders
* @param tags Cca tags
*/
public Cca(CcaName ccaName, Set<Person> personArrayList, Set<Tag> tags) {
public Cca(CcaName ccaName, Set<Person> personArrayList, Set<Reminder> reminders, Set<Tag> tags) {
requireAllNonNull(ccaName);
this.ccaName = ccaName;
this.personArrayList.addAll(personArrayList);
this.personArrayList = personArrayList;
this.reminders = reminders;
this.tags.addAll(tags);
}

Expand Down Expand Up @@ -70,6 +81,23 @@ public int getNumberOfMembers() {
return personArrayList.size();
}

/**
<<<<<<< HEAD
* Returns the reminders of this CCA.
* @return the reminders of this CCA
*/
public Set<Reminder> getReminders() {
return reminders;
}

/**
* Returns the number of reminders in this CCA.
* @return the number of reminders of this CCA
*/
public int getNumberOfReminders() {
return reminders.size();
}

/**
* Returns an immutable tag set, which throws {@code UnsupportedOperationException}
* if modification is attempted.
Expand All @@ -91,21 +119,6 @@ public boolean isSameCca(seedu.address.model.cca.Cca otherCca) {
&& otherCca.getName().equals(getName());
}

// Enrol a Person
public boolean enrolPerson(Person newPerson) {
return this.personArrayList.add(newPerson);
}

// Check if Person Exists but should not need as it is a Set<>
public boolean checkPerson(Person personToCheck) {
return this.personArrayList.contains(personToCheck);
}

// Expel a Person
public boolean expelPerson(Person personToExpel) {
return this.personArrayList.remove(personToExpel);
}

/**
* Returns true if both CCAs have the same identity and data fields.
* This defines a stronger notion of equality between two CCAs.
Expand Down Expand Up @@ -146,5 +159,29 @@ public String toString() {
}
return builder.toString();
}
}

// Enrol a Person
public boolean enrolPerson(Person newPerson) {
return this.personArrayList.add(newPerson);
}

// Check if Person Exists but should not need as it is a Set<>
public boolean checkPerson(Person personToCheck) {
return this.personArrayList.contains(personToCheck);
}

// Expel a Person
public boolean expelPerson(Person personToExpel) {
return this.personArrayList.remove(personToExpel);
}

// Add a reminder
public boolean addReminder(Reminder reminder) {
return this.reminders.add(reminder);
}

// Remove a reminder
public boolean removeReminder(Reminder reminder) {
return this.reminders.remove(reminder);
}
}
1 change: 1 addition & 0 deletions src/main/java/seedu/address/model/reminder/Reminder.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public boolean equals(Object other) {
return false;
}

// TODO
seedu.address.model.reminder.Reminder otherReminder = (seedu.address.model.reminder.Reminder) other;
return otherReminder.getName().equals(getName()) && otherReminder.getStartDate().equals(getStartDate())
&& otherReminder.getFrequency().equals(getFrequency())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ public ReminderOccurrence(int occurrences) {
this.occurrences = occurrences;
}

public int getOccurrences() {
return occurrences;
}

@Override
public String toString() {
return Integer.toString(occurrences);
Expand Down
Loading

0 comments on commit 2c934a5

Please sign in to comment.