diff --git a/OffenceList.txt b/OffenceList.txt new file mode 100644 index 000000000..513eff1a2 --- /dev/null +++ b/OffenceList.txt @@ -0,0 +1,26 @@ +abetment +accident +unsound +piracy +rioting +dispute +drug offences +homicide +murder +manslaughter +fire +suicide +attempted suicide +assault +kidnap +outrage of modesty +rape +robbery +gunman +hostage +cheating +house-break +corruption +wanted +chemical attack + diff --git a/src/seedu/addressbook/Main.java b/src/seedu/addressbook/Main.java index fca4d5d1d..03481ce4c 100644 --- a/src/seedu/addressbook/Main.java +++ b/src/seedu/addressbook/Main.java @@ -14,7 +14,7 @@ public class Main extends Application implements Stoppable{ /** Version info of the program. */ - public static final String VERSION = "AddressBook Level 3 - Version 1.0"; + public static final String VERSION = "EX-SI-53 - Version 1.0"; private Gui gui; diff --git a/src/seedu/addressbook/commands/AddCommand.java b/src/seedu/addressbook/commands/AddCommand.java index 78ad0da21..b1dd734f5 100644 --- a/src/seedu/addressbook/commands/AddCommand.java +++ b/src/seedu/addressbook/commands/AddCommand.java @@ -14,11 +14,10 @@ public class AddCommand extends Command { public static final String COMMAND_WORD = "add"; - public static final String MESSAGE_USAGE = COMMAND_WORD + ":\n" + "Adds a person to the address book. " - + "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" + public static final String MESSAGE_USAGE = COMMAND_WORD + ":\n" + "Adds a person to the system. " + + "Parameters: NAME n/NRIC d/DATEOFBIRTH p/POSTALCODE s/STATUS w/WANTEDFOR [o/PASTOFFENSES]...\n\t" + "Example: " + COMMAND_WORD - + " John Doe p/98765432 e/johnd@gmail.com a/311, Clementi Ave 2, #02-25 t/friends t/owesMoney"; + + " John Doe n/s1234567a d/1996 p/510246 s/xc w/none o/theft o/drugs"; public static final String MESSAGE_SUCCESS = "New person added: %1$s"; public static final String MESSAGE_DUPLICATE_PERSON = "This person already exists in the address book"; @@ -31,20 +30,24 @@ public class AddCommand extends Command { * @throws IllegalValueException if any of the raw values are invalid */ public AddCommand(String name, - String phone, boolean isPhonePrivate, - String email, boolean isEmailPrivate, - String address, boolean isAddressPrivate, - Set tags) throws IllegalValueException { - final Set tagSet = new HashSet<>(); - for (String tagName : tags) { - tagSet.add(new Tag(tagName)); + String nric, + String dateOfBirth, + String postalCode, + String status, + String wantedFor, + Set pastOffenses) throws IllegalValueException { + final Set pastOffenseSet = new HashSet<>(); + for (String offenseName : pastOffenses) { + pastOffenseSet.add(new Offense(offenseName)); } this.toAdd = new Person( new Name(name), - new Phone(phone, isPhonePrivate), - new Email(email, isEmailPrivate), - new Address(address, isAddressPrivate), - tagSet + new NRIC(nric), + new DateOfBirth(dateOfBirth), + new PostalCode(postalCode), + new Status(status), + new Offense(wantedFor), + pastOffenseSet ); } @@ -61,7 +64,7 @@ public CommandResult execute() { try { addressBook.addPerson(toAdd); return new CommandResult(String.format(MESSAGE_SUCCESS, toAdd)); - } catch (UniquePersonList.DuplicatePersonException dpe) { + } catch (UniquePersonList.DuplicateNricException dpe) { return new CommandResult(MESSAGE_DUPLICATE_PERSON); } } diff --git a/src/seedu/addressbook/commands/DeleteCommand.java b/src/seedu/addressbook/commands/DeleteCommand.java index 1dd78f85e..9f82378c1 100644 --- a/src/seedu/addressbook/commands/DeleteCommand.java +++ b/src/seedu/addressbook/commands/DeleteCommand.java @@ -13,9 +13,9 @@ public class DeleteCommand extends Command { public static final String COMMAND_WORD = "delete"; public static final String MESSAGE_USAGE = COMMAND_WORD + ":\n" - + "Deletes the person identified by the index number used in the last person listing.\n\t" - + "Parameters: INDEX\n\t" - + "Example: " + COMMAND_WORD + " 1"; + + "Deletes the person by nric.\n\t" + + "Parameters: NRIC\n\t" + + "Example: " + COMMAND_WORD + " s1234567"; public static final String MESSAGE_DELETE_PERSON_SUCCESS = "Deleted Person: %1$s"; diff --git a/src/seedu/addressbook/commands/HelpCommand.java b/src/seedu/addressbook/commands/HelpCommand.java index ef2ed7d0e..4e1c257e9 100644 --- a/src/seedu/addressbook/commands/HelpCommand.java +++ b/src/seedu/addressbook/commands/HelpCommand.java @@ -16,7 +16,7 @@ public class HelpCommand extends Command { + "\n" + ClearCommand.MESSAGE_USAGE + "\n" + FindCommand.MESSAGE_USAGE + "\n" + ListCommand.MESSAGE_USAGE - + "\n" + ViewCommand.MESSAGE_USAGE + //+ "\n" + ViewCommand.MESSAGE_USAGE + "\n" + ViewAllCommand.MESSAGE_USAGE + "\n" + HelpCommand.MESSAGE_USAGE + "\n" + ExitCommand.MESSAGE_USAGE; diff --git a/src/seedu/addressbook/commands/ViewCommand.java b/src/seedu/addressbook/commands/ViewCommand.java index 1058c4b52..c2707fc8a 100644 --- a/src/seedu/addressbook/commands/ViewCommand.java +++ b/src/seedu/addressbook/commands/ViewCommand.java @@ -8,6 +8,7 @@ * Shows details of the person identified using the last displayed index. * Private contact details are not shown. */ +/** public class ViewCommand extends Command { public static final String COMMAND_WORD = "view"; @@ -32,10 +33,11 @@ public CommandResult execute() { if (!addressBook.containsPerson(target)) { return new CommandResult(Messages.MESSAGE_PERSON_NOT_IN_ADDRESSBOOK); } - return new CommandResult(String.format(MESSAGE_VIEW_PERSON_DETAILS, target.getAsTextHidePrivate())); + return new CommandResult(String.format(MESSAGE_VIEW_PERSON_DETAILS, target.getAsTextShowAll())); } catch (IndexOutOfBoundsException ie) { return new CommandResult(Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX); } } } +*/ \ No newline at end of file diff --git a/src/seedu/addressbook/data/AddressBook.java b/src/seedu/addressbook/data/AddressBook.java index ba69c21e3..b4dcf1a8e 100644 --- a/src/seedu/addressbook/data/AddressBook.java +++ b/src/seedu/addressbook/data/AddressBook.java @@ -38,7 +38,7 @@ public AddressBook(UniquePersonList persons) { * * @throws DuplicatePersonException if an equivalent person already exists. */ - public void addPerson(Person toAdd) throws DuplicatePersonException { + public void addPerson(Person toAdd) throws UniquePersonList.DuplicateNricException { allPersons.add(toAdd); } diff --git a/src/seedu/addressbook/data/PoliceOfficers/Case.java b/src/seedu/addressbook/data/PoliceOfficers/Case.java new file mode 100644 index 000000000..02c6da91f --- /dev/null +++ b/src/seedu/addressbook/data/PoliceOfficers/Case.java @@ -0,0 +1,68 @@ +package seedu.addressbook.data.PoliceOfficers; + +import seedu.addressbook.Location; + + + +import java.sql.Timestamp; +import java.text.SimpleDateFormat; + + +public class Case { + + public static final String EXAMPLE_CASE = "PO3, robbery, GPS coordinates, timestamp"; + public static final String MESSAGE_CASE_CONSTRAINTS = "Case must have: PatrolID, message, GPS, timestamp"; + + public static PatrolID attendingPO; + public String caseMessage; + public static Location gpsCoordinates; + public static Timestamp caseTimeStamp; + public static String caseTimeStampFormatted; + private static final SimpleDateFormat timestampFormatter = new SimpleDateFormat("dd.MM.yyyy.HH.mm.ss"); + + + private String SPACE = ", "; + public String value; + + public Case(){ + this.attendingPO = null; + this.caseMessage = "none"; + this.gpsCoordinates = null; + this.caseTimeStamp = null; + } + public Case(PatrolID patrolIDNo, String message, Location location, Timestamp dateTime){ + + this.attendingPO = patrolIDNo; + this.caseMessage = message; + this.gpsCoordinates = location; + this.caseTimeStampFormatted = timestampFormatter.format(dateTime); + this.value = patrolIDNo.patrolID + SPACE + caseMessage + SPACE + Double.toString(location.getLongitude()) + SPACE + + Double.toString(location.getLatitude()) + SPACE + timestampFormatter.format(dateTime); + + } + + public String PrintCase() {return value;} + + public String getAttendingPO(){return attendingPO.patrolID;} + + public String getCaseMessage() {return caseMessage;} + + public String getGpsCoorinates() {return Double.toString(gpsCoordinates.getLongitude()) + SPACE + Double.toString(gpsCoordinates.getLatitude());} + + public Timestamp getCaseTimeStamp() {return caseTimeStamp;} + + public String getCaseTimeStampFormatted() {return caseTimeStampFormatted;} + + /*public static void main(String[] args) { + Location location = new Location(-6.206968,106.751365); + Location origin = new Location(-6.189482, 106.733902); + PatrolID id = new PatrolID(5); + String msg = "Fire"; + Timestamp now = new Timestamp(System.currentTimeMillis()); + Case c = new Case(id,msg,location,now); + System.out.print(c.PrintCase()); + + + }*/ + +} diff --git a/src/seedu/addressbook/data/PoliceOfficers/PatrolID.java b/src/seedu/addressbook/data/PoliceOfficers/PatrolID.java new file mode 100644 index 000000000..cf307d963 --- /dev/null +++ b/src/seedu/addressbook/data/PoliceOfficers/PatrolID.java @@ -0,0 +1,51 @@ +package seedu.addressbook.data.PoliceOfficers; + +import seedu.addressbook.data.exception.IllegalValueException; + +/** + * Represents a Patrol resource's ID in EX-SI-53. + * Guarantees: immutable + */ + +public class PatrolID { + public static final String EXAMPLE = "PO1"; + public static final String MESSAGE_ID_CONSTRAINTS = "Patrol ID has to be a number excluding 0, and must not be an existing ID"; + public static final String PATROL_ID_PREFIX = "PO"; + //public static final int CONSTRAINT = 0; + + public final int ID; + public final String patrolID; + + public PatrolID (int identification){ + + this.ID = identification; + this.patrolID = PATROL_ID_PREFIX + Integer.toString(identification); + } + + public String getPatrolID() {return patrolID;} + /** + * Validates given ID. + * + * @throws IllegalValueException if given ID is invalid. + */ + + //public static boolean isValidID(int test) {return test > CONSTRAINT; } + + @Override + public String toString() { + return patrolID; + } + + @Override + public boolean equals(Object other) { + return other == this // short circuit if same object + || (other instanceof PatrolID // instanceof handles nulls + && this.patrolID.equals(((PatrolID) other).patrolID)); // state check + } + + @Override + public int hashCode() { + return patrolID.hashCode(); + } + +} diff --git a/src/seedu/addressbook/data/PoliceOfficers/PatrolResource.java b/src/seedu/addressbook/data/PoliceOfficers/PatrolResource.java new file mode 100644 index 000000000..737b8f437 --- /dev/null +++ b/src/seedu/addressbook/data/PoliceOfficers/PatrolResource.java @@ -0,0 +1,80 @@ +package seedu.addressbook.data.PoliceOfficers; + + +import java.util.Objects; + +/** + * Represents a Patrol Resource in the system. + * Guarantees: details are present and not null, field values are validated. + */ +public class PatrolResource implements ReadOnlyPatrolResource { + public PatrolID patrolID; + public State state; + public Case currentCase; + + + /** + * Assumption: Every field must be present and not null (except current case). + */ + public PatrolResource(PatrolID patrolID, State state, Case currentCase) { + this.patrolID = patrolID; + this.state = state; + this.currentCase = (state.getCurrentState().equals(state.FREE)) ? new Case() : currentCase; + } + + public PatrolResource(ReadOnlyPatrolResource source) { + this(source.getPatrolID(), source.getState(), source.getCurrentCase()); + } + + public Case RA(){ + //would generate timestamp and GPS + //sent to HQP 'inbox' + return new Case(); //dummy line + } + + public Case RB(){ + //would generate timestamp and GPS + //sent to HQP 'inbox' + return new Case(); + } + + public Case RF(){ + //would generate timestamp and GPS + //sent to HQP 'inbox' + return new Case(); + } + + //@Override + public PatrolID getPatrolID() { + return patrolID; + } + + //@Override + public State getState() { + return state; + } + + //@Override + public Case getCurrentCase() { + return currentCase; + } + + @Override + public boolean equals(Object other) { + return other == this // short circuit if same object + || (other instanceof ReadOnlyPatrolResource // instanceof handles nulls + && this.isSameStateAs((ReadOnlyPatrolResource) other)); + } + + @Override + public int hashCode() { + // use this method for custom fields hashing instead of implementing your own + return Objects.hash(patrolID, state, currentCase); + } + + @Override + public String toString() { + return getAsTextShowAll(); + } + +} diff --git a/src/seedu/addressbook/data/PoliceOfficers/ReadOnlyPatrolResource.java b/src/seedu/addressbook/data/PoliceOfficers/ReadOnlyPatrolResource.java new file mode 100644 index 000000000..d82ba3414 --- /dev/null +++ b/src/seedu/addressbook/data/PoliceOfficers/ReadOnlyPatrolResource.java @@ -0,0 +1,41 @@ +package seedu.addressbook.data.PoliceOfficers; + +/** + * A read-only immutable interface for a Patrol Resource in the system. + * Implementations should guarantee: details are present and not null, field values are validated. + */ +public interface ReadOnlyPatrolResource { + + PatrolID getPatrolID(); + State getState(); + Case getCurrentCase(); + Case RA(); //request ambulance + Case RB(); //request backup, can be other POs or can be enhanced like SWAT + Case RF(); //request fire fighters + + + /** + * Returns true if the values inside this object is same as those of the other (Note: interfaces cannot override .equals) + */ + default boolean isSameStateAs(ReadOnlyPatrolResource other) { + return other == this // short circuit if same object + || (other != null // this is first to avoid NPE below + && other.getPatrolID().equals(this.getPatrolID()) // state checks here onwards + && other.getState().equals(this.getState()) + && other.getCurrentCase().equals(this.getCurrentCase())); + + } + + + /** + * Formats a patrol resource as text, showing all details. + */ + default String getAsTextShowAll() { + final StringBuilder builder = new StringBuilder(); + builder.append(" Patrol ID: ").append(getPatrolID()); + builder.append(" State: ").append(getState()); + builder.append(" Current Case: ").append(getCurrentCase()); + + return builder.toString(); + } +} diff --git a/src/seedu/addressbook/data/PoliceOfficers/State.java b/src/seedu/addressbook/data/PoliceOfficers/State.java new file mode 100644 index 000000000..bde958785 --- /dev/null +++ b/src/seedu/addressbook/data/PoliceOfficers/State.java @@ -0,0 +1,49 @@ +package seedu.addressbook.data.PoliceOfficers; + +import seedu.addressbook.data.exception.IllegalValueException; + +/** + * Represents a Patrol resource's current state in EX-SI-53. + * Guarantees: only 2 possible states; is valid as declared in {@link #isValidState(String)} + */ + +public class State { + + public static final String EXAMPLE_STATE = "free"; + public static final String MESSAGE_STATE_CONSTRAINTS = "Patrol resource can either be 'free' or 'engaged'"; + public static final String FREE = "free"; + public static final String ENGAGED = "engaged"; + public static final String DEFAULT_CASE = "none"; + public String currentState; + + + public State(String state) throws IllegalValueException{ + state = state.trim(); + if (!isValidState(state)){ + throw new IllegalValueException(MESSAGE_STATE_CONSTRAINTS); + } + this.currentState = state; + } + + public String getCurrentState() {return currentState;} + + public boolean isValidState(String test) {return test == FREE || test == ENGAGED;} + + @Override + public String toString() { + return currentState; + } + + @Override + public boolean equals(Object other) { + return other == this // short circuit if same object + || (other instanceof PatrolID // instanceof handles nulls + && this.currentState.equals(((State) other).currentState)); // state check + } + + @Override + public int hashCode() { + return currentState.hashCode(); + } + +} diff --git a/src/seedu/addressbook/data/person/DateOfBirth.java b/src/seedu/addressbook/data/person/DateOfBirth.java new file mode 100644 index 000000000..fcb973fa4 --- /dev/null +++ b/src/seedu/addressbook/data/person/DateOfBirth.java @@ -0,0 +1,47 @@ +package seedu.addressbook.data.person; + +import seedu.addressbook.data.exception.IllegalValueException; + +import java.util.Calendar; + +/** + * Represents a Person's Date of Birth in the EX-SI-53. + * Guarantees: immutable; is valid as declared in {@link #isValidDateOfBirth(String)} + */ + +public class DateOfBirth { + public static final String EXAMPLE = "1996"; + public static final String MESSAGE_DATE_OF_BIRTH_CONSTRAINTS = "DoB must from 1900 onwards, and less than or equal to current year"; + public static final String DATE_OF_BIRTH_VALIDATION_REGEX = "[1-2][0-9]{3}"; + public final int year = Calendar.getInstance().get(Calendar.YEAR); + public final String birthYear; + + + + + /** + * Validates given DoB. + * + * @throws IllegalValueException if given DoB string is invalid. + */ + + public DateOfBirth(String dob) throws IllegalValueException{ + dob = dob.trim(); + if (!isValidDateOfBirth(dob)){ + throw new IllegalValueException(MESSAGE_DATE_OF_BIRTH_CONSTRAINTS); + } + this.birthYear = dob; + + } + + + public String getDOB() { + return birthYear; + } + + public boolean isValidDateOfBirth(String test) {return test.matches(DATE_OF_BIRTH_VALIDATION_REGEX) && + Integer.parseInt(test) <= year;} + + + +} diff --git a/src/seedu/addressbook/data/person/NRIC.java b/src/seedu/addressbook/data/person/NRIC.java index 27f620833..9654b0b7d 100644 --- a/src/seedu/addressbook/data/person/NRIC.java +++ b/src/seedu/addressbook/data/person/NRIC.java @@ -6,7 +6,7 @@ import java.util.List; /** - * Represents a Person's identification number(NRIC or FIN) in the address book. + * Represents a Person's identification number(NRIC or FIN) in the EX-SI-53. * Guarantees: immutable; is valid as declared in {@link #isValidNRIC(String)} */ @@ -31,6 +31,10 @@ public NRIC(String nric) throws IllegalValueException { this.identificationNumber = nric; } + public String getIdentificationNumber() { + return identificationNumber; + } + /** * Returns true if a given string is a valid NRIC. */ diff --git a/src/seedu/addressbook/data/person/Offense.java b/src/seedu/addressbook/data/person/Offense.java new file mode 100644 index 000000000..78319a852 --- /dev/null +++ b/src/seedu/addressbook/data/person/Offense.java @@ -0,0 +1,61 @@ +package seedu.addressbook.data.person; + +import seedu.addressbook.data.exception.IllegalValueException; +import java.util.Arrays; + +public class Offense { + public static final String EXAMPLE = "theft"; + public static final String MESSAGE_OFFENSE_CONSTRAINTS = "Offense should be in lower case and must be inside the list"; + + private static final String[] OFFENSE_LIST = {"none","theft","drugs","riot","theft1","theft2","theft3","theft4"}; + public static final String NULL_OFFENSE = "none"; + public final String offense; + + public String getOffense() { + return offense; + } + + /** + * Default 'offense' when person is not wanted + * + */ + public Offense(){ + this.offense = "none"; + } + /** + * Validates given tag name. + * + * @throws IllegalValueException if the given tag name string is invalid. + */ + public Offense(String name) throws IllegalValueException { + name = name.trim(); + if (!isValidOffense(name)) { + throw new IllegalValueException(MESSAGE_OFFENSE_CONSTRAINTS); + } + this.offense = name; + } + + /** + * Returns true if a given string is a valid tag name. + */ + public static boolean isValidOffense(String test) { + return Arrays.asList(OFFENSE_LIST).contains(test); + } + + @Override + public boolean equals(Object other) { + return other == this // short circuit if same object + || (other instanceof Offense // instanceof handles nulls + && this.offense.equals(((Offense) other).offense)); // state check + } + + @Override + public int hashCode() { + return offense.hashCode(); + } + + @Override + public String toString() { + return '[' + offense + ']'; + } +} diff --git a/src/seedu/addressbook/data/person/Person.java b/src/seedu/addressbook/data/person/Person.java index fdd99358b..a7378a41f 100644 --- a/src/seedu/addressbook/data/person/Person.java +++ b/src/seedu/addressbook/data/person/Person.java @@ -1,39 +1,63 @@ package seedu.addressbook.data.person; -import java.util.HashSet; -import java.util.Objects; -import java.util.Set; +import java.util.*; +import seedu.addressbook.data.exception.IllegalValueException; import seedu.addressbook.data.tag.Tag; /** - * Represents a Person in the address book. + * Represents a Person in the system. * Guarantees: details are present and not null, field values are validated. */ public class Person implements ReadOnlyPerson { private Name name; - private Phone phone; - private Email email; - private Address address; + private NRIC nric; + private DateOfBirth dateOfBirth; + private PostalCode postalCode; + private Status status; + private Offense wantedFor; + + public static String WANTED_FOR_WARNING = "State the offence if person's status is wanted"; + + private final Set PastOffense = new HashSet<>(); + - private final Set tags = new HashSet<>(); /** * Assumption: Every field must be present and not null. */ - public Person(Name name, Phone phone, Email email, Address address, Set tags) { + public Person(Name name, NRIC nric, DateOfBirth dateOfBirth, PostalCode postalCode, Status status , + Offense wantedFor, Set PastOffense) throws IllegalValueException { this.name = name; - this.phone = phone; - this.email = email; - this.address = address; - this.tags.addAll(tags); + this.nric = nric; + this.dateOfBirth = dateOfBirth; + this.postalCode = postalCode; + this.status = status; + this.wantedFor = wantedFor; + if ((this.status.getCurrentStatus().equals(this.status.WANTED_KEYWORD)) && ((this.wantedFor.getOffense().equals(this.wantedFor.NULL_OFFENSE)) || + this.wantedFor == null)){ + throw new IllegalValueException(WANTED_FOR_WARNING); + } + + else if (!(this.status.getCurrentStatus().equals(this.status.WANTED_KEYWORD))){ + this.wantedFor = new Offense(); + + } + + else{ + + this.wantedFor = wantedFor; + } + this.PastOffense.addAll(PastOffense); } /** * Copy constructor. */ - public Person(ReadOnlyPerson source) { - this(source.getName(), source.getPhone(), source.getEmail(), source.getAddress(), source.getTags()); + public Person(ReadOnlyPerson source) throws IllegalValueException { + this(source.getName(), source.getNRIC(), + source.getDateOfBirth(), source.getPostalCode(), source.getStatus(), + source.getWantedFor(), source.getPastOffense()); } @Override @@ -42,31 +66,37 @@ public Name getName() { } @Override - public Phone getPhone() { - return phone; + public NRIC getNRIC() { + return nric; } @Override - public Email getEmail() { - return email; + public DateOfBirth getDateOfBirth() {return dateOfBirth;} + + @Override + public PostalCode getPostalCode() { + return postalCode; } @Override - public Address getAddress() { - return address; + public Status getStatus() { + return status; } @Override - public Set getTags() { - return new HashSet<>(tags); + public Offense getWantedFor() { + return wantedFor; } + @Override + public Set getPastOffense() {return PastOffense;} + /** * Replaces this person's tags with the tags in {@code replacement}. */ - public void setTags(Set replacement) { - tags.clear(); - tags.addAll(replacement); + public void setPastOffense(Set replacement) { + PastOffense.clear(); + PastOffense.addAll(replacement); } @Override @@ -79,7 +109,7 @@ public boolean equals(Object other) { @Override public int hashCode() { // use this method for custom fields hashing instead of implementing your own - return Objects.hash(name, phone, email, address, tags); + return Objects.hash(name, nric, dateOfBirth, postalCode, status, wantedFor, PastOffense); } @Override diff --git a/src/seedu/addressbook/data/person/PostalCode.java b/src/seedu/addressbook/data/person/PostalCode.java index ac2e77dff..382be88ca 100644 --- a/src/seedu/addressbook/data/person/PostalCode.java +++ b/src/seedu/addressbook/data/person/PostalCode.java @@ -13,7 +13,7 @@ public class PostalCode { public static final String EXAMPLE = "510123"; - public static final String MESSAGE_NAME_CONSTRAINTS = "Must be 6 digits long"; + public static final String MESSAGE_NAME_CONSTRAINTS = "Postal Code must be 6 digits long"; public static final String NAME_VALIDATION_REGEX = "[0-9]{6}"; public final String postalCode; @@ -31,6 +31,10 @@ public PostalCode(String pc) throws IllegalValueException { this.postalCode = pc; } + public String getPostalCode(){ + return postalCode; + } + /** * Returns true if a given string is a valid NRIC. */ diff --git a/src/seedu/addressbook/data/person/ReadOnlyPerson.java b/src/seedu/addressbook/data/person/ReadOnlyPerson.java index 4fab58808..11ebdb2dd 100644 --- a/src/seedu/addressbook/data/person/ReadOnlyPerson.java +++ b/src/seedu/addressbook/data/person/ReadOnlyPerson.java @@ -1,5 +1,6 @@ package seedu.addressbook.data.person; +import java.util.Date; import java.util.Set; import seedu.addressbook.data.tag.Tag; @@ -11,15 +12,17 @@ public interface ReadOnlyPerson { Name getName(); - Phone getPhone(); - Email getEmail(); - Address getAddress(); + NRIC getNRIC(); + DateOfBirth getDateOfBirth(); + PostalCode getPostalCode(); + Status getStatus(); + Offense getWantedFor(); /** * The returned {@code Set} is a deep copy of the internal {@code Set}, * changes on the returned list will not affect the person's internal tags. */ - Set getTags(); + Set getPastOffense(); /** * Returns true if the values inside this object is same as those of the other (Note: interfaces cannot override .equals) @@ -28,9 +31,11 @@ default boolean isSameStateAs(ReadOnlyPerson other) { return other == this // short circuit if same object || (other != null // this is first to avoid NPE below && other.getName().equals(this.getName()) // state checks here onwards - && other.getPhone().equals(this.getPhone()) - && other.getEmail().equals(this.getEmail()) - && other.getAddress().equals(this.getAddress())); + && other.getNRIC().equals(this.getNRIC()) + && other.getDateOfBirth().equals((this.getDateOfBirth())) + && other.getPostalCode().equals(this.getPostalCode()) + && other.getStatus().equals(this.getStatus()) + && other.getWantedFor().equals(this.getWantedFor())); } /** @@ -38,26 +43,20 @@ default boolean isSameStateAs(ReadOnlyPerson other) { */ default String getAsTextShowAll() { final StringBuilder builder = new StringBuilder(); - final String detailIsPrivate = "(private) "; builder.append(getName()) - .append(" Phone: "); - if (getPhone().isPrivate()) { - builder.append(detailIsPrivate); - } - builder.append(getPhone()) - .append(" Email: "); - if (getEmail().isPrivate()) { - builder.append(detailIsPrivate); - } - builder.append(getEmail()) - .append(" Address: "); - if (getAddress().isPrivate()) { - builder.append(detailIsPrivate); - } - builder.append(getAddress()) - .append(" Tags: "); - for (Tag tag : getTags()) { - builder.append(tag); + .append(" NRIC: "); + builder.append(getNRIC()) + .append(" DateOfBirth: "); + builder.append(getDateOfBirth().getDOB()) + .append(" Postal Code: "); + builder.append(getPostalCode()) + .append(" Status: "); + builder.append(getStatus()) + .append(" Wanted For: "); + builder.append(getWantedFor()) + .append(" Past Offences:"); + for (Offense offense : getPastOffense()) { + builder.append(offense); } return builder.toString(); } @@ -65,22 +64,25 @@ default String getAsTextShowAll() { /** * Formats a person as text, showing only non-private contact details. */ + /** default String getAsTextHidePrivate() { final StringBuilder builder = new StringBuilder(); - builder.append(getName()); - if (!getPhone().isPrivate()) { - builder.append(" Phone: ").append(getPhone()); - } - if (!getEmail().isPrivate()) { - builder.append(" Email: ").append(getEmail()); - } - if (!getAddress().isPrivate()) { - builder.append(" Address: ").append(getAddress()); - } - builder.append(" Tags: "); - for (Tag tag : getTags()) { - builder.append(tag); + builder.append(getName()) + .append(" NRIC: "); + builder.append(getNRIC()) + .append(" DateOfBirth: "); + builder.append(getDateOfBirth()) + .append(" Postal Code"); + builder.append(getPostalCode()) + .append(" Status: "); + builder.append(getStatus()) + .append(" Wanted For: "); + builder.append(getWantedFor()) + .append(" Past Offences:"); + for (Offense offense : getPastOffense()) { + builder.append(offense); } return builder.toString(); } + */ } diff --git a/src/seedu/addressbook/data/person/Status.java b/src/seedu/addressbook/data/person/Status.java new file mode 100644 index 000000000..56451385c --- /dev/null +++ b/src/seedu/addressbook/data/person/Status.java @@ -0,0 +1,66 @@ +package seedu.addressbook.data.person; + +import seedu.addressbook.data.exception.IllegalValueException; + +import java.util.Arrays; + +/** + * Represents a Person's criminal status (if any) in EX-SI-53. + * Guarantees: mutable; is valid as declared in {@link #isValidStatus(String)} + */ + +public class Status { + + public static final String EXAMPLE = "wanted"; + public static final String MESSAGE_NAME_CONSTRAINTS = "Status should be one of the 3: wanted/xc/clear"; + + public static final String WANTED_KEYWORD = "wanted"; + private static final String EXCONVICT_KEYWORD = "xc"; //ex-convict + private static final String CLEAR_KEYWORD = "clear"; + + private static final String[] STATUS_VALIDATION = {WANTED_KEYWORD,EXCONVICT_KEYWORD,CLEAR_KEYWORD}; + + public final String currentStatus; + + /** + * Validates given Status. + * + * @throws IllegalValueException if given name string is invalid. + */ + public Status(String status) throws IllegalValueException { + status = status.trim(); + if (!isValidStatus(status)) { + throw new IllegalValueException(MESSAGE_NAME_CONSTRAINTS); + } + this.currentStatus = status; + } + + public String getCurrentStatus() {return currentStatus;} + + /** + * Returns true if a given string is a valid Status. + */ + + public static boolean isValidStatus(String test) { + + return Arrays.asList(STATUS_VALIDATION).contains(test); + } + + @Override + public String toString() { + return currentStatus; + } + + @Override + public boolean equals(Object other) { + return other == this // short circuit if same object + || (other instanceof Status // instanceof handles nulls + && this.currentStatus.equals(((Status) other).currentStatus)); // state check + } + + @Override + public int hashCode() { + return currentStatus.hashCode(); + } + +} diff --git a/src/seedu/addressbook/data/person/UniquePersonList.java b/src/seedu/addressbook/data/person/UniquePersonList.java index c4848a1b4..5e85a4cc0 100644 --- a/src/seedu/addressbook/data/person/UniquePersonList.java +++ b/src/seedu/addressbook/data/person/UniquePersonList.java @@ -22,6 +22,12 @@ protected DuplicatePersonException() { } } + public static class DuplicateNricException extends DuplicateDataException { + protected DuplicateNricException() { + super("Operation would result in duplicate NRIC"); + } + } + /** * Signals that an operation targeting a specified person in the list would fail because * there is no such matching person in the list. @@ -35,6 +41,16 @@ public static class PersonNotFoundException extends Exception {} */ public UniquePersonList() {} + + public boolean containNric(Person toCheck) { + for ( Person person : internalList){ + if (person.getNRIC().getIdentificationNumber().equals(toCheck.getNRIC().getIdentificationNumber())){ + return true; + } + } + return false; + } + /** * Constructs a person list with the given persons. */ @@ -82,14 +98,16 @@ public boolean contains(ReadOnlyPerson toCheck) { return internalList.contains(toCheck); } + + /** * Adds a person to the list. * * @throws DuplicatePersonException if the person to add is a duplicate of an existing person in the list. */ - public void add(Person toAdd) throws DuplicatePersonException { - if (contains(toAdd)) { - throw new DuplicatePersonException(); + public void add(Person toAdd) throws DuplicateNricException { + if (contains(toAdd) || containNric(toAdd)) { + throw new DuplicateNricException(); } internalList.add(toAdd); } diff --git a/src/seedu/addressbook/parser/Parser.java b/src/seedu/addressbook/parser/Parser.java index 34eaa9ed8..03c63c518 100644 --- a/src/seedu/addressbook/parser/Parser.java +++ b/src/seedu/addressbook/parser/Parser.java @@ -21,10 +21,12 @@ public class Parser { public static final Pattern PERSON_DATA_ARGS_FORMAT = // '/' forward slashes are reserved for delimiter prefixes Pattern.compile("(?[^/]+)" - + " (?p?)p/(?[^/]+)" - + " (?p?)e/(?[^/]+)" - + " (?p?)a/(?
[^/]+)" - + "(?(?: t/[^/]+)*)"); // variable number of tags + + " n/(?[^/]+)" + + " d/(?[^/]+)" + + " p/(?[^/]+)" + + " s/(?[^/]+)" + + " w/(?[^/]+)" + + "(?(?: o/[^/]+)*)"); // variable number of offenses /** @@ -72,8 +74,9 @@ public Command parseCommand(String userInput) { case ListCommand.COMMAND_WORD: return new ListCommand(); - case ViewCommand.COMMAND_WORD: + /**case ViewCommand.COMMAND_WORD: return prepareView(arguments); + */ case ViewAllCommand.COMMAND_WORD: return prepareViewAll(arguments); @@ -108,17 +111,13 @@ private Command prepareAdd(String args){ try { return new AddCommand( matcher.group("name"), + matcher.group("nric"), + matcher.group("dateOfBirth"), + matcher.group("postalCode"), + matcher.group("status"), + matcher.group("wantedFor"), - 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")) + getTagsFromArgs(matcher.group("pastOffenseArguments")) ); } catch (IllegalValueException ive) { return new IncorrectCommand(ive.getMessage()); @@ -142,7 +141,7 @@ private static Set getTagsFromArgs(String tagArguments) throws IllegalVa return Collections.emptySet(); } // replace first delimiter prefix, then split - final Collection tagStrings = Arrays.asList(tagArguments.replaceFirst(" t/", "").split(" t/")); + final Collection tagStrings = Arrays.asList(tagArguments.replaceFirst(" o/", "").split(" o/")); return new HashSet<>(tagStrings); } @@ -172,10 +171,10 @@ private Command prepareView(String args) { try { final int targetIndex = parseArgsAsDisplayedIndex(args); - return new ViewCommand(targetIndex); + return new ViewAllCommand(targetIndex); } catch (ParseException | NumberFormatException e) { return new IncorrectCommand(String.format(MESSAGE_INVALID_COMMAND_FORMAT, - ViewCommand.MESSAGE_USAGE)); + ViewAllCommand.MESSAGE_USAGE)); } } diff --git a/src/seedu/addressbook/storage/jaxb/AdaptedPerson.java b/src/seedu/addressbook/storage/jaxb/AdaptedPerson.java index 29a46e9fd..66ded3f58 100644 --- a/src/seedu/addressbook/storage/jaxb/AdaptedPerson.java +++ b/src/seedu/addressbook/storage/jaxb/AdaptedPerson.java @@ -8,10 +8,7 @@ import javax.xml.bind.annotation.XmlAttribute; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlValue; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Set; +import java.util.*; /** * JAXB-friendly adapted person data holder class. @@ -28,11 +25,15 @@ private static class AdaptedContactDetail { @XmlElement(required = true) private String name; @XmlElement(required = true) - private AdaptedContactDetail phone; + private AdaptedContactDetail nric; @XmlElement(required = true) - private AdaptedContactDetail email; + private AdaptedContactDetail dateOfBirth; @XmlElement(required = true) - private AdaptedContactDetail address; + private AdaptedContactDetail postalCode; + @XmlElement(required = true) + private AdaptedContactDetail status; + @XmlElement(required = true) + private AdaptedContactDetail wantedFor; @XmlElement private List tagged = new ArrayList<>(); @@ -51,20 +52,23 @@ public AdaptedPerson() {} public AdaptedPerson(ReadOnlyPerson source) { name = source.getName().fullName; - phone = new AdaptedContactDetail(); - phone.isPrivate = source.getPhone().isPrivate(); - phone.value = source.getPhone().value; + nric = new AdaptedContactDetail(); + nric.value = source.getNRIC().getIdentificationNumber(); + + dateOfBirth = new AdaptedContactDetail(); + dateOfBirth.value = source.getDateOfBirth().getDOB(); + + postalCode = new AdaptedContactDetail(); + postalCode.value = source.getPostalCode().getPostalCode(); - email = new AdaptedContactDetail(); - email.isPrivate = source.getEmail().isPrivate(); - email.value = source.getEmail().value; + status = new AdaptedContactDetail(); + status.value = source.getStatus().getCurrentStatus(); - address = new AdaptedContactDetail(); - address.isPrivate = source.getAddress().isPrivate(); - address.value = source.getAddress().value; + wantedFor = new AdaptedContactDetail(); + wantedFor.value = source.getWantedFor().getOffense(); tagged = new ArrayList<>(); - for (Tag tag : source.getTags()) { + for (Offense tag : source.getPastOffense()) { tagged.add(new AdaptedTag(tag)); } } @@ -83,9 +87,9 @@ public boolean isAnyRequiredFieldMissing() { return true; } } - // second call only happens if phone/email/address are all not null - return Utils.isAnyNull(name, phone, email, address) - || Utils.isAnyNull(phone.value, email.value, address.value); + // second call only happens if nric/postalCode/status are all not null + return Utils.isAnyNull(name, nric, dateOfBirth, postalCode, status, wantedFor) + || Utils.isAnyNull(nric.value, dateOfBirth.value, postalCode.value, status.value, wantedFor.value); } /** @@ -94,14 +98,16 @@ public boolean isAnyRequiredFieldMissing() { * @throws IllegalValueException if there were any data constraints violated in the adapted person */ public Person toModelType() throws IllegalValueException { - final Set tags = new HashSet<>(); + final Set tags = new HashSet<>(); for (AdaptedTag tag : tagged) { tags.add(tag.toModelType()); } final Name name = new Name(this.name); - final Phone phone = new Phone(this.phone.value, this.phone.isPrivate); - final Email email = new Email(this.email.value, this.email.isPrivate); - final Address address = new Address(this.address.value, this.address.isPrivate); - return new Person(name, phone, email, address, tags); + final NRIC nric = new NRIC(this.nric.value); + final DateOfBirth dateOfBirth = new DateOfBirth(this.dateOfBirth.value); + final PostalCode postalCode = new PostalCode(this.postalCode.value); + final Status status = new Status(this.status.value); + final Offense wantedFor = new Offense(this.wantedFor.value); + return new Person(name, nric, dateOfBirth, postalCode, status, wantedFor, tags); } } diff --git a/src/seedu/addressbook/storage/jaxb/AdaptedTag.java b/src/seedu/addressbook/storage/jaxb/AdaptedTag.java index cd5286a36..67c95d816 100644 --- a/src/seedu/addressbook/storage/jaxb/AdaptedTag.java +++ b/src/seedu/addressbook/storage/jaxb/AdaptedTag.java @@ -2,6 +2,7 @@ import seedu.addressbook.common.Utils; import seedu.addressbook.data.exception.IllegalValueException; +import seedu.addressbook.data.person.Offense; import seedu.addressbook.data.tag.Tag; import javax.xml.bind.annotation.XmlValue; @@ -12,7 +13,7 @@ public class AdaptedTag { @XmlValue - public String tagName; + public String offenseName; /** * No-arg constructor for JAXB use. @@ -24,8 +25,8 @@ public AdaptedTag() {} * * @param source future changes to this will not affect the created AdaptedTag */ - public AdaptedTag(Tag source) { - tagName = source.tagName; + public AdaptedTag(Offense source) { + offenseName = source.offense; } /** @@ -37,7 +38,7 @@ public AdaptedTag(Tag source) { * so we check for that. */ public boolean isAnyRequiredFieldMissing() { - return Utils.isAnyNull(tagName); + return Utils.isAnyNull(offenseName); } /** @@ -45,7 +46,7 @@ public boolean isAnyRequiredFieldMissing() { * * @throws IllegalValueException if there were any data constraints violated in the adapted person */ - public Tag toModelType() throws IllegalValueException { - return new Tag(tagName); + public Offense toModelType() throws IllegalValueException { + return new Offense(offenseName); } } diff --git a/src/seedu/addressbook/ui/Formatter.java b/src/seedu/addressbook/ui/Formatter.java index 635df3f08..ea23b5b30 100644 --- a/src/seedu/addressbook/ui/Formatter.java +++ b/src/seedu/addressbook/ui/Formatter.java @@ -38,7 +38,7 @@ public String format(String... messages) { public String format(List persons) { final List formattedPersons = new ArrayList<>(); for (ReadOnlyPerson person : persons) { - formattedPersons.add(person.getAsTextHidePrivate()); + formattedPersons.add(person.getAsTextShowAll()); } return format(asIndexedList(formattedPersons)); } diff --git a/test/data/StorageFileTest/ValidData.txt b/test/data/StorageFileTest/ValidData.txt index fc6b00df6..b5e23eb54 100644 --- a/test/data/StorageFileTest/ValidData.txt +++ b/test/data/StorageFileTest/ValidData.txt @@ -2,16 +2,20 @@ John Doe - 98765432 - johnd@gmail.com -
John street, block 123, #01-01
+ s1234567a + 1998 + 510244 + clear + none
Betsy Crowe - 1234567 - betsycrowe@gmail.com -
Newgate Prison
- friend - criminal + g7654321b + 2000 + 123456 + wanted + drugs + riot + theft
diff --git a/test/java/seedu/addressbook/logic/LogicTest.java b/test/java/seedu/addressbook/logic/LogicTest.java index 396fb4bc9..d1f281211 100644 --- a/test/java/seedu/addressbook/logic/LogicTest.java +++ b/test/java/seedu/addressbook/logic/LogicTest.java @@ -112,9 +112,9 @@ public void execute_exit() throws Exception { @Test public void execute_clear() throws Exception { TestDataHelper helper = new TestDataHelper(); - addressBook.addPerson(helper.generatePerson(1, true)); - addressBook.addPerson(helper.generatePerson(2, true)); - addressBook.addPerson(helper.generatePerson(3, true)); + addressBook.addPerson(helper.generatePerson(1)); + addressBook.addPerson(helper.generatePerson(2)); + addressBook.addPerson(helper.generatePerson(3)); assertCommandBehavior("clear", ClearCommand.MESSAGE_SUCCESS, AddressBook.empty(), false, Collections.emptyList()); } @@ -123,25 +123,35 @@ public void execute_clear() throws Exception { public void execute_add_invalidArgsFormat() throws Exception { String expectedMessage = String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddCommand.MESSAGE_USAGE); assertCommandBehavior( - "add wrong args wrong args", expectedMessage); + "add wrong args wrong args wrong args", expectedMessage); assertCommandBehavior( - "add Valid Name 12345 e/valid@email.butNoPhonePrefix a/valid, address", expectedMessage); + "add Valid Name s1234567a d/1980 p/123456 s/clear w/none", expectedMessage); assertCommandBehavior( - "add Valid Name p/12345 valid@email.butNoPrefix a/valid, address", expectedMessage); + "add Valid Name n/s1234567a 1980 p/123456 s/clear w/none", expectedMessage); assertCommandBehavior( - "add Valid Name p/12345 e/valid@email.butNoAddressPrefix valid, address", expectedMessage); + "add Valid Name n/s1234567a d/1980 123456 s/clear w/none", expectedMessage); + assertCommandBehavior( + "add Valid Name n/s1234567a d/1980 p/123456 clear w/none", expectedMessage); + assertCommandBehavior( + "add Valid Name n/s1234567a d/1980 123456 s/clear none", expectedMessage); } @Test public void execute_add_invalidPersonData() throws Exception { assertCommandBehavior( - "add []\\[;] p/12345 e/valid@e.mail a/valid, address", Name.MESSAGE_NAME_CONSTRAINTS); + "add []\\[;] n/s1234567a d/1980 p/123456 s/clear w/none", Name.MESSAGE_NAME_CONSTRAINTS); + assertCommandBehavior( + "add Valid Name n/s123457a d/1980 p/123456 s/clear w/none", NRIC.MESSAGE_NAME_CONSTRAINTS); + assertCommandBehavior( + "add Valid Name n/s1234567a d/188 p/123456 s/clear w/none", DateOfBirth.MESSAGE_DATE_OF_BIRTH_CONSTRAINTS); + assertCommandBehavior( + "add Valid Name n/s1234567a d/1980 p/13456 s/clear w/none", PostalCode.MESSAGE_NAME_CONSTRAINTS); assertCommandBehavior( - "add Valid Name p/not_numbers e/valid@e.mail a/valid, address", Phone.MESSAGE_PHONE_CONSTRAINTS); + "add Valid Name n/s1234567a d/1980 p/123456 s/not a convict w/none", Status.MESSAGE_NAME_CONSTRAINTS); assertCommandBehavior( - "add Valid Name p/12345 e/notAnEmail a/valid, address", Email.MESSAGE_EMAIL_CONSTRAINTS); + "add Valid Name n/s1234567a d/1980 p/123456 s/wanted w/rob", Offense.MESSAGE_OFFENSE_CONSTRAINTS); assertCommandBehavior( - "add Valid Name p/12345 e/valid@e.mail a/valid, address t/invalid_-[.tag", Tag.MESSAGE_TAG_CONSTRAINTS); + "add Valid Name n/s1234567a d/1980 p/123456 s/excon w/none o/rob", Offense.MESSAGE_OFFENSE_CONSTRAINTS); } @@ -187,11 +197,11 @@ public void execute_addDuplicate_notAllowed() throws Exception { public void execute_list_showsAllPersons() throws Exception { // prepare expectations TestDataHelper helper = new TestDataHelper(); - AddressBook expectedAB = helper.generateAddressBook(false, true); + AddressBook expectedAB = helper.generateAddressBook(false, false); List expectedList = expectedAB.getAllPersons().immutableListView(); // prepare address book state - helper.addToAddressBook(addressBook, false, true); + helper.addToAddressBook(addressBook, false, false); assertCommandBehavior("list", Command.getMessageForPersonListShownSummary(expectedList), @@ -202,7 +212,7 @@ public void execute_list_showsAllPersons() throws Exception { @Test public void execute_view_invalidArgsFormat() throws Exception { - String expectedMessage = String.format(MESSAGE_INVALID_COMMAND_FORMAT, ViewCommand.MESSAGE_USAGE); + String expectedMessage = String.format(MESSAGE_INVALID_COMMAND_FORMAT, ViewAllCommand.MESSAGE_USAGE); assertCommandBehavior("view ", expectedMessage); assertCommandBehavior("view arg not number", expectedMessage); } @@ -230,12 +240,13 @@ private void assertInvalidIndexBehaviorForCommand(String commandWord) throws Exc } - @Test + //@Test + /** public void execute_view_onlyShowsNonPrivate() throws Exception { TestDataHelper helper = new TestDataHelper(); - Person p1 = helper.generatePerson(1, true); - Person p2 = helper.generatePerson(2, false); + Person p1 = helper.generatePerson(1); + Person p2 = helper.generatePerson(2); List lastShownList = helper.generatePersonList(p1, p2); AddressBook expectedAB = helper.generateAddressBook(lastShownList); helper.addToAddressBook(addressBook, lastShownList); @@ -254,12 +265,12 @@ public void execute_view_onlyShowsNonPrivate() throws Exception { false, lastShownList); } - +*/ @Test public void execute_tryToViewMissingPerson_errorMessage() throws Exception { TestDataHelper helper = new TestDataHelper(); - Person p1 = helper.generatePerson(1, false); - Person p2 = helper.generatePerson(2, false); + Person p1 = helper.generatePerson(1); + Person p2 = helper.generatePerson(2); List lastShownList = helper.generatePersonList(p1, p2); AddressBook expectedAB = new AddressBook(); @@ -290,8 +301,8 @@ public void execute_viewAll_invalidIndex() throws Exception { @Test public void execute_viewAll_alsoShowsPrivate() throws Exception { TestDataHelper helper = new TestDataHelper(); - Person p1 = helper.generatePerson(1, true); - Person p2 = helper.generatePerson(2, false); + Person p1 = helper.generatePerson(1); + Person p2 = helper.generatePerson(2); List lastShownList = helper.generatePersonList(p1, p2); AddressBook expectedAB = helper.generateAddressBook(lastShownList); helper.addToAddressBook(addressBook, lastShownList); @@ -299,13 +310,13 @@ public void execute_viewAll_alsoShowsPrivate() throws Exception { logic.setLastShownList(lastShownList); assertCommandBehavior("viewall 1", - String.format(ViewCommand.MESSAGE_VIEW_PERSON_DETAILS, p1.getAsTextShowAll()), + String.format(ViewAllCommand.MESSAGE_VIEW_PERSON_DETAILS, p1.getAsTextShowAll()), expectedAB, false, lastShownList); assertCommandBehavior("viewall 2", - String.format(ViewCommand.MESSAGE_VIEW_PERSON_DETAILS, p2.getAsTextShowAll()), + String.format(ViewAllCommand.MESSAGE_VIEW_PERSON_DETAILS, p2.getAsTextShowAll()), expectedAB, false, lastShownList); @@ -314,8 +325,8 @@ public void execute_viewAll_alsoShowsPrivate() throws Exception { @Test public void execute_tryToViewAllPersonMissingInAddressBook_errorMessage() throws Exception { TestDataHelper helper = new TestDataHelper(); - Person p1 = helper.generatePerson(1, false); - Person p2 = helper.generatePerson(2, false); + Person p1 = helper.generatePerson(1); + Person p2 = helper.generatePerson(2); List lastShownList = helper.generatePersonList(p1, p2); AddressBook expectedAB = new AddressBook(); @@ -346,9 +357,9 @@ public void execute_delete_invalidIndex() throws Exception { @Test public void execute_delete_removesCorrectPerson() throws Exception { TestDataHelper helper = new TestDataHelper(); - Person p1 = helper.generatePerson(1, false); - Person p2 = helper.generatePerson(2, true); - Person p3 = helper.generatePerson(3, true); + Person p1 = helper.generatePerson(1); + Person p2 = helper.generatePerson(2); + Person p3 = helper.generatePerson(3); List threePersons = helper.generatePersonList(p1, p2, p3); @@ -370,9 +381,9 @@ public void execute_delete_removesCorrectPerson() throws Exception { public void execute_delete_missingInAddressBook() throws Exception { TestDataHelper helper = new TestDataHelper(); - Person p1 = helper.generatePerson(1, false); - Person p2 = helper.generatePerson(2, true); - Person p3 = helper.generatePerson(3, true); + Person p1 = helper.generatePerson(1); + Person p2 = helper.generatePerson(2); + Person p3 = helper.generatePerson(3); List threePersons = helper.generatePersonList(p1, p2, p3); @@ -463,13 +474,15 @@ class TestDataHelper{ Person adam() throws Exception { Name name = new Name("Adam Brown"); - Phone privatePhone = new Phone("111111", true); - Email email = new Email("adam@gmail.com", false); - Address privateAddress = new Address("111, alpha street", true); - Tag tag1 = new Tag("tag1"); - Tag tag2 = new Tag("tag2"); - Set tags = new HashSet<>(Arrays.asList(tag1, tag2)); - return new Person(name, privatePhone, email, privateAddress, tags); + NRIC nric = new NRIC("f1234567j"); + DateOfBirth dateOfBirth = new DateOfBirth("2001"); + PostalCode postalCode = new PostalCode("444444"); + Status status = new Status("xc"); + Offense wantedFor = new Offense(); + Offense tag1 = new Offense("drugs"); + Offense tag2 = new Offense("riot"); + Set tags = new HashSet<>(Arrays.asList(tag1, tag2)); + return new Person(name, nric, dateOfBirth, postalCode, status, wantedFor, tags); } /** @@ -478,15 +491,17 @@ Person adam() throws Exception { * Each unique seed will generate a unique Person object. * * @param seed used to generate the person data field values - * @param isAllFieldsPrivate determines if private-able fields (phone, email, address) will be private + * */ - Person generatePerson(int seed, boolean isAllFieldsPrivate) throws Exception { + Person generatePerson(int seed) throws Exception { return new Person( new Name("Person " + seed), - new Phone("" + Math.abs(seed), isAllFieldsPrivate), - new Email(seed + "@email", isAllFieldsPrivate), - new Address("House of " + seed, isAllFieldsPrivate), - new HashSet<>(Arrays.asList(new Tag("tag" + Math.abs(seed)), new Tag("tag" + Math.abs(seed + 1)))) + new NRIC("g999999" + Math.abs(seed) + "t"), + new DateOfBirth(Integer.toString(seed + Integer.parseInt("1901"))), + new PostalCode("77777" + seed), + new Status("xc"), + new Offense(), + new HashSet<>(Arrays.asList(new Offense("theft" + Math.abs(seed)), new Offense("theft" + Math.abs(seed + 1)))) ); } @@ -497,13 +512,15 @@ String generateAddCommand(Person p) { cmd.add("add"); cmd.add(p.getName().toString()); - cmd.add((p.getPhone().isPrivate() ? "pp/" : "p/") + p.getPhone()); - cmd.add((p.getEmail().isPrivate() ? "pe/" : "e/") + p.getEmail()); - cmd.add((p.getAddress().isPrivate() ? "pa/" : "a/") + p.getAddress()); - - Set tags = p.getTags(); - for(Tag t: tags){ - cmd.add("t/" + t.tagName); + cmd.add("n/" + p.getNRIC()); + cmd.add("d/" + p.getDateOfBirth()); + cmd.add("p/" + p.getPostalCode()); + cmd.add("s/" + p.getStatus()); + cmd.add("w/" + p.getWantedFor()); + + Set tags = p.getPastOffense(); + for(Offense t: tags){ + cmd.add("o/" + t.getOffense()); } return cmd.toString(); @@ -568,7 +585,7 @@ List generatePersonList(Boolean... isPrivateStatuses) throws Exception{ List persons = new ArrayList<>(); int i = 1; for(Boolean p: isPrivateStatuses){ - persons.add(generatePerson(i++, p)); + persons.add(generatePerson(i++)); } return persons; } @@ -579,10 +596,12 @@ List generatePersonList(Boolean... isPrivateStatuses) throws Exception{ Person generatePersonWithName(String name) throws Exception { return new Person( new Name(name), - new Phone("1", false), - new Email("1@email", false), - new Address("House of 1", false), - Collections.singleton(new Tag("tag")) + new NRIC("S1234567A"), + new DateOfBirth("2005"), + new PostalCode("123456"), + new Status("excon"), + new Offense(), + Collections.singleton(new Offense("riot")) ); } } diff --git a/test/java/seedu/addressbook/parser/ParserTest.java b/test/java/seedu/addressbook/parser/ParserTest.java index 5b5f5b013..4a29d47db 100644 --- a/test/java/seedu/addressbook/parser/ParserTest.java +++ b/test/java/seedu/addressbook/parser/ParserTest.java @@ -8,6 +8,7 @@ import seedu.addressbook.data.person.*; import java.util.Arrays; +import java.util.Date; import java.util.HashSet; import java.util.Set; @@ -90,17 +91,17 @@ public void deleteCommand_numericArg_indexParsedCorrectly() { assertEquals(result.getTargetIndex(), testIndex); } - @Test + /**@Test public void viewCommand_noArgs() { final String[] inputs = { "view", "view " }; - final String resultMessage = String.format(MESSAGE_INVALID_COMMAND_FORMAT, ViewCommand.MESSAGE_USAGE); + final String resultMessage = String.format(MESSAGE_INVALID_COMMAND_FORMAT, ViewAllCommand.MESSAGE_USAGE); parseAndAssertIncorrectWithMessage(resultMessage, inputs); - } + }*/ @Test public void viewCommand_argsIsNotSingleNumber() { final String[] inputs = { "view notAnumber ", "view 8*wh12", "view 1 2 3 4 5" }; - final String resultMessage = String.format(MESSAGE_INVALID_COMMAND_FORMAT, ViewCommand.MESSAGE_USAGE); + final String resultMessage = String.format(MESSAGE_INVALID_COMMAND_FORMAT, ViewAllCommand.MESSAGE_USAGE); parseAndAssertIncorrectWithMessage(resultMessage, inputs); } @@ -108,7 +109,7 @@ public void viewCommand_argsIsNotSingleNumber() { public void viewCommand_numericArg_indexParsedCorrectly() { final int testIndex = 2; final String input = "view " + testIndex; - final ViewCommand result = parseAndAssertCommandType(input, ViewCommand.class); + final ViewAllCommand result = parseAndAssertCommandType(input, ViewAllCommand.class); assertEquals(result.getTargetIndex(), testIndex); } @@ -184,12 +185,21 @@ public void addCommand_invalidArgs() { "add", "add ", "add wrong args format", - // no phone prefix - String.format("add $s $s e/$s a/$s", Name.EXAMPLE, Phone.EXAMPLE, Email.EXAMPLE, Address.EXAMPLE), - // no email prefix - String.format("add $s p/$s $s a/$s", Name.EXAMPLE, Phone.EXAMPLE, Email.EXAMPLE, Address.EXAMPLE), - // no address prefix - String.format("add $s p/$s e/$s $s", Name.EXAMPLE, Phone.EXAMPLE, Email.EXAMPLE, Address.EXAMPLE) + // no nric prefix + String.format("add $s $s d/$s p/$s s/$s w/$s", Name.EXAMPLE, NRIC.EXAMPLE, DateOfBirth.EXAMPLE, PostalCode.EXAMPLE, + Status.EXAMPLE, Offense.EXAMPLE), + // no dateOfBirth prefix + String.format("add $s n/$s $s p/$s s/$s w/$s", Name.EXAMPLE, NRIC.EXAMPLE, DateOfBirth.EXAMPLE, PostalCode.EXAMPLE, + Status.EXAMPLE, Offense.EXAMPLE), + // no postalCode prefix + String.format("add $s n/$s d/$s $s s/$s w/$s", Name.EXAMPLE, NRIC.EXAMPLE, DateOfBirth.EXAMPLE, PostalCode.EXAMPLE, + Status.EXAMPLE, Offense.EXAMPLE), + // no status prefix + String.format("add $s n/$s d/$s p/$s /$s w/$s", Name.EXAMPLE, NRIC.EXAMPLE, DateOfBirth.EXAMPLE, PostalCode.EXAMPLE, + Status.EXAMPLE, Offense.EXAMPLE), + // no offense(for wantedFor) prefix + String.format("add $s n/$s d/$s p/$s s/$s /$s", Name.EXAMPLE, NRIC.EXAMPLE, DateOfBirth.EXAMPLE, PostalCode.EXAMPLE, + Status.EXAMPLE, Offense.EXAMPLE) }; final String resultMessage = String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddCommand.MESSAGE_USAGE); parseAndAssertIncorrectWithMessage(resultMessage, inputs); @@ -199,25 +209,36 @@ public void addCommand_invalidArgs() { public void addCommand_invalidPersonDataInArgs() { final String invalidName = "[]\\[;]"; final String validName = Name.EXAMPLE; - final String invalidPhoneArg = "p/not__numbers"; - final String validPhoneArg = "p/" + Phone.EXAMPLE; - final String invalidEmailArg = "e/notAnEmail123"; - final String validEmailArg = "e/" + Email.EXAMPLE; - final String invalidTagArg = "t/invalid_-[.tag"; + final String invalidNricArg = "n/not__numbers"; + final String validNricArg = "n/" + NRIC.EXAMPLE; + final String invalidDateOfBirthArg = "d/1000"; + final String validDateOfBirthArg = "d/" + DateOfBirth.EXAMPLE; + final String invalidPostalCodeArg = "p/11234565"; + final String validPostalCode = "p/" + PostalCode.EXAMPLE; + final String invalidStatusArg = "s/not a convict"; + final String validStatusArg = "s/" + Status.EXAMPLE; + final String invalidWantedForArg = "w/no offence"; + final String validWantedForArg = "w/" + Offense.EXAMPLE; + final String invalidTagArg = "o/invalid_-[.tag"; // address can be any string, so no invalid address - final String addCommandFormatString = "add $s $s $s a/" + Address.EXAMPLE; + final String addCommandFormatString = "add $s $s $s $s $s $s"; // test each incorrect person data field argument individually final String[] inputs = { // invalid name - String.format(addCommandFormatString, invalidName, validPhoneArg, validEmailArg), - // invalid phone - String.format(addCommandFormatString, validName, invalidPhoneArg, validEmailArg), - // invalid email - String.format(addCommandFormatString, validName, validPhoneArg, invalidEmailArg), - // invalid tag - String.format(addCommandFormatString, validName, validPhoneArg, validEmailArg) + " " + invalidTagArg + String.format(addCommandFormatString, invalidName, validNricArg, validDateOfBirthArg, validPostalCode, validStatusArg, validWantedForArg), + // invalid nric + String.format(addCommandFormatString, validName, invalidNricArg, validDateOfBirthArg, validPostalCode, validStatusArg, validWantedForArg), + // invalid dateOfBirth + String.format(addCommandFormatString, validName, validNricArg, invalidDateOfBirthArg, validPostalCode, validStatusArg, validWantedForArg), + // invalid postalCode + String.format(addCommandFormatString, validName, validNricArg, validDateOfBirthArg, invalidPostalCodeArg, validStatusArg, validWantedForArg), + // invalid status + String.format(addCommandFormatString, validName, validNricArg, validDateOfBirthArg, validPostalCode, invalidStatusArg, validWantedForArg), + // invalid wantedFor + String.format(addCommandFormatString, validName, validNricArg, validDateOfBirthArg, validPostalCode, validStatusArg, invalidWantedForArg), + String.format(addCommandFormatString, validName, validNricArg, validDateOfBirthArg, validPostalCode, validStatusArg, validWantedForArg) + " " + invalidTagArg }; for (String input : inputs) { parseAndAssertCommandType(input, IncorrectCommand.class); @@ -236,9 +257,9 @@ public void addCommand_validPersonData_parsedCorrectly() { public void addCommand_duplicateTags_merged() throws IllegalValueException { final Person testPerson = generateTestPerson(); String input = convertPersonToAddCommandString(testPerson); - for (Tag tag : testPerson.getTags()) { + for (Offense tag : testPerson.getPastOffense()) { // create duplicates by doubling each tag - input += " t/" + tag.tagName; + input += " o/" + tag.getOffense(); } final AddCommand result = parseAndAssertCommandType(input, AddCommand.class); @@ -249,10 +270,12 @@ private static Person generateTestPerson() { try { return new Person( new Name(Name.EXAMPLE), - new Phone(Phone.EXAMPLE, true), - new Email(Email.EXAMPLE, false), - new Address(Address.EXAMPLE, true), - new HashSet<>(Arrays.asList(new Tag("tag1"), new Tag("tag2"), new Tag("tag3"))) + new NRIC(NRIC.EXAMPLE), + new DateOfBirth(DateOfBirth.EXAMPLE), + new PostalCode(PostalCode.EXAMPLE), + new Status(Status.EXAMPLE), + new Offense(Offense.EXAMPLE), + new HashSet<>(Arrays.asList(new Offense("theft"), new Offense("drugs"), new Offense("riot"))) ); } catch (IllegalValueException ive) { throw new RuntimeException("test person data should be valid by definition"); @@ -262,11 +285,13 @@ private static Person generateTestPerson() { private static String convertPersonToAddCommandString(ReadOnlyPerson person) { String addCommand = "add " + person.getName().fullName - + (person.getPhone().isPrivate() ? " pp/" : " p/") + person.getPhone().value - + (person.getEmail().isPrivate() ? " pe/" : " e/") + person.getEmail().value - + (person.getAddress().isPrivate() ? " pa/" : " a/") + person.getAddress().value; - for (Tag tag : person.getTags()) { - addCommand += " t/" + tag.tagName; + + " n/" + person.getNRIC().getIdentificationNumber() + + " d/" + person.getDateOfBirth().getDOB() + + " p/" + person.getPostalCode().getPostalCode() + + " s/" + person.getStatus().getCurrentStatus() + + " w/" + person.getWantedFor().getOffense(); + for (Offense tag : person.getPastOffense()) { + addCommand += " o/" + tag.getOffense(); } return addCommand; } diff --git a/test/java/seedu/addressbook/storage/StorageFileTest.java b/test/java/seedu/addressbook/storage/StorageFileTest.java index f7d9721db..d0fdcd3f5 100644 --- a/test/java/seedu/addressbook/storage/StorageFileTest.java +++ b/test/java/seedu/addressbook/storage/StorageFileTest.java @@ -13,11 +13,7 @@ import seedu.addressbook.data.AddressBook; import seedu.addressbook.data.exception.IllegalValueException; -import seedu.addressbook.data.person.Address; -import seedu.addressbook.data.person.Email; -import seedu.addressbook.data.person.Name; -import seedu.addressbook.data.person.Person; -import seedu.addressbook.data.person.Phone; +import seedu.addressbook.data.person.*; import seedu.addressbook.data.tag.Tag; import seedu.addressbook.storage.StorageFile.StorageOperationException; import static seedu.addressbook.util.TestUtil.assertTextFilesEqual; @@ -97,15 +93,19 @@ private StorageFile getTempStorage() throws Exception { private AddressBook getTestAddressBook() throws Exception { AddressBook ab = new AddressBook(); ab.addPerson(new Person(new Name("John Doe"), - new Phone("98765432", false), - new Email("johnd@gmail.com", false), - new Address("John street, block 123, #01-01", false), + new NRIC("s1234567a"), + new DateOfBirth("1998"), + new PostalCode("510244"), + new Status("clear"), + new Offense(), Collections.emptySet())); ab.addPerson(new Person(new Name("Betsy Crowe"), - new Phone("1234567", true), - new Email("betsycrowe@gmail.com", false), - new Address("Newgate Prison", true), - new HashSet<>(Arrays.asList(new Tag("friend"), new Tag("criminal"))))); + new NRIC("g7654321b"), + new DateOfBirth("2000"), + new PostalCode("123456"), + new Status("wanted"), + new Offense("drugs"), + new HashSet<>(Arrays.asList(new Offense("theft"), new Offense("riot"))))); return ab; } }