Skip to content

Commit

Permalink
Merge pull request nus-cs2103-AY1718S2#72 from wynonaK/newAppointment…
Browse files Browse the repository at this point in the history
…Storage

Updated XmlAdaptedAppointment, Added UniqueAppointmentTag Field
  • Loading branch information
chialejing authored Mar 27, 2018
2 parents 2be17fd + 2eb4851 commit 047462c
Show file tree
Hide file tree
Showing 9 changed files with 223 additions and 133 deletions.
31 changes: 26 additions & 5 deletions src/main/java/seedu/address/model/AddressBook.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public class AddressBook implements ReadOnlyAddressBook {
private final UniquePersonList persons;
private final UniqueTagList tags;
private final UniqueAppointmentList appointments;
private final UniqueTagList appointmentTags;
private final UniquePetPatientList petPatients;
private final UniqueTagList petPatientTags;

Expand All @@ -46,6 +47,7 @@ public class AddressBook implements ReadOnlyAddressBook {
persons = new UniquePersonList();
tags = new UniqueTagList();
appointments = new UniqueAppointmentList();
appointmentTags = new UniqueTagList();
petPatients = new UniquePetPatientList();
petPatientTags = new UniqueTagList();
}
Expand Down Expand Up @@ -75,6 +77,10 @@ public void setAppointments(List<Appointment> appointments) throws DuplicateAppo
this.appointments.setAppointments(appointments);
}

public void setAppointmentTags(Set<Tag> appointmentTags) {
this.appointmentTags.setTags(appointmentTags);
}

public void setPetPatients(List<PetPatient> petPatients) throws DuplicatePetPatientException {
this.petPatients.setPetPatients(petPatients);
}
Expand All @@ -99,6 +105,7 @@ public void resetData(ReadOnlyAddressBook newData) {
throw new AssertionError("AddressBooks should not have duplicate persons");
}

