Skip to content

Commit 678c0fd

Browse files
authored
Merge pull request nus-cs2103-AY2021S1#90 from gloon99/branch-Add-Meeting
Branch add meeting
2 parents 0be8caf + 72f7839 commit 678c0fd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+1469
-158
lines changed

src/main/java/seedu/address/MainApp.java

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,19 @@
1616
import seedu.address.logic.Logic;
1717
import seedu.address.logic.LogicManager;
1818
import seedu.address.model.AddressBook;
19+
import seedu.address.model.MeetingBook;
1920
import seedu.address.model.Model;
2021
import seedu.address.model.ModelManager;
2122
import seedu.address.model.ReadOnlyAddressBook;
23+
import seedu.address.model.ReadOnlyMeetingBook;
2224
import seedu.address.model.ReadOnlyUserPrefs;
2325
import seedu.address.model.UserPrefs;
2426
import seedu.address.model.util.SampleDataUtil;
2527
import seedu.address.storage.AddressBookStorage;
2628
import seedu.address.storage.JsonAddressBookStorage;
29+
import seedu.address.storage.JsonMeetingBookStorage;
2730
import seedu.address.storage.JsonUserPrefsStorage;
31+
import seedu.address.storage.MeetingBookStorage;
2832
import seedu.address.storage.Storage;
2933
import seedu.address.storage.StorageManager;
3034
import seedu.address.storage.UserPrefsStorage;
@@ -57,7 +61,8 @@ public void init() throws Exception {
5761
UserPrefsStorage userPrefsStorage = new JsonUserPrefsStorage(config.getUserPrefsFilePath());
5862
UserPrefs userPrefs = initPrefs(userPrefsStorage);
5963
AddressBookStorage addressBookStorage = new JsonAddressBookStorage(userPrefs.getAddressBookFilePath());
60-
storage = new StorageManager(addressBookStorage, userPrefsStorage);
64+
MeetingBookStorage meetingBookStorage = new JsonMeetingBookStorage(userPrefs.getMeetingBookFilePath());
65+
storage = new StorageManager(addressBookStorage, meetingBookStorage, userPrefsStorage);
6166

6267
initLogging(config);
6368

@@ -75,22 +80,38 @@ public void init() throws Exception {
7580
*/
7681
private Model initModelManager(Storage storage, ReadOnlyUserPrefs userPrefs) {
7782
Optional<ReadOnlyAddressBook> addressBookOptional;
78-
ReadOnlyAddressBook initialData;
83+
ReadOnlyAddressBook addressBookInitialData;
7984
try {
8085
addressBookOptional = storage.readAddressBook();
8186
if (!addressBookOptional.isPresent()) {
8287
logger.info("Data file not found. Will be starting with a sample AddressBook");
8388
}
84-
initialData = addressBookOptional.orElseGet(SampleDataUtil::getSampleAddressBook);
89+
addressBookInitialData = addressBookOptional.orElseGet(SampleDataUtil::getSampleAddressBook);
8590
} catch (DataConversionException e) {
8691
logger.warning("Data file not in the correct format. Will be starting with an empty AddressBook");
87-
initialData = new AddressBook();
92+
addressBookInitialData = new AddressBook();
8893
} catch (IOException e) {
8994
logger.warning("Problem while reading from the file. Will be starting with an empty AddressBook");
90-
initialData = new AddressBook();
95+
addressBookInitialData = new AddressBook();
9196
}
9297

93-
return new ModelManager(initialData, userPrefs);
98+
Optional<ReadOnlyMeetingBook> meetingBookOptional;
99+
ReadOnlyMeetingBook meetingBookInitialData;
100+
try {
101+
meetingBookOptional = storage.readMeetingBook();
102+
if (!meetingBookOptional.isPresent()) {
103+
logger.info("Data file not found. Will be starting with a sample AddressBook");
104+
}
105+
meetingBookInitialData = meetingBookOptional.orElseGet(SampleDataUtil::getSampleMeetingBook);
106+
} catch (DataConversionException e) {
107+
logger.warning("Data file not in the correct format. Will be starting with an empty AddressBook");
108+
meetingBookInitialData = new MeetingBook();
109+
} catch (IOException e) {
110+
logger.warning("Problem while reading from the file. Will be starting with an empty AddressBook");
111+
meetingBookInitialData = new MeetingBook();
112+
}
113+
114+
return new ModelManager(addressBookInitialData, meetingBookInitialData, userPrefs);
94115
}
95116

96117
private void initLogging(Config config) {

src/main/java/seedu/address/logic/LogicManager.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import seedu.address.logic.commands.CommandResult;
1212
import seedu.address.logic.commands.exceptions.CommandException;
1313
import seedu.address.logic.parser.AddressBookParser;
14+
import seedu.address.logic.parser.MeetingBookParser;
1415
import seedu.address.logic.parser.exceptions.ParseException;
1516
import seedu.address.model.Model;
1617
import seedu.address.model.ReadOnlyAddressBook;
@@ -27,6 +28,7 @@ public class LogicManager implements Logic {
2728
private final Model model;
2829
private final Storage storage;
2930
private final AddressBookParser addressBookParser;
31+
private final MeetingBookParser meetingBookParser;
3032

3133
/**
3234
* Constructs a {@code LogicManager} with the given {@code Model} and {@code Storage}.
@@ -35,18 +37,27 @@ public LogicManager(Model model, Storage storage) {
3537
this.model = model;
3638
this.storage = storage;
3739
addressBookParser = new AddressBookParser();
40+
meetingBookParser = new MeetingBookParser();
3841
}
3942

4043
@Override
4144
public CommandResult execute(String commandText) throws CommandException, ParseException {
4245
logger.info("----------------[USER COMMAND][" + commandText + "]");
4346

47+
String firstWord = commandText.split(" ")[0];
48+
4449
CommandResult commandResult;
45-
Command command = addressBookParser.parseCommand(commandText);
50+
Command command;
51+
if (firstWord.equals("meeting")) {
52+
command = meetingBookParser.parseCommand(commandText);
53+
} else {
54+
command = addressBookParser.parseCommand(commandText);
55+
}
4656
commandResult = command.execute(model);
4757

4858
try {
4959
storage.saveAddressBook(model.getAddressBook());
60+
storage.saveMeetingBook(model.getMeetingBook());
5061
} catch (IOException ioe) {
5162
throw new CommandException(FILE_OPS_ERROR_MESSAGE + ioe, ioe);
5263
}
Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
package seedu.address.logic.commands;
2+
3+
import static java.util.Objects.requireNonNull;
4+
import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG;
5+
import static seedu.address.model.Model.PREDICATE_SHOW_ALL_PERSONS;
6+
7+
import java.util.Collections;
8+
import java.util.HashSet;
9+
import java.util.List;
10+
import java.util.Optional;
11+
import java.util.Set;
12+
import java.util.stream.Collectors;
13+
14+
import seedu.address.commons.core.Messages;
15+
import seedu.address.logic.commands.exceptions.CommandException;
16+
import seedu.address.model.Model;
17+
import seedu.address.model.person.Name;
18+
import seedu.address.model.person.Person;
19+
import seedu.address.model.tag.Tag;
20+
21+
/**
22+
* Edits the details of an existing person in the address book.
23+
*/
24+
public class AddLabelCommand extends Command {
25+
26+
public static final String COMMAND_WORD = "label add";
27+
28+
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Adds a label to the person specified.\n"
29+
+ "Parameters: NAME (must be name of person existing in ModDuke) "
30+
+ "[" + PREFIX_TAG + "TAG]...\n"
31+
+ "Example: " + COMMAND_WORD + " "
32+
+ "Roy "
33+
+ PREFIX_TAG + "classmate";
34+
35+
public static final String MESSAGE_EDIT_PERSON_SUCCESS = "Labelled Person: %1$s";
36+
public static final String MESSAGE_NOT_EDITED = "At least one field to edit must be provided.";
37+
public static final String MESSAGE_DUPLICATE_PERSON = "This person already exists in the address book.";
38+
39+
private final Name targetName;
40+
private final LabelPersonDescriptor labelPersonDescriptor;
41+
42+
/**
43+
* @param targetName of the person in the filtered person list to label
44+
*/
45+
public AddLabelCommand(Name targetName, LabelPersonDescriptor labelPersonDescriptor) {
46+
requireNonNull(targetName);
47+
requireNonNull(labelPersonDescriptor);
48+
49+
this.targetName = targetName;
50+
this.labelPersonDescriptor = new LabelPersonDescriptor(labelPersonDescriptor);
51+
}
52+
53+
@Override
54+
public CommandResult execute(Model model) throws CommandException {
55+
requireNonNull(model);
56+
boolean isValidContact = model.hasPersonName(targetName);
57+
58+
if (!isValidContact) {
59+
throw new CommandException(Messages.MESSAGE_INVALID_PERSON_DISPLAYED);
60+
}
61+
62+
List<Person> filteredList = model.getFilteredPersonList().stream()
63+
.filter(person -> person.isSameName(targetName)).collect(Collectors.toList());
64+
Person personToLabel = filteredList.get(0);
65+
66+
Person labelledPerson = createLabelledPerson(personToLabel, labelPersonDescriptor);
67+
68+
if (!personToLabel.isSamePerson(labelledPerson) && model.hasPerson(labelledPerson)) {
69+
throw new CommandException(MESSAGE_DUPLICATE_PERSON);
70+
}
71+
72+
model.setPerson(personToLabel, labelledPerson);
73+
model.updateFilteredPersonList(PREDICATE_SHOW_ALL_PERSONS);
74+
return new CommandResult(String.format(MESSAGE_EDIT_PERSON_SUCCESS, labelledPerson));
75+
}
76+
77+
/**
78+
* Creates and returns a {@code Person} with the details of {@code personToEdit}
79+
* edited with {@code editPersonDescriptor}.
80+
*/
81+
private static Person createLabelledPerson(Person personToLabel, LabelPersonDescriptor labelPersonDescriptor) {
82+
assert personToLabel != null;
83+
84+
Set<Tag> updatedTags = labelPersonDescriptor.getTags().orElse(personToLabel.getTags());
85+
86+
return new Person(personToLabel.getName(), personToLabel.getPhone(), personToLabel.getEmail(), updatedTags);
87+
}
88+
89+
@Override
90+
public boolean equals(Object other) {
91+
// short circuit if same object
92+
if (other == this) {
93+
return true;
94+
}
95+
96+
// instanceof handles nulls
97+
if (!(other instanceof AddLabelCommand)) {
98+
return false;
99+
}
100+
101+
// state check
102+
AddLabelCommand e = (AddLabelCommand) other;
103+
return targetName.equals(e.targetName)
104+
&& labelPersonDescriptor.equals(e.labelPersonDescriptor);
105+
}
106+
107+
/**
108+
* Stores the details to edit the person with. Each non-empty field value will replace the
109+
* corresponding field value of the person.
110+
*/
111+
public static class LabelPersonDescriptor {
112+
private Set<Tag> tags;
113+
114+
public LabelPersonDescriptor() {}
115+
116+
/**
117+
* Copy constructor.
118+
* A defensive copy of {@code tags} is used internally.
119+
*/
120+
public LabelPersonDescriptor(LabelPersonDescriptor toCopy) {
121+
setTags(toCopy.tags);
122+
}
123+
124+
/**
125+
* Sets {@code tags} to this object's {@code tags}.
126+
* A defensive copy of {@code tags} is used internally.
127+
*/
128+
public void setTags(Set<Tag> tags) {
129+
this.tags = (tags != null) ? new HashSet<>(tags) : null;
130+
}
131+
132+
/**
133+
* Returns an unmodifiable tag set, which throws {@code UnsupportedOperationException}
134+
* if modification is attempted.
135+
* Returns {@code Optional#empty()} if {@code tags} is null.
136+
*/
137+
public Optional<Set<Tag>> getTags() {
138+
return (tags != null) ? Optional.of(Collections.unmodifiableSet(tags)) : Optional.empty();
139+
}
140+
141+
@Override
142+
public boolean equals(Object other) {
143+
// short circuit if same object
144+
if (other == this) {
145+
return true;
146+
}
147+
148+
// instanceof handles nulls
149+
if (!(other instanceof LabelPersonDescriptor)) {
150+
return false;
151+
}
152+
153+
// state check
154+
LabelPersonDescriptor e = (LabelPersonDescriptor) other;
155+
156+
return getTags().equals(e.getTags());
157+
}
158+
}
159+
}

src/main/java/seedu/address/logic/commands/AddMeetingCommand.java

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
package seedu.address.logic.commands;
22

33
import static java.util.Objects.requireNonNull;
4-
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME;
54
import static seedu.address.logic.parser.CliSyntax.PREFIX_DATE;
5+
import static seedu.address.logic.parser.CliSyntax.PREFIX_MEETINGNAME;
66
import static seedu.address.logic.parser.CliSyntax.PREFIX_TIME;
7-
import static seedu.address.logic.parser.CliSyntax.PREFIX_CONTACTADD;
87

98
import seedu.address.logic.commands.exceptions.CommandException;
109
import seedu.address.model.Model;
@@ -19,16 +18,13 @@ public class AddMeetingCommand extends Command {
1918

2019
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Adds a person to the address book. "
2120
+ "Parameters: "
22-
+ PREFIX_NAME + "MEETING NAME "
21+
+ PREFIX_MEETINGNAME + "MEETING NAME "
2322
+ PREFIX_DATE + "DATE "
2423
+ PREFIX_TIME + "TIME "
25-
+ "[" + PREFIX_CONTACTADD + "PERSON]...\n"
2624
+ "Example: " + COMMAND_WORD + " "
27-
+ PREFIX_NAME + "CS2103 weekly meeting "
25+
+ PREFIX_MEETINGNAME + "CS2103 weekly meeting "
2826
+ PREFIX_DATE + "2020-09-20 "
29-
+ PREFIX_TIME+ "10:00 "
30-
+ PREFIX_CONTACTADD + "Roy "
31-
+ PREFIX_CONTACTADD + "Jerryl ";
27+
+ PREFIX_TIME + "10:00 ";
3228

3329
public static final String MESSAGE_SUCCESS = "New person added: %1$s";
3430
public static final String MESSAGE_DUPLICATE_MEETING = "This meeting already exists in the address book";

src/main/java/seedu/address/logic/commands/EditCommand.java

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
import java.util.List;
1313
import java.util.Optional;
1414
import java.util.Set;
15+
import java.util.stream.Collectors;
1516

1617
import seedu.address.commons.core.Messages;
17-
import seedu.address.commons.core.index.Index;
1818
import seedu.address.commons.util.CollectionUtil;
1919
import seedu.address.logic.commands.exceptions.CommandException;
2020
import seedu.address.model.Model;
@@ -29,36 +29,36 @@
2929
*/
3030
public class EditCommand extends Command {
3131

32-
public static final String COMMAND_WORD = "edit";
32+
public static final String COMMAND_WORD = "contact edit";
3333

3434
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Edits the details of the person identified "
35-
+ "by the index number used in the displayed person list. "
35+
+ "by the name of the person in the displayed person list. "
3636
+ "Existing values will be overwritten by the input values.\n"
37-
+ "Parameters: INDEX (must be a positive integer) "
38-
+ "[" + PREFIX_NAME + "NAME] "
37+
+ "Parameters: NAME (must be name of person existing in ModDuke) "
38+
+ "[" + PREFIX_NAME + "NEW_NAME] "
3939
+ "[" + PREFIX_PHONE + "PHONE] "
4040
+ "[" + PREFIX_EMAIL + "EMAIL] "
4141
+ "[" + PREFIX_TAG + "TAG]...\n"
42-
+ "Example: " + COMMAND_WORD + " 1 "
42+
+ "Example: " + COMMAND_WORD + " john doe "
4343
+ PREFIX_PHONE + "91234567 "
4444
+ PREFIX_EMAIL + "[email protected]";
4545

4646
public static final String MESSAGE_EDIT_PERSON_SUCCESS = "Edited Person: %1$s";
4747
public static final String MESSAGE_NOT_EDITED = "At least one field to edit must be provided.";
4848
public static final String MESSAGE_DUPLICATE_PERSON = "This person already exists in the address book.";
4949

50-
private final Index index;
50+
private final Name name;
5151
private final EditPersonDescriptor editPersonDescriptor;
5252

5353
/**
54-
* @param index of the person in the filtered person list to edit
54+
* @param name of the person in the filtered person list to edit
5555
* @param editPersonDescriptor details to edit the person with
5656
*/
57-
public EditCommand(Index index, EditPersonDescriptor editPersonDescriptor) {
58-
requireNonNull(index);
57+
public EditCommand(Name name, EditPersonDescriptor editPersonDescriptor) {
58+
requireNonNull(name);
5959
requireNonNull(editPersonDescriptor);
6060

61-
this.index = index;
61+
this.name = name;
6262
this.editPersonDescriptor = new EditPersonDescriptor(editPersonDescriptor);
6363
}
6464

@@ -67,11 +67,15 @@ public CommandResult execute(Model model) throws CommandException {
6767
requireNonNull(model);
6868
List<Person> lastShownList = model.getFilteredPersonList();
6969

70-
if (index.getZeroBased() >= lastShownList.size()) {
71-
throw new CommandException(Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX);
70+
boolean isValidContact = model.hasPersonName(name);
71+
if (!isValidContact) {
72+
throw new CommandException(Messages.MESSAGE_INVALID_PERSON_DISPLAYED);
7273
}
7374

74-
Person personToEdit = lastShownList.get(index.getZeroBased());
75+
List<Person> filteredList = lastShownList.stream()
76+
.filter(person -> person.isSameName(name)).collect(Collectors.toList());
77+
Person personToEdit = filteredList.get(0);
78+
7579
Person editedPerson = createEditedPerson(personToEdit, editPersonDescriptor);
7680

7781
if (!personToEdit.isSamePerson(editedPerson) && model.hasPerson(editedPerson)) {
@@ -112,7 +116,7 @@ public boolean equals(Object other) {
112116

113117
// state check
114118
EditCommand e = (EditCommand) other;
115-
return index.equals(e.index)
119+
return name.equals(e.name)
116120
&& editPersonDescriptor.equals(e.editPersonDescriptor);
117121
}
118122

0 commit comments

Comments
 (0)