From 36bfc79b3f2a044a9fcbf372f2e91f66c0d4211c Mon Sep 17 00:00:00 2001 From: Jacqueline Cheong Date: Sat, 24 Mar 2018 01:40:32 +0800 Subject: [PATCH 1/8] Implement full parsing logic for Add command and update the relevant classes --- .../address/logic/commands/AddCommand.java | 148 ++++++++++++++++-- .../logic/parser/AddCommandParser.java | 143 ++++++++++++++--- .../address/logic/parser/ParserUtil.java | 1 - .../java/seedu/address/model/AddressBook.java | 2 +- .../model/appointment/Appointment.java | 58 ++++--- .../address/model/petpatient/PetPatient.java | 26 +-- .../storage/XmlAdaptedAppointment.java | 6 +- 7 files changed, 316 insertions(+), 68 deletions(-) diff --git a/src/main/java/seedu/address/logic/commands/AddCommand.java b/src/main/java/seedu/address/logic/commands/AddCommand.java index 5491886c0833..3c21b81e39fa 100644 --- a/src/main/java/seedu/address/logic/commands/AddCommand.java +++ b/src/main/java/seedu/address/logic/commands/AddCommand.java @@ -2,17 +2,27 @@ import static java.util.Objects.requireNonNull; import static seedu.address.logic.parser.CliSyntax.PREFIX_ADDRESS; +import static seedu.address.logic.parser.CliSyntax.PREFIX_DATE; import static seedu.address.logic.parser.CliSyntax.PREFIX_EMAIL; import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME; import static seedu.address.logic.parser.CliSyntax.PREFIX_NRIC; +import static seedu.address.logic.parser.CliSyntax.PREFIX_PET_PATIENT_BLOODTYPE; +import static seedu.address.logic.parser.CliSyntax.PREFIX_PET_PATIENT_BREED; +import static seedu.address.logic.parser.CliSyntax.PREFIX_PET_PATIENT_COLOUR; +import static seedu.address.logic.parser.CliSyntax.PREFIX_PET_PATIENT_SPECIES; import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE; +import static seedu.address.logic.parser.CliSyntax.PREFIX_REMARK; import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG; import seedu.address.logic.commands.exceptions.CommandException; import seedu.address.model.appointment.Appointment; +import seedu.address.model.appointment.exceptions.DuplicateAppointmentException; +import seedu.address.model.person.Nric; import seedu.address.model.person.Person; import seedu.address.model.person.exceptions.DuplicatePersonException; import seedu.address.model.petpatient.PetPatient; +import seedu.address.model.petpatient.PetPatientName; +import seedu.address.model.petpatient.exceptions.DuplicatePetPatientException; /** * Adds a person to the address book. @@ -22,6 +32,7 @@ public class AddCommand extends UndoableCommand { public static final String COMMAND_WORD = "add"; public static final String COMMAND_ALIAS = "a"; + //NEED TO UPDATE THE MESSAGE_USAGE (CONSOLIDATE) public static final String MESSAGE_USAGE = COMMAND_WORD + " -o : Adds a person to the address book. " + "Parameters: " + PREFIX_NAME + "NAME " @@ -39,12 +50,47 @@ public class AddCommand extends UndoableCommand { + PREFIX_TAG + "friends " + PREFIX_TAG + "owesMoney"; + public static final String MESSAGE_APPOINTMENT = COMMAND_WORD + " -a : Adds an appointment. " + + "Parameters: " + + PREFIX_DATE + "DATE " + + PREFIX_REMARK + "REMARK " + + "[" + PREFIX_TAG + "TYPE OF APPOINTMENT]...\n" + + "Example: " + COMMAND_WORD + " " + + PREFIX_DATE + "2018-12-31 12:30 " + + PREFIX_REMARK + "nil " + + PREFIX_TAG + "checkup " + + PREFIX_TAG + "vaccination"; + + public static final String MESSAGE_PETPATIENT = COMMAND_WORD + " -p : Adds a pet patient to the address book. " + + "Parameters: " + + PREFIX_NAME + "NAME " + + PREFIX_PET_PATIENT_SPECIES + "SPECIES " + + PREFIX_PET_PATIENT_BREED + "BREED " + + PREFIX_PET_PATIENT_COLOUR + "COLOUR " + + PREFIX_PET_PATIENT_BLOODTYPE + "BLOOD_TYPE " + + "[" + PREFIX_TAG + "TAG]...\n" + + "Example: " + COMMAND_WORD + " " + + PREFIX_NAME + "Jewel " + + PREFIX_PET_PATIENT_SPECIES + "Cat " + + PREFIX_PET_PATIENT_BREED + "Persian Ragdoll " + + PREFIX_PET_PATIENT_COLOUR + "Calico " + + PREFIX_PET_PATIENT_BLOODTYPE + "AB"; + public static final String MESSAGE_SUCCESS = "New person added: %1$s\n"; - public static final String MESSAGE_DUPLICATE_PERSON = "This person already exists in the address book"; + public static final String MESSAGE_DUPLICATE_PERSON = "This person already exists in Medeina."; + public static final String MESSAGE_DUPLICATE_APPOINTMENT = "This particular appointment already exists in Medeina."; + public static final String MESSAGE_DUPLICATE_PET_PATIENT = "This pet patient already exists in Medeina"; + public static final String MESSAGE_INVALID_NRIC = "The specified NRIC does not belong to anyone in Medeina." + + " Please add a new person."; + public static final String MESSAGE_INVALID_PET_PATIENT = "The specified pet cannot be found under the specified " + + "owner in Medeina. Please add a new pet patient."; private Person toAddOwner; private PetPatient toAddPet; private Appointment toAddAppt; + private Nric ownerNric; + private PetPatientName petPatientName; + private int type; private String message = "New person added: %1$s\n"; /** @@ -57,28 +103,35 @@ public AddCommand(Person owner, PetPatient pet, Appointment appt) { toAddOwner = owner; toAddPet = pet; toAddAppt = appt; - message += "New pet patient added: " + toAddPet.toString() - + "\nNew appointment made: " + toAddAppt.toString(); - System.out.println("ADDED ALL THREE"); + type = 1; + message += "New pet patient added: %2$s\nNew appointment made: %3$s"; } /** - * Creates an AddCommand to add the specified {@code Person} and {@code PetPatient} + * Creates an AddCommand to add the specified {@code Person} and {@code PetPatient} and {@code Appointment} */ - public AddCommand(Person owner, PetPatient pet) { - requireNonNull(owner); - requireNonNull(pet); - toAddOwner = owner; - toAddPet = pet; - message += "New pet patient added: " + toAddPet.toString(); + public AddCommand(Appointment appt, Nric ownerNric, PetPatientName petPatientName) { + requireNonNull(appt); + requireNonNull(ownerNric); + requireNonNull(petPatientName); + toAddAppt = appt; + this.ownerNric = ownerNric; + this.petPatientName = petPatientName; + type = 2; + message = "New appointment made: %1$s\nunder owner: %2$s\nfor pet patient: %3$s"; } /** - * Creates an AddCommand to add the specified {@code PetPatient} + * Creates an AddCommand to add the specified {@code PetPatient} if an existing Person object has Nric equivalent + * to {@code Nric} */ - public AddCommand(PetPatient pet) { + public AddCommand(PetPatient pet, Nric ownerNric) { requireNonNull(pet); + requireNonNull(ownerNric); toAddPet = pet; + this.ownerNric = ownerNric; + type = 3; + message = "New pet patient added: %1$s \nunder owner: %2$s"; } /** @@ -87,22 +140,85 @@ public AddCommand(PetPatient pet) { public AddCommand(Person owner) { requireNonNull(owner); toAddOwner = owner; + type = 4; } public String getMessage() { return message; } + public Person getPersonOfNric() { + for (Person p : model.getAddressBook().getPersonList()) { + if (p.getNric().equals(ownerNric)) { + return p; + } + } + return null; + } + + public PetPatient getPetPatientOfNricAndName() { + for (PetPatient p : model.getAddressBook().getPetPatientList()) { + if(p.getOwner().equals(ownerNric) && p.getName().equals(petPatientName)) { + return p; + } + } + return null; + } + @Override public CommandResult executeUndoableCommand() throws CommandException { requireNonNull(model); try { - model.addPerson(toAddOwner); - return new CommandResult(String.format(message, toAddOwner)); + switch (type){ + case 1: //add new owner, new pet patient, and new appointment + model.addPerson(toAddOwner); + model.addPetPatient(toAddPet); + model.addAppointment(toAddAppt); + return new CommandResult(String.format(message, toAddOwner, toAddPet, toAddAppt)); + + case 2: //add new appointment for pet patient under an existing owner + Person owner = getPersonOfNric(); + PetPatient pet = getPetPatientOfNricAndName(); + if (owner != null) { + toAddAppt.setOwnerNric(ownerNric); + } else { + throw new CommandException(MESSAGE_INVALID_NRIC); + } + + if (pet != null) { + toAddAppt.setPetPatientName(petPatientName); + } else { + throw new CommandException(MESSAGE_INVALID_PET_PATIENT); + } + + toAddAppt.setPetPatientName(petPatientName); + model.addAppointment(toAddAppt); + return new CommandResult(String.format(message, toAddAppt, owner)); + + case 3: //add new pet patient under an existing person + Person p = getPersonOfNric(); + if (p != null) { + toAddPet.setOwnerNRIC(ownerNric); + model.addPetPatient(toAddPet); + return new CommandResult(String.format(message, toAddPet, p)); + } + throw new CommandException(MESSAGE_INVALID_NRIC); + + case 4: //add Person only + model.addPerson(toAddOwner); + return new CommandResult(String.format(message, toAddOwner)); + + default: + throw new CommandException(MESSAGE_USAGE); + } + } catch (DuplicatePersonException e) { throw new CommandException(MESSAGE_DUPLICATE_PERSON); + } catch (DuplicatePetPatientException e) { + throw new CommandException(MESSAGE_DUPLICATE_PET_PATIENT); + } catch (DuplicateAppointmentException e) { + throw new CommandException(MESSAGE_DUPLICATE_APPOINTMENT); } - } @Override diff --git a/src/main/java/seedu/address/logic/parser/AddCommandParser.java b/src/main/java/seedu/address/logic/parser/AddCommandParser.java index 9ad2e1c1068c..9c7ed568ca40 100644 --- a/src/main/java/seedu/address/logic/parser/AddCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/AddCommandParser.java @@ -2,12 +2,19 @@ import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT; import static seedu.address.logic.parser.CliSyntax.PREFIX_ADDRESS; +import static seedu.address.logic.parser.CliSyntax.PREFIX_DATE; import static seedu.address.logic.parser.CliSyntax.PREFIX_EMAIL; import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME; import static seedu.address.logic.parser.CliSyntax.PREFIX_NRIC; +import static seedu.address.logic.parser.CliSyntax.PREFIX_PET_PATIENT_BLOODTYPE; +import static seedu.address.logic.parser.CliSyntax.PREFIX_PET_PATIENT_BREED; +import static seedu.address.logic.parser.CliSyntax.PREFIX_PET_PATIENT_COLOUR; +import static seedu.address.logic.parser.CliSyntax.PREFIX_PET_PATIENT_SPECIES; import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE; +import static seedu.address.logic.parser.CliSyntax.PREFIX_REMARK; import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG; +import java.time.LocalDateTime; import java.util.Set; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -17,6 +24,7 @@ import seedu.address.logic.commands.AddCommand; import seedu.address.logic.parser.exceptions.ParseException; import seedu.address.model.appointment.Appointment; +import seedu.address.model.appointment.Remark; import seedu.address.model.person.Address; import seedu.address.model.person.Email; import seedu.address.model.person.Name; @@ -24,6 +32,7 @@ import seedu.address.model.person.Person; import seedu.address.model.person.Phone; import seedu.address.model.petpatient.PetPatient; +import seedu.address.model.petpatient.PetPatientName; import seedu.address.model.tag.Tag; /** @@ -31,13 +40,13 @@ */ public class AddCommandParser implements Parser { - private static final Pattern ADD_COMMAND_FORMAT_OWNERONLY = Pattern.compile("-(o)+(?.*)"); + private static final Pattern ADD_COMMAND_FORMAT_OWNER_ONLY = Pattern.compile("-(o)+(?.*)"); private static final Pattern ADD_COMMAND_FORMAT_ALL_NEW = Pattern.compile("-(o)+(?.*)" + "-(p)+(?.*)-(a)+(?.*)"); - private static final Pattern ADD_COMMAND_FORMAT_OWNER = Pattern.compile("-(o)+(?.*)-(p)+(?.*)"); - private static final Pattern ADD_COMMAND_FORMAT_PET = Pattern.compile("-(p)+(?.*)-(o)+(?.*)"); - private static final Pattern ADD_COMMAND_FORMAT_APPT = Pattern.compile("-(a)+(?.*)-(o)(?.*)" - + "-(p)+(?.*)"); + private static final Pattern ADD_COMMAND_FORMAT_NEW_PET_EXISTING_OWNER = Pattern.compile("-(p)+(?.*)" + + "-(o)+(?.*)"); + private static final Pattern ADD_COMMAND_FORMAT_NEW_APPT_EXISTING_OWNER_PET = Pattern.compile("-(a)+(?.*)" + + "-(o)(?.*)" + "-(p)+(?.*)"); /** * Parses the given {@code String} of arguments in the context of the Person class * and returns an Person object. @@ -69,17 +78,93 @@ public Person parsePerson(String ownerInfo) throws ParseException { } } + /** + * Parses the given {@code String} of arguments in the context of the Appointment class + * and returns an Appointment object. + * @throws ParseException if the user input does not conform the expected format + */ + public Appointment parseAppointment(String apptInfo) throws ParseException { + ArgumentMultimap argMultimap = + ArgumentTokenizer.tokenize(apptInfo, PREFIX_DATE, PREFIX_REMARK, PREFIX_TAG); + + if (!arePrefixesPresent(argMultimap, PREFIX_DATE, PREFIX_REMARK, PREFIX_TAG) + || !argMultimap.getPreamble().isEmpty()) { + throw new ParseException( + String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddCommand.MESSAGE_APPOINTMENT)); + } + + try { + LocalDateTime localDateTime = ParserUtil.parseDateTime(argMultimap.getValue(PREFIX_DATE)).get(); + Remark remark = ParserUtil.parseRemark(argMultimap.getValue(PREFIX_REMARK)).get(); + Set type = ParserUtil.parseTags(argMultimap.getAllValues(PREFIX_TAG)); + + Appointment appointment = new Appointment(remark, localDateTime, type); + + return appointment; + } catch (IllegalValueException ive) { + throw new ParseException(ive.getMessage(), ive); + } + } + + /** + * Parses the given {@code String} of arguments in the context of the PetPatient class + * and returns an PetPatient object. + * @throws ParseException if the user input does not conform the expected format + */ + public PetPatient parsePetPatient(String petInfo) throws ParseException { + ArgumentMultimap argMultimap = + ArgumentTokenizer.tokenize( + petInfo, + PREFIX_NAME, + PREFIX_PET_PATIENT_SPECIES, + PREFIX_PET_PATIENT_BREED, + PREFIX_PET_PATIENT_COLOUR, + PREFIX_PET_PATIENT_BLOODTYPE, + PREFIX_TAG); + + if (!arePrefixesPresent( + argMultimap, + PREFIX_NAME, + PREFIX_PET_PATIENT_BREED, + PREFIX_PET_PATIENT_SPECIES, + PREFIX_PET_PATIENT_COLOUR, + PREFIX_PET_PATIENT_BLOODTYPE) + || !argMultimap.getPreamble().isEmpty()) { + throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddCommand.MESSAGE_PETPATIENT)); + } + + try { + PetPatientName name = ParserUtil.parsePetPatientName(argMultimap.getValue(PREFIX_NAME)).get(); + String species = ParserUtil.parseSpecies(argMultimap.getValue(PREFIX_PET_PATIENT_SPECIES)).get(); + String breed = ParserUtil.parseBreed(argMultimap.getValue(PREFIX_PET_PATIENT_BREED)).get(); + String color = ParserUtil.parseColour(argMultimap.getValue(PREFIX_PET_PATIENT_COLOUR)).get(); + String bloodType = ParserUtil.parseBloodType(argMultimap.getValue(PREFIX_PET_PATIENT_BLOODTYPE)).get(); + Set tagList = ParserUtil.parseTags(argMultimap.getAllValues(PREFIX_TAG)); + + PetPatient petPatient = new PetPatient(name, species, breed, color, bloodType, tagList); + + return petPatient; + } catch (IllegalValueException ive) { + throw new ParseException(ive.getMessage(), ive); + } + } + /** * Parses the given {@code String} of arguments in the context of AddCommand * and returns an AddCommand object. * @throws ParseException if the user input does not conform the expected format */ - public AddCommand parseNewOwnerPetAppt(String ownerInfo, String petInfo, String apptInfo) + public AddCommand createNewOwnerPetAppt(String ownerInfo, String petInfo, String apptInfo) throws ParseException { - System.out.println("I AM PARSING 3 NOW"); Person owner = parsePerson(ownerInfo); - PetPatient petPatient = new AddPetPatientCommandParser().parse(petInfo, owner); - Appointment appt = new AddAppointmentCommandParser().parse(apptInfo, owner, petPatient); + + PetPatient petPatient = parsePetPatient(petInfo); + petPatient.setOwnerNRIC(owner.getNric()); + + Appointment appt = parseAppointment(apptInfo); + appt.setOwnerNric(owner.getNric()); + appt.setPetPatientName(petPatient.getName()); + return new AddCommand(owner, petPatient, appt); } @@ -88,10 +173,20 @@ public AddCommand parseNewOwnerPetAppt(String ownerInfo, String petInfo, String * and returns an AddCommand object. * @throws ParseException if the user input does not conform the expected format */ - public AddCommand parseNewOwnerAndPet(String ownerInfo, String petInfo) throws ParseException { - Person owner = parsePerson(ownerInfo); - PetPatient petPatient = new AddPetPatientCommandParser().parse(petInfo, owner); - return new AddCommand(owner, petPatient); + public AddCommand createNewApptforExistingOwnerAndPet(String apptInfo, String ownerNric, String petName) + throws ParseException { + Appointment appt = parseAppointment(apptInfo); + return new AddCommand(appt, new Nric(ownerNric), new PetPatientName(petName)); + } + + /** + * Parses the given {@code String} of arguments in the context of AddCommand + * and returns an AddCommand object. + * @throws ParseException if the user input does not conform the expected format + */ + public AddCommand createNewPetForExistingPerson(String petInfo, String ownerNric) throws ParseException { + PetPatient petPatient = parsePetPatient(petInfo); + return new AddCommand(petPatient, new Nric(ownerNric.trim())); } /** @@ -120,29 +215,33 @@ private static boolean arePrefixesPresent(ArgumentMultimap argumentMultimap, Pre public AddCommand parse(String args) throws ParseException { String trimmedArgs = args.trim(); + //to add a new person (owner), new pet patient, and a new appointment Matcher matcher = ADD_COMMAND_FORMAT_ALL_NEW.matcher(trimmedArgs); if (matcher.matches()) { String ownerInfo = matcher.group("ownerInfo"); String petInfo = matcher.group("petInfo"); String apptInfo = matcher.group("apptInfo"); - return parseNewOwnerPetAppt(ownerInfo, petInfo, apptInfo); + return createNewOwnerPetAppt(ownerInfo, petInfo, apptInfo); } - - matcher = ADD_COMMAND_FORMAT_OWNER.matcher(trimmedArgs); + //add a new appointment for existing person and pet patient + matcher = ADD_COMMAND_FORMAT_NEW_APPT_EXISTING_OWNER_PET.matcher(trimmedArgs); if (matcher.matches()) { - String ownerInfo = matcher.group("ownerInfo"); - String petInfo = matcher.group("petInfo"); - return parseNewOwnerAndPet(ownerInfo, petInfo); + String apptInfo = matcher.group("apptInfo"); + String ownerNric = matcher.group("ownerNric"); + String petName = matcher.group("petName"); + return createNewApptforExistingOwnerAndPet(apptInfo, ownerNric, petName); } - matcher = ADD_COMMAND_FORMAT_PET.matcher(trimmedArgs); + //add a new patient to an existing owner + matcher = ADD_COMMAND_FORMAT_NEW_PET_EXISTING_OWNER.matcher(trimmedArgs); if (matcher.matches()) { String petInfo = matcher.group("petInfo"); String ownerNric = matcher.group("ownerNric"); - //return new AddPetPatientCommandParser().parse(petInfo, ownerNric); + return createNewPetForExistingPerson(petInfo, ownerNric); } - matcher = ADD_COMMAND_FORMAT_OWNERONLY.matcher(trimmedArgs); + //add a new person + matcher = ADD_COMMAND_FORMAT_OWNER_ONLY.matcher(trimmedArgs); if (matcher.matches()) { String ownerInfo = matcher.group("ownerInfo"); return parseNewOwnerOnly(ownerInfo); diff --git a/src/main/java/seedu/address/logic/parser/ParserUtil.java b/src/main/java/seedu/address/logic/parser/ParserUtil.java index f9e2472d1988..f06781e1720f 100644 --- a/src/main/java/seedu/address/logic/parser/ParserUtil.java +++ b/src/main/java/seedu/address/logic/parser/ParserUtil.java @@ -16,7 +16,6 @@ import seedu.address.model.appointment.Remark; import seedu.address.model.person.Address; import seedu.address.model.person.Email; -//import seedu.address.model.person.NRIC; import seedu.address.model.person.Name; import seedu.address.model.person.Nric; import seedu.address.model.person.Phone; diff --git a/src/main/java/seedu/address/model/AddressBook.java b/src/main/java/seedu/address/model/AddressBook.java index d33fbe13c9bf..340d447d2a16 100644 --- a/src/main/java/seedu/address/model/AddressBook.java +++ b/src/main/java/seedu/address/model/AddressBook.java @@ -257,7 +257,7 @@ private Appointment syncWithAppointmentMasterTagList(Appointment appointment) { final Set correctTagReferences = new HashSet<>(); appointmentTags.forEach(tag -> correctTagReferences.add(masterTagObjects.get(tag))); return new Appointment( - appointment.getOwner(), appointment.getPetPatient(), appointment.getRemark(), + appointment.getOwnerNric(), appointment.getPetPatientName(), appointment.getRemark(), appointment.getDateTime(), correctTagReferences); } /** diff --git a/src/main/java/seedu/address/model/appointment/Appointment.java b/src/main/java/seedu/address/model/appointment/Appointment.java index 7d3dfbf89b39..eb2de0d1fe48 100644 --- a/src/main/java/seedu/address/model/appointment/Appointment.java +++ b/src/main/java/seedu/address/model/appointment/Appointment.java @@ -9,8 +9,8 @@ import java.util.Set; import seedu.address.model.person.Name; -import seedu.address.model.person.Person; -import seedu.address.model.petpatient.PetPatient; +import seedu.address.model.person.Nric; +import seedu.address.model.petpatient.PetPatientName; import seedu.address.model.tag.Tag; import seedu.address.model.tag.UniqueTagList; @@ -19,9 +19,9 @@ * Guarantees: details are present and not null, field values are validated. */ public class Appointment { - private Person owner = null; //owner of the appointment + private Nric ownerNric; private Name ownerName = null; - private PetPatient pet = null; + private PetPatientName petPatientName; private Remark remark; //remarks private LocalDateTime localDateTime; //date of appointment @@ -30,16 +30,29 @@ public class Appointment { /** * Every field must be present and not null. */ - public Appointment(Person owner, PetPatient pet, Remark remark, LocalDateTime localDateTime, Set type) { - requireAllNonNull(owner, remark, localDateTime, type); - this.owner = owner; - this.pet = pet; + public Appointment(Nric ownerNric, PetPatientName petPatientName, Remark remark, + LocalDateTime localDateTime,Set type) { + requireAllNonNull(ownerNric, petPatientName, remark, localDateTime, type); + this.ownerNric = ownerNric; + this.petPatientName = petPatientName; this.remark = remark; this.localDateTime = localDateTime; // protect internal tags from changes in the arg list this.type = new UniqueTagList(type); } + /** + * ownerNric and petName can be set later using setter methods. + */ + public Appointment(Remark remark, LocalDateTime localDateTime, Set type) { + requireAllNonNull(remark, localDateTime, type); + this.remark = remark; + this.localDateTime = localDateTime; + // protect internal tags from changes in the arg list + this.type = new UniqueTagList(type); + } + + //Please remove this constructor if it is no longer in use public Appointment(Name owner, Remark remark, LocalDateTime localDateTime, Set type) { requireAllNonNull(owner, remark, localDateTime, type); this.ownerName = owner; @@ -49,16 +62,24 @@ public Appointment(Name owner, Remark remark, LocalDateTime localDateTime, Set dateOfBirth; // can be null + private Nric ownerNric; // can be null (initially) private StringBuilder medicalHistory; // can be null (initially) + //keep this constructor public PetPatient(PetPatientName name, String species, String breed, @@ -43,7 +46,7 @@ public PetPatient(PetPatientName name, this.bloodType = bloodType; this.tags = new UniqueTagList(tags); - this.owner = null; + this.ownerNric = null; this.dateOfBirth = null; this.medicalHistory = new StringBuilder(); } @@ -53,7 +56,7 @@ public PetPatient(PetPatientName name, String breed, String colour, String bloodType, - Person owner, + Nric ownerNric, Set tags) { requireAllNonNull(name, species, breed, colour, bloodType, tags); this.name = name; @@ -62,26 +65,27 @@ public PetPatient(PetPatientName name, this.colour = colour; this.bloodType = bloodType; this.tags = new UniqueTagList(tags); - this.owner = owner; + this.ownerNric = ownerNric; this.dateOfBirth = null; this.medicalHistory = new StringBuilder(); } + //keep this constructor public PetPatient(PetPatientName name, String species, String breed, String colour, String bloodType, - Person owner, + Nric ownerNric, Optional dateOfBirth, Set tags) { - requireAllNonNull(name, species, breed, colour, bloodType, owner, dateOfBirth, tags); + requireAllNonNull(name, species, breed, colour, bloodType, ownerNric, dateOfBirth, tags); this.name = name; this.species = species; this.breed = breed; this.colour = colour; this.bloodType = bloodType; - this.owner = owner; + this.ownerNric = ownerNric; this.dateOfBirth = dateOfBirth; this.tags = new UniqueTagList(tags); this.medicalHistory = new StringBuilder(); @@ -111,8 +115,12 @@ public String getBloodType() { return bloodType; } - public Person getOwner() { - return owner; + public Nric getOwner() { + return ownerNric; + } + + public void setOwnerNRIC(Nric ownerNRIC) { + this.ownerNric = ownerNRIC; } public StringBuilder getMedicalHistory() { diff --git a/src/main/java/seedu/address/storage/XmlAdaptedAppointment.java b/src/main/java/seedu/address/storage/XmlAdaptedAppointment.java index 96b8f81c0b82..2032d7450ab2 100644 --- a/src/main/java/seedu/address/storage/XmlAdaptedAppointment.java +++ b/src/main/java/seedu/address/storage/XmlAdaptedAppointment.java @@ -27,6 +27,8 @@ public class XmlAdaptedAppointment { @XmlElement(required = true) private String owner; @XmlElement(required = true) + private String petPatient; + @XmlElement(required = true) private String remark; @XmlElement(required = true) private String dateTime; @@ -58,7 +60,8 @@ public XmlAdaptedAppointment(String owner, String remark, String dateTime, List< * @param source future changes to this will not affect the created XmlAdaptedAppointment */ public XmlAdaptedAppointment(Appointment source) { - owner = source.getOwner().getName().toString(); + owner = source.getOwnerNric().toString(); + petPatient = source.getPetPatientName().toString(); remark = source.getRemark().value; dateTime = source.getFormattedLocalDateTime(); tagged = new ArrayList<>(); @@ -127,6 +130,7 @@ public boolean equals(Object other) { XmlAdaptedAppointment otherAppointment = (XmlAdaptedAppointment) other; return Objects.equals(owner, otherAppointment.owner) + && Objects.equals(petPatient, otherAppointment.petPatient) && Objects.equals(remark, otherAppointment.remark) && Objects.equals(dateTime, otherAppointment.dateTime) && tagged.equals(otherAppointment.tagged); From e64b377206c1fb489acf42d650f91d1ff54dbcd6 Mon Sep 17 00:00:00 2001 From: Jacqueline Cheong Date: Sat, 24 Mar 2018 01:46:09 +0800 Subject: [PATCH 2/8] Update JUnit tests and remove redundant java classes --- .../logic/commands/AddAppointmentCommand.java | 62 --------------- .../logic/commands/AddPetPatientCommand.java | 67 ---------------- .../parser/AddAppointmentCommandParser.java | 61 --------------- .../parser/AddPetPatientCommandParser.java | 76 ------------------- .../logic/parser/AddCommandParserTest.java | 12 ++- .../address/testutil/AppointmentBuilder.java | 18 +++-- .../address/testutil/AppointmentUtil.java | 15 ++-- .../address/testutil/TypicalAppointments.java | 4 +- .../address/testutil/TypicalPetPatients.java | 2 +- 9 files changed, 25 insertions(+), 292 deletions(-) delete mode 100644 src/main/java/seedu/address/logic/commands/AddAppointmentCommand.java delete mode 100644 src/main/java/seedu/address/logic/commands/AddPetPatientCommand.java delete mode 100644 src/main/java/seedu/address/logic/parser/AddAppointmentCommandParser.java delete mode 100644 src/main/java/seedu/address/logic/parser/AddPetPatientCommandParser.java diff --git a/src/main/java/seedu/address/logic/commands/AddAppointmentCommand.java b/src/main/java/seedu/address/logic/commands/AddAppointmentCommand.java deleted file mode 100644 index 5817d8961a76..000000000000 --- a/src/main/java/seedu/address/logic/commands/AddAppointmentCommand.java +++ /dev/null @@ -1,62 +0,0 @@ -package seedu.address.logic.commands; - -import static java.util.Objects.requireNonNull; -import static seedu.address.logic.parser.CliSyntax.PREFIX_DATE; -import static seedu.address.logic.parser.CliSyntax.PREFIX_REMARK; -import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG; - -import seedu.address.logic.commands.exceptions.CommandException; -import seedu.address.model.appointment.Appointment; -import seedu.address.model.appointment.exceptions.DuplicateAppointmentException; - -/** - * Adds an appointment. - */ -public class AddAppointmentCommand extends UndoableCommand { - - public static final String COMMAND_WORD = "add"; - public static final String COMMAND_ALIAS = "a"; - - public static final String MESSAGE_USAGE = COMMAND_WORD + " -a : Adds an appointment. " - + "Parameters: " - + PREFIX_DATE + "DATE " - + PREFIX_REMARK + "REMARK " - + "[" + PREFIX_TAG + "TYPE OF APPOINTMENT]...\n" - + "Example: " + COMMAND_WORD + " " - + PREFIX_DATE + "2018-12-31 12:30 " - + PREFIX_REMARK + "nil " - + PREFIX_TAG + "checkup " - + PREFIX_TAG + "vaccination"; - - public static final String MESSAGE_SUCCESS = "New appointment added: %1$s"; - public static final String MESSAGE_DUPLICATE_APPOINTMENT = "This particular appointment already exists"; - - private final Appointment toAdd; - - /** - * Creates an AddAppointmentCommand to add the specified {@code Appointment} - */ - public AddAppointmentCommand(Appointment appointment) { - requireNonNull(appointment); - toAdd = appointment; - } - - @Override - public CommandResult executeUndoableCommand() throws CommandException { - requireNonNull(model); - try { - model.addAppointment(toAdd); - return new CommandResult(String.format(MESSAGE_SUCCESS, toAdd)); - } catch (DuplicateAppointmentException e) { - throw new CommandException(MESSAGE_DUPLICATE_APPOINTMENT); - } - - } - - @Override - public boolean equals(Object other) { - return other == this // short circuit if same object - || (other instanceof AddAppointmentCommand // instanceof handles nulls - && toAdd.equals(((AddAppointmentCommand) other).toAdd)); - } -} diff --git a/src/main/java/seedu/address/logic/commands/AddPetPatientCommand.java b/src/main/java/seedu/address/logic/commands/AddPetPatientCommand.java deleted file mode 100644 index 7ddf3830fc6e..000000000000 --- a/src/main/java/seedu/address/logic/commands/AddPetPatientCommand.java +++ /dev/null @@ -1,67 +0,0 @@ -package seedu.address.logic.commands; - -import static java.util.Objects.requireNonNull; -import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME; -import static seedu.address.logic.parser.CliSyntax.PREFIX_PET_PATIENT_BLOODTYPE; -import static seedu.address.logic.parser.CliSyntax.PREFIX_PET_PATIENT_BREED; -import static seedu.address.logic.parser.CliSyntax.PREFIX_PET_PATIENT_COLOUR; -import static seedu.address.logic.parser.CliSyntax.PREFIX_PET_PATIENT_SPECIES; -import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG; - -import seedu.address.logic.commands.exceptions.CommandException; -import seedu.address.model.petpatient.PetPatient; -import seedu.address.model.petpatient.exceptions.DuplicatePetPatientException; - -/** - * Adds a pet patient to the address book. - */ -public class AddPetPatientCommand extends UndoableCommand { - public static final String COMMAND_WORD = "add"; - public static final String COMMAND_ALIAS = "a"; - - public static final String MESSAGE_USAGE = COMMAND_WORD + " -p : Adds a pet patient to the address book. " - + "Parameters: " - + PREFIX_NAME + "NAME " - + PREFIX_PET_PATIENT_SPECIES + "SPECIES " - + PREFIX_PET_PATIENT_BREED + "BREED " - + PREFIX_PET_PATIENT_COLOUR + "COLOUR " - + PREFIX_PET_PATIENT_BLOODTYPE + "BLOOD_TYPE " - + "[" + PREFIX_TAG + "TAG]...\n" - + "Example: " + COMMAND_WORD + " " - + PREFIX_NAME + "Jewel " - + PREFIX_PET_PATIENT_SPECIES + "Cat " - + PREFIX_PET_PATIENT_BREED + "Persian Ragdoll " - + PREFIX_PET_PATIENT_COLOUR + "Calico " - + PREFIX_PET_PATIENT_BLOODTYPE + "AB"; - - public static final String MESSAGE_SUCCESS = "New pet patient added: %1$s"; - public static final String MESSAGE_DUPLICATE_PET_PATIENT = "This pet patient already exists in the address book"; - - private final PetPatient toAddPetPatient; - - /** - * Creates an AddCommand to add the specified {@code PetPatient} - */ - public AddPetPatientCommand(PetPatient petPatient) { - requireNonNull(petPatient); - toAddPetPatient = petPatient; - } - - @Override - public CommandResult executeUndoableCommand() throws CommandException { - requireNonNull(model); - try { - model.addPetPatient(toAddPetPatient); - return new CommandResult(String.format(MESSAGE_SUCCESS, toAddPetPatient)); - } catch (DuplicatePetPatientException e) { - throw new CommandException(MESSAGE_DUPLICATE_PET_PATIENT); - } - } - - @Override - public boolean equals(Object other) { - return other == this // short circuit if same object - || (other instanceof AddCommand // instanceof handles nulls - && toAddPetPatient.equals(((AddPetPatientCommand) other).toAddPetPatient)); - } -} diff --git a/src/main/java/seedu/address/logic/parser/AddAppointmentCommandParser.java b/src/main/java/seedu/address/logic/parser/AddAppointmentCommandParser.java deleted file mode 100644 index 3249cc76af4d..000000000000 --- a/src/main/java/seedu/address/logic/parser/AddAppointmentCommandParser.java +++ /dev/null @@ -1,61 +0,0 @@ -package seedu.address.logic.parser; - -import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT; -import static seedu.address.logic.parser.CliSyntax.PREFIX_DATE; -import static seedu.address.logic.parser.CliSyntax.PREFIX_REMARK; -import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG; - -import java.time.LocalDateTime; -import java.util.Set; -import java.util.stream.Stream; - -import seedu.address.commons.exceptions.IllegalValueException; -import seedu.address.logic.commands.AddAppointmentCommand; -import seedu.address.logic.parser.exceptions.ParseException; -import seedu.address.model.appointment.Appointment; -import seedu.address.model.appointment.Remark; -import seedu.address.model.person.Person; -import seedu.address.model.petpatient.PetPatient; -import seedu.address.model.tag.Tag; - -/** - * Parses input arguments and creates a new AddAppointmentCommand object - */ -public class AddAppointmentCommandParser { - - /** - * Parses the given {@code String} of arguments in the context of the Appointment class - * and returns an Appointment object. - * @throws ParseException if the user input does not conform the expected format - */ - public Appointment parse(String args, Person owner, PetPatient pet) throws ParseException { - ArgumentMultimap argMultimap = - ArgumentTokenizer.tokenize(args, PREFIX_DATE, PREFIX_REMARK, PREFIX_TAG); - - if (!arePrefixesPresent(argMultimap, PREFIX_DATE, PREFIX_REMARK, PREFIX_TAG) - || !argMultimap.getPreamble().isEmpty()) { - throw new ParseException( - String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddAppointmentCommand.MESSAGE_USAGE)); - } - - try { - LocalDateTime localDateTime = ParserUtil.parseDateTime(argMultimap.getValue(PREFIX_DATE)).get(); - Remark remark = ParserUtil.parseRemark(argMultimap.getValue(PREFIX_REMARK)).get(); - Set type = ParserUtil.parseTags(argMultimap.getAllValues(PREFIX_TAG)); - - Appointment appointment = new Appointment(owner, pet, remark, localDateTime, type); - - return appointment; - } catch (IllegalValueException ive) { - throw new ParseException(ive.getMessage(), ive); - } - } - - /** - * Returns true if none of the prefixes contains empty {@code Optional} values in the given - * {@code ArgumentMultimap}. - */ - private static boolean arePrefixesPresent (ArgumentMultimap argumentMultimap, Prefix... prefixes) { - return Stream.of(prefixes).allMatch(prefix -> argumentMultimap.getValue(prefix).isPresent()); - } -} diff --git a/src/main/java/seedu/address/logic/parser/AddPetPatientCommandParser.java b/src/main/java/seedu/address/logic/parser/AddPetPatientCommandParser.java deleted file mode 100644 index d3c2b61191b7..000000000000 --- a/src/main/java/seedu/address/logic/parser/AddPetPatientCommandParser.java +++ /dev/null @@ -1,76 +0,0 @@ -package seedu.address.logic.parser; - -import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT; -import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME; -import static seedu.address.logic.parser.CliSyntax.PREFIX_PET_PATIENT_BLOODTYPE; -import static seedu.address.logic.parser.CliSyntax.PREFIX_PET_PATIENT_BREED; -import static seedu.address.logic.parser.CliSyntax.PREFIX_PET_PATIENT_COLOUR; -import static seedu.address.logic.parser.CliSyntax.PREFIX_PET_PATIENT_SPECIES; -import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG; - -import java.util.Set; -import java.util.stream.Stream; - -import seedu.address.commons.exceptions.IllegalValueException; -import seedu.address.logic.commands.AddPetPatientCommand; -import seedu.address.logic.parser.exceptions.ParseException; -import seedu.address.model.person.Person; -import seedu.address.model.petpatient.PetPatient; -import seedu.address.model.petpatient.PetPatientName; -import seedu.address.model.tag.Tag; - -/** - * Parses input arguments and creates a new AddPetPatientCommand object - */ -public class AddPetPatientCommandParser { - /** - * Parses the given {@code String} of arguments in the context of the PetPatient class - * and returns an PetPatient object. - * @throws ParseException if the user input does not conform the expected format - */ - public PetPatient parse(String petInfo, Person owner) throws ParseException { - ArgumentMultimap argMultimap = - ArgumentTokenizer.tokenize( - petInfo, - PREFIX_NAME, - PREFIX_PET_PATIENT_SPECIES, - PREFIX_PET_PATIENT_BREED, - PREFIX_PET_PATIENT_COLOUR, - PREFIX_PET_PATIENT_BLOODTYPE, - PREFIX_TAG); - - if (!arePrefixesPresent( - argMultimap, - PREFIX_NAME, - PREFIX_PET_PATIENT_BREED, - PREFIX_PET_PATIENT_SPECIES, - PREFIX_PET_PATIENT_COLOUR, - PREFIX_PET_PATIENT_BLOODTYPE) - || !argMultimap.getPreamble().isEmpty()) { - throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddPetPatientCommand.MESSAGE_USAGE)); - } - - try { - PetPatientName name = ParserUtil.parsePetPatientName(argMultimap.getValue(PREFIX_NAME)).get(); - String species = ParserUtil.parseSpecies(argMultimap.getValue(PREFIX_PET_PATIENT_SPECIES)).get(); - String breed = ParserUtil.parseBreed(argMultimap.getValue(PREFIX_PET_PATIENT_BREED)).get(); - String color = ParserUtil.parseColour(argMultimap.getValue(PREFIX_PET_PATIENT_COLOUR)).get(); - String bloodType = ParserUtil.parseBloodType(argMultimap.getValue(PREFIX_PET_PATIENT_BLOODTYPE)).get(); - Set tagList = ParserUtil.parseTags(argMultimap.getAllValues(PREFIX_TAG)); - - PetPatient petPatient = new PetPatient(name, species, breed, color, bloodType, owner, tagList); - - return petPatient; - } catch (IllegalValueException ive) { - throw new ParseException(ive.getMessage(), ive); - } - } - - /** - * Returns true if none of the prefixes contains empty {@code Optional} values in the given - * {@code ArgumentMultimap}. - */ - private static boolean arePrefixesPresent(ArgumentMultimap argumentMultimap, Prefix... prefixes) { - return Stream.of(prefixes).allMatch(prefix -> argumentMultimap.getValue(prefix).isPresent()); - } -} diff --git a/src/test/java/seedu/address/logic/parser/AddCommandParserTest.java b/src/test/java/seedu/address/logic/parser/AddCommandParserTest.java index a0bae4607991..b4883ed3d496 100644 --- a/src/test/java/seedu/address/logic/parser/AddCommandParserTest.java +++ b/src/test/java/seedu/address/logic/parser/AddCommandParserTest.java @@ -67,20 +67,18 @@ public void parse_allFieldsPresent_success() { .withNric(VALID_NRIC_BOB).withTags(VALID_TAG_FRIEND).build(); PetPatient expectedPet = new PetPatient(new PetPatientName("joker"), "cat", "domestic shorthair", - "brown and white", "O", expectedPerson, new HashSet<>()); + "brown and white", "" + + "O", expectedPerson.getNric(), new HashSet<>()); - //add new owner and new pet patient - assertParseSuccess(parser, OPTION_OWNER + NAME_DESC_BOB + PHONE_DESC_BOB - + EMAIL_DESC_BOB + ADDRESS_DESC_BOB + NRIC_DESC_BOB + TAG_DESC_FRIEND + OPTION_PET + NAME_DESC_JOKER - + SPECIES_DESC_JOKER + BREED_DESC_JOKER + COLOUR_DESC_JOKER + BLOODTYPE_DESC_JOKER, - new AddCommand(expectedPerson, expectedPet)); // whitespace only preamble assertParseSuccess(parser, PREAMBLE_WHITESPACE + OPTION_OWNER + NAME_DESC_BOB + PHONE_DESC_BOB + EMAIL_DESC_BOB + ADDRESS_DESC_BOB + NRIC_DESC_BOB + TAG_DESC_FRIEND, new AddCommand(expectedPerson)); + // multiple names - last name accepted - assertParseSuccess(parser, OPTION_OWNER + NAME_DESC_AMY + NAME_DESC_BOB + PHONE_DESC_BOB + assertParseSuccess(parser, + OPTION_OWNER + NAME_DESC_AMY + NAME_DESC_BOB + PHONE_DESC_BOB + EMAIL_DESC_BOB + ADDRESS_DESC_BOB + NRIC_DESC_BOB + TAG_DESC_FRIEND, new AddCommand(expectedPerson)); // multiple phones - last phone accepted diff --git a/src/test/java/seedu/address/testutil/AppointmentBuilder.java b/src/test/java/seedu/address/testutil/AppointmentBuilder.java index ba0a64fe9e0d..1d1d8b4a7d0e 100644 --- a/src/test/java/seedu/address/testutil/AppointmentBuilder.java +++ b/src/test/java/seedu/address/testutil/AppointmentBuilder.java @@ -7,8 +7,10 @@ import seedu.address.model.appointment.Appointment; import seedu.address.model.appointment.Remark; +import seedu.address.model.person.Nric; import seedu.address.model.person.Person; import seedu.address.model.petpatient.PetPatient; +import seedu.address.model.petpatient.PetPatientName; import seedu.address.model.tag.Tag; import seedu.address.model.util.SampleDataUtil; @@ -22,15 +24,15 @@ public class AppointmentBuilder { public static final String DEFAULT_DATE = "2018-12-31 12:30"; public static final String DEFAULT_TYPE = "surgery"; - private Person owner; - private PetPatient petPatient; + private Nric owner; + private PetPatientName petPatient; private Remark remark; private LocalDateTime localDateTime; private Set type; public AppointmentBuilder() { - owner = DEFAULT_PERSON; - petPatient = DEFAULT_PET_PATIENT; + owner = DEFAULT_PERSON.getNric(); + petPatient = DEFAULT_PET_PATIENT.getName(); remark = new Remark(DEFAULT_REMARK); DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm"); localDateTime = LocalDateTime.parse(DEFAULT_DATE, formatter); @@ -41,8 +43,8 @@ public AppointmentBuilder() { * Initializes the AppointmentBuilder with the data of {@code appointmentToCopy}. */ public AppointmentBuilder(Appointment appointmentToCopy) { - owner = appointmentToCopy.getOwner(); - petPatient = appointmentToCopy.getPetPatient(); + owner = appointmentToCopy.getOwnerNric(); + petPatient = appointmentToCopy.getPetPatientName(); remark = appointmentToCopy.getRemark(); localDateTime = appointmentToCopy.getDateTime(); type = new HashSet<>(appointmentToCopy.getType()); @@ -51,7 +53,7 @@ public AppointmentBuilder(Appointment appointmentToCopy) { /** * Sets the {@code Person} of the {@code Appointment} that we are building. */ - public AppointmentBuilder withOwner(Person owner) { + public AppointmentBuilder withOwner(Nric owner) { this.owner = owner; return this; } @@ -59,7 +61,7 @@ public AppointmentBuilder withOwner(Person owner) { /** * Sets the {@code PetPatient} of the {@code Appointment} that we are building. */ - public AppointmentBuilder withPetPatient(PetPatient petPatient) { + public AppointmentBuilder withPetPatient(PetPatientName petPatient) { this.petPatient = petPatient; return this; } diff --git a/src/test/java/seedu/address/testutil/AppointmentUtil.java b/src/test/java/seedu/address/testutil/AppointmentUtil.java index 665965aff932..0af31b6d622d 100644 --- a/src/test/java/seedu/address/testutil/AppointmentUtil.java +++ b/src/test/java/seedu/address/testutil/AppointmentUtil.java @@ -5,7 +5,6 @@ import static seedu.address.logic.parser.CliSyntax.PREFIX_REMARK; import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG; -import seedu.address.logic.commands.AddAppointmentCommand; import seedu.address.model.appointment.Appointment; /** @@ -15,23 +14,23 @@ public class AppointmentUtil { /** * Returns an add appointment command string for adding the {@code appointment}. */ - public static String getAddAppointmentCommand(Appointment appointment) { - return AddAppointmentCommand.COMMAND_WORD + " " + getAppointmentDetails(appointment); - } + //public static String getAddAppointmentCommand(Appointment appointment) { + // return AddAppointmentCommand.COMMAND_WORD + " " + getAppointmentDetails(appointment); + //} /** * Returns an add appointment command string for adding the {@code appointment}. */ - public static String getAddAppointmentCommandAlias(Appointment appointment) { - return AddAppointmentCommand.COMMAND_ALIAS + " " + getAppointmentDetails(appointment); - } + //public static String getAddAppointmentCommandAlias(Appointment appointment) { + //return AddAppointmentCommand.COMMAND_ALIAS + " " + getAppointmentDetails(appointment); + //} /** * Returns the part of command string for the given {@code appointment}'s details. */ public static String getAppointmentDetails(Appointment appointment) { StringBuilder sb = new StringBuilder(); - sb.append(PREFIX_OWNER + appointment.getOwner().getName().toString() + " "); + sb.append(PREFIX_OWNER + appointment.getOwnerNric().toString() + " "); sb.append(PREFIX_REMARK + appointment.getRemark().value + " "); sb.append(PREFIX_DATE + appointment.getFormattedLocalDateTime() + " "); appointment.getType().stream().forEach( diff --git a/src/test/java/seedu/address/testutil/TypicalAppointments.java b/src/test/java/seedu/address/testutil/TypicalAppointments.java index 2ab790d81648..a69c45c42bbc 100644 --- a/src/test/java/seedu/address/testutil/TypicalAppointments.java +++ b/src/test/java/seedu/address/testutil/TypicalAppointments.java @@ -11,10 +11,10 @@ */ public class TypicalAppointments { - public static final Appointment ALLY = new AppointmentBuilder().withOwner(TypicalPersons.ALICE) + public static final Appointment ALLY = new AppointmentBuilder().withOwner(TypicalPersons.ALICE.getNric()) .withRemark("Requires Home Visit").withDateTime("2018-12-31 12:30") .withTags("checkup").build(); - public static final Appointment BENNY = new AppointmentBuilder().withOwner(TypicalPersons.BENSON) + public static final Appointment BENNY = new AppointmentBuilder().withOwner(TypicalPersons.BENSON.getNric()) .withRemark("May require isolation").withDateTime("2018-12-31 14:30") .withTags("surgery").build(); diff --git a/src/test/java/seedu/address/testutil/TypicalPetPatients.java b/src/test/java/seedu/address/testutil/TypicalPetPatients.java index a8315c9e971e..3d4713efadf2 100644 --- a/src/test/java/seedu/address/testutil/TypicalPetPatients.java +++ b/src/test/java/seedu/address/testutil/TypicalPetPatients.java @@ -9,5 +9,5 @@ public class TypicalPetPatients { public static final PetPatient JOKER = new PetPatient(new PetPatientName("joker"), "cat", - "domestic shorthair", "brown and white", "O", TypicalPersons.BOB, null); + "domestic shorthair", "brown and white", "O", TypicalPersons.BOB.getNric(), null); } From 95e08151b41fbb46b26233f772c033eb288197d2 Mon Sep 17 00:00:00 2001 From: Jacqueline Cheong Date: Sat, 24 Mar 2018 01:59:47 +0800 Subject: [PATCH 3/8] Fix checkstyle errors --- src/main/java/seedu/address/logic/commands/AddCommand.java | 4 ++-- .../java/seedu/address/model/appointment/Appointment.java | 2 +- .../java/seedu/address/model/petpatient/PetPatient.java | 7 +++---- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/main/java/seedu/address/logic/commands/AddCommand.java b/src/main/java/seedu/address/logic/commands/AddCommand.java index 3c21b81e39fa..ac6516191caf 100644 --- a/src/main/java/seedu/address/logic/commands/AddCommand.java +++ b/src/main/java/seedu/address/logic/commands/AddCommand.java @@ -158,7 +158,7 @@ public Person getPersonOfNric() { public PetPatient getPetPatientOfNricAndName() { for (PetPatient p : model.getAddressBook().getPetPatientList()) { - if(p.getOwner().equals(ownerNric) && p.getName().equals(petPatientName)) { + if (p.getOwner().equals(ownerNric) && p.getName().equals(petPatientName)) { return p; } } @@ -169,7 +169,7 @@ public PetPatient getPetPatientOfNricAndName() { public CommandResult executeUndoableCommand() throws CommandException { requireNonNull(model); try { - switch (type){ + switch (type) { case 1: //add new owner, new pet patient, and new appointment model.addPerson(toAddOwner); model.addPetPatient(toAddPet); diff --git a/src/main/java/seedu/address/model/appointment/Appointment.java b/src/main/java/seedu/address/model/appointment/Appointment.java index eb2de0d1fe48..bfa85063e6aa 100644 --- a/src/main/java/seedu/address/model/appointment/Appointment.java +++ b/src/main/java/seedu/address/model/appointment/Appointment.java @@ -31,7 +31,7 @@ public class Appointment { * Every field must be present and not null. */ public Appointment(Nric ownerNric, PetPatientName petPatientName, Remark remark, - LocalDateTime localDateTime,Set type) { + LocalDateTime localDateTime, Set type) { requireAllNonNull(ownerNric, petPatientName, remark, localDateTime, type); this.ownerNric = ownerNric; this.petPatientName = petPatientName; diff --git a/src/main/java/seedu/address/model/petpatient/PetPatient.java b/src/main/java/seedu/address/model/petpatient/PetPatient.java index 21464bf3e7e9..3430a630a854 100644 --- a/src/main/java/seedu/address/model/petpatient/PetPatient.java +++ b/src/main/java/seedu/address/model/petpatient/PetPatient.java @@ -8,9 +8,8 @@ import java.util.Optional; import java.util.Set; -import seedu.address.commons.events.ui.NewResultAvailableEvent; +//import seedu.address.commons.events.ui.NewResultAvailableEvent; import seedu.address.model.person.Nric; -import seedu.address.model.person.Person; import seedu.address.model.tag.Tag; import seedu.address.model.tag.UniqueTagList; @@ -119,8 +118,8 @@ public Nric getOwner() { return ownerNric; } - public void setOwnerNRIC(Nric ownerNRIC) { - this.ownerNric = ownerNRIC; + public void setOwnerNRIC(Nric ownerNric) { + this.ownerNric = ownerNric; } public StringBuilder getMedicalHistory() { From c3394eac61c034337c925acc47f045f244ae1588 Mon Sep 17 00:00:00 2001 From: chialejing Date: Sat, 24 Mar 2018 15:34:30 +0800 Subject: [PATCH 4/8] Update AddCommand.java Resolved checkstyle error. --- src/main/java/seedu/address/logic/commands/AddCommand.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/seedu/address/logic/commands/AddCommand.java b/src/main/java/seedu/address/logic/commands/AddCommand.java index ac6516191caf..c622ccd0f837 100644 --- a/src/main/java/seedu/address/logic/commands/AddCommand.java +++ b/src/main/java/seedu/address/logic/commands/AddCommand.java @@ -198,7 +198,7 @@ public CommandResult executeUndoableCommand() throws CommandException { case 3: //add new pet patient under an existing person Person p = getPersonOfNric(); if (p != null) { - toAddPet.setOwnerNRIC(ownerNric); + toAddPet.setOwnerNric(ownerNric); model.addPetPatient(toAddPet); return new CommandResult(String.format(message, toAddPet, p)); } From 12fac77f9ee0879ce6d3c0b31ef41265b73c14ea Mon Sep 17 00:00:00 2001 From: chialejing Date: Sat, 24 Mar 2018 15:35:44 +0800 Subject: [PATCH 5/8] Update AddCommandParser.java Resolved checkstyle error. --- src/main/java/seedu/address/logic/parser/AddCommandParser.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/seedu/address/logic/parser/AddCommandParser.java b/src/main/java/seedu/address/logic/parser/AddCommandParser.java index 9c7ed568ca40..b82316c423bb 100644 --- a/src/main/java/seedu/address/logic/parser/AddCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/AddCommandParser.java @@ -159,7 +159,7 @@ public AddCommand createNewOwnerPetAppt(String ownerInfo, String petInfo, String Person owner = parsePerson(ownerInfo); PetPatient petPatient = parsePetPatient(petInfo); - petPatient.setOwnerNRIC(owner.getNric()); + petPatient.setOwnerNric(owner.getNric()); Appointment appt = parseAppointment(apptInfo); appt.setOwnerNric(owner.getNric()); From 0273dea52e1afd6b678cb56fad2616023a40b455 Mon Sep 17 00:00:00 2001 From: chialejing Date: Sat, 24 Mar 2018 15:37:35 +0800 Subject: [PATCH 6/8] Update PetPatient.java Resolved checkstyle error. --- src/main/java/seedu/address/model/petpatient/PetPatient.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/seedu/address/model/petpatient/PetPatient.java b/src/main/java/seedu/address/model/petpatient/PetPatient.java index 3430a630a854..3b1c3f507d90 100644 --- a/src/main/java/seedu/address/model/petpatient/PetPatient.java +++ b/src/main/java/seedu/address/model/petpatient/PetPatient.java @@ -8,7 +8,6 @@ import java.util.Optional; import java.util.Set; -//import seedu.address.commons.events.ui.NewResultAvailableEvent; import seedu.address.model.person.Nric; import seedu.address.model.tag.Tag; import seedu.address.model.tag.UniqueTagList; @@ -118,7 +117,7 @@ public Nric getOwner() { return ownerNric; } - public void setOwnerNRIC(Nric ownerNric) { + public void setOwnerNric(Nric ownerNric) { this.ownerNric = ownerNric; } From bffb898d8f4804c685418d2056c85b6593ac67e2 Mon Sep 17 00:00:00 2001 From: chialejing Date: Sun, 25 Mar 2018 04:35:53 +0800 Subject: [PATCH 7/8] Update AddCommandParserTest.java --- .../logic/parser/AddCommandParserTest.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/test/java/seedu/address/logic/parser/AddCommandParserTest.java b/src/test/java/seedu/address/logic/parser/AddCommandParserTest.java index b4883ed3d496..30a24b378a96 100644 --- a/src/test/java/seedu/address/logic/parser/AddCommandParserTest.java +++ b/src/test/java/seedu/address/logic/parser/AddCommandParserTest.java @@ -3,9 +3,9 @@ import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT; import static seedu.address.logic.commands.CommandTestUtil.ADDRESS_DESC_AMY; import static seedu.address.logic.commands.CommandTestUtil.ADDRESS_DESC_BOB; -import static seedu.address.logic.commands.CommandTestUtil.BLOODTYPE_DESC_JOKER; -import static seedu.address.logic.commands.CommandTestUtil.BREED_DESC_JOKER; -import static seedu.address.logic.commands.CommandTestUtil.COLOUR_DESC_JOKER; +// import static seedu.address.logic.commands.CommandTestUtil.BLOODTYPE_DESC_JOKER; +// import static seedu.address.logic.commands.CommandTestUtil.BREED_DESC_JOKER; +// import static seedu.address.logic.commands.CommandTestUtil.COLOUR_DESC_JOKER; import static seedu.address.logic.commands.CommandTestUtil.EMAIL_DESC_AMY; import static seedu.address.logic.commands.CommandTestUtil.EMAIL_DESC_BOB; import static seedu.address.logic.commands.CommandTestUtil.INVALID_ADDRESS_DESC; @@ -15,16 +15,16 @@ import static seedu.address.logic.commands.CommandTestUtil.INVALID_TAG_DESC; import static seedu.address.logic.commands.CommandTestUtil.NAME_DESC_AMY; import static seedu.address.logic.commands.CommandTestUtil.NAME_DESC_BOB; -import static seedu.address.logic.commands.CommandTestUtil.NAME_DESC_JOKER; +// import static seedu.address.logic.commands.CommandTestUtil.NAME_DESC_JOKER; import static seedu.address.logic.commands.CommandTestUtil.NRIC_DESC_AMY; import static seedu.address.logic.commands.CommandTestUtil.NRIC_DESC_BOB; import static seedu.address.logic.commands.CommandTestUtil.OPTION_OWNER; -import static seedu.address.logic.commands.CommandTestUtil.OPTION_PET; +// import static seedu.address.logic.commands.CommandTestUtil.OPTION_PET; import static seedu.address.logic.commands.CommandTestUtil.PHONE_DESC_AMY; import static seedu.address.logic.commands.CommandTestUtil.PHONE_DESC_BOB; import static seedu.address.logic.commands.CommandTestUtil.PREAMBLE_NON_EMPTY; import static seedu.address.logic.commands.CommandTestUtil.PREAMBLE_WHITESPACE; -import static seedu.address.logic.commands.CommandTestUtil.SPECIES_DESC_JOKER; +// import static seedu.address.logic.commands.CommandTestUtil.SPECIES_DESC_JOKER; import static seedu.address.logic.commands.CommandTestUtil.TAG_DESC_FRIEND; import static seedu.address.logic.commands.CommandTestUtil.TAG_DESC_HUSBAND; import static seedu.address.logic.commands.CommandTestUtil.VALID_ADDRESS_AMY; @@ -67,8 +67,8 @@ public void parse_allFieldsPresent_success() { .withNric(VALID_NRIC_BOB).withTags(VALID_TAG_FRIEND).build(); PetPatient expectedPet = new PetPatient(new PetPatientName("joker"), "cat", "domestic shorthair", - "brown and white", "" + - "O", expectedPerson.getNric(), new HashSet<>()); + "brown and white", "" + + "O", expectedPerson.getNric(), new HashSet<>()); // whitespace only preamble From 8c2a0119735719daf2e70c72bb2c42f2a2fe153a Mon Sep 17 00:00:00 2001 From: chialejing Date: Sun, 25 Mar 2018 04:37:04 +0800 Subject: [PATCH 8/8] Update AppointmentUtil.java --- src/test/java/seedu/address/testutil/AppointmentUtil.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/seedu/address/testutil/AppointmentUtil.java b/src/test/java/seedu/address/testutil/AppointmentUtil.java index 0af31b6d622d..6acba6010940 100644 --- a/src/test/java/seedu/address/testutil/AppointmentUtil.java +++ b/src/test/java/seedu/address/testutil/AppointmentUtil.java @@ -22,7 +22,7 @@ public class AppointmentUtil { * Returns an add appointment command string for adding the {@code appointment}. */ //public static String getAddAppointmentCommandAlias(Appointment appointment) { - //return AddAppointmentCommand.COMMAND_ALIAS + " " + getAppointmentDetails(appointment); + // return AddAppointmentCommand.COMMAND_ALIAS + " " + getAppointmentDetails(appointment); //} /**