Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
iamputradanish committed Oct 5, 2018
2 parents a4ef98b + eecb9f9 commit 75b4ce4
Show file tree
Hide file tree
Showing 23 changed files with 192 additions and 16 deletions.
10 changes: 5 additions & 5 deletions docs/AboutUs.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,31 @@ We are a team based in the http://www.comp.nus.edu.sg[School of Computing, Natio
== Project Team

=== Putra Danish
image::Putra.jpeg[width="150", align="left"]
image::Putra.png[width="150", align="left"]

Role: Team Lead +
Responsibilities: Deadlines

'''

=== Matthew Alexander
image::Matthew.jpeg[width="150", align="left"]
image::Matthew.png[width="150", align="left"]

Role: Developer +
Responsibilities: Integration

'''

=== Muhammad Harun
image::Harun.jpg[width="150", align="left"]
image::Harun.png[width="150", align="left"]

Role: Developer +
Responsibilities: Documentation

'''

=== Shreyas
image::Shreyas.jpeg[width="150", align="left"]
image::Shreyas.png[width="150", align="left"]


Role: Developer +
Expand All @@ -44,7 +44,7 @@ Responsibilities: Code Quality
'''

=== Ong Wee Keong
image::WeeKeong.jpeg[width="150", align="left"]
image::WeeKeong.png[width="150", align="left"]

Role: Developer +
Responsibilities: Intellij, Git and SourceTree expert
Expand Down
2 changes: 1 addition & 1 deletion docs/DeveloperGuide.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

== Design

image::mainClassDiagram1.png[]
image::mainClassDiagram.png[]

== Testing

Expand Down
Binary file modified docs/images/mainClassDiagram.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed docs/images/mainClassDiagram1.png
Binary file not shown.
Binary file removed docs/images/profiles/Harun.jpg
Binary file not shown.
Binary file added docs/images/profiles/Harun.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed docs/images/profiles/Matthew.jpeg
Binary file not shown.
Binary file added docs/images/profiles/Matthew.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed docs/images/profiles/Putra.jpeg
Binary file not shown.
Binary file added docs/images/profiles/Putra.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed docs/images/profiles/Shreyas.jpeg
Binary file not shown.
Binary file added docs/images/profiles/Shreyas.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed docs/images/profiles/WeeKeong.jpeg
Binary file not shown.
Binary file added docs/images/profiles/WeeKeong.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 8 additions & 1 deletion src/seedu/addressbook/Location.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,13 @@ private ArrayList<Pair<Integer, String>> getEtaListFromJsonObject(JSONObject jso
return etaList;
}

/**
* Returns ETA for this location from multiple locations
*
* @param locations Arraylist is of Locations objects
* @return ArrayList of Pair of Number of seconds of ETA and text description of ETA
*/

