package models.dto;
import models.entities.Contact;
import models.entities.Phone;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
/**
* Created by Inspiron on 27.08.2014.
*/
public class ContactDTO {
int id;
String firstName;
String middleName;
String lastName;
Date birthDate;
String email;
String city;
String street;
String house;
String apartment;
List<PhoneListItemDTO> phones;
public static ContactDTO createFrom(Contact contact) {
if (contact == null) {
return null;
}
ContactDTO contactDTO = new ContactDTO();
contactDTO.setId(contact.getId());
contactDTO.setFirstName(contact.getFirstName());
contactDTO.setMiddleName(contact.getMiddleName());
contactDTO.setLastName(contact.getLastName());
contactDTO.setBirthDate(contact.getDateOfBirth());
contactDTO.setEmail(contact.getEmail());
contactDTO.setCity(contact.getCity());
contactDTO.setStreet(contact.getStreet());
contactDTO.setHouse(contact.getHouse());
contactDTO.setApartment(contact.getApartment());
return contactDTO;
}
public void mapBack(Contact contact) {
contact.setId(getId());
contact.setFirstName(getFirstName()==null?"":getFirstName());
contact.setMiddleName(getMiddleName()==null?"":getMiddleName());
contact.setLastName(getLastName()==null?"":getLastName());
contact.setDateOfBirth(getBirthDate());
contact.setEmail(getEmail()==null?"":getEmail());
contact.setCity(getCity()==null?"":getCity());
contact.setStreet(getStreet()==null?"":getStreet());
contact.setHouse(getHouse()==null?"":getHouse());
contact.setApartment(getApartment()==null?"":getApartment());
List<Phone> phones = new ArrayList<Phone>();
Phone p;
// for(PhoneListItemDTO phone: getPhones()) {
// p = new Phone();
// phone.mapBack(p);
// phones.add(p);
// }
contact.setPhones(phones);
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public void setFirstName(String firstName) {
this.firstName=firstName;
}
public String getFirstName() {
return firstName;
}
public void setMiddleName(String middleName) {
this.middleName = middleName;
}
public String getMiddleName() {
return middleName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public String getLastName() {
return lastName;
}
public void setBirthDate(Date birthDate) {
this.birthDate = birthDate;
}
public Date getBirthDate() {
return birthDate;
}
public void setEmail(String email) {
this.email = email;
}
public String getEmail() {
return email;
}
public void setCity(String city) {
this.city = city;
}
public String getCity() {
return city;
}
public void setStreet(String street) {
this.street = street;
}
public String getStreet() {
return street;
}
public void setHouse(String house) {
this.house = house;
}
public String getHouse() {
return house;
}
public void setApartment(String apartment) {
this.apartment = apartment;
}
public String getApartment() {
return apartment;
}
public List<PhoneListItemDTO> getPhones() {
return phones;
}
public void setPhones(List<PhoneListItemDTO> phones) {
this.phones = phones;
}
}