setAppointmentTags(new HashSet<>(newData.getAppointmentTagList()));
List<Appointment> syncedAppointmentList = newData.getAppointmentList().stream()
.map(this::syncWithAppointmentMasterTagList)
.collect(Collectors.toList());
Expand Down Expand Up @@ -245,7 +252,7 @@ private PetPatient syncWithMasterTagList (PetPatient petPatient) {
* points to a Tag object in the master list.
*/
private Appointment syncWithAppointmentMasterTagList(Appointment appointment) {
final UniqueTagList appointmentTags = new UniqueTagList(appointment.getType());
final UniqueTagList appointmentTags = new UniqueTagList(appointment.getAppointmentTags());
tags.mergeFrom(appointmentTags);

// Create map with values = tag object references in the master list
Expand All @@ -257,8 +264,11 @@ private Appointment syncWithAppointmentMasterTagList(Appointment appointment) {
final Set<Tag> correctTagReferences = new HashSet<>();
appointmentTags.forEach(tag -> correctTagReferences.add(masterTagObjects.get(tag)));
return new Appointment(
appointment.getOwnerNric(), appointment.getPetPatientName(), appointment.getRemark(),
appointment.getDateTime(), correctTagReferences);
appointment.getOwnerNric(),
appointment.getPetPatientName(),
appointment.getRemark(),
appointment.getDateTime(),
correctTagReferences);
}
/**
* Removes {@code key} from this {@code AddressBook}.
Expand Down Expand Up @@ -297,6 +307,10 @@ public void addPetPatientTag(Tag t) throws UniqueTagList.DuplicateTagException {
petPatientTags.add(t);
}

public void addAppointmentTag(Tag t) throws UniqueTagList.DuplicateTagException {
appointmentTags.add(t);
}

/**
* Removes {@code tag} from {@code person} with that tag this {@code AddressBook}.
*
Expand Down Expand Up @@ -342,7 +356,8 @@ public void removeTag(Tag tag) {
public String toString() {
return persons.asObservableList().size() + " persons, "
+ tags.asObservableList().size() + " tags, "
+ appointments.asObservableList().size() + " appointments"
+ appointments.asObservableList().size() + " appointments, "
+ appointmentTags.asObservableList().size() + " appointment tags, "
+ petPatients.asObservableList().size() + " pet patients, "
+ petPatientTags.asObservableList().size() + " pet patient tags";
// TODO: refine later
Expand All @@ -363,6 +378,11 @@ public ObservableList<Appointment> getAppointmentList() {
return appointments.asObservableList();
}

@Override
public ObservableList<Tag> getAppointmentTagList() {
return appointmentTags.asObservableList();
}

@Override
public ObservableList<PetPatient> getPetPatientList() {
return petPatients.asObservableList();
Expand All @@ -380,13 +400,14 @@ public boolean equals(Object other) {
&& this.persons.equals(((AddressBook) other).persons)
&& this.tags.equalsOrderInsensitive(((AddressBook) other).tags))
&& this.appointments.equals(((AddressBook) other).appointments)
&& this.appointmentTags.equals(((AddressBook) other).appointmentTags)
&& this.petPatients.equals(((AddressBook) other).petPatients)
&& this.petPatientTags.equalsOrderInsensitive(((AddressBook) other).petPatientTags);
}

@Override
public int hashCode() {
// use this method for custom fields hashing instead of implementing your own
return Objects.hash(persons, tags, appointments, petPatients, petPatientTags);
return Objects.hash(persons, tags, appointments, appointmentTags, petPatients, petPatientTags);
}
}
7 changes: 7 additions & 0 deletions src/main/java/seedu/address/model/ReadOnlyAddressBook.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ public interface ReadOnlyAddressBook {
*/
ObservableList<Appointment> getAppointmentList();

/**
* Returns an unmodifiable view of the appointment tag list.
* This list will not contain any duplicate appointment tags.
*/
ObservableList<Tag> getAppointmentTagList();

/**
* Returns an unmodifiable view of the pet patient list.
Expand Down
40 changes: 10 additions & 30 deletions src/main/java/seedu/address/model/appointment/Appointment.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import java.util.Objects;
import java.util.Set;

import seedu.address.model.person.Name;
import seedu.address.model.person.Nric;
import seedu.address.model.petpatient.PetPatientName;
import seedu.address.model.tag.Tag;
Expand All @@ -20,25 +19,24 @@
*/
public class Appointment {
private Nric ownerNric;
private Name ownerName = null;
private PetPatientName petPatientName;
private Remark remark; //remarks
private LocalDateTime localDateTime; //date of appointment

private final UniqueTagList type; //type of appointment
private UniqueTagList appointmentTags; //type of appointment

/**
* Every field must be present and not null.
*/
public Appointment(Nric ownerNric, PetPatientName petPatientName, Remark remark,
LocalDateTime localDateTime, Set<Tag> type) {
requireAllNonNull(ownerNric, petPatientName, remark, localDateTime, type);
LocalDateTime localDateTime, Set<Tag> appointmentTags) {
requireAllNonNull(ownerNric, petPatientName, remark, localDateTime, appointmentTags);
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);
this.appointmentTags = new UniqueTagList(appointmentTags);
}

/**
Expand All @@ -49,17 +47,7 @@ public Appointment(Remark remark, LocalDateTime localDateTime, Set<Tag> 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<Tag> type) {
requireAllNonNull(owner, remark, localDateTime, type);
this.ownerName = owner;
this.remark = remark;
this.localDateTime = localDateTime;
// protect internal tags from changes in the arg list
this.type = new UniqueTagList(type);
this.appointmentTags = new UniqueTagList(type);
}

public Nric getOwnerNric() {
Expand All @@ -70,10 +58,6 @@ public void setOwnerNric(Nric ownerNric) {
this.ownerNric = ownerNric;
}

public Name getOwnerName() {
return ownerName;
}

public PetPatientName getPetPatientName() {
return petPatientName;
}
Expand All @@ -87,20 +71,20 @@ public Remark getRemark() {
}

public LocalDateTime getDateTime() {

return localDateTime;
}

public String getFormattedLocalDateTime() {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm");
return localDateTime.format(formatter);
}

/**
* Returns an immutable tag set, which throws {@code UnsupportedOperationException}
* if modification is attempted.
*/
public Set<Tag> getType() {
return Collections.unmodifiableSet(type.toSet());
public Set<Tag> getAppointmentTags() {
return Collections.unmodifiableSet(appointmentTags.toSet());
}

@Override
Expand All @@ -123,22 +107,18 @@ public boolean equals(Object other) {
@Override
public int hashCode() {
// use this method for custom fields hashing instead of implementing your own
return Objects.hash(ownerNric, petPatientName, remark, localDateTime, type);
return Objects.hash(ownerNric, petPatientName, remark, localDateTime, appointmentTags);
}

@Override
public String toString() {
final StringBuilder builder = new StringBuilder();
builder.append("\t")
.append(getFormattedLocalDateTime())
//.append("\tOwner: ")
//.append(getOwnerNric().toString())
//.append("\tPet Patient: ")
//.append(getPetPatientName().toString())
.append("\tRemarks: ")
.append(getRemark())
.append("\tType(s): ");
getType().forEach(builder::append);
getAppointmentTags().forEach(builder::append);
return builder.toString();
}

Expand Down
61 changes: 37 additions & 24 deletions src/main/java/seedu/address/storage/XmlAdaptedAppointment.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
import seedu.address.commons.exceptions.IllegalValueException;
import seedu.address.model.appointment.Appointment;
import seedu.address.model.appointment.Remark;
import seedu.address.model.person.Name;
import seedu.address.model.person.Nric;
import seedu.address.model.petpatient.PetPatientName;
import seedu.address.model.tag.Tag;

/**
Expand All @@ -25,16 +26,16 @@ public class XmlAdaptedAppointment {
public static final String MISSING_FIELD_MESSAGE_FORMAT = "Appointment %s field is missing!";

@XmlElement(required = true)
private String owner;
private String ownerNric;
@XmlElement(required = true)
private String petPatient;
private String petPatientName;
@XmlElement(required = true)
private String remark;
@XmlElement(required = true)
private String dateTime;

@XmlElement
private List<XmlAdaptedTag> tagged = new ArrayList<>();
private List<XmlAdaptedTag> appointmentTagged = new ArrayList<>();

/**
* Constructs an XmlAdaptedAppointment.
Expand All @@ -45,12 +46,14 @@ public XmlAdaptedAppointment() {}
/**
* Constructs an {@code XmlAdaptedAppointment} with the given appointment details.
*/
public XmlAdaptedAppointment(String owner, String remark, String dateTime, List<XmlAdaptedTag> tagged) {
this.owner = owner;
public XmlAdaptedAppointment(String ownerNric, String petPatientName, String remark,
String dateTime, List<XmlAdaptedTag> appointmentTagged) {
this.ownerNric = ownerNric;
this.petPatientName = petPatientName;
this.remark = remark;
this.dateTime = dateTime;
if (tagged != null) {
this.tagged = new ArrayList<>(tagged);
if (appointmentTagged != null) {
this.appointmentTagged = new ArrayList<>(appointmentTagged);
}
}

Expand All @@ -60,13 +63,13 @@ 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.getOwnerNric().toString();
petPatient = source.getPetPatientName().toString();
ownerNric = source.getOwnerNric().toString();
petPatientName = source.getPetPatientName().toString();
remark = source.getRemark().value;
dateTime = source.getFormattedLocalDateTime();
tagged = new ArrayList<>();
for (Tag tag : source.getType()) {
tagged.add(new XmlAdaptedTag(tag));
appointmentTagged = new ArrayList<>();
for (Tag tag : source.getAppointmentTags()) {
appointmentTagged.add(new XmlAdaptedTag(tag));
}
}

Expand All @@ -77,24 +80,34 @@ public XmlAdaptedAppointment(Appointment source) {
*/
public Appointment toModelType() throws IllegalValueException {
final List<Tag> appointmentTags = new ArrayList<>();
for (XmlAdaptedTag tag : tagged) {
for (XmlAdaptedTag tag : appointmentTagged) {
appointmentTags.add(tag.toModelType());
}

if (this.owner == null) {
throw new IllegalValueException(String.format(MISSING_FIELD_MESSAGE_FORMAT, Name.class.getSimpleName()));
if (this.ownerNric == null) {
throw new IllegalValueException(String.format(MISSING_FIELD_MESSAGE_FORMAT, Nric.class.getSimpleName()));
}
if (!Name.isValidName(this.owner)) {
throw new IllegalValueException(Name.MESSAGE_NAME_CONSTRAINTS);
if (!Nric.isValidNric(this.ownerNric)) {
throw new IllegalValueException(Nric.MESSAGE_NRIC_CONSTRAINTS);
}
final Name owner = new Name(this.owner);
final Nric ownerNric = new Nric(this.ownerNric);

if (this.petPatientName == null) {
throw new IllegalValueException(
String.format(MISSING_FIELD_MESSAGE_FORMAT, PetPatientName.class.getSimpleName()));
}
if (!PetPatientName.isValidName(this.petPatientName)) {
throw new IllegalValueException(PetPatientName.MESSAGE_PET_NAME_CONSTRAINTS);
}
final PetPatientName petPatientName = new PetPatientName(this.petPatientName);

if (this.remark == null) {
throw new IllegalValueException(String.format(MISSING_FIELD_MESSAGE_FORMAT, Remark.class.getSimpleName()));
}
if (!Remark.isValidRemark(this.remark)) {
throw new IllegalValueException(Remark.MESSAGE_REMARK_CONSTRAINTS);
}

final Remark remark = new Remark(this.remark);

if (this.dateTime == null) {
Expand All @@ -114,8 +127,8 @@ public Appointment toModelType() throws IllegalValueException {
final LocalDateTime dateTime = localDateTime;


final Set<Tag> tags = new HashSet<>(appointmentTags);
return new Appointment(owner, remark, dateTime, tags);
final Set<Tag> thisAppointmentTags = new HashSet<>(appointmentTags);
return new Appointment(ownerNric, petPatientName, remark, dateTime, thisAppointmentTags);
}

@Override
Expand All @@ -129,10 +142,10 @@ public boolean equals(Object other) {
}

XmlAdaptedAppointment otherAppointment = (XmlAdaptedAppointment) other;
return Objects.equals(owner, otherAppointment.owner)
&& Objects.equals(petPatient, otherAppointment.petPatient)
return Objects.equals(ownerNric, otherAppointment.ownerNric)
&& Objects.equals(petPatientName, otherAppointment.petPatientName)
&& Objects.equals(remark, otherAppointment.remark)
&& Objects.equals(dateTime, otherAppointment.dateTime)
&& tagged.equals(otherAppointment.tagged);
&& appointmentTagged.equals(otherAppointment.appointmentTagged);
}
}
Loading

0 comments on commit 047462c

Please sign in to comment.