public ArrayList<Pair<Integer, String>> getEtaFromMultipleLocations(ArrayList<Location> locations) {
ArrayList<Pair<Integer, String>> etaList = new ArrayList<>();

Expand All @@ -105,7 +112,7 @@ public ArrayList<Pair<Integer, String>> getEtaFromMultipleLocations(ArrayList<Lo
return etaList;
}

public String getLocationURL() {
public String getGooglemMapsURL() {
return GOOGLE_MAPS_BASE_URL + this.getLatitude() + "," + this.getLongitude();
}

Expand Down
4 changes: 2 additions & 2 deletions src/seedu/addressbook/commands/Command.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ protected ReadOnlyPerson getTargetPerson() throws IndexOutOfBoundsException {
return relevantPersons.get(getTargetIndex() - DISPLAYED_INDEX_OFFSET);
}

protected ReadOnlyPerson getTargetPerson(String name) throws UniquePersonList.PersonNotFoundException {
protected ReadOnlyPerson getTargetPerson(Name name) throws UniquePersonList.PersonNotFoundException {
for (ReadOnlyPerson person: relevantPersons) {
if (person.getName().toString().equals(name)) {
if (person.getName().toString().equalsIgnoreCase(name.toString())) {
return person;
}
}
Expand Down
9 changes: 5 additions & 4 deletions src/seedu/addressbook/commands/DeleteCommand.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package seedu.addressbook.commands;

import seedu.addressbook.common.Messages;
import seedu.addressbook.data.person.Name;
import seedu.addressbook.data.person.ReadOnlyPerson;
import seedu.addressbook.data.person.UniquePersonList.PersonNotFoundException;

Expand All @@ -19,21 +20,21 @@ public class DeleteCommand extends Command {

public static final String MESSAGE_DELETE_PERSON_SUCCESS = "Deleted Person: %1$s";

private String nameToSearch = "";
private Name toDelete;

public DeleteCommand(int targetVisibleIndex) {
super(targetVisibleIndex);
}

public DeleteCommand(String name) {
this.nameToSearch = name;
public DeleteCommand(Name name) {
this.toDelete = name;
}


@Override
public CommandResult execute() {
try {
final ReadOnlyPerson target = (nameToSearch.isEmpty()) ? getTargetPerson() : getTargetPerson(nameToSearch);
final ReadOnlyPerson target = (toDelete == null) ? getTargetPerson() : getTargetPerson(toDelete);
addressBook.removePerson(target);
return new CommandResult(String.format(MESSAGE_DELETE_PERSON_SUCCESS, target));
} catch (IndexOutOfBoundsException ie) {
Expand Down
59 changes: 59 additions & 0 deletions src/seedu/addressbook/commands/EditCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package seedu.addressbook.commands;

import seedu.addressbook.common.Messages;
import seedu.addressbook.data.exception.IllegalValueException;
import seedu.addressbook.data.person.*;
import seedu.addressbook.data.tag.Tag;

import java.util.HashSet;
import java.util.Set;

public class EditCommand extends Command {
private final Person afterEdited;

public static final String COMMAND_WORD = "edit";

public static final String MESSAGE_USAGE = COMMAND_WORD + ":\n"
+ "Edits the person identified by the NRIC number.\n\t"
+ "Contact details can be marked private by prepending 'p' to the prefix.\n\t"
+ "Parameters: NAME [p]p/PHONE [p]e/EMAIL [p]a/ADDRESS [t/TAG]...\n\t"
+ "Example: " + COMMAND_WORD
+ " John Doe p/987654321 e/johndoe@gmail.com a/311, Clementi Ave 3, #02-25 t/enemies t/paysOnTime";

public static final String MESSAGE_EDIT_PERSON_SUCCESS = "Edited Person: %s";
public static final String MESSAGE_DUPLICATE_PERSON = "This person already exists in the addressbook";

// TODO: Matthew clean code, refactor edit and add command constructor
public EditCommand(String name,
String phone, boolean isPhonePrivate,
String email, boolean isEmailPrivate,
String address, boolean isAddressPrivate,
Set<String> tags) throws IllegalValueException {

final Set<Tag> tagSet = new HashSet<>();
for (String tagName : tags) {
tagSet.add(new Tag(tagName));
}
this.afterEdited = new Person(
new Name(name),
new Phone(phone, isPhonePrivate),
new Email(email, isEmailPrivate),
new Address(address, isAddressPrivate),
tagSet
);

}

@Override
public CommandResult execute() {
try {
final ReadOnlyPerson target = getTargetPerson(afterEdited.getName());
addressBook.editPerson(target, afterEdited);
return new CommandResult(String.format(MESSAGE_EDIT_PERSON_SUCCESS, afterEdited.getName().toString()));
} catch (UniquePersonList.PersonNotFoundException nfe) {
return new CommandResult(Messages.MESSAGE_PERSON_NOT_IN_ADDRESSBOOK);
} catch (UniquePersonList.DuplicatePersonException dpe) {
return new CommandResult(MESSAGE_DUPLICATE_PERSON);
}
}
}
1 change: 1 addition & 0 deletions src/seedu/addressbook/commands/HelpCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public class HelpCommand extends Command {
public static final String MESSAGE_ALL_USAGES = AddCommand.MESSAGE_USAGE
+ "\n" + DeleteCommand.MESSAGE_USAGE
+ "\n" + ClearCommand.MESSAGE_USAGE
+ "\n" + EditCommand.MESSAGE_USAGE
+ "\n" + FindCommand.MESSAGE_USAGE
+ "\n" + ListCommand.MESSAGE_USAGE
+ "\n" + ViewCommand.MESSAGE_USAGE
Expand Down
11 changes: 11 additions & 0 deletions src/seedu/addressbook/data/AddressBook.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,17 @@ public void removePerson(ReadOnlyPerson toRemove) throws PersonNotFoundException
allPersons.remove(toRemove);
}

/**
* Edits the equivalent person from the address book with new data fields.
*
* @throws PersonNotFoundException if no such Person could be found.
* @throws DuplicatePersonException if an equivalent person already exists.
*/
public void editPerson(ReadOnlyPerson toDelete, Person toAdd) throws PersonNotFoundException, DuplicatePersonException {
removePerson(toDelete);
addPerson(toAdd);
}

/**
* Clears all persons from the address book.
*/
Expand Down
73 changes: 71 additions & 2 deletions src/seedu/addressbook/parser/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
import seedu.addressbook.commands.*;
import seedu.addressbook.common.Utils;
import seedu.addressbook.data.exception.IllegalValueException;
import seedu.addressbook.data.person.Name;

import java.io.IOException;
import java.util.*;
import java.util.logging.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

Expand All @@ -14,6 +17,7 @@
* Parses user input.
*/
public class Parser {
private final static Logger logr = Logger.getLogger( Parser.class.getName() );

public static final Pattern PERSON_INDEX_ARGS_FORMAT = Pattern.compile("(?<targetIndex>.+)");

Expand Down Expand Up @@ -43,20 +47,41 @@ public static class ParseException extends Exception {
*/
public static final Pattern BASIC_COMMAND_FORMAT = Pattern.compile("(?<commandWord>\\S+)(?<arguments>.*)");

private static void setupLogger() {
LogManager.getLogManager().reset();
logr.setLevel(Level.ALL);

ConsoleHandler ch = new ConsoleHandler();
ch.setLevel(Level.INFO);
logr.addHandler(ch);

try {
FileHandler fh = new FileHandler("parserLog.log");
fh.setLevel(Level.FINE);
logr.addHandler(fh);
} catch (IOException ioe) {
logr.log(Level.SEVERE, "File logger not working.", ioe);
}
}

/**
* Parses user input into command for execution.
*
* @param userInput full user input string
* @return the command based on the user input
*/
public Command parseCommand(String userInput) {
setupLogger();
final Matcher matcher = BASIC_COMMAND_FORMAT.matcher(userInput.trim());
if (!matcher.matches()) {
return new IncorrectCommand(String.format(MESSAGE_INVALID_COMMAND_FORMAT, HelpCommand.MESSAGE_USAGE));
}

final String commandWord = matcher.group("commandWord");
final String arguments = matcher.group("arguments");

logr.info("Parsed the user input and matching commands.");

switch (commandWord) {

case AddCommand.COMMAND_WORD:
Expand All @@ -65,6 +90,9 @@ public Command parseCommand(String userInput) {
case DeleteCommand.COMMAND_WORD:
return prepareDelete(arguments);

case EditCommand.COMMAND_WORD:
return prepareEdit(arguments);

case ClearCommand.COMMAND_WORD:
return new ClearCommand();

Expand Down Expand Up @@ -166,9 +194,47 @@ private Command prepareDelete(String args) {
return new DeleteCommand(targetIndex);
}

return new DeleteCommand(name);
return new DeleteCommand(new Name(name));
} catch (ParseException e) {
logr.log(Level.WARNING, "Invalid delete command format.", e);
return new IncorrectCommand(String.format(MESSAGE_INVALID_COMMAND_FORMAT, DeleteCommand.MESSAGE_USAGE));
} catch (IllegalValueException ive) {
logr.log(Level.WARNING, "Invalid name/id inputted.", ive);
return new IncorrectCommand(ive.getMessage());
}
}

/**
* Parses arguments in the context of the edit person command.
*
* @param args full command args string
* @return the prepared command
*/
// TODO: Refactor prepareEdit and prepareAdd
private Command prepareEdit(String args) {
final Matcher matcher = PERSON_DATA_ARGS_FORMAT.matcher(args.trim());
// Validate arg string format
if (!matcher.matches()) {
return new IncorrectCommand(String.format(MESSAGE_INVALID_COMMAND_FORMAT, EditCommand.MESSAGE_USAGE));
}
try {
return new EditCommand(
matcher.group("name"),

matcher.group("phone"),
isPrivatePrefixPresent(matcher.group("isPhonePrivate")),

matcher.group("email"),
isPrivatePrefixPresent(matcher.group("isEmailPrivate")),

matcher.group("address"),
isPrivatePrefixPresent(matcher.group("isAddressPrivate")),

getTagsFromArgs(matcher.group("tagArguments"))
);
} catch (IllegalValueException ive) {
logr.log(Level.WARNING, "Invalid edit command format.", ive);
return new IncorrectCommand(ive.getMessage());
}
}

Expand All @@ -179,11 +245,11 @@ private Command prepareDelete(String args) {
* @return the prepared command
*/
private Command prepareView(String args) {

try {
final int targetIndex = parseArgsAsDisplayedIndex(args);
return new ViewCommand(targetIndex);
} catch (ParseException | NumberFormatException e) {
logr.log(Level.WARNING, "Invalid view command format.", e);
return new IncorrectCommand(String.format(MESSAGE_INVALID_COMMAND_FORMAT,
ViewCommand.MESSAGE_USAGE));
}
Expand Down Expand Up @@ -217,6 +283,7 @@ private Command prepareViewAll(String args) {
private int parseArgsAsDisplayedIndex(String args) throws ParseException, NumberFormatException {
final Matcher matcher = PERSON_INDEX_ARGS_FORMAT.matcher(args.trim());
if (!matcher.matches()) {
logr.warning("Index number does not exist in argument");
throw new ParseException("Could not find index number to parse");
}
return Integer.parseInt(matcher.group("targetIndex"));
Expand All @@ -225,6 +292,7 @@ private int parseArgsAsDisplayedIndex(String args) throws ParseException, Number
private String parseArgsAsName(String args) throws ParseException {
final Matcher matcher = PERSON_NAME_FORMAT.matcher(args.trim());
if (!matcher.matches()) {
logr.warning("Name does not exist in argument");
throw new ParseException("Could not find name to parse");
}
return matcher.group(0);
Expand All @@ -239,6 +307,7 @@ private String parseArgsAsName(String args) throws ParseException {
private Command prepareFind(String args) {
final Matcher matcher = KEYWORDS_ARGS_FORMAT.matcher(args.trim());
if (!matcher.matches()) {
logr.warning("Argument for finding NRIC is invalid");
return new IncorrectCommand(String.format(MESSAGE_INVALID_COMMAND_FORMAT,
FindCommand.MESSAGE_USAGE));
}
Expand Down
2 changes: 1 addition & 1 deletion src/seedu/addressbook/ui/MainWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ else if(isPO && !isHQPPasswordCommand(result)){
}

else if (isInvalidPasswordCommand(result)){
displayResult(logic.execute("akshay")); //EDIT THIS
displayResult(logic.execute("akshay")); //TODO EDIT THIS
clearCommandInput();
}

Expand Down

0 comments on commit 75b4ce4

Please sign in to comment.